Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nicer names of PartOfSpeech #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/analyzer/units/by_hyphen/ha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use analyzer::MorphAnalyzer;
use container::abc::*;
use container::stack::StackSource;
use container::{HyphenAdverb, Lex, ParseResult, Parsed, Score, SeenSet, WordStruct};
use opencorpora::kind::{Case, Number, PartOfSpeach};
use opencorpora::kind::{Case, Number, PartOfSpeech};
use opencorpora::OpencorporaTagReg;

const HA_PREFIX: &str = "по-";
Expand Down Expand Up @@ -48,7 +48,7 @@ impl AnalyzerUnit for HyphenAdverbAnalyzer {
.filter(|parsed| {
let tag = parsed.lex.get_tag(morph);
match (tag.pos, tag.number, tag.case) {
(Some(PartOfSpeach::Adjf), Some(Number::Sing), Some(Case::Datv)) => true,
(Some(PartOfSpeech::AdjectiveFull), Some(Number::Sing), Some(Case::Datv)) => true,
_ => false,
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/opencorpora/kind/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use self::involvement::Involvement;
pub use self::mood::Mood;
pub use self::number::Number;
pub use self::person::Person;
pub use self::pos::PartOfSpeach;
pub use self::pos::PartOfSpeech;
pub use self::tense::Tense;
pub use self::transitivity::Transitivity;
pub use self::voice::Voice;
85 changes: 46 additions & 39 deletions src/opencorpora/kind/pos.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum PartOfSpeach {
pub enum PartOfSpeech {
/// имя существительное
Noun,
/// имя прилагательное (полное)
Adjf,
AdjectiveFull,
/// имя прилагательное (краткое)
Adjs,
AdjectiveShort,
/// компаратив
Comp,
Comparative,
/// глагол (личная форма)
Verb,
/// глагол (инфинитив)
Infn,
Infinitive,
/// причастие (полное)
Prtf,
ParticipleFull,
/// причастие (краткое)
Prts,
ParticipleShort,
/// деепричастие
Grnd,
Gerund,
/// числительное
Numr,
Number,
/// наречие
Advb,
Adverb,
/// местоимение-существительное
Npro,
Pronoun,
/// предикатив
Pred,
Predicative,
/// предлог
Prep,
Preposition,
/// союз
Conj,
Conjunction,
/// частица
Prcl,
Particle,
/// междометие
Intj,
Interjection,
}

regex!(
Expand Down Expand Up @@ -61,43 +61,50 @@ regex!(
"
);

impl PartOfSpeach {
impl PartOfSpeech {
pub fn try_from_str<S>(s: S) -> Option<Self>
where
S: AsRef<str>,
{
use self::PartOfSpeach::*;
use self::PartOfSpeech::*;

TAG_RE
.captures_iter(s.as_ref())
.next()
.and_then(|cap| match &cap[1] {
"NOUN" => Some(Noun),
"ADJF" => Some(Adjf),
"ADJS" => Some(Adjs),
"COMP" => Some(Comp),
"ADJF" => Some(AdjectiveFull),
"ADJS" => Some(AdjectiveShort),
"COMP" => Some(Comparative),
"VERB" => Some(Verb),
"INFN" => Some(Infn),
"PRTF" => Some(Prtf),
"PRTS" => Some(Prts),
"GRND" => Some(Grnd),
"NUMR" => Some(Numr),
"ADVB" => Some(Advb),
"NPRO" => Some(Npro),
"PRED" => Some(Pred),
"PREP" => Some(Prep),
"CONJ" => Some(Conj),
"PRCL" => Some(Prcl),
"INTJ" => Some(Intj),
"INFN" => Some(Infinitive),
"PRTF" => Some(ParticipleFull),
"PRTS" => Some(ParticipleShort),
"GRND" => Some(Gerund),
"NUMR" => Some(Number),
"ADVB" => Some(Adverb),
"NPRO" => Some(Pronoun),
"PRED" => Some(Predicative),
"PREP" => Some(Preposition),
"CONJ" => Some(Conjunction),
"PRCL" => Some(Particle),
"INTJ" => Some(Interjection),
_ => None,
})
}

pub fn is_productive(self) -> bool {
use self::PartOfSpeach::*;
use self::PartOfSpeech::*;

match self {
Conj | Numr | Npro | Pred | Prep | Prcl | Intj => false,
| Conjunction
| Number
| Pronoun
| Predicative
| Preposition
| Particle
| Interjection
=> false,
_ => true,
}
}
Expand All @@ -109,11 +116,11 @@ mod tests {

#[test]
fn try_from_str() {
assert_eq!(Some(PartOfSpeach::Noun), PartOfSpeach::try_from_str("NOUN"));
assert_eq!(Some(PartOfSpeech::Noun), PartOfSpeech::try_from_str("NOUN"));
assert_eq!(
Some(PartOfSpeach::Noun),
PartOfSpeach::try_from_str("NOUN,anim,masc,Fixd,Abbr sing,nomn")
Some(PartOfSpeech::Noun),
PartOfSpeech::try_from_str("NOUN,anim,masc,Fixd,Abbr sing,nomn")
);
assert_eq!(None, PartOfSpeach::try_from_str("UNKN"));
assert_eq!(None, PartOfSpeech::try_from_str("UNKN"));
}
}
17 changes: 10 additions & 7 deletions src/opencorpora/tag/reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct OpencorporaTagReg {
pub string: String,
pub grammemes: GrammemeSet,

pub pos: Option<PartOfSpeach>,
pub pos: Option<PartOfSpeech>,
pub animacy: Option<Animacy>,
pub aspect: Option<Aspect>,
pub case: Option<Case>,
Expand Down Expand Up @@ -48,7 +48,7 @@ impl OpencorporaTagReg {

let grammemes = GrammemeSet::new(&string);

let pos = PartOfSpeach::try_from_str(&string);
let pos = PartOfSpeech::try_from_str(&string);
let animacy = Animacy::try_from_str(&string);
let aspect = Aspect::try_from_str(&string);
let case = Case::try_from_str(&string);
Expand Down Expand Up @@ -106,9 +106,12 @@ impl OpencorporaTagReg {
};

let x = match self.pos {
Some(PartOfSpeach::Noun) | Some(PartOfSpeach::Adjf) | Some(PartOfSpeach::Prtf) => {
| Some(PartOfSpeech::Noun)
| Some(PartOfSpeech::AdjectiveFull)
| Some(PartOfSpeech::ParticipleFull)
=> {
match self.pos {
Some(PartOfSpeach::Noun)
Some(PartOfSpeech::Noun)
if self.case != Some(Case::Nomn) && self.case != Some(Case::Accs) =>
{
match self.case {
Expand All @@ -122,11 +125,11 @@ impl OpencorporaTagReg {
_ => Some((Number::Sing, Some(Case::Accs))),
},

Some(PartOfSpeach::Noun) if index == 1 => {
Some(PartOfSpeech::Noun) if index == 1 => {
Some((Number::Sing, Some(Case::Gent)))
}

Some(PartOfSpeach::Adjf) | Some(PartOfSpeach::Prtf)
Some(PartOfSpeech::AdjectiveFull) | Some(PartOfSpeech::ParticipleFull)
if index == 1 && self.gender == Some(Gender::Femn) =>
{
Some((Number::Plur, Some(Case::Nomn)))
Expand Down Expand Up @@ -158,7 +161,7 @@ impl OpencorporaTagReg {
// let sample = OpencorporaTagReg::from_str("PRTF,impf,tran,past,actv anim,masc,sing,accs,Infr");
// let tag = OpencorporaTagReg {
// string: "PRTF,impf,tran,past,actv anim,masc,sing,accs,Infr".into(),
// pos: Some(PartOfSpeach::Prtf),
// pos: Some(PartOfSpeech::Prtf),
// animacy: Some(Animacy::Anim),
// aspect: Some(Aspect::Impf),
// case: Some(Case::Accs),
Expand Down