示例#1
0
文件: grammar.py 项目: dim-an/gnTai
def rule(verb, no, obj):
    """ neg_action : VERB NOT object """
    if verb.base != 'be':
        raise AISyntaxError("Expected *be* in negation.")
    action = Action(verb.word, **verb.form)
    action.set_negative(True)
    action.objects[''] = obj
    return action
示例#2
0
文件: grammar.py 项目: dim-an/gnTai
def rule(verb, main_obj, obj):
    """ question : VERB object object """ # ! shift/reduce
    if verb.base != 'be':
        raise AISyntaxError('Expected *be* in the question.')
    action = Action(verb.word, **verb.form)
    action.objects[''] = obj
    ret = Thought(main_obj, action)
    ret.set_question(True)
    return ret
示例#3
0
 def extract_action(self, words):
     """
     Извлекает сказуемое из списка слов (предполагается, что подлежащее уже извлечено).
     """
     variants = self.knowledge.get_part_of_speech_(words.pop(0))
     if 'verb' in variants:
         verb = variants['verb'][0][0]
         if verb is self.knowledge.to_do:
             if len(words) > 0 and words[0] == 'not':
                 words.pop(0)
                 res = self.extract_action(words)
                 res.set_negative(True)
                 return res
         res = Action(verb, **(variants['verb'][0][1]))
         res.set_direct_object(self.extract_object(words))
         return res
     else:
         raise AIException(u'not an action')
示例#4
0
文件: grammar.py 项目: dim-an/gnTai
def rule1(verb, obj):
    """ action : VERB object """
    action = Action(verb.word, **verb.form)
    action.objects[''] = obj
    return action
示例#5
0
class PossessionImplementation(AttributeImplementation):
    def __str__(self):
        form = merge_dicts(self.form, {'common':False})
        return self.concept.word.to_string(**form)

class OtherAttributeImplementation(AttributeImplementation):
    def __str__(self):
        return self.concept.word.to_string(**self.form)

from gnTai.concepts.attribute import Possession, OtherAttribute
from gnTai.concepts.object import Object
from gnTai.concepts.action import Action
from gnTai.thoughts.thought import Thought
Possession.english_implement = PossessionImplementation.get_implementer()
OtherAttribute.english_implement= OtherAttributeImplementation.get_implementer()
Object.english_implement = ObjectImplementation.get_implementer()
Action.english_implement = ActionImplementation.get_implementer()

if __name__ == '__main__':
    from gnTai.thoughts.thought import Thought
    from gnTai.concepts.object import Object
    from gnTai.concepts.action import Action
    from words.noun import Noun
    from words.verb import Verb
    obj = Object(Noun("apple"))
    action = Action(to_be, objects={'':Object(Noun('fruit'))})
    action.set_negative()
    thought =  Thought(obj, action)
    print ThoughtImplementation(thought)