Examples of POSSample


Examples of opennlp.tools.postag.POSSample

     
      tokens.add(tokenAnnotation.getCoveredText().trim());
      tags.add(tag);
    }
   
    mPOSSamples.add(new POSSample(tokens, tags));
  }
View Full Code Here

Examples of opennlp.tools.postag.POSSample

    // One paragraph contains a whole sentence and, the token
    // and tag will be read from the FORM and POSTAG field.
   
   String paragraph = samples.read();
  
   POSSample sample = null;
  
   if (paragraph != null) {
    
     // paragraph get lines
     BufferedReader reader = new BufferedReader(new StringReader(paragraph));
    
     List<String> tokens = new ArrayList<String>(100);
     List<String> tags = new ArrayList<String>(100);
    
     String line;
     while ((line = reader.readLine())  != null) {
    
       final int minNumberOfFields = 5;
      
       String parts[] = line.split("\t");
      
       if (parts.length >= minNumberOfFields) {
         tokens.add(parts[1]);
         tags.add(parts[4]);
       }
       else {
         throw new InvalidFormatException("Every non-empty line must have at least " +
             minNumberOfFields + " fields!");
       }
     }
    
     // just skip empty samples and read next sample
     if (tokens.size() == 0)
       sample = read();
      
     sample = new POSSample(tokens.toArray(new String[tokens.size()]), tags.toArray(new String[tags.size()]));
   }
  
   return sample;
  }
View Full Code Here

Examples of opennlp.tools.postag.POSSample

   
    InputStream in = ConllXPOSSampleStreamTest.class.getResourceAsStream("/opennlp/tools/formats/conllx.sample");
   
    ObjectStream<POSSample> sampleStream = new ConllXPOSSampleStream(new InputStreamReader(in, "UTF-8"));
   
    POSSample a = sampleStream.read();
   
    String aSentence[] = a.getSentence();
    String aTags[] = a.getTags();
   
    assertEquals(22, aSentence.length);
    assertEquals(22, aTags.length);
   
    assertEquals("To", aSentence[0]);
    assertEquals("AC", aTags[0]);
   
    assertEquals("kendte", aSentence[1]);
    assertEquals("AN", aTags[1]);
   
    assertEquals("russiske", aSentence[2]);
    assertEquals("AN", aTags[2]);
   
    assertEquals("historikere", aSentence[3]);
    assertEquals("NC", aTags[3]);
   
    assertEquals("Andronik", aSentence[4]);
    assertEquals("NP", aTags[4]);
   
    assertEquals("Andronik", aSentence[5]);
    assertEquals("NP", aTags[5]);
   
    assertEquals("og", aSentence[6]);
    assertEquals("CC", aTags[6]);
   
    assertEquals("Igor", aSentence[7]);
    assertEquals("NP", aTags[7]);
   
    assertEquals("Klamkin", aSentence[8]);
    assertEquals("NP", aTags[8]);
   
    assertEquals("tror", aSentence[9]);
    assertEquals("VA", aTags[9]);
   
    assertEquals("ikke", aSentence[10]);
    assertEquals("RG", aTags[10]);

    assertEquals(",", aSentence[11]);
    assertEquals("XP", aTags[11]);
   
    assertEquals("at", aSentence[12]);
    assertEquals("CS", aTags[12]);
   
    assertEquals("Rusland", aSentence[13]);
    assertEquals("NP", aTags[13]);
   
    assertEquals("kan", aSentence[14]);
    assertEquals("VA", aTags[14]);
   
    assertEquals("udvikles", aSentence[15]);
    assertEquals("VA", aTags[15]);
   
    assertEquals("uden", aSentence[16]);
    assertEquals("SP", aTags[16]);
   
    assertEquals("en", aSentence[17]);
    assertEquals("PI", aTags[17]);
   
    assertEquals("\"", aSentence[18]);
    assertEquals("XP", aTags[18]);
   
    assertEquals("jernnæve", aSentence[19]);
    assertEquals("NC", aTags[19]);
   
    assertEquals("\"", aSentence[20]);
    assertEquals("XP", aTags[20]);
   
    assertEquals(".", aSentence[21]);
    assertEquals("XP", aTags[21]);
   
    POSSample b = sampleStream.read();
   
    String bSentence[] = b.getSentence();
    String bTags[] = b.getTags();
   
    assertEquals(12, bSentence.length);
    assertEquals(12, bTags.length);
   
    assertEquals("De", bSentence[0]);
View Full Code Here

Examples of opennlp.tools.postag.POSSample

    this.detokenizer = detokenizer;
  }
 
  public TokenSample read() throws IOException {
   
    POSSample posSample = samples.read();
   
    TokenSample tokenSample = null;
   
    if (posSample != null ) {
      tokenSample = new TokenSample(detokenizer, posSample.getSentence());
    }
   
    return tokenSample;
  }
View Full Code Here

Examples of opennlp.tools.postag.POSSample

        Parse tok = nodes[ti];
        toks[ti] = tok.toString();
        preds[ti] = tok.getType();
      }
     
      return new POSSample(toks, preds);
    }
    else {
      return null;
    }
  }
View Full Code Here

Examples of opennlp.tools.postag.POSSample

   
    try {
      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());
       
        perfMon.incrementCounter();
      }
    }
    catch (IOException e) {
View Full Code Here

Examples of opennlp.tools.postag.POSSample

     
      tokens.add(tokenAnnotation.getCoveredText().trim());
      tags.add(tag);
    }
   
    mPOSSamples.add(new POSSample(tokens, tags));
  }
View Full Code Here

Examples of opennlp.tools.postag.POSSample

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

Examples of opennlp.tools.postag.POSSample

      while ((line = lineStream.read()) != null) {
       
        String whitespaceTokenizerLine[] = WhitespaceTokenizer.INSTANCE.tokenize(line);
        String[] tags = tagger.tag(whitespaceTokenizerLine);
       
        POSSample sample = new POSSample(whitespaceTokenizerLine, tags);
        System.out.println(sample.toString());
       
        perfMon.incrementCounter();
      }
    }
    catch (IOException e) {
View Full Code Here

Examples of opennlp.tools.postag.POSSample

        Parse tok = nodes[ti];
        toks[ti] = tok.getCoveredText();
        preds[ti] = tok.getType();
      }
     
      return new POSSample(toks, preds);
    }
    else {
      return null;
    }
  }
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.