Exemplo n.º 1
0
 def lm_file(self):
     output = "# Parameters 1\n"
     output += "MainLM\tMainLM\n"
     corpora = Set()
     for key, data in self.lmdata[0].items():
         output += "# LMDefinition " + str(len(data)) + "\n"
         output += "Name\t" + key + "\n"
         for field, value in data.items():
             # The coordinates and default LM
             # are saved so we can reconstruct the LM in the browser,
             # but don't output them in the LM file
             if (field=="coords" or field=="default_lm"):
                 continue
             if isinstance(value, list):
                 if(value[0] == 'lm'):
                     output += field + "\t" + str(value[1]) + "\n"
                 elif(value[0] == 'corpus'):
                     n = str(data["M"])
                     value.append("2")
                     output += "Tree\tTree" + value[1] + "_" + n + "\n"
                     corpora.add((value[1], n))
             else:
                 output += field + "\t" + str(value) + "\n"
     for corpus in corpora:
         c = Corpus.objects.get(id=corpus[0])
         output += "# TreeDefinition 2\n"
         output += "Name\tTree" + corpus[0] + "_" + str(corpus[1]) + "\n"
         tree_file = files.file_name(c.name) + ".M" + str(corpus[1]) + ".cnt"
         output += "File " + os.path.join(files.CLUSTER_CORPORA_DIR, files.TREE_PATH, str(c.id), tree_file) + "\n"
     return output
Exemplo n.º 2
0
 def file_name(self):
     return files.file_name(self.corpus.name) + ".M" + str(self.m) + ".cnt"