Skip to content

Commit

Permalink
Create separate entries for each gloss
Browse files Browse the repository at this point in the history
Fixes #12.
  • Loading branch information
eagleflo committed Nov 24, 2020
1 parent e1706ad commit 7536fc7
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,33 @@ fn read_dictionary() -> (Dictionary, Dictionary, Dictionary) {
Some(e) => e.text().unwrap(),
None => continue,
};
let gloss = match node.descendants().find(|n| n.has_tag_name("gloss")) {
Some(e) => e.text().unwrap(),
None => continue,
};

let entry = Entry {
keb: keb.to_string(),
reb: reb.to_string(),
gloss: gloss.to_string(),
};

if let Some(entries) = j2e.get_mut(&keb.to_string()) {
entries.push(entry.clone());
} else {
j2e.insert(keb.to_string(), vec![entry.clone()]);
}
if let Some(entries) = e2j.get_mut(&gloss.to_string()) {
entries.push(entry.clone());
} else {
e2j.insert(gloss.to_string(), vec![entry.clone()]);
}
if let Some(entries) = reading.get_mut(&reb.to_string()) {
entries.push(entry.clone());
} else {
reading.insert(reb.to_string(), vec![entry.clone()]);
let glosses = node
.descendants()
.filter(|n| n.has_tag_name("gloss"))
.map(|n| n.text().unwrap());

for gloss in glosses {
let entry = Entry {
keb: keb.to_string(),
reb: reb.to_string(),
gloss: gloss.to_string(),
};

if let Some(entries) = j2e.get_mut(&keb.to_string()) {
entries.push(entry.clone());
} else {
j2e.insert(keb.to_string(), vec![entry.clone()]);
}
if let Some(entries) = e2j.get_mut(&gloss.to_string()) {
entries.push(entry.clone());
} else {
e2j.insert(gloss.to_string(), vec![entry.clone()]);
}
if let Some(entries) = reading.get_mut(&reb.to_string()) {
entries.push(entry.clone());
} else {
reading.insert(reb.to_string(), vec![entry.clone()]);
}
}
}
}
Expand Down

0 comments on commit 7536fc7

Please sign in to comment.