Example #1
0
 def test_different_instances_with_same_content_are_equal(self):
     """ If two different instances has the same content are equal. """
     value = (
         grammar.SingleTerm('terminal1'),
         'terminal2'
     )
     self.assertEquals(
         grammar.And(*value),
         grammar.And(*value),
     )
Example #2
0
 def test_correct_construction(self):
     """ If value is correct, the term is correctly initialized. """
     value = (
         grammar.SingleTerm('terminal1'),
         'terminal2'
     )
     and_connector = grammar.And(*value)
     self.assertEquals(value[0], and_connector.value[0])
     self.assertEquals(grammar.SingleTerm(value[1]), and_connector.value[1])
Example #3
0
 def test_not_all_values_in_value_tuple_are_terms_or_strings(self):
     """ If elements in value are not Term, an error is raised. """
     invalid_values = (
         (grammar.SingleTerm('terminal'), 'a nice dog', 9),
         (1, 2, 3, 4, 5),
     )
     for value in invalid_values:
         with self.assertRaises(ValueError):
             grammar.And(value)
Example #4
0
 def test_value_is_a_tuple_of_less_than_two_terms(self):
     """ If value is a tuple of less than 2 terms, an error is raised. """
     invalid_values = (
         tuple(),
         grammar.SingleTerm('terminal'),
     )
     for value in invalid_values:
         with self.assertRaises(ValueError):
             grammar.And(value)
Example #5
0
 def test_value_is_not_a_tuple(self):
     """ If value is not a tuple, an error is raised. """
     with self.assertRaises(ValueError):
         grammar.And(grammar.SingleTerm('terminal'))
Example #6
0
from pprint import pprint

from pynetics.gggp import grammar

awesome_grammar = grammar.Grammar(
    start_symbol='frase',
    productions=[
        grammar.Production(
            'frase',
            grammar.And(
                grammar.Multiplier('sujeto', upper=1), 'predicado',
                grammar.Multiplier(
                    grammar.And('conjuncion',
                                grammar.Multiplier('sujeto', upper=1),
                                'predicado'), )),
        ),
        grammar.Production('conjuncion', grammar.Or(('y', 4), ('o', 6))),
        grammar.Production('sujeto', grammar.Or('sujeto_masc', 'sujeto_fem')),
        grammar.Production(
            'sujeto_masc',
            grammar.Or(
                grammar.And('el', 'nombre_comun_masc'),
                grammar.And(grammar.Multiplier('el', upper=1),
                            'nombre_propio_masc'),
            )),
        grammar.Production(
            'sujeto_fem',
            grammar.Or(
                grammar.And('la', 'nombre_comun_fem'),
                grammar.And(grammar.Multiplier('la', upper=1),
                            'nombre_propio_fem'),