예제 #1
0
 def test__cache(self):
     parser = QLCParserWithRowsAndCols(test_data('KSL.qlc'), 'gloss', 'cogid', {})
     idx = list(parser._data.keys())[0]
     parser._get_cached(idx)
     parser._get_cached(idx)
     parser._clean_cache()
     parser._data.pop(idx)
     self.assertRaises(KeyError, parser._get_cached, idx)
예제 #2
0
파일: wordlist.py 프로젝트: kadster/lingpy
    def __init__(self, filename, row='concept', col='doculect', conf=None):
        QLCParserWithRowsAndCols.__init__(
            self, filename, row, col, conf or util.data_path('conf', 'wordlist.rc'))

        # setup other local temporary storage
        self._etym_dict = {}

        # check for taxa in meta
        if 'taxa' in self._alias:
            if self._alias['taxa'] not in self._meta:
                self._meta[self._alias['taxa']] = self.cols
예제 #3
0
    def __init__(self, filename, row='concept', col='doculect', conf=None):
        QLCParserWithRowsAndCols.__init__(
            self, filename, row, col, conf or util.data_path('conf', 'wordlist.rc'))

        # setup other local temporary storage
        self._etym_dict = {}

        # check for taxa in meta
        if 'taxa' in self._alias:
            if self._alias['taxa'] not in self._meta:
                self._meta[self._alias['taxa']] = self.cols
예제 #4
0
파일: basvoc.py 프로젝트: tjade273/lingpy
    def __init__(self, infile=None, col='list', row='key', conf=None):
        QLCParserWithRowsAndCols.__init__(
            self, infile or util.data_path('swadesh', 'swadesh.qlc'), row, col,
            conf or util.data_path('conf', 'swadesh.rc'))

        # get row and key index
        if not hasattr(self, '_rowidx'):
            # add indices to alias dictionary for swadesh lists
            for i, col in enumerate(self.cols):
                self._meta[col] = self._array[np.nonzero(self._array[:, i]),
                                              i][0]
예제 #5
0
파일: basvoc.py 프로젝트: anukat2015/lingpy
    def __init__(self, infile=None, col='list', row='key', conf=None):
        QLCParserWithRowsAndCols.__init__(
            self,
            infile or util.data_path('swadesh', 'swadesh.qlc'),
            row,
            col,
            conf or util.data_path('conf', 'swadesh.rc'))

        # get row and key index
        if not hasattr(self, '_rowidx'):
            # add indices to alias dictionary for swadesh lists
            for i, col in enumerate(self.cols):
                self._meta[col] = self._array[np.nonzero(self._array[:, i]), i][0]
예제 #6
0
 def test_init(self):
     p = QLCParser({0: ['a']})
     QLCParser(p)
     self.assertRaises(IOError, QLCParser, 'not-extisting-file')
     self.assertRaises(TypeError, QLCParser, None)
     self.assertRaises(ValueError, QLCParserWithRowsAndCols, {0: ['a']}, 'x', 'y', {})
     
     self.assertRaises(ValueError, QLCParserWithRowsAndCols, 
             {0: ['concept', 'language', 'bla'],
                 1 : ['bla', 'blu']}, 'concept', 'language', '')
     
     p2 = QLCParserWithRowsAndCols(test_data('bad_file2.tsv'), 'concept',
         'language', data_path('conf', 'wordlist.rc'))
     assert p2.get_entries('cogid')[0][-1] == 'ff'
     self.assertRaises(KeyError, p2.__getitem__, tuple([2000, 'bla']))
     assert p2[3, 'language'] == 'l3'
     assert p2[3, 'nothing'] is None
예제 #7
0
def test_init(test_data):
    p = QLCParser({0: ['a']})
    QLCParser(p)
    with pytest.raises(IOError):
        QLCParser('not-extisting-file')
    with pytest.raises(TypeError):
        QLCParser(None)
    with pytest.raises(ValueError):
        QLCParserWithRowsAndCols({0: ['a']}, 'x', 'y', {})

    with pytest.raises(ValueError):
        QLCParserWithRowsAndCols(
            {
                0: ['concept', 'language', 'bla'],
                1: ['bla', 'blu']
            }, 'concept', 'language', '')

    p2 = QLCParserWithRowsAndCols(str(test_data / 'bad_file2.tsv'), 'concept',
                                  'language', data_path('conf', 'wordlist.rc'))

    assert p2.get_entries('cogid')[0][-1] == 'ff'
    with pytest.raises(KeyError):
        p2.__getitem__(tuple([2000, 'bla']))
    assert p2[3, 'language'] == 'l3'
    assert p2[3, 'nothing'] is None
예제 #8
0
 def test_get_entries(self):
     parser = QLCParserWithRowsAndCols(test_data('KSL.qlc'), 'gloss', 'cogid', {})
     assert parser.get_entries('cogid')
예제 #9
0
 def test_getattr(self):
     parser = QLCParserWithRowsAndCols(test_data('KSL.qlc'), 'concept',
                                       'cogid', {})
     assert parser.cogid
예제 #10
0
 def test_get_entries(self):
     parser = QLCParserWithRowsAndCols(test_data('KSL.qlc'), 'concept',
                                       'cogid', {})
     assert parser.get_entries('cogid')