use of edu.illinois.cs.cogcomp.annotation.AnnotatorException in project cogcomp-nlp by CogComp.
the class ClauseViewGeneratorTest method testClauseViewGenerator.
// public void setUp() throws Exception {
// super.setUp();
// }
@Test
public final void testClauseViewGenerator() {
String text = "Freeport-McMoRan Inc. said it will convert its Freeport-McMoRan Energy Partners Ltd. " + "partnership into a publicly traded company through the exchange of units of the partnership " + "for common shares .";
TextAnnotation ta = TextAnnotationUtilities.createFromTokenizedString(text);
Tree<String> tree = TreeParserFactory.getStringTreeParser().parse("(S1 (S (NP-SBJ (NNP Freeport-McMoRan) (NNP Inc.)) (VP (VBD said)" + " (SBAR (-NONE- 0) (S (NP-SBJ (PRP it)) " + "(VP (MD will) (VP (VB convert) " + "(NP (PRP$ its) (NNP Freeport-McMoRan) " + " (NNP Energy) (NNPS Partners)" + " (NNP Ltd.) (NN partnership)) " + " (PP-CLR (IN into) (NP (DT a)" + " (ADJP (RB publicly)" + " (VBN traded))" + " (NN company))) " + " (PP-MNR (IN through) " + " (NP (NP (DT the) " + " (NN exchange)) " + " (PP (IN of) " + " (NP (NP (NNS units)) " + " (PP (IN of) " + " (NP (DT the) " + " (NN partnership))))) " + " (PP (IN for) (NP (JJ common) " + " (NNS shares)))))))))) (. .)))");
TreeView parse = new TreeView("", ta);
parse.setParseTree(0, tree);
ta.addView(ViewNames.PARSE_GOLD, parse);
ClauseViewGenerator clg = new ClauseViewGenerator(ViewNames.PARSE_GOLD, "clauses");
try {
ta.addView(clg);
} catch (AnnotatorException e) {
fail(e.getMessage());
}
logger.info(ta.getView("clauses").toString());
}
use of edu.illinois.cs.cogcomp.annotation.AnnotatorException in project cogcomp-nlp by CogComp.
the class SimpleGazetteerAnnotatorTest method testMultiThreading.
/**
* Test method for
* {@link edu.illinois.cs.cogcomp.edison.annotators.SimpleGazetteerAnnotator#addView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)}
* .
*
* @throws URISyntaxException
* @throws IOException
* @throws AnnotatorException
*/
@Test
public void testMultiThreading() throws IOException, URISyntaxException, AnnotatorException {
final SimpleGazetteerAnnotator sga = new SimpleGazetteerAnnotator(defaultRm);
class TestThread extends Thread {
Throwable throwable;
public void run() {
long start = System.currentTimeMillis();
while (true) {
final TextAnnotation ta = tab.createTextAnnotation("I hail from the university of illinois at champaign urbana.");
try {
sga.addView(ta);
} catch (AnnotatorException e) {
throwable = e;
return;
}
SpanLabelView view = (SpanLabelView) ta.getView(ViewNames.TREE_GAZETTEER);
List<Constituent> entities = view.getConstituents();
Constituent c1 = entities.get(0);
try {
assertEquals(c1.toString(), "university of illinois");
Constituent c2 = entities.get(1);
assertEquals(c2.toString(), "university of illinois at champaign urbana");
Constituent c3 = entities.get(2);
assertEquals(c3.toString(), "illinois");
Constituent c4 = entities.get(3);
assertEquals(c4.toString(), "champaign");
Constituent c5 = entities.get(4);
assertEquals(c5.toString(), "urbana");
assertEquals(c1.getLabel(), "organizations(IC)");
assertEquals(c2.getLabel(), "organizations(IC)");
assertEquals(c3.getLabel(), "places(IC)");
assertEquals(c4.getLabel(), "places(IC)");
assertEquals(c5.getLabel(), "places(IC)");
if ((System.currentTimeMillis() - start) > 10000l) {
// run for one minute.
throwable = null;
return;
}
} catch (AssertionError ae) {
throwable = ae;
ae.printStackTrace();
return;
}
}
}
}
final int numthreads = 20;
TestThread[] threads = new TestThread[numthreads];
for (int i = 0; i < numthreads; i++) {
threads[i] = new TestThread();
threads[i].start();
}
logger.info("Begin multithreaded test.");
for (int i = 0; i < numthreads; i++) {
while (true) try {
threads[i].join();
assertEquals("Exception during multithreading test : " + threads[i].throwable, threads[i].throwable, null);
break;
} catch (InterruptedException e) {
continue;
}
}
}
use of edu.illinois.cs.cogcomp.annotation.AnnotatorException in project cogcomp-nlp by CogComp.
the class TestHeadFinderDependencyHelper method testHeadFinderDependencyHelper.
@Test
public final void testHeadFinderDependencyHelper() {
String s = "There is no recovery period -- it 's go , go , go .";
String treeString = "(S1 (S (S (NP (EX There)) (VP (AUX is) (NP (DT no) (NN recovery) " + " (NN period)))) (: --) (S (NP (PRP it)) (VP (AUX 's) (S (VP (VB go) " + " (, ,) (VB go) (, ,) (VB go))))) (. .)))";
TextAnnotation ta = TextAnnotationUtilities.createFromTokenizedString(s);
TreeView parse = new TreeView(ViewNames.PARSE_CHARNIAK, "", ta, 1.0);
parse.setParseTree(0, TreeParserFactory.getStringTreeParser().parse(treeString));
ta.addView(ViewNames.PARSE_CHARNIAK, parse);
logger.info(ta.getView(ViewNames.PARSE_CHARNIAK).toString());
HeadFinderDependencyViewGenerator dep = new HeadFinderDependencyViewGenerator(ViewNames.PARSE_CHARNIAK);
TreeView depTree = null;
try {
depTree = (TreeView) dep.getView(ta);
} catch (AnnotatorException e) {
e.printStackTrace();
fail(e.getMessage());
}
logger.info(depTree.toString());
assertEquals(depTree.getNumberOfConstituents(), ta.size());
}
use of edu.illinois.cs.cogcomp.annotation.AnnotatorException in project cogcomp-nlp by CogComp.
the class PathLSTMHandler method addView.
@Override
public void addView(TextAnnotation ta) throws AnnotatorException {
// Check if all required views are present
try {
View srlView = getSRL(ta);
ta.addView(getViewName(), srlView);
} catch (Exception e) {
e.printStackTrace();
throw new AnnotatorException(e.getMessage());
}
}
use of edu.illinois.cs.cogcomp.annotation.AnnotatorException in project cogcomp-nlp by CogComp.
the class RunPipeline method RunPipelineWithCorpusReader.
public void RunPipelineWithCorpusReader(AnnotationReader reader) {
Iterator<TextAnnotation> iter = reader.iterator();
boolean replaceExistingViews = false;
while (iter.hasNext()) {
TextAnnotation ta = iter.next();
try {
ta = pipeline.annotateTextAnnotation(ta, replaceExistingViews);
} catch (AnnotatorException e) {
e.printStackTrace();
logger.error("failed to preprocess ta with id '" + ta.getId() + "'.");
}
logger.debug("processed file (assumed this is TextAnnotation docid): '" + ta.getId() + "'");
}
}
Aggregations