Beispiel #1
0
def main():
    search = SearchIndex(dictionary_file, postings_file)
    with open(query_file, 'r') as fquery:
        with open(output_file, 'w') as foutput:
            for query in fquery.readlines():
                result = search.search(query)
                # print result
                foutput.write(result + '\n')
Beispiel #2
0
 def __init__(self, aerospike_connector):
     self._search_index = SearchIndex(aerospike_connector)
Beispiel #3
0
        if len(tuples) > MAX_CANDIDATE_TUPLES:
          tuples = set(random.sample(tuples, MAX_CANDIDATE_TUPLES))
        sources = extract_dimension_from_tuples_as_list(tuples, 0)
        relations = extract_dimension_from_tuples_as_list(tuples, 1)
        targets = extract_dimension_from_tuples_as_list(tuples, 2)
        output_row = {
          'question': question,
          'qn_entities': get_str_of_seq(qn_entities),
          'ans_entities': get_str_of_seq(ans_entities),
          'sources': get_str_of_seq(sources),
          'relations': get_str_of_seq(relations),
          'targets': get_str_of_seq(targets)
        }
        writer.writerow(output_row)


if __name__ == "__main__":
  parser = argparse.ArgumentParser(description='Specify arguments')
  parser.add_argument('--input_examples', help='the raw qa pairs', required=True)
  parser.add_argument('--input_graph', help='the graph file', required=True)
  parser.add_argument('--input_doc', help='the doc file', required=False)
  parser.add_argument('--stopwords', help='stopwords file', required=False)
  parser.add_argument('--output_examples', help='the processed output file', required=True)
  args = parser.parse_args()

  #global variables
  knowledge_base = KnowledgeGraph(args.input_graph, unidirectional=False)
  search_index = SearchIndex(args.input_doc, args.stopwords)
  stop_vocab = read_file_as_dict(args.stopwords)
  question_parser = QuestionParser(knowledge_base.get_entities(), stop_vocab)
  main(args)