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 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 load_dvt(path=''): """ Function loads the default characters for IPA diacritics and IPA vowels of LingPy. """ # check for specific evolaemp path which sues asjp alphabet instead of IPA if path in ['el', 'evolaemp']: fn = 'dvt_el' else: fn = 'dvt' try: dvt = cache.load(fn) except: compile_dvt(path) dvt = cache.load(fn) return dvt
def test_cache(self): d = {'a': 123} filename = 'lingpy_test.CSV' cache.dump(d, filename) self.assertTrue(cache.path(filename).exists()) self.assertEqual(cache.load(filename), d) os.remove(str(cache.path(filename)))
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']
def test_compile_dvt(self): from lingpy.data.derive import compile_dvt compile_dvt() self.assertEqual(len(cache.load('dvt')), 3)
def unpickle(filename): obj = cache.load(filename) obj._recreate_unpicklables() return obj
def test_cache(tmppath): d = {'a': 123} filename = 'lingpy_test.CSV' cache.dump(d, filename, d=tmppath / 'cache') assert cache.load(filename, d=tmppath / 'cache') == d