Package org.uimafit.factory

Examples of org.uimafit.factory.AggregateBuilder


        paths);
  }

  @Override
  public void train(CollectionReader collectionReader, File directory) throws Exception {
    AggregateBuilder builder = new AggregateBuilder();
    // replace cTAKES entity mentions and modifiers in the system view with the gold annotations
    builder.add(AnalysisEngineFactory.createPrimitiveDescription(ReplaceCTakesEntityMentionsAndModifiersWithGold.class));
    // add the relation extractor, configured for training mode
    AnalysisEngineDescription classifierAnnotator = AnalysisEngineFactory.createPrimitiveDescription(
        this.classifierAnnotatorClass,
        this.additionalParameters);
    ConfigurationParameterFactory.addConfigurationParameters(
        classifierAnnotator,
        RelationExtractorAnnotator.PARAM_GOLD_VIEW_NAME,
        RelationExtractorEvaluation.GOLD_VIEW_NAME,
        DefaultDataWriterFactory.PARAM_DATA_WRITER_CLASS_NAME,
        this.dataWriterClass,
        DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY,
        directory.getPath());
    builder.add(classifierAnnotator);

    // run the data-writing pipeline
    SimplePipeline.runPipeline(collectionReader, builder.createAggregateDescription());

    // train the classifier and package it into a .jar file
    HideOutput hider = new HideOutput();
    JarClassifierBuilder.trainAndPackage(directory, this.trainingArguments);
    hider.restoreOutput();
View Full Code Here


  }

  @Override
  protected AnnotationStatistics<String> test(CollectionReader collectionReader, File directory)
      throws Exception {
    AggregateBuilder builder = new AggregateBuilder();
    // replace cTAKES entity mentions and modifiers in the system view with the gold annotations
    builder.add(AnalysisEngineFactory.createPrimitiveDescription(ReplaceCTakesEntityMentionsAndModifiersWithGold.class));
    // add the relation extractor, configured for classification mode
    AnalysisEngineDescription classifierAnnotator = AnalysisEngineFactory.createPrimitiveDescription(
        this.classifierAnnotatorClass,
        this.additionalParameters);
    ConfigurationParameterFactory.addConfigurationParameters(
        classifierAnnotator,
        GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
        new File(directory, "model.jar").getPath());
    builder.add(classifierAnnotator);

    // statistics will be based on the "category" feature of the BinaryTextRelations
    AnnotationStatistics<String> stats = new AnnotationStatistics<String>();
    Function<BinaryTextRelation, HashableArguments> getSpan = new Function<BinaryTextRelation, HashableArguments>() {
      @Override
      public HashableArguments apply(BinaryTextRelation relation) {
        return new HashableArguments(relation);
      }
    };
    Function<BinaryTextRelation, String> getOutcome = AnnotationStatistics.annotationToFeatureValue("category");

    // calculate statistics, iterating over the results of the classifier
    AnalysisEngine engine = builder.createAggregate();
    for (JCas jCas : new JCasIterable(collectionReader, engine)) {

      // get the gold view
      JCas goldView;
      try {
View Full Code Here

 
 
  public static AnalysisEngine createGoldAnnotator(File knowtatorXMLDirectory)
      throws ResourceInitializationException {
    // pipeline to read manual annotations into the gold view, not the default view
        AggregateBuilder goldAnnotatorBuilder = new AggregateBuilder();
        goldAnnotatorBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(
            ViewCreatorAnnotator.class,
            ViewCreatorAnnotator.PARAM_VIEW_NAME,
            RelationExtractorEvaluation.GOLD_VIEW_NAME));
        goldAnnotatorBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(
            CopyDocumentTextToGoldView.class));
        goldAnnotatorBuilder.add(
            AnalysisEngineFactory.createPrimitiveDescription(DocumentIDAnnotator.class),
            CAS.NAME_DEFAULT_SOFA, RelationExtractorEvaluation.GOLD_VIEW_NAME);
        goldAnnotatorBuilder.add(
            AnalysisEngineFactory.createPrimitiveDescription(
              GoldEntityAndRelationReader.class,
              GoldEntityAndRelationReader.PARAM_INPUTDIR,
              knowtatorXMLDirectory.getPath()),
            CAS.NAME_DEFAULT_SOFA, RelationExtractorEvaluation.GOLD_VIEW_NAME);
        AnalysisEngine goldAnnotator = goldAnnotatorBuilder.createAggregate();
        return goldAnnotator;
  }
View Full Code Here

    // Write standalone description files
    clearparserDepParserDesc.toXML(new FileOutputStream(new File(options.outputRoot, "ClearParserDependencyParserAE.xml")));
    clearparserSRLDesc.toXML(new FileOutputStream(new File(options.outputRoot, "ClearParserSemanticRoleLabelerAE.xml")));

    // Write aggregate plaintext description files
    AggregateBuilder aggregateBuilder = getPlaintextAggregateBuilder();
    writeAggregateDescriptions(aggregateBuilder, clearparserDepParserDesc, clearparserSRLDesc, options.outputRoot, "PlaintextAggregate.xml");

    // Write aggregate tokenized description files
    aggregateBuilder = getTokenizedAggregateBuilder();
    writeAggregateDescriptions(aggregateBuilder, clearparserDepParserDesc, clearparserSRLDesc, options.outputRoot, "TokenizedAggregate.xml");
View Full Code Here

   * @return
   * @throws InvalidXMLException
   * @throws IOException
   */
  public static AggregateBuilder getPlaintextAggregateBuilder() throws InvalidXMLException, IOException {
    AggregateBuilder aggregateBuilder = new AggregateBuilder();
    aggregateBuilder.add(loadDescription(SIMPLE_SEGMENTER_PATH));
    aggregateBuilder.add(loadDescription(SENTENCE_DETECTOR_PATH));
    aggregateBuilder.add(loadDescription(TOKENIZER_PATH));
    aggregateBuilder.add(loadDescription(LVG_BASE_TOKEN_ANNOTATOR_PATH));
    aggregateBuilder.add(loadDescription(POS_TAGGER_PATH));
    return aggregateBuilder;
  }
View Full Code Here

   * @return
   * @throws InvalidXMLException
   * @throws IOException
   */
  public static AggregateBuilder getTokenizedAggregateBuilder() throws InvalidXMLException, IOException {
    AggregateBuilder aggregateBuilder = new AggregateBuilder();
    aggregateBuilder.add(loadDescription(SIMPLE_SEGMENTER_PATH));
    aggregateBuilder.add(loadDescription(LVG_BASE_TOKEN_ANNOTATOR_PATH));
    return aggregateBuilder;
  }
View Full Code Here

   * @return
   * @throws InvalidXMLException
   * @throws IOException
   */
  public static AggregateBuilder getTokenizedInfPosAggregateBuilder() throws InvalidXMLException, IOException {
    AggregateBuilder aggregateBuilder = new AggregateBuilder();
    aggregateBuilder.add(loadDescription(SIMPLE_SEGMENTER_PATH));
    aggregateBuilder.add(loadDescription(LVG_BASE_TOKEN_ANNOTATOR_PATH));
    aggregateBuilder.add(loadDescription(POS_TAGGER_PATH));
    return aggregateBuilder;
  }
View Full Code Here

public class RelationExtractorAnnotatorsTest {

  @Test
  public void test() throws Exception {
    // create the pipeline
    AggregateBuilder builder = new AggregateBuilder();
    builder.add(this.findDescription(ModifierExtractorAnnotator.class));
    builder.add(this.findDescription(DegreeOfRelationExtractorAnnotator.class));
    builder.add(this.findDescription(EntityMentionPairRelationExtractorAnnotator.class));
    AnalysisEngine engine = builder.createAggregate();
    JCas jCas = engine.newJCas();

    // populate the CAS with an example sentence
    // TODO: add annotations to support phrase chunk and dependency features
    TokenBuilder<BaseToken, Sentence> tokenBuilder = new TokenBuilder<BaseToken, Sentence>(
View Full Code Here

    writeDesc(options.descDir, "DegreeOfRelationExtractorAnnotator", degreeOfRelationExtractorDesc);
    AnalysisEngineDescription emPairRelationExtractorDesc = trainRelationExtractor(modelsDirEMPair, trainFiles, EntityMentionPairRelationExtractorAnnotator.class, dataWriterClass, emPairParams);
    writeDesc(options.descDir, "EntityMentionPairRelationExtractorAnnotator", emPairRelationExtractorDesc);

    // create the aggregate description
    AggregateBuilder builder = new AggregateBuilder();
    File preprocessDescFile = new File("desc/analysis_engine/RelationExtractorPreprocessor.xml");
    XMLParser parser = UIMAFramework.getXMLParser();
    XMLInputSource source = new XMLInputSource(preprocessDescFile);
    builder.add(parser.parseAnalysisEngineDescription(source));
    builder.add(modifierExtractorDesc);
    builder.add(degreeOfRelationExtractorDesc);
    builder.add(emPairRelationExtractorDesc);
    AnalysisEngineDescription aggregateDescription = builder.createAggregateDescription();
   
    // write out the XML version of the aggregate description
    writeDesc(options.descDir, "RelationExtractorAggregate", aggregateDescription);
  }
View Full Code Here

  @Override
  protected void train(CollectionReader collectionReader, File directory) throws Exception {
    //    if(this.baseline) return;
    if(this.skipTrain) return;
    AggregateBuilder aggregateBuilder = this.getPreprocessorAggregateBuilder();
    aggregateBuilder.add(CopyFromGold.getDescription(EventMention.class, TimeMention.class, BinaryTextRelation.class));
    aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(RemoveCrossSentenceRelations.class));
    if(!this.useGoldAttributes){
      aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(RemoveGoldAttributes.class));
    }
    if (this.useClosure) {
      aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(AddClosure.class));//aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(AddTransitiveContainsRelations.class));
//      aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(AddContain2Overlap.class));
      //      aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(AddTransitiveBeforeAndOnRelations.class));
    }
//    aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(RemoveNonContainsRelations.class));
    aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(AddFlippedOverlap.class));//add flipped overlap instances to training data
   
    aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(RemoveEventEventRelations.class));
    aggregateBuilder.add(EventTimeRelationAnnotator.createDataWriterDescription(
        //                LIBSVMStringOutcomeDataWriter.class,
        TKSVMlightStringOutcomeDataWriter.class,
        //        TKLIBSVMStringOutcomeDataWriter.class,
        //        SVMlightStringOutcomeDataWriter.class,       
        directory,
        params.probabilityOfKeepingANegativeExample));
    SimplePipeline.runPipeline(collectionReader, aggregateBuilder.createAggregate());
    String[] optArray;

    if(this.kernelParams == null){
      ArrayList<String> svmOptions = new ArrayList<String>();
      svmOptions.add("-c"); svmOptions.add(""+params.svmCost);        // svm cost
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.