Package opennlp.tools.chunker

Examples of opennlp.tools.chunker.ChunkSample


      tokens.add(tokenAnnotation.getCoveredText().trim());
      tags.add(tokenAnnotation.getFeatureValueAsString(mPOSFeature));
      chunkTags.add(chunkTag);
    }
   
    mChunkSamples.add(new ChunkSample(tokens, tags, chunkTags));
  }
View Full Code Here


  @Test
  public void testConvertParseToPosSample() throws IOException {
    ObjectStream<ChunkSample> chunkSampleStream = new ChunkSampleStream(new ParseSampleStream(
        ObjectStreamUtils.createObjectStream(ParseTest.PARSE_STRING)));
   
    ChunkSample sample = chunkSampleStream.read();
   
    assertEquals("She", sample.getSentence()[0]);
    assertEquals("PRP", sample.getTags()[0]);
    assertEquals("S-NP", sample.getPreds()[0]);
    assertEquals("was", sample.getSentence()[1]);
    assertEquals("VBD", sample.getTags()[1]);
    assertEquals("O", sample.getPreds()[1]);
    assertEquals("just", sample.getSentence()[2]);
    assertEquals("RB", sample.getTags()[2]);
    assertEquals("S-ADVP", sample.getPreds()[2]);
    assertEquals("another", sample.getSentence()[3]);
    assertEquals("DT", sample.getTags()[3]);
    assertEquals("S-NP", sample.getPreds()[3]);
    assertEquals("freighter", sample.getSentence()[4]);
    assertEquals("NN", sample.getTags()[4]);
    assertEquals("C-NP", sample.getPreds()[4]);
    assertEquals("from", sample.getSentence()[5]);
    assertEquals("IN", sample.getTags()[5]);
    assertEquals("O", sample.getPreds()[5]);
    assertEquals("the", sample.getSentence()[6]);
    assertEquals("DT", sample.getTags()[6]);
    assertEquals("S-NP", sample.getPreds()[6]);
    assertEquals("States", sample.getSentence()[7]);
    assertEquals("NNPS", sample.getTags()[7]);
    assertEquals("C-NP", sample.getPreds()[7]);
    assertEquals(",", sample.getSentence()[8]);
    assertEquals(",", sample.getTags()[8]);
    assertEquals("O", sample.getPreds()[8]);
    assertEquals("and", sample.getSentence()[9]);
    assertEquals("CC", sample.getTags()[9]);
    assertEquals("O", sample.getPreds()[9]);
    assertEquals("she", sample.getSentence()[10]);
    assertEquals("PRP", sample.getTags()[10]);
    assertEquals("S-NP", sample.getPreds()[10]);
    assertEquals("seemed", sample.getSentence()[11]);
    assertEquals("VBD", sample.getTags()[11]);
    assertEquals("O", sample.getPreds()[11]);
    assertEquals("as", sample.getSentence()[12]);
    assertEquals("RB", sample.getTags()[12]);
    assertEquals("S-ADJP", sample.getPreds()[12]);
    assertEquals("commonplace", sample.getSentence()[13]);
    assertEquals("JJ", sample.getTags()[13]);
    assertEquals("C-ADJP", sample.getPreds()[13]);
    assertEquals("as", sample.getSentence()[14]);
    assertEquals("IN", sample.getTags()[14]);
    assertEquals("O", sample.getPreds()[14]);
    assertEquals("her", sample.getSentence()[15]);
    assertEquals("PRP$", sample.getTags()[15]);
    assertEquals("S-NP", sample.getPreds()[15]);
    assertEquals("name", sample.getSentence()[16]);
    assertEquals("NN", sample.getTags()[16]);
    assertEquals("C-NP", sample.getPreds()[16]);
    assertEquals(".", sample.getSentence()[17]);
    assertEquals(".", sample.getTags()[17]);
    assertEquals("O", sample.getPreds()[17]);
   
    assertNull(chunkSampleStream.read());
  }
View Full Code Here

        processRoot(root, sentence, tags, target);

        if (sentence.size() > 0) {
          index++;
          return new ChunkSample(sentence, tags, target);
        }

      }

    }
View Full Code Here

            }
          }
        }
      }
     
      return new ChunkSample(toks.toArray(new String[toks.size()]),
          tags.toArray(new String[tags.size()]),
          preds.toArray(new String[preds.size()]));
    }
    else {
      return null;
View Full Code Here

      tokens.add(tokenAnnotation.getCoveredText().trim());
      tags.add(tokenAnnotation.getFeatureValueAsString(mPOSFeature));
      chunkTags.add(chunkTag);
    }
   
    mChunkSamples.add(new ChunkSample(tokens, tags, chunkTags));
  }
View Full Code Here

        }
       
        String[] chunks = chunker.chunk(posSample.getSentence(),
            posSample.getTags());
       
        System.out.println(new ChunkSample(posSample.getSentence(),
            posSample.getTags(), chunks).nicePrint());
       
        perfMon.incrementCounter();
      }
    }
View Full Code Here

  .getResourceAsStream("/opennlp/tools/formats/ad.sample");

    ADChunkSampleStream stream = new ADChunkSampleStream(
  new PlainTextByLineStream(in, "UTF-8"));

    ChunkSample sample = stream.read();

    while (sample != null) {
      samples.add(sample);
      sample = stream.read();
    }
View Full Code Here

            }
          }
        }
      }
     
      return new ChunkSample(toks.toArray(new String[toks.size()]),
          tags.toArray(new String[tags.size()]),
          preds.toArray(new String[preds.size()]));
    }
    else {
      return null;
View Full Code Here

  .getResourceAsStream("/opennlp/tools/formats/ad.sample");

    ADChunkSampleStream stream = new ADChunkSampleStream(
      new PlainTextByLineStream(in, "UTF-8"));

    ChunkSample sample = stream.read();

    while (sample != null) {
      samples.add(sample);
      sample = stream.read();
    }
View Full Code Here

        processRoot(root, sentence, tags, target);

        if (sentence.size() > 0) {
          index++;
          return new ChunkSample(sentence, tags, target);
        }

      }

    }
View Full Code Here

TOP

Related Classes of opennlp.tools.chunker.ChunkSample

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.