def test_classify(self): corpus_inst = CorpusInst() descriptor = create_setting().descriptor corpus_inst.loadtxt("exp/inst/dev001.inst", descriptor.dtype) graph_inst = corpus_inst[0] # clear relevant fields graph_inst["pred_relation"] = "None" graph_inst["pred_weight"] = 0.0 # backup original for comparison later on pred_before = graph_inst["pred_relation"].copy() weight_before = graph_inst["pred_weight"].copy() classifier = TimblClassifier(descriptor, "exp/inst/dev001.inst") classifier.classify(graph_inst) # delete classifier to make sure that server is killed, # even if test fails del classifier # check that at least one prediction is different (i.e. not None) self.assertTrue(any(graph_inst["pred_relation"] != pred_before)) # check that at least one weight is different (i.e. not 0.0) self.assertTrue(any(graph_inst["pred_weight"] != weight_before))
def test_aligner(self): descriptor = create_setting().descriptor classifier = TimblClassifier(descriptor, "exp/inst/dev001.inst") aligner = GraphAligner(descriptor=descriptor, classifier=classifier) corpus = ParallelGraphCorpus(inf="exp/true/dev001_true.pgc") for graph_pair in corpus[:3]: graph_inst = aligner.align(graph_pair, clear=True)
def test_merge(self): corpus_inst = CorpusInst() dtype = create_setting().descriptor.dtype corpus_inst.loadtxt("exp/inst/dev001.inst", dtype) graph_inst = corpus_inst[0] pgc = ParallelGraphCorpus(inf="exp/true/dev001_true.pgc") graph_pair = pgc[0] gm = Merger() gm.merge(graph_inst, graph_pair)
def test_aligner(self): descriptor = create_setting().descriptor classifier = TimblClassifier(descriptor, "exp/inst/dev001.inst") aligner = GraphAligner( descriptor=descriptor, classifier=classifier) corpus = ParallelGraphCorpus(inf="exp/true/dev001_true.pgc") for graph_pair in corpus[:3]: graph_inst = aligner.align(graph_pair, clear=True)
def test_match(self): corpus_inst = CorpusInst() dtype = create_setting().descriptor.dtype corpus_inst.loadtxt("exp/inst/dev001.inst", dtype) graph_inst = corpus_inst[0] graph_inst["match_relation"] = "None" match_before = graph_inst["match_relation"].copy() gm = Matcher() gm.match(graph_inst) ## print graph_inst["match_relation"] # check that at least one match is different self.assertTrue(any(graph_inst["match_relation"] != match_before))
def test_align(self): # create graph aligner descriptor = create_setting().descriptor classifier = TimblClassifier(descriptor, "exp/inst/dev001.inst") graph_aligner = GraphAligner(descriptor=descriptor, classifier=classifier) # create corpus aligner corpus_aligner = CorpusAligner(graph_aligner=graph_aligner, graph_selector=select_parsed_graph_pair) # align part of corpus corpus = ParallelGraphCorpus(inf="exp/true/dev001_true.pgc")[:3] corpus_aligner.align(corpus[:3], clear=True) #corpus.write(pprint=True) self.assertTrue(corpus[0].alignments() or corpus[1].alignments() or corpus[2].alignments())
def test_align(self): # create graph aligner descriptor = create_setting().descriptor classifier = TimblClassifier(descriptor, "exp/inst/dev001.inst") graph_aligner = GraphAligner( descriptor=descriptor, classifier=classifier) # create corpus aligner corpus_aligner = CorpusAligner( graph_aligner=graph_aligner, graph_selector=select_parsed_graph_pair) # align part of corpus corpus = ParallelGraphCorpus(inf="exp/true/dev001_true.pgc")[:3] corpus_aligner.align(corpus[:3], clear=True) #corpus.write(pprint=True) self.assertTrue( corpus[0].alignments() or corpus[1].alignments() or corpus[2].alignments())