org.apache.uima.UIMAException Java Examples

The following examples show how to use org.apache.uima.UIMAException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SelectorTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testPseudoContains() throws UIMAException {
  Node<Structure> doc =
      createStructure(
          "<div><p>The Rain.</p> <p class=light>The <i>rain</i>.</p> <p>Rain, the.</p></div>");

  Nodes<Structure> ps1 = doc.select("Paragraph:contains(Rain)");
  assertEquals(3, ps1.size());

  Nodes<Structure> ps2 = doc.select("Paragraph:contains(the rain)");
  assertEquals(2, ps2.size());
  assertEquals("The Rain.", ps2.first().text());
  assertEquals("The rain.", ps2.last().text());

  Nodes<Structure> ps3 = doc.select("Paragraph:contains(the Rain):has(Style)");
  assertEquals(1, ps3.size());
  assertEquals("The rain.", ps3.first().text());

  Nodes<Structure> ps5 = doc.select(":contains(rain)");
  assertEquals(5, ps5.size()); // Section, Paragraph, Paragraph, Style, Paragraph
}
 
Example #2
Source File: StructuralAnnotationsTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testArticle() throws UIMAException {
  final JCas jCas = JCasSingleton.getJCasInstance();
  final StructuralAnnotations sa = new StructuralAnnotations();

  final Map<String, Class<?>> expectedArticle = new HashMap<>();
  expectedArticle.put("Sheet", Sheet.class);
  expectedArticle.put("Slide", Slide.class);
  expectedArticle.put("Page", Page.class);
  expectedArticle.put("Another", Page.class);

  for (final Map.Entry<String, Class<?>> e : expectedArticle.entrySet()) {
    final Element anchor = new Element(Tag.valueOf("article"), "");
    anchor.attr("class", e.getKey());

    final AnnotationCollector collector = new AnnotationCollector();
    sa.map(jCas, anchor, collector);

    if (e.getValue() != null) {
      assertTrue(e.getValue().isInstance(collector.getAnnotations().get(0)));
    } else {
      assertNull(collector.getAnnotations());
    }
  }
}
 
Example #3
Source File: DocumentGraphFactoryTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testDocumentGraphWithTypeFiltering() throws UIMAException {

  Set<Class<? extends Entity>> typeClasses =
      TypeUtils.getTypeClasses(Entity.class, Person.class.getSimpleName());
  DocumentGraphOptions options =
      DocumentGraphOptions.builder().withTypeClasses(typeClasses).build();
  DocumentGraphFactory factory = createfactory(options);

  JCas jCas = JCasFactory.createJCas();
  JCasTestGraphUtil.populateJcas(jCas);
  Graph graph = factory.create(jCas);

  assertEquals(2, graph.traversal().V().hasLabel(REFERENCE_TARGET).count().next().intValue());
  assertEquals(1, graph.traversal().V().hasLabel(EVENT).count().next().intValue());
  assertEquals(3, graph.traversal().V().hasLabel(MENTION).count().next().intValue());
  assertEquals(1, graph.traversal().V().hasLabel(RELATION).count().next().intValue());
  assertEquals(3, graph.traversal().E().hasLabel(MENTION_OF).count().next().intValue());
  assertEquals(2, graph.traversal().E().hasLabel(PARTICIPANT_IN).count().next().intValue());

  assertNoDocumentNode(graph);
  assertNoRelationEdges(graph);

  assertEquals(7, IteratorUtils.count(graph.vertices()));
  assertEquals(7, IteratorUtils.count(graph.edges()));
}
 
Example #4
Source File: PrintTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testRelations() throws UIMAException {

  final Person s = new Person(jCas);
  s.setValue("source");
  final Location t = new Location(jCas);
  t.setValue("target");

  final Relation r = new Relation(jCas);
  r.setSource(s);
  r.setTarget(t);
  r.setRelationshipType("check");
  r.addToIndexes();

  SimplePipeline.runPipeline(jCas, AnalysisEngineFactory.createEngine(Relations.class));
}
 
Example #5
Source File: ExternalRecommenderIntegrationTest.java    From inception with Apache License 2.0 6 votes vote down vote up
private List<CAS> loadData(Dataset ds, File ... files) throws UIMAException, IOException
{
    CollectionReader reader = createReader(Conll2002Reader.class,
        Conll2002Reader.PARAM_PATTERNS, files,
        Conll2002Reader.PARAM_LANGUAGE, ds.getLanguage(),
        Conll2002Reader.PARAM_COLUMN_SEPARATOR, Conll2002Reader.ColumnSeparators.TAB.getName(),
        Conll2002Reader.PARAM_HAS_TOKEN_NUMBER, true,
        Conll2002Reader.PARAM_HAS_HEADER, true,
        Conll2002Reader.PARAM_HAS_EMBEDDED_NAMED_ENTITY, true);

    List<CAS> casList = new ArrayList<>();
    while (reader.hasNext()) {
        // Add the CasMetadata type to the CAS
        List<TypeSystemDescription> typeSystems = new ArrayList<>();
        typeSystems.add(createTypeSystemDescription());
        typeSystems.add(CasMetadataUtils.getInternalTypeSystem());
        JCas cas = JCasFactory.createJCas(mergeTypeSystems(typeSystems));
        reader.getNext(cas.getCas());
        casList.add(cas.getCas());
    }
    return casList;
}
 
Example #6
Source File: AnnotationViewerMain.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Displays an error message to the user.
 * 
 * @param aThrowable
 *          Throwable whose message is to be displayed.
 */
public void displayError(Throwable aThrowable) {
  aThrowable.printStackTrace();

  String message = aThrowable.toString();

  // For UIMAExceptions or UIMARuntimeExceptions, add cause info.
  // We have to go through this nonsense to support Java 1.3.
  // In 1.4 all exceptions can have a cause, so this wouldn't involve
  // all of this typecasting.
  while ((aThrowable instanceof UIMAException) || (aThrowable instanceof UIMARuntimeException)) {
    if (aThrowable instanceof UIMAException) {
      aThrowable = ((UIMAException) aThrowable).getCause();
    } else if (aThrowable instanceof UIMARuntimeException) {
      aThrowable = ((UIMARuntimeException) aThrowable).getCause();
    }

    if (aThrowable != null) {
      message += ("\nCausedBy: " + aThrowable.toString());
    }
  }

  displayError(message);
}
 
Example #7
Source File: Html5Test.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateExternalIdFile() throws UIMAException {
  AnalysisEngine consumer =
      AnalysisEngineFactory.createEngine(
          Html5.class,
          TypeSystemSingleton.getTypeSystemDescriptionInstance(),
          Html5.PARAM_OUTPUT_FOLDER,
          outputFolder.getPath(),
          Html5.PARAM_USE_EXTERNAL_ID,
          true,
          Html5.PARAM_CONTENT_HASH_AS_ID,
          false);

  jCas.setDocumentText("Hello World!");
  DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs();
  da.setSourceUri("hello.txt");

  consumer.process(jCas);

  File f =
      new File(
          outputFolder, "734cad14909bedfafb5b273b6b0eb01fbfa639587d217f78ce9639bba41f4415.html");
  assertTrue(f.exists());
}
 
Example #8
Source File: SentenceFactoryTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void canCreateSentenceFromAnnotations() throws UIMAException {
  JCas jCas = JCasFactory.createJCas();

  addWordTokens(jCas);

  SentenceFactory factory = new SentenceFactory(jCas);

  List<OdinSentence> sentences = factory.create();
  assertEquals(1, sentences.size());
  Sentence sentence = sentences.get(0);

  assertEquals(
      ImmutableSet.of("This", "is", "a", "sentence", "."), ImmutableSet.copyOf(sentence.words()));

  assertTrue(Arrays.equals(new int[] {0, 5, 8, 10, 18}, sentence.startOffsets()));
  assertTrue(Arrays.equals(new int[] {4, 7, 9, 18, 19}, sentence.endOffsets()));

  assertEquals(
      ImmutableSet.of("this", "is", "a", "lemma", "."),
      ImmutableSet.copyOf(sentence.lemmas().get()));
  assertEquals(
      ImmutableSet.of("DT", "VBZ", "DT", "NN", "."), ImmutableSet.copyOf(sentence.tags().get()));
}
 
Example #9
Source File: JsonJCasConverterTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeserializeBlacklist() throws IOException, UIMAException {

  List<Class<? extends BaleenAnnotation>> blackList =
      ImmutableList.<Class<? extends BaleenAnnotation>>of(Person.class);

  final JsonJCasConverter serializer = createConverter();
  final JsonJCasConverter deserializer = createConverter(Collections.emptyList(), blackList);

  JCasSerializationTester testUtil = new JCasSerializationTester();

  final String json = serializer.serialise(testUtil.getIn());
  deserializer.deserialise(testUtil.getOut(), json);

  testUtil.assertTopLevel();
  testUtil.assertLocationMatches();
  assertFalse(JCasUtil.exists(testUtil.getOut(), Person.class));
}
 
Example #10
Source File: Html5Test.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateFile() throws UIMAException {
  AnalysisEngine consumer =
      AnalysisEngineFactory.createEngine(
          Html5.class,
          TypeSystemSingleton.getTypeSystemDescriptionInstance(),
          Html5.PARAM_OUTPUT_FOLDER,
          outputFolder.getPath());

  jCas.setDocumentText("Hello World!");
  DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs();
  da.setSourceUri("hello.txt");

  consumer.process(jCas);

  File f = new File(outputFolder, "hello.txt.html");
  assertTrue(f.exists());
}
 
Example #11
Source File: Launcher.java    From bluima with Apache License 2.0 6 votes vote down vote up
/**
 * @param args
 *            the relative path to a pipeline file. If none provided, lists
 *            all available pipelines and asks the user to make a choice.
 *            Then launches the pipeline.
 */
public static void main(String[] args) throws IOException, UIMAException,
        ParseException {

    // no pipeline --> list and ask
    if (args == null || args.length == 0) {
        String home = System.getProperty("basedir");
        listPipelinesAndAsk(new File(home + "/pipelines"));
    }

    // pipeline provided --> run it
    else if (args.length > 0) {

        List<String> cliArgs = new ArrayList<String>();
        for (int i = 1; i < args.length; i++) {
            cliArgs.add(args[i]);
        }
        runPipeline(new File(args[0]), cliArgs);
    }

    else {
        System.err.println("Please provide a script file");
    }
}
 
Example #12
Source File: NamedEntityLinkerTest.java    From inception with Apache License 2.0 6 votes vote down vote up
private List<CAS> loadData(Dataset ds, File ... files) throws UIMAException, IOException
{
    CollectionReader reader = createReader(
        Conll2002Reader.class,
        Conll2002Reader.PARAM_PATTERNS, files, 
        Conll2002Reader.PARAM_LANGUAGE, ds.getLanguage(), 
        Conll2002Reader.PARAM_COLUMN_SEPARATOR, Conll2002Reader.ColumnSeparators.TAB.getName(),
        Conll2002Reader.PARAM_HAS_TOKEN_NUMBER, true, 
        Conll2002Reader.PARAM_HAS_HEADER, true, 
        Conll2002Reader.PARAM_HAS_EMBEDDED_NAMED_ENTITY, true);

    List<CAS> casList = new ArrayList<>();
    while (reader.hasNext()) {
        JCas cas = JCasFactory.createJCas();
        reader.getNext(cas.getCas());
        casList.add(cas.getCas());
    }
    return casList;
}
 
Example #13
Source File: AnnotationViewerDialog.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Displays an error message to the user.
 * 
 * @param aThrowable
 *          Throwable whose message is to be displayed.
 */
public void displayError(Throwable aThrowable) {
  aThrowable.printStackTrace();

  String message = aThrowable.toString();

  // For UIMAExceptions or UIMARuntimeExceptions, add cause info.
  // We have to go through this nonsense to support Java 1.3.
  // In 1.4 all exceptions can have a cause, so this wouldn't involve
  // all of this typecasting.
  while ((aThrowable instanceof UIMAException) || (aThrowable instanceof UIMARuntimeException)) {
    if (aThrowable instanceof UIMAException) {
      aThrowable = ((UIMAException) aThrowable).getCause();
    } else if (aThrowable instanceof UIMARuntimeException) {
      aThrowable = ((UIMARuntimeException) aThrowable).getCause();
    }

    if (aThrowable != null) {
      message += ("\nCausedBy: " + aThrowable.toString());
    }
  }

  displayError(message);
}
 
Example #14
Source File: StructuralAnnotationsTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Test
public void testMain() throws UIMAException {
  final JCas jCas = JCasSingleton.getJCasInstance();
  final StructuralAnnotations sa = new StructuralAnnotations();

  final Map<String, Class<?>> expectedMain = new HashMap<>();
  expectedMain.put("Document", Document.class);
  expectedMain.put("SlideShow", SlideShow.class);
  expectedMain.put("SpreadSheet", SpreadSheet.class);
  expectedMain.put("Another", Document.class);

  for (final Map.Entry<String, Class<?>> e : expectedMain.entrySet()) {
    final Element anchor = new Element(Tag.valueOf("main"), "");
    anchor.attr("class", e.getKey());

    final AnnotationCollector collector = new AnnotationCollector();
    sa.map(jCas, anchor, collector);

    if (e.getValue() != null) {
      assertTrue(e.getValue().isInstance(collector.getAnnotations().get(0)));
    } else {
      assertNull(collector.getAnnotations());
    }
  }
}
 
Example #15
Source File: RemoteStringMatchingNerRecommender.java    From inception with Apache License 2.0 6 votes vote down vote up
public String predict(String aPredictionRequestJson) throws IOException, UIMAException,
    SAXException, RecommendationException
{
    PredictionRequest request = deserializePredictionRequest(aPredictionRequestJson);
    CAS cas = deserializeCas(request.getDocument().getXmi(), request.getTypeSystem());

    // Only work on real annotations, not on predictions
    Type predictedType = CasUtil.getType(cas, recommender.getLayer().getName());
    Feature feature = predictedType.getFeatureByBaseName(FEATURE_NAME_IS_PREDICTION);

    for (AnnotationFS fs : CasUtil.select(cas, predictedType)) {
        if (fs.getBooleanValue(feature)) {
            cas.removeFsFromIndexes(fs);
        }
    }

    recommendationEngine.predict(context, cas);

    return buildPredictionResponse(cas);
}
 
Example #16
Source File: TOLocationEntityTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void testIncorrect() throws UIMAException {
  jCas.setDocumentText("James sent a letter to Sam");
  process();

  assertAnnotations(0, Location.class);
}
 
Example #17
Source File: OpenNlpPosRecommenderTest.java    From inception with Apache License 2.0 5 votes vote down vote up
private List<CAS> loadData(Dataset ds, File ... files) throws UIMAException, IOException
{
    CollectionReader reader = createReader(Conll2006Reader.class,
        Conll2006Reader.PARAM_PATTERNS, files,
        Conll2006Reader.PARAM_LANGUAGE, ds.getLanguage());

    List<CAS> casList = new ArrayList<>();
    while (reader.hasNext()) {
        JCas cas = JCasFactory.createJCas();
        reader.getNext(cas.getCas());
        casList.add(cas.getCas());
    }
    return casList;
}
 
Example #18
Source File: RemoteStringMatchingNerRecommender.java    From inception with Apache License 2.0 5 votes vote down vote up
private CAS deserializeCas(String xmi, String typeSystem)
    throws SAXException, IOException, UIMAException
{
    CAS cas = buildCas(typeSystem);
    try (InputStream bais = new ByteArrayInputStream(xmi.getBytes(UTF_8))) {
        XmiCasDeserializer.deserialize(bais, cas);
    }
    return cas;
}
 
Example #19
Source File: SelectorTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void and() throws UIMAException {
  String h = "<a href=foo><img src=foo>Hello</img></a>";
  Node<Structure> doc = createStructure(h);

  Nodes<Structure> a = doc.select("Link[target=foo]");
  assertEquals(1, a.size());
  assertEquals("Link", a.first().getTypeName());

  Nodes<Structure> img = doc.select("Link [target=foo]");
  assertEquals(1, img.size());
  assertEquals("Figure", img.first().getTypeName());
}
 
Example #20
Source File: JcasPipelineBuilder.java    From bluima with Apache License 2.0 5 votes vote down vote up
private static AnalysisEngine[] createEngines(
        AnalysisEngineDescription... descs) throws UIMAException {
    AnalysisEngine[] engines = new AnalysisEngine[descs.length];
    for (int i = 0; i < engines.length; ++i) {
        if (descs[i].isPrimitive()) {
            engines[i] = AnalysisEngineFactory.createEngine(descs[i]);
        } else {
            engines[i] = AnalysisEngineFactory.createEngine(descs[i]);
        }
    }
    return engines;
}
 
Example #21
Source File: OpenNlpHelperTest.java    From bluima with Apache License 2.0 5 votes vote down vote up
private void testTokenizerImpl(AnalysisEngineDescription tokenizer)
        throws UIMAException, AnalysisEngineProcessException,
        ResourceInitializationException {
    // First test
    JCas jCas = UimaTests.getTestCas("the red cat is blue");
    SimplePipeline.runPipeline(jCas, tokenizer);

    Collection<Token> tokens = JCasUtil.select(jCas, Token.class);
    assertEquals(5, tokens.size());

    Iterator<Token> it = tokens.iterator();
    assertEquals("the", it.next().getCoveredText());

    // Second test
    String text = "CD44, at any stage, is a XYZ";
    String offsets = "0-4;4-5;6-8;9-12;13-18;18-19;20-22;23-24;25-28";
    jCas = UimaTests.getTestCas(text);
    SimplePipeline.runPipeline(jCas, tokenizer);

    tokens = JCasUtil.select(jCas, Token.class);

    Iterator<Token> tokenIt = tokens.iterator();
    String predictedOffsets = "";

    while (tokenIt.hasNext()) {
        Token t = tokenIt.next();
        predictedOffsets += (predictedOffsets.length() > 0) ? ";" : "";
        predictedOffsets += t.getBegin() + "-" + t.getEnd();
    }

    assertEquals(offsets, predictedOffsets);
}
 
Example #22
Source File: RecommendationServiceImpl.java    From inception with Apache License 2.0 5 votes vote down vote up
public CAS cloneAndMonkeyPatchCAS(Project aProject, CAS aSourceCas, CAS aTargetCas)
    throws UIMAException, IOException
{
    try (StopWatch watch = new StopWatch(log, "adding score features")) {
        TypeSystemDescription tsd = annoService.getFullProjectTypeSystem(aProject);

        for (AnnotationLayer layer : annoService.listAnnotationLayer(aProject)) {
            TypeDescription td = tsd.getType(layer.getName());

            if (td == null) {
                log.trace("Could not monkey patch type [{}]", layer.getName());
                continue;
            }

            for (FeatureDescription feature : td.getFeatures()) {
                String scoreFeatureName = feature.getName() + FEATURE_NAME_SCORE_SUFFIX;
                td.addFeature(scoreFeatureName, "Score feature", CAS.TYPE_NAME_DOUBLE);
                
                String scoreExplanationFeatureName = feature.getName() + 
                        FEATURE_NAME_SCORE_EXPLANATION_SUFFIX;
                td.addFeature(scoreExplanationFeatureName, "Score explanation feature", 
                        CAS.TYPE_NAME_STRING);
            }

            td.addFeature(FEATURE_NAME_IS_PREDICTION, "Is Prediction", CAS.TYPE_NAME_BOOLEAN);
        }

        annoService.upgradeCas(aSourceCas, aTargetCas, tsd);
    }

    return aTargetCas;
}
 
Example #23
Source File: DocumentFactoryTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void ensureSenteceOrderingCorrect() throws UIMAException {
  JCas jCas = JCasFactory.createJCas();
  jCas.setDocumentText("This is sentence one. This is sentence two. This is sentence three.");

  Annotations.createWordTokens(jCas);
  List<Sentence> sentences = Annotations.createSentences(jCas);

  OdinSentence sentence1 = mock(OdinSentence.class, "s1");
  OdinSentence sentence2 = mock(OdinSentence.class, "s2");
  OdinSentence sentence3 = mock(OdinSentence.class, "s3");

  when(sentenceFactory.create()).thenReturn(ImmutableList.of(sentence1, sentence2, sentence3));
  when(sentence1.getBaleenSentence()).thenReturn(sentences.get(0));
  when(sentence2.getBaleenSentence()).thenReturn(sentences.get(1));
  when(sentence3.getBaleenSentence()).thenReturn(sentences.get(2));

  DocumentFactory documentFactory = new DocumentFactory(jCas, sentenceFactory);

  OdinDocument document = documentFactory.create();
  OdinSentence[] odinSentences = (OdinSentence[]) document.sentences();
  assertEquals(3, odinSentences.length);

  assertEquals(sentences.get(0), odinSentences[0].getBaleenSentence());
  assertEquals(sentences.get(1), odinSentences[1].getBaleenSentence());
  assertEquals(sentences.get(2), odinSentences[2].getBaleenSentence());

  assertEquals(document.findSentence(sentences.get(0)), odinSentences[0]);
  assertEquals(document.findSentence(sentences.get(1)), odinSentences[1]);
  assertEquals(document.findSentence(sentences.get(2)), odinSentences[2]);
}
 
Example #24
Source File: GenericVehicleTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleVehicle() throws UIMAException {
  jCas.setDocumentText("Natalie owns a lime green van and a red jumbo jet.");
  createSentences(jCas);
  createWordTokens(jCas);

  processJCas();

  assertAnnotations(
      2,
      Vehicle.class,
      new TestVehicle(0, "lime green van", "ROAD"),
      new TestVehicle(1, "red jumbo jet", "AIR"));
}
 
Example #25
Source File: TypeUtilsTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void testRelation() throws UIMAException {
  JCas jCas = JCasSingleton.getJCasInstance();
  Class<?> c = TypeUtils.getType("Relation", jCas);

  assertEquals(Relation.class, c);
}
 
Example #26
Source File: JCasInformationCollectorTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void testCanCollectInformation() throws UIMAException {
  JCas jCas = JCasFactory.createJCas();

  jCas.setDocumentText(
      "Sir John Major was Prime Minister of the United Kingdom. Major became Prime Minister after Thatcher resigned.");

  List<Sentence> s = Annotations.createSentences(jCas);

  Person j1 = Annotations.createPerson(jCas, 0, 14, "Sir John Major");
  Person j2 = Annotations.createPerson(jCas, 59, 64, "Major");
  ReferenceTarget jRT = Annotations.createReferenceTarget(jCas, j1, j2);

  JCasInformationCollector collector = new JCasInformationCollector();

  Set<EntityInformation<Person>> entityInformations =
      collector.getEntityInformation(jCas, Person.class);

  assertEquals(1, entityInformations.size());
  EntityInformation<Person> entityInformation = entityInformations.iterator().next();

  assertEquals(jRT, entityInformation.getReferenceTarget());
  assertTrue(
      CollectionUtils.isEqualCollection(
          ImmutableSet.of(j1, j2), entityInformation.getMentions()));
  assertTrue(CollectionUtils.isEqualCollection(s, entityInformation.getSentences()));
}
 
Example #27
Source File: TaxonomyFactoryTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws UIMAException {
  String[] includedTypes = {Entity.class.getName(), Event.class.getName()};
  typeSystem = JCasFactory.createJCas().getTypeSystem();
  taxonomyFactory = new TaxonomyFactory(typeSystem, includedTypes);
  taxonomy = taxonomyFactory.create();
}
 
Example #28
Source File: ManualEvaluation.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
private static void evaluateTrainedFile(String fileName) throws IOException, UIMAException {
        Path directoryPath;
        String trainedFile = directory + fileName;
        if (singleLabelling) {
            directoryPath = Paths.get(directory, fileName + "-singleLabel-evaluation");

            Path trainedPath = generateSingleLabeledFile(trainedFile);
            trainedFile = trainedPath.toString();
        } else {
            directoryPath = Paths.get(trainedFile + "-evaluation");
        }

        Files.createDirectory(directoryPath);
//         produce jcas with trained file
        CollectionReaderDescription reader = createReaderDescription(Conll2003AidaReader.class,
                PARAM_LANGUAGE, language,
                Conll2003AidaReader.PARAM_SINGLE_FILE, true,
                Conll2003AidaReader.PARAM_ORDER, WORD_POSITION_TYPE,
                PARAM_SOURCE_LOCATION, trainedFile,
                Conll2003AidaReader.PARAM_MANUAL_TOKENS_NER, false,
                Conll2003AidaReader.PARAM_NAMED_ENTITY_PER_TOKEN, true);

        AnalysisEngineDescription mentionSpansWriter = createEngineDescription(MentionSpansEvaluationWriter.class,
                MentionSpansEvaluationWriter.PARAM_OUTPUT_FILE, directoryPath.toString() + "/ManualSpanEvaluation.txt");

        System.out.println("Running mention spans evaluation");
        SimplePipeline.runPipeline(reader, manualAnnotatorPerMentionDescription, nerMentionAnnotatorDescription, mentionSpansWriter);

        AnalysisEngineDescription predictionsWriter = createEngineDescription(PredictionsWriter.class,
                PredictionsWriter.PARAM_LANGUAGE, language,
                PredictionsWriter.PARAM_MENTION_OUTPUT_FILE, directoryPath.toString() + "/ConllMentionEvaluation.txt",
                PredictionsWriter.PARAM_TOKEN_OUTPUT_FILE, directoryPath.toString() + "/ConllTokenEvaluation.txt",
                PredictionsWriter.PARAM_KNOW_NER, true,
                PredictionsWriter.PARAM_POSITION_TYPE,  ConllEvaluation.TrainedPositionType.ORIGINAL);

        System.out.println("Running tokens and mentions evaluation");
        SimplePipeline.runPipeline(reader, manualAnnotatorPerTokenDescription, predictionsWriter);
    }
 
Example #29
Source File: AutomationUtil.java    From webanno with Apache License 2.0 5 votes vote down vote up
/**
 * Repeat annotation will repeat annotations of same pattern to all documents on the project
 * load CAS from document in case no initial CORRECTION_CAS is not created before
 */
public static void loadDocument(SourceDocument aDocument,
        AnnotationSchemaService annotationService, DocumentService aDocumentService,
        CorrectionDocumentService aCorrectionDocumentService, User logedInUser)
    throws UIMAException, ClassNotFoundException, IOException, AnnotationException
{
    CAS cas = null;
    if (!aCorrectionDocumentService.existsCorrectionCas(aDocument)) {
        try {
            AnnotationDocument logedInUserAnnotationDocument = aDocumentService
                    .getAnnotationDocument(aDocument, logedInUser);
            cas = aDocumentService.readAnnotationCas(logedInUserAnnotationDocument);
            annotationService.upgradeCas(cas, logedInUserAnnotationDocument);
            aCorrectionDocumentService.writeCorrectionCas(cas, aDocument);
        }
        catch (DataRetrievalFailureException | NoResultException e) {
            cas = aDocumentService.readAnnotationCas(
                    aDocumentService.createOrGetAnnotationDocument(aDocument, logedInUser));
            // upgrade this cas
            annotationService.upgradeCas(cas,
                    aDocumentService.createOrGetAnnotationDocument(aDocument, logedInUser));
            aCorrectionDocumentService.writeCorrectionCas(cas, aDocument);
        }
    }
    else {
        cas = aCorrectionDocumentService.readCorrectionCas(aDocument);
        // upgrade this automation cas
        aCorrectionDocumentService.upgradeCorrectionCas(cas, aDocument);
    }
}
 
Example #30
Source File: NPVNPTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void test3() throws UIMAException {
  createPOS();

  Person person = new Person(jCas, 0, 2); // He
  person.addToIndexes();

  Money money = new Money(jCas, 54, 71); // only $1.8 billion
  money.addToIndexes();

  Temporal date = new Temporal(jCas, 75, 84); // September
  date.addToIndexes();

  processJCas();

  assertEquals(2, JCasUtil.select(jCas, Relation.class).size());

  Relation r1 = JCasUtil.selectByIndex(jCas, Relation.class, 0);
  assertEquals("reckons", r1.getValue());
  assertEquals(person, r1.getSource());
  assertEquals("uk.gov.dstl.baleen.types.semantic.Entity", r1.getTarget().getTypeName());
  assertEquals("the current account deficit", r1.getTarget().getCoveredText());

  Relation r2 = JCasUtil.selectByIndex(jCas, Relation.class, 1);
  assertEquals("will narrow to", r2.getValue());
  assertEquals("uk.gov.dstl.baleen.types.semantic.Entity", r2.getSource().getTypeName());
  assertEquals("the current account deficit", r2.getSource().getCoveredText());
  assertEquals(money, r2.getTarget());
}