Datasets:
File size: 1,936 Bytes
cf15858 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | --- 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 = {}
|