def match_pattern(tree): if not tree.is_question(): return None adjective = pt.find_node(tree, pt.match_POS("JJ")) who = pt.find_node(adjective, pt.match_word("who")) if who: return {"adjective": adjective} return None
def match_pattern(tree): if not tree.is_question(): return None verb_tree = pt.find_node(tree, pt.match_POS("VB", "VBD", "VBG", "VBN", "VBP", "VBZ")) copular = pt.find_node(verb_tree, pt.match_word("are", "is")) subject_tree = pt.find_node(verb_tree, pt.match_gram("nsubj")) object_tree = pt.find_node(verb_tree, pt.match_gram("dobj")) if copular and verb_tree and subject_tree: return {"verb_tree": verb_tree, "subject_tree": subject_tree, "object_tree": object_tree} return None
def match_pattern(tree): greeting = pt.find_node(tree, pt.match_word("hi", "hello", "greetings", "howdy")) if greeting: return {"greeting": greeting.word} return None
def match_pattern2(tree): tell = pt.find_node(tree, pt.match_word("tell")) person = pt.find_node(tell, pt.match_POS("NNP")) about = pt.find_node(person, pt.match_word("about")) if about: return {"name": person, "negative_response": "Who is that?"}