Package edu.stanford.nlp.util

Examples of edu.stanford.nlp.util.ArrayCoreMap


   */
  public void testMultipleSentencesAnnotation() {
    List<CoreLabel> firstLabels = makeSentence(testSentences[0]);
    List<CoreLabel> secondLabels = makeSentence(testSentences[1]);

    CoreMap firstSentence = new ArrayCoreMap();
    firstSentence.set(CoreAnnotations.TokensAnnotation.class, firstLabels);
    CoreMap secondSentence = new ArrayCoreMap();
    secondSentence.set(CoreAnnotations.TokensAnnotation.class, secondLabels);
    List<CoreMap> sentences = new ArrayList<CoreMap>();
    sentences.add(firstSentence);
    sentences.add(secondSentence);

    Annotation annotation = new Annotation(longText);
View Full Code Here


  public static Annotation makeAnnotation(String ... testText) {
    List<CoreMap> sentences = new ArrayList<CoreMap>();
    for (String text : testText) {
      List<CoreLabel> labels = makeSentence(text);     
      CoreMap sentence = new ArrayCoreMap();
      sentence.set(CoreAnnotations.TokensAnnotation.class, labels);
      sentences.add(sentence);
    }
    Annotation annotation = new Annotation(StringUtils.join(testText));
    annotation.set(CoreAnnotations.SentencesAnnotation.class, sentences);
    return annotation;
View Full Code Here

    int offset = 0;
    List<CoreMap> sentences = new ArrayList<CoreMap>();
    Elements sentenceElements = textElem.getChildElements("SENT");
    for (int crtsent = 0; crtsent < sentenceElements.size(); crtsent ++){
      Element sentElem = sentenceElements.get(crtsent);
      CoreMap sentence = new ArrayCoreMap();
      sentence.set(CoreAnnotations.CharacterOffsetBeginAnnotation.class, offset);
      Tree tree = Tree.valueOf(sentElem.getChild(0).getValue()); // XXX ms: is this the same as sentElem.getText() in JDOM?
      List<CoreLabel> tokens = new ArrayList<CoreLabel>();
      List<Tree> preTerminals = preTerminals(tree);
      for (Tree preTerminal: preTerminals) {
        String posTag = preTerminal.value();
        for (Tree wordTree: preTerminal.children()) {
          String word = wordTree.value();
          CoreLabel token = new CoreLabel();
          token.set(CoreAnnotations.TextAnnotation.class, word);
          token.set(CoreAnnotations.TextAnnotation.class, word);
          token.set(CoreAnnotations.PartOfSpeechAnnotation.class, posTag);
          token.set(CoreAnnotations.CharacterOffsetBeginAnnotation.class, offset);
          offset += word.length();
          token.set(CoreAnnotations.CharacterOffsetEndAnnotation.class, offset);
          text.append(word);
          text.append(' ');
          offset += 1;
          tokens.add(token);
        }
      }
      if (preTerminals.size() > 0) {
        text.setCharAt(text.length() - 1, '\n');
      }
      sentence.set(CoreAnnotations.CharacterOffsetEndAnnotation.class, offset - 1);
      sentence.set(CoreAnnotations.TokensAnnotation.class, tokens);
      sentence.set(TreeCoreAnnotations.TreeAnnotation.class, tree);
      sentences.add(sentence);
    }

    String docID = docElem.getAttributeValue("id");
    Matcher matcher = datePattern.matcher(docID);
View Full Code Here

   * Test a bug a user reported where the text would wind up having the list toString used, adding extra []
   */
  public void testFromList() {
    List<CoreMap> sentences = Generics.newArrayList();

    CoreMap sentence = new ArrayCoreMap();
    List<CoreLabel> words = Sentence.toCoreLabelList("This", "is", "a", "test", ".");
    sentence.set(CoreAnnotations.TokensAnnotation.class, words);
    sentences.add(sentence);

    Annotation annotation = new Annotation(sentences);
    assertEquals("This is a test .", annotation.toString());

    sentence.set(CoreAnnotations.TextAnnotation.class, "This is a test.");
    annotation = new Annotation(sentences);
    assertEquals("This is a test.", annotation.toString());
  }
View Full Code Here

TOP

Related Classes of edu.stanford.nlp.util.ArrayCoreMap

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.