Search in sources :

Example 36 with AnnotatorException

use of edu.illinois.cs.cogcomp.annotation.AnnotatorException in project cogcomp-nlp by CogComp.

the class CuratorFactoryTest method testGetTextAnnotation.

@Test
public void testGetTextAnnotation() {
    // if we are running the test on Semaphore, ignore this test, since Gurobi is not provided on Semaphore.
    if (System.getenv().containsKey("CI") && System.getenv().get("CI").equals("true") && System.getenv().containsKey("SEMAPHORE") && System.getenv().get("SEMAPHORE").equals("true") && System.getenv().containsKey("CIRCLECI") && System.getenv().get("CIRCLECI").equals("true")) {
        System.out.println("Running the test on Semaphore. Skipping this test  . . . ");
    } else {
        TextAnnotation ta = null;
        try {
            ta = curator.createBasicTextAnnotation("test", "0", text);
        } catch (AnnotatorException e) {
            e.printStackTrace();
            fail(e.getMessage());
        } catch (IllegalArgumentException e) {
            // If this is a "connection timeout" exception we can ignore it
            if (e.getMessage().contains("Connection timed out"))
                return;
        }
        assertTrue(ta.hasView(ViewNames.SENTENCE));
        assertTrue(ta.hasView(ViewNames.TOKENS));
        List<Constituent> tokens = ta.getView(ViewNames.TOKENS).getConstituents();
        List<Constituent> sentences = ta.getView(ViewNames.SENTENCE).getConstituents();
        assertEquals(NUM_TOKS, tokens.size());
        assertEquals(NUM_SENTS, sentences.size());
    }
}
Also used : AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Constituent(edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent) Test(org.junit.Test)

Example 37 with AnnotatorException

use of edu.illinois.cs.cogcomp.annotation.AnnotatorException in project cogcomp-nlp by CogComp.

the class CuratorFactoryTest method testGetAllTextAnnotationViews.

@Test
public void testGetAllTextAnnotationViews() {
    // if we are running the test on Semaphore, ignore this test, since Gurobi is not provided on Semaphore.
    if (System.getenv().containsKey("CI") && System.getenv().get("CI").equals("true") && System.getenv().containsKey("SEMAPHORE") && System.getenv().get("SEMAPHORE").equals("true") && System.getenv().containsKey("CIRCLECI") && System.getenv().get("CIRCLECI").equals("true")) {
        System.out.println("Running the test on Semaphore. Skipping this test  . . . ");
    } else {
        TextAnnotation ta = null;
        try {
            ta = curator.createAnnotatedTextAnnotation("test", "0", text);
        } catch (AnnotatorException e) {
            e.printStackTrace();
            fail(e.getMessage());
        } catch (IllegalArgumentException e) {
            // If this is a "connection timeout" exception we can ignore it
            if (e.getMessage().contains("Connection timed out"))
                return;
        }
        testViews(ta);
    }
}
Also used : AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Test(org.junit.Test)

Example 38 with AnnotatorException

use of edu.illinois.cs.cogcomp.annotation.AnnotatorException in project cogcomp-nlp by CogComp.

the class CuratorFactoryTest method testGetIndividualTextAnnotationViews.

@Test
public void testGetIndividualTextAnnotationViews() throws IOException {
    // if we are running the test on Semaphore, ignore this test, since Gurobi is not provided on Semaphore.
    if (System.getenv().containsKey("CI") && System.getenv().get("CI").equals("true") && System.getenv().containsKey("SEMAPHORE") && System.getenv().get("SEMAPHORE").equals("true") && System.getenv().containsKey("CIRCLECI") && System.getenv().get("CIRCLECI").equals("true")) {
        System.out.println("Running the test on Semaphore. Skipping this test  . . . ");
    } else {
        TextAnnotation ta = null;
        try {
            ResourceManager rm = new ResourceManager(CONFIG_FILE);
            ta = curator.createBasicTextAnnotation("test", "0", text);
            for (String viewName : rm.getCommaSeparatedValues(CuratorConfigurator.VIEWS_TO_ADD.key)) curator.addView(ta, viewName);
        } catch (AnnotatorException e) {
            e.printStackTrace();
            fail(e.getMessage());
        } catch (IllegalArgumentException e) {
            // If this is a "connection timeout" exception we can ignore it
            if (e.getMessage().contains("Connection timed out"))
                return;
        }
        testViews(ta);
    }
}
Also used : AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException) ResourceManager(edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) Test(org.junit.Test)

Example 39 with AnnotatorException

use of edu.illinois.cs.cogcomp.annotation.AnnotatorException in project cogcomp-nlp by CogComp.

the class CuratorAnnotatorService method addView.

@Override
public boolean addView(TextAnnotation ta, String viewName) throws AnnotatorException {
    if (ViewNames.SENTENCE.equals(viewName) || ViewNames.TOKENS.equals(viewName))
        return false;
    if (!viewProviders.containsKey(viewName))
        throw new AnnotatorException("View " + viewName + " is not supported.");
    boolean isUpdated = false;
    // AnnotatorService will not support caching
    if (ta.hasView(viewName))
        return false;
    Annotator annotator = viewProviders.get(viewName);
    for (String prereqView : annotator.getRequiredViews()) isUpdated = addView(ta, prereqView);
    ta.addView(annotator);
    // AnnotatorService will not support caching
    return isUpdated;
}
Also used : Annotator(edu.illinois.cs.cogcomp.annotation.Annotator) AnnotatorException(edu.illinois.cs.cogcomp.annotation.AnnotatorException)

Aggregations

AnnotatorException (edu.illinois.cs.cogcomp.annotation.AnnotatorException)39 TextAnnotation (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation)28 Test (org.junit.Test)14 Constituent (edu.illinois.cs.cogcomp.core.datastructures.textannotation.Constituent)11 IOException (java.io.IOException)8 View (edu.illinois.cs.cogcomp.core.datastructures.textannotation.View)7 TreeView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TreeView)6 FileNotFoundException (java.io.FileNotFoundException)6 ResourceManager (edu.illinois.cs.cogcomp.core.utilities.configuration.ResourceManager)4 TextAnnotationBuilder (edu.illinois.cs.cogcomp.annotation.TextAnnotationBuilder)3 Tree (edu.illinois.cs.cogcomp.core.datastructures.trees.Tree)3 StatefulTokenizer (edu.illinois.cs.cogcomp.nlp.tokenizer.StatefulTokenizer)3 TokenizerTextAnnotationBuilder (edu.illinois.cs.cogcomp.nlp.utility.TokenizerTextAnnotationBuilder)3 Properties (java.util.Properties)3 AnnotatorService (edu.illinois.cs.cogcomp.annotation.AnnotatorService)2 Pair (edu.illinois.cs.cogcomp.core.datastructures.Pair)2 PredicateArgumentView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.PredicateArgumentView)2 SpanLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.SpanLabelView)2 TokenLabelView (edu.illinois.cs.cogcomp.core.datastructures.textannotation.TokenLabelView)2 Token (edu.illinois.cs.cogcomp.lbjava.nlp.seg.Token)2