def test_grammar(): rules = Rules(A="B C | D E", B="E | a | b c") lexicon = Lexicon(Article="the | a | an", Pronoun="i | you | he") grammar = Grammar("Simplegram", rules, lexicon) assert grammar.rewrites_for('A') == [['B', 'C'], ['D', 'E']] assert grammar.isa('the', 'Article')
def test_grammar(): rules = Rules(A="B C | D E", B="E | a | b c") lexicon = Lexicon(Article="the | a | an", Pronoun="i | you | he") grammar = Grammar("Simplegram", rules, lexicon) assert grammar.rewrites_for('A') == [['B', 'C'], ['D', 'E']] assert grammar.isa('the', 'Article') grammar = nlp.E_Chomsky for rule in grammar.cnf_rules(): assert len(rule) == 3
def test_generation(): lexicon = Lexicon(Article="the | a | an", Pronoun="i | you | he") rules = Rules(S="Article | More | Pronoun", More="Article Pronoun | Pronoun Pronoun") grammar = Grammar("Simplegram", rules, lexicon) sentence = grammar.generate_random('S') for token in sentence.split(): found = False for non_terminal, terminals in grammar.lexicon.items(): if token in terminals: found = True assert found
def test_generation(): lexicon = Lexicon(Article="the | a | an", Pronoun="i | you | he") rules = Rules( S="Article | More | Pronoun", More="Article Pronoun | Pronoun Pronoun" ) grammar = Grammar("Simplegram", rules, lexicon) sentence = grammar.generate_random('S') for token in sentence.split(): found = False for non_terminal, terminals in grammar.lexicon.items(): if token in terminals: found = True assert found