def __init__(self): self.kb = ResourcePool().ontology_server # Store the list of subproperties of 'hasFeature' # used in create_nominal_group_with_object() try: self.features_properties = self.kb[ "* rdfs:subPropertyOf hasFeature"] except TypeError: # No ontology server? self.features_properties = []
def create_w_question_answer(self, w_question, w_answer, current_speaker, query_on_field): """Create the answer of a W-Question w_question is the current question w_answer is the response found in the ontology query_on_field is the part of the W_question to fill with the answer. it takes the following values: - None : - QUERY_ON_INDIRECT_OBJ - QUERY_ON_DIRECT_OBJ """ #Nominal group holding the answer nominal_groupL = [] #if "me", "you", "us" myself = False yourself = False #Return. I am sorry. I don't know if not w_answer: return [ Sentence(STATEMENT, "", [NominalGroup([], ['I'], [], [], [])], [ VerbalGroup(['be'], [], "present simple", [ NominalGroup([], [], [['sorry', []]], [], []) ], [], [], [], "affirmative", []) ]), Sentence(STATEMENT, "", [NominalGroup([], ['I'], [], [], [])], [ VerbalGroup(['know'], [], "present simple", [], [], [], [], "negative", []) ]) ] # Case of adjectives only if w_question.aim in ResourcePool().adjectives_ontology_classes: ng = NominalGroup([], [], [[w_answer[0][1][0], []]], [], []) preposition = w_answer[0][0] ng._resolved = True nominal_groupL = [[preposition, [ng]]] else: for [preposition, response] in w_answer: ngL = [] for resp in response: if resp == "myself": myself = True if resp == current_speaker: yourself = True ng = self.create_nominal_group_with_object( resp, current_speaker) if ng: ng.id = resp ng._resolved = True ngL.append(ng) #Arraging preposition if preposition and preposition[0] in ResourcePool( ).direction_words: if preposition[0] == 'front': preposition[0] = "in+front+of" elif preposition[0] == "back": preposition[0] == "behind" elif preposition[0] == "bottom": preposition[0] == "underneath" elif preposition[0] == "top": prepsosition[0] = "above" else: # Here we try to output something similar to My left, or Your left or at the left of ACHILLE # Case of "my and your" if myself and yourself: ngL = [ NominalGroup(["our"], preposition, [], [], []) ] # elif myself: ngL = [ NominalGroup(["my"], preposition, [], [], []) ] elif yourself: ngL = [ NominalGroup(["your"], preposition, [], [], []) ] else: ngL = [ NominalGroup(["the"], preposition, [], ngL, []) ] preposition = ["at"] nominal_groupL.append([preposition, ngL]) #Sentence holding the answer # work on a new sentence, so that changes made here do not affect the original w_question sentence = Sentence(STATEMENT, w_question.aim, w_question.sn, w_question.sv) sentence = self.reverse_personal_pronoun(sentence) if not query_on_field: #Default case on sentence.sn sentence.sn = [ng for [prep, ngL] in nominal_groupL for ng in ngL] sentence.sv = [] elif query_on_field == 'QUERY_ON_DIRECT_OBJ': sentence.sv[0].d_obj = [ ng for [prep, ngL] in nominal_groupL for ng in ngL ] elif query_on_field == 'QUERY_ON_INDIRECT_OBJ': sentence.sv[0].i_cmpl = [ IndirectComplement(ng[0], ng[1]) for ng in nominal_groupL ] sentence.aim = "" return [sentence]