def describe(self): output = "Answers questions of the form: 'What proteins does tranilast target?' and 'What genes are affected by " \ "Fanconi anemia?'" + "\n" output += "You can ask: 'What X does Y Z?' where X is one of the following: \n" for label in RU.get_node_labels(): output = output + label + "\n" output += "\n The term Y is any of the nodes that are in our graph (currently " + str( RU.count_nodes()) + " nodes in total). \n" output += "\n The term Z is any relationship of the following kind: \n" for rel in RU.get_relationship_types(): rel_split = rel.split("_") for term in rel_split: output += term + " " output += "\n" output += "Assumes that Z directly connects X and Y." return output
def test_correct_question(): """ Point of this test is to form a bunch of sentences, match them against all queries, and make sure the correct question template is matched :return: None """ # get a random selection of nodes property_to_nodes = dict() for label in RU.get_node_labels(): nodes = RU.get_random_nodes(label, property="description") property_to_nodes[label] = nodes # import the questions questions = [] with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'Questions.tsv'), 'r') as fid: for line in fid.readlines(): if line[0] == "#": pass else: questions.append(Question(line)) # form the corpora corpora = [q.corpus for q in questions] for q in questions: # populate the sentence template parameters = dict() # ignore the what is question if q.parameter_names and q.parameter_names[0] != "term": for label in q.parameter_names: node = random.choice(property_to_nodes[label]) parameters[label] = node input_sentence = q.restate_question(parameters) input_sentence = input_sentence.strip(string.punctuation) # Run it against all the questions (corpus_index, similarity) = wd.find_corpus(input_sentence, corpora) if questions[corpus_index].restated_question_template.template != q.restated_question_template.template: temp_parameters = questions[corpus_index].get_parameters(input_sentence) # test if the parameters were populated if all([val is not None for val in temp_parameters.values()]): print("Bad classification! input: %s\n matched template: %s" % (input_sentence, questions[corpus_index].restated_question_template.template)) print(questions[corpus_index].get_parameters(input_sentence))