All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.stanford.nlp.coref.statistical.FeatureExtractorRunner Maven / Gradle / Ivy

Go to download

Stanford CoreNLP provides a set of natural language analysis tools which can take raw English language text input and give the base forms of words, their parts of speech, whether they are names of companies, people, etc., normalize dates, times, and numeric quantities, mark up the structure of sentences in terms of phrases and word dependencies, and indicate which noun phrases refer to the same entities. It provides the foundational building blocks for higher level text understanding applications.

There is a newer version: 4.5.7
Show newest version
package edu.stanford.nlp.coref.statistical;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import edu.stanford.nlp.coref.CorefDocumentProcessor;
import edu.stanford.nlp.coref.data.Dictionaries;
import edu.stanford.nlp.coref.data.Document;
import edu.stanford.nlp.io.IOUtils;
import edu.stanford.nlp.util.Pair;

/**
 * Runs feature extraction over coreference documents.
 * @author Kevin Clark
 */
public class FeatureExtractorRunner implements CorefDocumentProcessor {
  private final FeatureExtractor extractor;
  private final Compressor compressor;

  private final Map, Boolean>> dataset;
  private final List documents;

  public FeatureExtractorRunner(Properties props, Dictionaries dictionaries) {
    documents = new ArrayList<>();
    compressor = new Compressor<>();
    extractor = new FeatureExtractor(props, dictionaries, compressor);
    try {
      dataset = IOUtils.readObjectFromFile(StatisticalCorefTrainer.datasetFile);
    } catch(Exception e) {
      throw new RuntimeException("Error initializing FeatureExtractorRunner", e);
    }
  }

  @Override
  public void process(int id, Document document) {
    if (dataset.containsKey(id)) {
      documents.add(extractor.extract(id, document, dataset.get(id)));
    }
  }

  @Override
  public void finish() throws Exception {
    IOUtils.writeObjectToFile(documents, StatisticalCorefTrainer.extractedFeaturesFile);
    IOUtils.writeObjectToFile(compressor, StatisticalCorefTrainer.compressorFile);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy