cleaner code

parent 8efcf35a
Pipeline #227 passed with stage
in 1 minute and 15 seconds
......@@ -200,6 +200,8 @@ lætt,vi
léc,adj
léþ,vt
marcéð,n
matté,np
mattér,np
maþtyr,n
meccil,adj
mein,n
......@@ -269,9 +271,18 @@ un,art.dem.sg.far
urby,n
ut,art.dem.pau.far
uð,art.dem.pl.far
vatþ,être.perf.3pau
vaþ,être.perf.3sg
veaen,être.perf.3pl
veat,être.perf.2pl
vein,être.perf.1pl
velgi,adv
vend,adj
venþ,être.perf.2pau
ver,être.perf.1sg
verd,vt
vet,être.perf.2sg
veð,être.perf.1pau
vinþtri,adj
vitt,vt
voc,n
......@@ -281,6 +292,7 @@ vérr,vt
vétter,n
vétter,vi
wyrm,n
y,aux.fut
yhae,pron.3sg.m.voc
yhei,pron.3pau.n.voc
yhi,pron.3sg.n.voc
......@@ -324,7 +336,6 @@ yþu,pron.3pl.f.voc
þcyrm,n
þean,nbr
þeg,vt
þror,np
þett,vt
þi,pron.1pau.nom
þid,pron.1pau.acc
......@@ -340,6 +351,7 @@ yþu,pron.3pl.f.voc
þou,pron.3pau.f.dat
þou,pron.3pl.f.dat
þpiċ,vt
þror,np
þtein,vt
þteinér,n
þtiern,n
......
......@@ -7,6 +7,30 @@ use std::fs;
use std::io::Write;
use xml::writer::{EmitterConfig, EventWriter, XmlEvent};
struct Word {
word: String,
morpheme: String,
gloss: String,
}
impl Word {
fn new(word: String) -> Word {
Word {
word: word,
morpheme: String::new(),
gloss: String::new(),
}
}
fn xml_event(&self) -> XmlEvent {
XmlEvent::start_element("word")
.attr("text", &self.word)
.attr("morpheme", &self.morpheme)
.attr("gloss", &self.gloss)
.into()
}
}
fn import_morphemes() -> HashMap<String, String> {
let contents = fs::read_to_string("matter-dict.csv")
.expect("Something went wrong reading the dictionary");
......@@ -38,30 +62,34 @@ fn read_text(filename: &str) -> Vec<String> {
sentences
}
fn process_suffixes(word: &mut Word) {
let (_, affixes) = word.word.split_at(word.morpheme.len());
if affixes != "" {
println!("{}-{}", word.morpheme, affixes);
}
}
fn process_word<W: Write>(
w: &mut EventWriter<W>,
word: &str,
morphemes: &HashMap<String, String>,
) {
let mut details = String::new();
let mut morpheme = String::new();
for (key, value) in morphemes {
if word.starts_with(key.as_str()) && key.len() >= morpheme.len() {
morpheme = key.clone();
details = value.clone();
let mut word = Word::new(word.to_string());
for (morpheme, gloss) in morphemes {
if word.word.starts_with(morpheme.as_str()) &&
morpheme.len() >= word.morpheme.len()
{
word.morpheme = morpheme.clone();
word.gloss = gloss.clone();
}
}
let event: XmlEvent = XmlEvent::start_element("word")
.attr("text", word)
.attr("morpheme", &morpheme)
.attr("gloss", &details)
.into();
if morpheme != "" {
let word = word.split_at(morpheme.len());
if word.1 != "" {
println!("{}-{}", morpheme, word.1);
}
if word.morpheme != "" {
process_suffixes(&mut word);
} else {
word.morpheme = word.word.clone();
word.gloss = String::from("unknown");
}
let event : XmlEvent = word.xml_event();
w.write(event).unwrap();
let event: XmlEvent = XmlEvent::end_element().into();
w.write(event).unwrap();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment