示例#1
0
 def setUp(self):
     # make sure to create a new Parser for each test
     self.prs = Parser(wordlist=[],
                       addons=dict(),
                       stems=dict(),
                       uniques=dict(),
                       inflects=dict(),
                       wordkeys=set())
示例#2
0
 def setUpClass(cls):
     cls.par = Parser()
示例#3
0
 def setUpClass(cls):
     cls.par = Parser()
     cls.full_par = Parser(frequency="X")
示例#4
0
class MinimalDictionaryParseTest(unittest.TestCase):
    def setUp(self):
        # make sure to create a new Parser for each test
        self.prs = Parser(wordlist=[],
                          addons=dict(),
                          stems=dict(),
                          uniques=dict(),
                          inflects=dict(),
                          wordkeys=set())

    def test_empty(self):
        result = self.prs.parse("word")
        self.assertEqual(result.forms, [])

    def test_minimal_functional(self):
        self.prs.data.wordkeys.add("")
        self.prs.data.inflects["0"] = {'': [{'ending': ''}]}
        result = self.prs.parse("word")
        self.assertEqual(result.forms, [])

    def test_minimal_with_result(self):
        word: DictEntry = {
            'orth': 'word',
            'pos': 'NUM',
            'n': ['a'],
            'form': ['CARD'],
            'wid': 0,
            'parts': ['word'],
            'senses': []
        }
        self.prs.data.wordkeys.add("word")
        self.prs.data.empty = {
            'NUM': [{
                'ending': '',
                'pos': 'NUM',
                'n': ['a'],
                'form': ['X', 'X', 'X', 'CARD'],
                'iid': 0,
                'stem': 0
            }]
        }
        self.prs.data.stems["word"] = [word]
        self.prs.data.wordlist.append(word)
        result = self.prs.parse("word")
        self.assertEqual(len(result.forms), 1)
        self.assertEqual(len(result.forms[0].analyses), 1)
        self.assertEqual(result.forms[0].analyses[0].lexeme.category, ['a'])
        self.assertEqual(result.forms[0].analyses[0].lexeme.wordType,
                         WordType.NUM)
        self.assertEqual(len(result.forms[0].analyses[0].inflections), 1)
        self.assertEqual(result.forms[0].analyses[0].inflections[0].category,
                         ['a'])
        self.assertEqual(result.forms[0].analyses[0].inflections[0].wordType,
                         WordType.NUM)

    def test_minimal_empty_unique(self):
        self.prs.data.uniques['word'] = []
        result = self.prs.parse("word")
        self.assertEqual(result.forms, [])

    def test_minimal_unique_with_result(self):
        word: Unique = {
            'orth': 'word',
            'pos': 'PREP',
            'n': [],
            'form': 'a cdef',
            'senses': []
        }
        self.prs.data.uniques['word'] = [word]
        result = self.prs.parse("word")
        self.assertEqual(len(result.forms), 1)
        self.assertEqual(len(result.forms[0].analyses), 1)
        self.assertEqual(result.forms[0].analyses[0].lexeme.category, [])
        self.assertEqual(result.forms[0].analyses[0].lexeme.wordType,
                         WordType.PREP)

    def test_minimal_unique_with_addon(self):
        word = {'orth': 'wor', 'pos': 'PREP', 'form': 'abc', 'senses': []}
        self.prs.data.uniques['wor'] = [word]
        self.prs.data.addons['tackons'] = [{
            'orth': 'd',
            'pos': '',
            'senses': []
        }]
        result = self.prs.parse("word")
        self.assertEqual(len(result.forms), 1)
        self.assertEqual(result.forms[0].enclitic.text, 'd')
        self.assertEqual(result.forms[0].text, 'wor')
        self.assertEqual(len(result.forms[0].analyses), 1)
        self.assertEqual(result.forms[0].analyses[0].lexeme.category, [])
        self.assertEqual(result.forms[0].analyses[0].lexeme.wordType,
                         WordType.PREP)
示例#5
0
 def test_subsetting_interference(self):
     subsetParser = Parser()
     fullParser = Parser(frequency="X")
     self.assertNotEqual(len(subsetParser.data.stems), len(fullParser.data.stems))