Skip to content
This repository was archived by the owner on Nov 11, 2023. It is now read-only.

Commit 2f58dfa

Browse files
committed
Split the Word struct into the classes/types
The word struct previously described every word imaginable in the German language. However moving on it became apparent that it is much more sensible to split it into Nouns/Verbs/Adjectives (possibly more in the future) since rules correspond to these classes.
1 parent cf5fa03 commit 2f58dfa

File tree

5 files changed

+297
-212
lines changed

5 files changed

+297
-212
lines changed

src/german/word.rs

-212
This file was deleted.

src/german/word/adjective.rs

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (C) 2018 Arne Dußin.
2+
//
3+
// This Program may be used by anyone in accordance with the terms of the
4+
// German Free Software License
5+
//
6+
// The License may be obtained under http://www.d-fsl.org.
7+
8+
use super::{Definition, Gender, Number, Word};
9+
use definable::Definable;
10+
11+
#[derive(Clone)]
12+
pub struct Adjective {
13+
/// The raw String that describes this word
14+
raw: String,
15+
/// Contains the definition, if available
16+
definition: Option<Definition>,
17+
/// The Genus this adjective is in or None in case it is in the base form
18+
gender: Option<Gender>,
19+
/// If available or applicable, this describes if the Noun this describes is
20+
/// Singular or Plural
21+
number: Option<Number>
22+
}
23+
24+
impl Adjective {
25+
/// Create a new Adjective from its String representation. Everything else
26+
/// is set to unknown.
27+
pub fn new<R: AsRef<str>>(raw: R) -> Verb {
28+
Verb {
29+
raw: raw.as_ref().to_string(),
30+
definition: None,
31+
gender: None,
32+
number: None
33+
}
34+
}
35+
36+
/// The gender of the thing this Adjective describes if it is known and
37+
/// applicable.
38+
pub fn gender(&self) -> Option<Gender> { self.gender }
39+
40+
/// If applicable, is this verb in singular or plural
41+
pub fn number(&self) -> Option<Number> { self.number }
42+
}
43+
44+
impl Word for Verb {
45+
/// The word class is always Adjective.
46+
fn class(&self) -> Class { Class::Adjective }
47+
48+
fn raw(&self) -> &str { &self.raw }
49+
}
50+
51+
impl Definable for Adjective {
52+
fn definition(&self) -> Option<&Definition> {
53+
match &self.definition {
54+
&Some(ref def) => Some(&def),
55+
&None => None
56+
}
57+
}
58+
59+
fn set_definition(&mut self, definition: &Definition) {
60+
self.definition = Some(definition.clone());
61+
}
62+
}

src/german/word/mod.rs

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright (C) 2018 Arne Dußin.
2+
//
3+
// This Program may be used by anyone in accordance with the terms of the
4+
// German Free Software License
5+
//
6+
// The License may be obtained under http://www.d-fsl.org.
7+
8+
//! Module for word operations in the German language.
9+
10+
pub mod noun;
11+
pub use self::noun::*;
12+
13+
pub mod verb;
14+
pub use self::verb::*;
15+
16+
use std::ops::Deref;
17+
18+
use definable::Definable;
19+
20+
/// Representation of a German grammatical word class/type.
21+
#[allow(missing_docs)]
22+
#[derive(Copy, Clone)]
23+
pub enum Class {
24+
Noun,
25+
Verb,
26+
Adjective
27+
}
28+
29+
/// Representation of a German grammatical gender.
30+
#[allow(missing_docs)]
31+
#[derive(Copy, Clone)]
32+
pub enum Gender {
33+
Masculine,
34+
Feminine,
35+
Neuter
36+
}
37+
38+
/// Representation of a German grammatical number.
39+
#[allow(missing_docs)]
40+
#[derive(Copy, Clone)]
41+
pub enum Number {
42+
Singular,
43+
Plural
44+
}
45+
46+
// Representation of a German grammatical person.
47+
#[allow(missing_docs)]
48+
#[derive(Copy, Clone)]
49+
pub enum Person {
50+
First,
51+
Second,
52+
Third
53+
}
54+
55+
/// Representation of a German grammatical mood.
56+
#[allow(missing_docs)]
57+
#[derive(Copy, Clone)]
58+
pub enum Mood {
59+
Indicative,
60+
ConjunctiveOne,
61+
ConjunctiveTwo
62+
}
63+
64+
pub type Definition = String;
65+
66+
pub trait Word<Def=Definition>: Definable {
67+
/// The word class aka. type this word is known as.
68+
fn class(&self) -> Class;
69+
70+
/// Get the raw string representation of the word in its current form.
71+
fn raw(&self) -> &str;
72+
}
73+
74+
impl Deref for Word<Def=Definition> {
75+
type Target = str;
76+
77+
fn deref(&self) -> &str {
78+
self.raw()
79+
}
80+
}

0 commit comments

Comments
 (0)