Package org.uimafit.factory

Examples of org.uimafit.factory.AggregateBuilder


  }

  @Override
  protected AnnotationStatistics<String> test(CollectionReader collectionReader, File directory)
      throws Exception {
    AggregateBuilder aggregateBuilder = this.getPreprocessorAggregateBuilder();
    aggregateBuilder.add(CopyFromGold.getDescription(EventMention.class, TimeMention.class));
   
    aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(
        RemoveCrossSentenceRelations.class,
        RemoveCrossSentenceRelations.PARAM_SENTENCE_VIEW,
        CAS.NAME_DEFAULT_SOFA,
        RemoveCrossSentenceRelations.PARAM_RELATION_VIEW,
        GOLD_VIEW_NAME));
    if (this.useClosure) {
      aggregateBuilder.add(
          AnalysisEngineFactory.createPrimitiveDescription(AddClosure.class),//AnalysisEngineFactory.createPrimitiveDescription(AddTransitiveContainsRelations.class),
          CAS.NAME_DEFAULT_SOFA,
          GOLD_VIEW_NAME);
         
//      aggregateBuilder.add(
//          AnalysisEngineFactory.createPrimitiveDescription(AddContain2Overlap.class),
//          CAS.NAME_DEFAULT_SOFA,
//          GOLD_VIEW_NAME);
      //      aggregateBuilder.add(
      //          AnalysisEngineFactory.createPrimitiveDescription(AddTransitiveBeforeAndOnRelations.class),
      //          CAS.NAME_DEFAULT_SOFA,
      //          GOLD_VIEW_NAME);
    }
   
//    aggregateBuilder.add(
//        AnalysisEngineFactory.createPrimitiveDescription(RemoveNonContainsRelations.class,
//            RemoveNonContainsRelations.PARAM_RELATION_VIEW,
//            GOLD_VIEW_NAME));
    aggregateBuilder.add(
        AnalysisEngineFactory.createPrimitiveDescription(RemoveEventEventRelations.class),
        CAS.NAME_DEFAULT_SOFA,
        GOLD_VIEW_NAME);

    aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(RemoveRelations.class));
    aggregateBuilder.add(this.baseline ? RecallBaselineEventTimeRelationAnnotator.createAnnotatorDescription(directory) :
      EventTimeRelationAnnotator.createAnnotatorDescription(directory));
    if(this.i2b2Output != null){
      aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(WriteI2B2XML.class, WriteI2B2XML.PARAM_OUTPUT_DIR, this.i2b2Output), "TimexView", CAS.NAME_DEFAULT_SOFA);
    }
    if (this.useClosure) {//add closure for system output
      aggregateBuilder.add(
          AnalysisEngineFactory.createPrimitiveDescription(AddClosure.class),//AnalysisEngineFactory.createPrimitiveDescription(AddTransitiveContainsRelations.class),
          GOLD_VIEW_NAME,
          CAS.NAME_DEFAULT_SOFA
          );
    }
    Function<BinaryTextRelation, ?> getSpan = new Function<BinaryTextRelation, HashableArguments>() {
      public HashableArguments apply(BinaryTextRelation relation) {
        return new HashableArguments(relation);
      }
    };
    Function<BinaryTextRelation, String> getOutcome = AnnotationStatistics.annotationToFeatureValue("category");

    AnnotationStatistics<String> stats = new AnnotationStatistics<String>();
    JCasIterable jcasIter =new JCasIterable(collectionReader, aggregateBuilder.createAggregate());
    JCas jCas = null;
    while(jcasIter.hasNext()) {
      jCas = jcasIter.next();
      JCas goldView = jCas.getView(GOLD_VIEW_NAME);
      JCas systemView = jCas.getView(CAS.NAME_DEFAULT_SOFA);
View Full Code Here


    }
  }

  @Override
  protected void train(CollectionReader collectionReader, File directory) throws Exception {
    AggregateBuilder aggregateBuilder = this.getPreprocessorAggregateBuilder();
    aggregateBuilder.add(CopyFromGold.getDescription(EventMention.class));
    aggregateBuilder.add(CopyFromGold.getDescription(EventProperties.class));
    SimplePipeline.runPipeline(collectionReader, aggregateBuilder.createAggregate());
  }
View Full Code Here

  @Override
  protected Map<String, AnnotationStatistics<String>> test(
      CollectionReader collectionReader,
      File directory) throws Exception {
    AggregateBuilder aggregateBuilder = this.getPreprocessorAggregateBuilder();
    aggregateBuilder.add(CopyFromGold.getDescription(EventMention.class));
    aggregateBuilder.add(CopyFromGold.getDescription(TimeMention.class));
    aggregateBuilder.add(SentenceAnnotator.getDescription());
    aggregateBuilder.add(TokenAnnotator.getDescription());
    aggregateBuilder.add(PosTaggerAnnotator.getDescription());
    aggregateBuilder.add(DefaultSnowballStemmer.getDescription("English"));
    aggregateBuilder.add(ParserAnnotator.getDescription());
    aggregateBuilder.add(EventToClearTKEventAnnotator.getAnnotatorDescription());//for every cTakes eventMention, create a cleartk event
    aggregateBuilder.add(ClearTKDocumentCreationTimeAnnotator.getAnnotatorDescription());//for every jCAS create an empty DCT, and add it to index
    aggregateBuilder.add(EventTenseAnnotator.FACTORY.getAnnotatorDescription("/org/cleartk/timeml/event/eventtenseannotator/model.jar"));
    aggregateBuilder.add(EventAspectAnnotator.FACTORY.getAnnotatorDescription("/org/cleartk/timeml/event/eventaspectannotator/model.jar"));
    aggregateBuilder.add(EventClassAnnotator.FACTORY.getAnnotatorDescription("/org/cleartk/timeml/event/eventclassannotator/model.jar"));
    aggregateBuilder.add(EventPolarityAnnotator.FACTORY.getAnnotatorDescription("/org/cleartk/timeml/event/eventpolarityannotator/model.jar"));
    aggregateBuilder.add(EventModalityAnnotator.FACTORY.getAnnotatorDescription("/org/cleartk/timeml/event/eventmodalityannotator/model.jar"));
    aggregateBuilder.add(TemporalLinkEventToDocumentCreationTimeAnnotator.FACTORY.getAnnotatorDescription("/org/cleartk/timeml/tlink/temporallinkeventtodocumentcreationtimeannotator/model.jar"));
    aggregateBuilder.add(ClearTKDocTimeRelAnnotator.getAnnotatorDescription());// for every tlink, check if it cover and event, add the tlink type to the event's docTimeRel attribute

    Function<EventMention, ?> eventMentionToSpan = AnnotationStatistics.annotationToSpan();
    Map<String, Function<EventMention, String>> propertyGetters;
    propertyGetters = new HashMap<String, Function<EventMention, String>>();
    for (String name : PROPERTY_NAMES) {
      propertyGetters.put(name, getPropertyGetter(name));
    }

    Map<String, AnnotationStatistics<String>> statsMap = new HashMap<String, AnnotationStatistics<String>>();
    statsMap.put(DOC_TIME_REL, new AnnotationStatistics<String>());
    for (JCas jCas : new JCasIterable(collectionReader, aggregateBuilder.createAggregate())) {
      JCas goldView = jCas.getView(GOLD_VIEW_NAME);
      JCas systemView = jCas.getView(CAS.NAME_DEFAULT_SOFA);
      String text = goldView.getDocumentText();
      for (Segment segment : JCasUtil.select(jCas, Segment.class)) {
        if (!THYMEData.SEGMENTS_TO_SKIP.contains(segment.getId())) {
View Full Code Here

  protected abstract void trainAndPackage(File directory) throws Exception;

  @Override
  protected void train(CollectionReader collectionReader, File directory) throws Exception {
    AggregateBuilder aggregateBuilder = this.getPreprocessorAggregateBuilder();
    aggregateBuilder.add(CopyFromGold.getDescription(this.annotationClass));
    aggregateBuilder.add(this.getDataWriterDescription(directory), "TimexView", CAS.NAME_DEFAULT_SOFA);
    SimplePipeline.runPipeline(collectionReader, aggregateBuilder.createAggregate());
    this.trainAndPackage(directory);
  }
View Full Code Here

  protected abstract Collection<? extends Annotation> getSystemAnnotations(JCas jCas, Segment segment);

  @Override
  protected AnnotationStatistics<String> test(CollectionReader collectionReader, File directory)
      throws Exception {
    AggregateBuilder aggregateBuilder = this.getPreprocessorAggregateBuilder();
    aggregateBuilder.add(this.getAnnotatorDescription(directory), "TimexView", CAS.NAME_DEFAULT_SOFA);
    if(this.i2b2Output != null){
      aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(WriteI2B2XML.class, WriteI2B2XML.PARAM_OUTPUT_DIR, this.i2b2Output), "TimexView", CAS.NAME_DEFAULT_SOFA);
    }
    AnnotationStatistics<String> stats = new AnnotationStatistics<String>();
    Ordering<Annotation> bySpans = Ordering.<Integer> natural().lexicographical().onResultOf(
        new Function<Annotation, List<Integer>>() {
          @Override
          public List<Integer> apply(Annotation annotation) {
            return Arrays.asList(annotation.getBegin(), annotation.getEnd());
          }
        });
    for (JCas jCas : new JCasIterable(collectionReader, aggregateBuilder.createAggregate())) {
      JCas goldView = jCas.getView(GOLD_VIEW_NAME);
      JCas systemView = jCas.getView(CAS.NAME_DEFAULT_SOFA);
      for (Segment segment : JCasUtil.select(jCas, Segment.class)) {
        if (!THYMEData.SEGMENTS_TO_SKIP.contains(segment.getId())) {
          Collection<? extends Annotation> goldAnnotations = this.getGoldAnnotations(goldView, segment);
View Full Code Here

   
    JCasIterable[] casIters = new JCasIterable[nFolds];
    for (int fold = 0; fold < nFolds; ++fold) {
      List<Integer> xfoldTrain = selectTrainItems(allTrain, nFolds, fold);
      List<Integer> xfoldTest = selectTestItems(allTrain, nFolds, fold);
      AggregateBuilder aggregateBuilder = this.getPreprocessorAggregateBuilder();
      File modelDirectory = getModelDirectory(new File("target/eval/time-spans/fold_"+fold));
      for (Class<? extends JCasAnnotator_ImplBase> annotatorClass : annotatorClasses) {
        EvaluationOfTimeSpans evaluation = new EvaluationOfTimeSpans(
            new File("target/eval/time-spans/" ),
            this.rawTextDirectory,
            this.xmlDirectory,
            this.xmlFormat,
            this.xmiDirectory,
            this.treebankDirectory,
            1,
            0,
            annotatorClass,
            false,
            annotatorTrainingArguments.get(annotatorClass));
        evaluation.prepareXMIsFor(allTrain);
        String name = String.format("%s.errors", annotatorClass.getSimpleName());
        evaluation.setLogging(Level.FINE, new File("target/eval", name));

        // train on 4 of the folds of the training data:
        evaluation.train(evaluation.getCollectionReader(xfoldTrain), modelDirectory);
        if(fold == 0){
          // train the main model as well:
          evaluation.train(evaluation.getCollectionReader(allTrain), directory);
        }
       
      }
      casIters[fold] = new JCasIterable(getCollectionReader(xfoldTest), aggregateBuilder.createAggregate());
    }
    // run meta data-writer for this fold:
    AggregateBuilder writerBuilder = new AggregateBuilder();
    writerBuilder.add(CopyFromGold.getDescription(TimeMention.class));
    writerBuilder.add(this.getDataWriterDescription(directory));
    AnalysisEngine writer = writerBuilder.createAggregate();
    for(JCasIterable casIter : casIters){
      for(JCas jcas : casIter){
        SimplePipeline.runPipeline(jcas, writer);
      }
    }
View Full Code Here

    assertTrue(tokens.get(29).getCanonicalForm() == null);
   
  }
 
  public static AnalysisEngineDescription getPrerequisitePipeline() throws ResourceInitializationException{
    AggregateBuilder builder = new AggregateBuilder();
    builder.add(SimpleSegmentAnnotator.createAnnotatorDescription());
    builder.add(SentenceDetector.createAnnotatorDescription());
    builder.add(TokenizerAnnotatorPTB.createAnnotatorDescription());
    return builder.createAggregateDescription();
  }
View Full Code Here

    builder.add(TokenizerAnnotatorPTB.createAnnotatorDescription());
    return builder.createAggregateDescription();
  }
 
  public static AnalysisEngineDescription getDefaultPipeline() throws ResourceInitializationException, URISyntaxException{
    AggregateBuilder builder = new AggregateBuilder();
    builder.add(getPrerequisitePipeline());
    builder.add(LvgAnnotator.createAnnotatorDescription());
    return builder.createAggregateDescription();
  }
View Full Code Here

        + "The patient was well till 6 months ago, when he started having a little blood with stool.";
    JCas jcas = JCasFactory.createJCas();
    jcas.setDocumentText(note);

    // Get the default pipeline
    AggregateBuilder builder = new AggregateBuilder();
    builder.add(ClinicalPipelineFactory.getTokenProcessingPipeline());
    builder.add(AnalysisEngineFactory
        .createPrimitiveDescription(CopyNPChunksToLookupWindowAnnotations.class));
    builder.add(AnalysisEngineFactory
        .createPrimitiveDescription(RemoveEnclosedLookupWindows.class));
    // Commented out the Dictionary lookup for the test
    // Uncomment and set -Dctakes.umlsuser and -Dctakes.umlspw env params if
    // needed
    // builder.add(UmlsDictionaryLookupAnnotator.createAnnotatorDescription());
    builder.add(ClearNLPDependencyParserAE.createAnnotatorDescription());

    // Add EventAnnotator
    builder.add(EventAnnotator
        .createAnnotatorDescription("/org/apache/ctakes/temporal/ae/eventannotator/model.jar"));

    SimplePipeline.runPipeline(jcas, builder.createAggregateDescription());

    Collection<EventMention> mentions = JCasUtil.select(jcas,
        EventMention.class);

    ArrayList<String> temp = new ArrayList<>();
View Full Code Here

        + "The patient was well till 6 months ago, when he started having a little blood with stool.";
    JCas jcas = JCasFactory.createJCas();
    jcas.setDocumentText(note);

    // Get the default pipeline with umls dictionary lookup
    AggregateBuilder builder = new AggregateBuilder();
    builder.add(ClinicalPipelineFactory.getTokenProcessingPipeline());
    builder.add(AnalysisEngineFactory
        .createPrimitiveDescription(CopyNPChunksToLookupWindowAnnotations.class));
    builder.add(AnalysisEngineFactory
        .createPrimitiveDescription(RemoveEnclosedLookupWindows.class));
    // Commented out the Dictionary lookup for the test
    // Uncomment and set -Dctakes.umlsuser and -Dctakes.umlspw env params if
    // needed
    // builder.add(UmlsDictionaryLookupAnnotator.createAnnotatorDescription());
    builder.add(ClearNLPDependencyParserAE.createAnnotatorDescription());

    // Add BackwardsTimeAnnotator
    builder.add(BackwardsTimeAnnotator
        .createAnnotatorDescription("/org/apache/ctakes/temporal/ae/timeannotator/model.jar"));

    SimplePipeline.runPipeline(jcas, builder.createAggregateDescription());

    Collection<TimeMention> mentions = JCasUtil.select(jcas,
        TimeMention.class);

    ArrayList<String> temp = new ArrayList<>();
View Full Code Here

TOP

Related Classes of org.uimafit.factory.AggregateBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.