Examples of ChunkerME


Examples of opennlp.tools.chunker.ChunkerME

    if(params.getDetailedF()) {
      detailedFMeasureListener = new ChunkerDetailedFMeasureListener();
      listeners.add(detailedFMeasureListener);
    }

    ChunkerEvaluator evaluator = new ChunkerEvaluator(new ChunkerME(model,
        ChunkerME.DEFAULT_BEAM_SIZE),
        listeners.toArray(new ChunkerEvaluationMonitor[listeners.size()]));

    final PerformanceMonitor monitor = new PerformanceMonitor("sent");
View Full Code Here

Examples of opennlp.tools.chunker.ChunkerME

    if (args.length != 1) {
      System.out.println(getHelp());
    } else {
      ChunkerModel model = new ChunkerModelLoader().load(new File(args[0]));

      ChunkerME chunker = new ChunkerME(model, ChunkerME.DEFAULT_BEAM_SIZE);

      ObjectStream<String> lineStream = null;
      PerformanceMonitor perfMon = null;

      try {
        lineStream = new PlainTextByLineStream(new SystemInputStreamFactory(), SystemInputStreamFactory.encoding());
        perfMon = new PerformanceMonitor(System.err, "sent");
        String line;
        while ((line = lineStream.read()) != null) {

          POSSample posSample;
          try {
            posSample = POSSample.parse(line);
          } catch (InvalidFormatException e) {
            System.err.println("Invalid format:");
            System.err.println(line);
            continue;
          }

          String[] chunks = chunker.chunk(posSample.getSentence(),
                  posSample.getTags());

          System.out.println(new ChunkSample(posSample.getSentence(),
                  posSample.getTags(), chunks).nicePrint());
View Full Code Here

Examples of opennlp.tools.chunker.ChunkerME

    }
    catch (ResourceAccessException e) {
        throw new ResourceInitializationException(e);
    }

    mChunker = new ChunkerME(model);
  }
View Full Code Here

Examples of opennlp.tools.chunker.ChunkerME

        if(sentenceDetector != null){ //sentence detection is requirement
            posTagger = initTagger(language);
        } else {
            posTagger = null;
        }
        ChunkerME chunker;
        if(posTagger != null && useChunker ){ //pos tags requirement
            chunker = initChunker(language);
        } else {
            chunker = null;
        }
        Map<String,Suggestion> suggestionCache = new TreeMap<String,Suggestion>();
        if(sentenceDetector != null){
            //add dots for multiple line breaks
            text = text.replaceAll("\\n\\n", ".\n");
            Span[] sentenceSpans = sentenceDetector.sentPosDetect(text);
            for (int i = 0; i < sentenceSpans.length; i++) {
                String sentence = sentenceSpans[i].getCoveredText(text).toString();
                Span[] tokenSpans = tokenizer.tokenizePos(sentence);
                String[] tokens = getTokensForSpans(sentence, tokenSpans);
                String[] pos;
                double[] posProbs;
                if(posTagger != null){
                    pos = posTagger.tag(tokens);
                    posProbs = posTagger.probs();
                } else {
                    pos = null;
                    posProbs = null;
                }
                Span[] chunkSpans;
                double[] chunkProps;
                if(chunker != null){
                    chunkSpans = chunker.chunkAsSpans(tokens, pos);
                    chunkProps = chunker.probs();
                } else {
                    chunkSpans = null;
                    chunkProps = null;
                }
                enhance(suggestionCache,site,ci,language, //the site, metadata and lang
View Full Code Here

Examples of opennlp.tools.chunker.ChunkerME

    }
    /**
     * @param language
     */
    private ChunkerME initChunker(String language) {
        ChunkerME chunker;
        try {
            ChunkerModel chunkerModel = openNLP.getChunkerModel(language);
            if(chunkerModel != null){
                chunker = new ChunkerME(chunkerModel);
            } else {
                log.debug("No Chunker Model for language {}",language);
                chunker = null;
            }
        } catch (IOException e) {
View Full Code Here

Examples of opennlp.tools.chunker.ChunkerME

        }
        if(chunker == null && !chunkerNotAvailable) {
            try {
                ChunkerModel chunkerModel = openNLP.getChunkerModel(language);
                if(chunkerModel != null){
                    chunker = new ChunkerME(chunkerModel);
                } else {
                    log.debug("No Chunker Model for language {}",language);
                    chunkerNotAvailable = true;
                }
            } catch (IOException e) {
View Full Code Here

Examples of opennlp.tools.chunker.ChunkerME

                    "The parsed offset MUST NOT be a negative number (offset="+offset+")");
            }
            this.offset = offset;
            Span[] tokenSpans = getTokenizer().tokenizePos(sentence);
            POSTaggerME tagger = getPosTagger();
            ChunkerME chunker = getChunker();
            PosTypeChunker posTypeChunker = getPosTypeChunker();
            String[] tokens = new String[tokenSpans.length];
            for(int ti = 0; ti<tokenSpans.length;ti++) {
                tokens[ti] = tokenSpans[ti].getCoveredText(sentence).toString();
            }
            String[][] posTags;
            double[][] posProbs;
            Span[] chunkSpans;
            double[] chunkProps;
            if(tagger != null){
                posTags = new String[tokens.length][];
                posProbs = new double[tokens.length][];
                //get the topK POS tags and props and copy it over to the 2dim Arrays
                Sequence[] posSequences = tagger.topKSequences(tokens);
                //extract the POS tags and props for the current token from the
                //posSequences.
                //NOTE: Sequence includes always POS tags for all Tokens. If
                //      less then posSequences.length are available it adds the
                //      best match for all followings.
                //      We do not want such copies.
                String[] actPos = new String[posSequences.length];
                double[] actProp = new double[posSequences.length];
                for(int i=0;i<tokenSpans.length;i++){
                    boolean done = false;
                    int j = 0;
                    while( j < posSequences.length && !done){
                        String p = posSequences[j].getOutcomes().get(i);
                        done = j > 0 && p.equals(actPos[0]);
                        if(!done){
                            actPos[j] = p;
                            actProp[j] = posSequences[j].getProbs()[i];
                            j++;
                        }
                    }
                    posTags[i] = new String[j];
                    System.arraycopy(actPos, 0, posTags[i], 0, j);
                    posProbs[i] = new double[j];
                    System.arraycopy(actProp, 0, posProbs[i], 0, j);
                }
                //posProbs = tagger.probs();
                if(chunker != null){
                    //we still need the Array of the best ranked POS tags for the chunker
                    String[] pos = posSequences[0].getOutcomes().toArray(new String[tokens.length]);
                    chunkSpans = chunker.chunkAsSpans(tokens, pos);
                    chunkProps = chunker.probs();
                } else if(posTypeChunker != null){
                    chunkSpans = posTypeChunker.chunkAsSpans(tokens, posTags, posProbs);
                    chunkProps = new double[chunkSpans.length];
                    Arrays.fill(chunkProps, 1.0);
                } else {
View Full Code Here

Examples of opennlp.tools.chunker.ChunkerME

       
       
        {
          File f = new File(d, "chunk.bin.gz");
          MaxentModel chunkModel = new opennlp.maxent.io.SuffixSensitiveGISModelReader(f).getModel();
          chunker = new ChunkerME(chunkModel);
        }
     
        {
          FileReader fr = new FileReader(new File(d, "head_rules"));
          headRules = new HeadRules(fr);
View Full Code Here

Examples of opennlp.tools.chunker.ChunkerME

  private int[] attachments;

  public Parser(ParserModel model, int beamSize, double advancePercentage) {
    this(model.getBuildModel(), model.getAttachModel(), model.getCheckModel(),
        new POSTaggerME(model.getParserTaggerModel()),
        new ChunkerME(model.getParserChunkerModel(),
        ChunkerME.DEFAULT_BEAM_SIZE,
        new ParserChunkerSequenceValidator(model.getParserChunkerModel()),
        new ChunkContextGenerator(ChunkerME.DEFAULT_BEAM_SIZE)),
        model.getHeadRules(),
        beamSize, advancePercentage);
View Full Code Here

Examples of opennlp.tools.chunker.ChunkerME

      throw new TerminateToolException(1);
    }

    ChunkerModel model = new ChunkerModelLoader().load(new File(params.getModel()));

    ChunkerEvaluator evaluator = new ChunkerEvaluator(new ChunkerME(model));
   
    final ObjectStream<ChunkSample> sampleStream = ChunkerTrainerTool.openSampleData("Test",
        testData, encoding);

    final PerformanceMonitor monitor = new PerformanceMonitor("sent");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.