def test_compile_model(self): from lingpy.data.derive import compile_model compile_model('_test', self.tmp) sound_classes = cache.load('_test.converter') self.assertEqual(sound_classes['b'], 'b') self.assertTrue(self.tmp_path('_test', 'matrix').exists())
def test_compile_model(self): from lingpy.data.derive import compile_model compile_model('_test', self.tmp.as_posix()) sound_classes = cache.load('_test.converter') self.assertEqual(sound_classes['b'], 'b') self.assertTrue(self.tmp_path('_test', 'matrix').exists())
def __init__(self, model, path=None): new_path = lambda *cmps: \ os.path.join(path or util.data_path('models'), model, *cmps) self.name = model # try to load the converter try: self.converter = cache.load(model + '.converter') except: compile_model(model, path) self.converter = cache.load(model + '.converter') # give always preference to scorer matrix files if os.path.isfile(new_path('matrix')): self.scorer = read_scorer(new_path('matrix')) elif os.path.isfile(new_path('scorer.bin')): try: self.scorer = cache.load(model + '.scorer') except compat.FileNotFoundError: pass # if none of the above fits, leave it else: pass # read information from the info-file self.info = {} info = util.read_text_file(new_path('INFO')) data = ['description', 'compiler', 'source', 'date', 'vowels', 'tones'] for line in data: try: self.info[line] = re.findall('@' + line + ': (.*)', info)[0] except: self.info[line] = 'unknown' # check for vowels and tones if "vowels" in self.info: self.vowels = self.info['vowels'] if "tones" in self.info: self.tones = self.info['tones']
asjp[i,j] = 5 keys = [] for keyA,keyB in asjp.keys(): keys.append((keyA,keyB)) for keyA,keyB in keys: for i in '123456': if keyA not in '123456' and keyB not in '123456': asjp[keyA,i] = -20 asjp[i,keyB] = -20 asjp[keyA,'_'] = -50 asjp['_',keyB] = -50 asjp['_','_'] = 0 for x in asjp.keys(): asjp[x] = asjp[x] / 4.0 if asjp[x] > 0 and asjp[x] != 10: asjp[x] += 0.75 * asjp[x] elif asjp[x] < 0: asjp[x] += 0.75 * asjp[x] out = open('scorer.bin','wb') dump(asjp,out) out.close() compile_model('asjp') print("[i] Compilation of the ASJP model was successful!") sleep(1)
else: asjp[i, j] = 5 keys = [] for keyA, keyB in asjp.keys(): keys.append((keyA, keyB)) for keyA, keyB in keys: for i in '123456': if keyA not in '123456' and keyB not in '123456': asjp[keyA, i] = -20 asjp[i, keyB] = -20 asjp[keyA, '_'] = -50 asjp['_', keyB] = -50 asjp['_', '_'] = 0 for x in asjp.keys(): asjp[x] = asjp[x] / 4.0 if asjp[x] > 0 and asjp[x] != 10: asjp[x] += 0.75 * asjp[x] elif asjp[x] < 0: asjp[x] += 0.75 * asjp[x] out = open('scorer.bin', 'wb') dump(asjp, out) out.close() compile_model('asjp') print("[i] Compilation of the ASJP model was successful!") sleep(1)