Ejemplo n.º 1
0
    def subproc(pid, tasks, results, exits, lockTask):
      setting.runningMode = "normal"
      setting.load(["file_translation_input_tree","file_translation_input_dep","file_translation_output","size_cube_pruning"])
      decoder = GentileDecoder()

      while True:
        lockTask.acquire()
        if not tasks.empty():
          task = tasks.get()
        else:
          task = None
        lockTask.release()
        if not task:
          exits.put(pid)
          return
        tid, lineTree, lineDep = task
        
        hyps = decoder.translateNBest(lineTree, lineDep)
        result = hyps[0].getTranslation()
        output = result + "\n"
        msgStream = StringIO.StringIO()
        hyps[0].trace(stream=msgStream)
        print >> msgStream, "[%d]" % tid , result
        
        msg = msgStream.getvalue()
        results.put((tid, output, msg))
Ejemplo n.º 2
0
      def subproc(pid, tasks, results, exits, lockTask):
        setting.runningMode = "mert"
        setting.load(["file_translation_input_tree","file_translation_input_dep","file_translation_output"])
        decoder = GentileDecoder()

        while True:
          lockTask.acquire()
          if not tasks.empty():
            task = tasks.get()
          else:
            task = None
          lockTask.release()
          if not task:
            exits.put(pid)
            return
          tid, lineTree, lineDep = task
          
          hyps = decoder.translateNBest(lineTree, lineDep)
          output = ""
          for hyp in hyps:
            line_output = " ||| ".join([str(tid),hyp.getTranslation(),
                                      " ".join([str(n) for n in hyp.getLambdas()])
                                     ])
            output += line_output + "\n"
          msg = "[%d] Got %d | %s" % (tid,len(hyps),hyps[0].getTranslation())
          results.put((tid, output, msg))
Ejemplo n.º 3
0
from gentile.decoder import GentileDecoder

if __name__ == "__main__":
  #sys.argv.append ("config.yaml")
  #sys.argv.append ("mert")
  arg_length = len(sys.argv)
  if arg_length == 1:
    # abraham.py
    print "usage : python abraham.py config.yaml"

  elif arg_length == 2:
    # abraham.py config.yaml
    setting.runningMode = "normal"
    setting.load(["file_translation_input_tree","file_translation_input_dep","file_translation_output","size_cube_pruning"])
    
    decoder = GentileDecoder()
    

    print "[Gentile]", "Interactive Mode"

    while True:
      sentence = raw_input("[INPUT]")

      sentence = sentence.strip()

      _, pathText = tempfile.mkstemp()
      _, pathCFG = tempfile.mkstemp()
      _, pathDep = tempfile.mkstemp()

      open(pathText, "w").write(sentence)
      print "[Gentile] Parsing CFG Tree ..."
Ejemplo n.º 4
0
if __name__ == "__main__":
  #sys.argv.append ("config.yaml")
  #sys.argv.append ("mert")
  arg_length = len(sys.argv)
  if arg_length == 1:
    # abraham.py
    print "usage : python abraham.py config.yaml"

  elif arg_length == 2:
    # abraham.py config.yaml
    setting.runningMode = "normal"
    setting.load(["file_translation_input_tree","file_translation_input_dep","file_translation_output","size_cube_pruning"])
    linesDep = open(setting.file_translation_input_dep).read().split("\n\n")
    linesTree = open(setting.file_translation_input_tree).readlines()

    decoder = GentileDecoder()
    foutput = open(setting.file_translation_output, "w")

    print "[Abraham]","translate %d sentences..." % (len(linesTree))
    
    for i in range(len(linesTree)):
      lineTree = linesTree[i].strip()
      lineDep = linesDep[i].strip()
      hyps = decoder.translateNBest(lineTree, lineDep)
      hyps[0].trace()
      if len(hyps)==0:
        print "[%d]" % i , "Translation Failed!!!"
        foutput.write("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n")
        continue
      result = hyps[0].getTranslation()