# LING 573 Question Answering System
# Code last updated 4/17/14 by Clara Gordon
# This code implements an InfoRetriever for the question answering system.


from pymur import *
from general_classes import *


class InfoRetriever:

    # builds a QueryEnvironment associated with the indexed document collection
    def __init__(self, queries, index_env):
        # how to get this to link up to the doc collection?
        self.query_env = QueryEnvironment()
        self.query_env.addIndex("/home2/cjaja/classwork/spring-2014/ling573/question-answering/src/index2/")



    # creates a list of all the passages returned by all the queries generated by
    # the query-processing module
    def retrieve_passages(self, queries):
        results = []
        for query in queries:
            # second argument is the number of documents desired
            query_results = self.query_env.runQuery(query, 10)
            for result in query_results:
                idx = result.document
                begin = result.begin
                end = result.end
                doc = self.query_env.documents([idx])
                passage = Passage(doc.text[begin:end], result.score)
                results.append(passage)

        return results



# LING 573 Question Answering System
# Code last updated 4/17/14 by Clara Gordon
# This code implements an InfoRetriever for the question answering system.


from pymur import *
from general_classes import *


class InfoRetriever:

    path_to_idx =  "/home2/cjaja/classwork/spring-2014/ling573/question-answering/src/index2/"

    # builds a QueryEnvironment associated with the indexed document collection
    def __init__(self, queries, index_env):
        # how to get this to link up to the doc collection?

        self.index = new Index(self.path_to_idx);
        self.query_env = QueryEnvironment()
        self.query_env.addIndex(self.path_to_idx)



    # creates a list of all the passages returned by all the queries generated by
    # the query-processing module
    def retrieve_passages(self, queries):
        passages = []
        for query in queries:
            # second argument is the number of documents desired
            docs = self.query_env.runQuery(query, 10)
            for doc in docs:
                doc_num = doc.document
                begin = doc.begin
                end = doc.end
                doc = self.query_env.documents([doc_num])
                passage = Passage(self.index.document(doc_num)[begin, end], doc.score)
                passages.append(passage)

                # copied from email - not sure what this part does?
                doc_id = self.query_env.documents([doc_num])[0].metadata['docno'] # need this for output

        return passages



Edit pymur code in info_retrieval module, according to Claire's message on email thread