old_contents: # LING 573 Question Answering System
  # Code last updated 4/22/14 by Claire Jaja
  # This code implements an InfoRetriever for the question answering system.
  
  
  # from pymur import *
  import sys
  import subprocess
  # this needs to be commented out when running this code directly
  # can be added back in when running from the wrapper script
  # has to do with the paths Python checks for modules
  #from general_classes import *
  
  
  class InfoRetriever:
  
      indri_loc = "/NLP_TOOLS/info_retrieval/indri/latest/bin/IndriRunQuery"
  
      # builds a QueryEnvironment associated with the indexed document collection
      def __init__(self, index_path):
          # how to get this to link up to the doc collection?
  
          self.path_to_idx = index_path
  
  
      # 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:
              # query = " ".join(query.search_terms.keys())
              sys.stderr.write(query + '\n')
              # second argument is the number of documents desired
              try:
                  print "Opening Popen object"
                  p1 = subprocess.Popen([self.indri_loc,'-query="#combine(' + query + ')"', '-index=' + self.path_to_idx, '-printSnippets=true'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                  # ''.join(['-query=', '"#combine("', query,')"'])
                  print "Gathering output"
                  results = p1.communicate()
                  print "Output gathered"
                  print results
              except:
                  sys.stderr.write(str(sys.exc_info()[0]) +' ' + str(sys.exc_info()[1]) + ' ' + str(sys.exc_info()[2]) + '\n')
                  sys.stderr.write("Couldn't run query: " + query + '\n')
  
  
  
  
  # quick testing script 
  def main():
      ir = InfoRetriever("/home2/cjaja/classwork/spring-2014/ling573/question-answering/src/index")
      ir.retrieve_passages(["test query"])
  
  
  main()
  
  
  
  
  
  
  
new_contents: # LING 573 Question Answering System
  # Code last updated 4/22/14 by Claire Jaja
  # This code implements an InfoRetriever for the question answering system.
  
  
  # from pymur import *
  import sys
  import subprocess
  # this needs to be commented out when running this code directly
  # can be added back in when running from the wrapper script
  # has to do with the paths Python checks for modules
  #from general_classes import *
  
  
  class InfoRetriever:
  
      indri_loc = "/NLP_TOOLS/info_retrieval/indri/latest/bin/IndriRunQuery"
  
      # builds a QueryEnvironment associated with the indexed document collection
      def __init__(self, index_path):
          # how to get this to link up to the doc collection?
  
          self.path_to_idx = index_path
  
  
      # 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:
              # query = " ".join(query.search_terms.keys())
              sys.stderr.write(query + '\n')
              # second argument is the number of documents desired
              try:
                  print "Opening Popen object"
                  args = [self.indri_loc,'-query=#combine(' + query + ')', '-index=' + self.path_to_idx, '-printSnippets=true']
                  print args
                  p1 = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                  # ''.join(['-query=', '"#combine("', query,')"'])
                  print "Gathering output"
                  results = p1.communicate()
                  print "Output gathered"
                  print results
              except:
                  sys.stderr.write(str(sys.exc_info()[0]) +' ' + str(sys.exc_info()[1]) + ' ' + str(sys.exc_info()[2]) + '\n')
                  sys.stderr.write("Couldn't run query: " + query + '\n')
  
  
  
  
  # quick testing script 
  def main():
      ir = InfoRetriever("/home2/cjaja/classwork/spring-2014/ling573/question-answering/src/index")
      ir.retrieve_passages(["test query"])
  
  
  main()
  
  
  
  
  
  
  
subject: Fix alternative info retrieval script - now subprocess for IndriRunQuery works.