Chapimenge's picture
Amharic gemination lexicon v3
cf15858 verified
Raw History Blame Contribute Delete
1.94 kB
--- a/hm/morpho/morphology.py
+++ b/hm/morpho/morphology.py
@@ -73,6 +73,19 @@
# Files where unanalyzed words and abbreviations (surface forms) are found.
WORDS1 = "words1.srf"
WORDSM = "wordsM.srf"
+
+ @staticmethod
+ def _ortho_phon(lines):
+ """First two whitespace fields of each real line, as ortho -> phon."""
+ out = {}
+ for line in lines:
+ line = line.strip()
+ if not line or line.startswith("#"):
+ continue
+ parts = line.split()
+ if len(parts) >= 2:
+ out[parts[0]] = parts[1]
+ return out
ABBREVS = "abbrev.srf"
def __init__(self, pos_morphs=[], punctuation='', characters='', abbrev_chars='.'):
@@ -364,7 +377,11 @@
self.words1 = dict([(w[0].strip(), w[1:]) for w in pairs])
else:
# Read in ortho:phon pairs as a dict
- self.words_phon1 = dict([w.strip().split() for w in file])
+ # words1.srf is `ortho phon POS`, three fields, and
+ # carries `#` comment lines. dict() of the raw split
+ # therefore raised on the first real entry, which took
+ # the whole phonetic path down for Amharic.
+ self.words_phon1 = Morphology._ortho_phon(file)
else:
self.words1 = []
self.words_phon1 = {}
@@ -377,7 +394,7 @@
self.wordsM = dict([(w[0].strip(), w[1:]) for w in pairs])
else:
# Read in ortho:phon pairs as a dict
- self.words_phonM = dict([w.strip().split() for w in file])
+ self.words_phonM = Morphology._ortho_phon(file)
else:
self.wordsM = []
self.words_phonM = {}