edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation.getNumberOfSentences()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(14.2k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation.getNumberOfSentences()方法的一些代码示例,展示了TextAnnotation.getNumberOfSentences()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextAnnotation.getNumberOfSentences()方法的具体详情如下:
包路径:edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation
类名称:TextAnnotation
方法名:getNumberOfSentences

TextAnnotation.getNumberOfSentences介绍

暂无

代码示例

代码示例来源:origin: CogComp/cogcomp-nlp

/**
 * Ugly hack to initialize the trees arraylist with the correct number elements. There should be
 * as many trees as there are sentences. Later on, we can say trees.set(sentenceId, tree);
 */
private void safeInitializeTrees() {
  if (this.trees == null) {
    trees = new ArrayList<>();
    for (int i = 0; i < this.getTextAnnotation().getNumberOfSentences(); i++) {
      trees.add(null);
    }
  }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-core-utilities

/**
 * Ugly hack to initialize the trees arraylist with the correct number elements. There should be
 * as many trees as there are sentences. Later on, we can say trees.set(sentenceId, tree);
 */
private void safeInitializeTrees() {
  if (this.trees == null) {
    trees = new ArrayList<>();
    for (int i = 0; i < this.getTextAnnotation().getNumberOfSentences(); i++) {
      trees.add(null);
    }
  }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-core-utilities

@Override
public String toString() {
  if (trees == null)
    makeTrees();
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < this.getTextAnnotation().getNumberOfSentences(); i++) {
    if (this.trees.get(i) != null)
      sb.append(this.getTree(i).toString()).append("\n");
  }
  return sb.toString();
}

代码示例来源:origin: CogComp/cogcomp-nlp

@Override
public String toString() {
  if (trees == null)
    makeTrees();
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < this.getTextAnnotation().getNumberOfSentences(); i++) {
    if (this.trees.get(i) != null)
      sb.append(this.getTree(i).toString()).append("\n");
  }
  return sb.toString();
}

代码示例来源:origin: CogComp/cogcomp-nlp

/**
 * Gets the index of the sentence that contains the token, indexed by tokenPosition. If no
 * sentence contains the token, then this function throws an IllegalArgumentException. The
 * sentence index can further be used to get the Sentence itself by calling
 * {@link edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation#getSentence(int)}
 * .
 *
 * @param tokenId The index of the token whose sentenceId is needed
 * @return The index of the sentence that contains this token
 * @throws IllegalArgumentException if no sentence contains the {@code tokenId}
 */
public int getSentenceId(int tokenId) {
  for (int i = 0; i < this.getNumberOfSentences(); i++) {
    if (this.sentences.get(i).getSentenceConstituent().doesConstituentCover(tokenId))
      return i;
  }
  throw new IllegalArgumentException("No sentence contains token id " + tokenId);
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-core-utilities

/**
 * Gets the index of the sentence that contains the token, indexed by tokenPosition. If no
 * sentence contains the token, then this function throws an IllegalArgumentException. The
 * sentence index can further be used to get the Sentence itself by calling
 * {@link edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation#getSentence(int)}
 * .
 *
 * @param tokenId The index of the token whose sentenceId is needed
 * @return The index of the sentence that contains this token
 * @throws IllegalArgumentException if no sentence contains the {@code tokenId}
 */
public int getSentenceId(int tokenId) {
  for (int i = 0; i < this.getNumberOfSentences(); i++) {
    if (this.sentences.get(i).getSentenceConstituent().doesConstituentCover(tokenId))
      return i;
  }
  throw new IllegalArgumentException("No sentence contains token id " + tokenId);
}

代码示例来源:origin: CogComp/cogcomp-nlp

public static void main(String[] args) {

    TextAnnotationBuilder tokenizer = MultiLingualTokenizer.getTokenizer("ja");
    String text = "\"ペンシルベニアドイツ語\",\"text\":\"ペンシルベニアドイツ語(標準ドイ"
            + "ツ語:Pennsylvania-Dutch, Pennsilfaani-Deitsch、アレマン語:Pennsylvania-Ditsch、英語:Pennsylvania-German)"
            + "は、北アメリカのカナダおよびアメリカ中西部でおよそ15万から25万人の人びとに話されているドイツ語の系統である。高地ドイツ語の"
            + "うち上部ドイツ語の一派アレマン語の一方言である。ペンシルベニアアレマン語(Pennsilfaani-Alemanisch, Pennsylvania-Alemannic)"
            + "とも呼ばれる。";

    TextAnnotation ta = tokenizer.createTextAnnotation(text);
    for(int i = 0; i < ta.getNumberOfSentences(); i++)
      System.out.println(ta.getSentence(i).getTokenizedText());

  }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/wikipediaAPI-multilingual

public static void main(String[] args) {

    TextAnnotationBuilder tokenizer = MultiLingualTokenizer.getTokenizer("he");
    String text = "Barack Obama Zum Anhören bitte klicken! ist ein US-amerikanischer Politiker und seit dem 20. Januar 2009 der 44. Präsident der Vereinigten Staaten. Obama ist ein auf US-Verfassungsrecht spezialisierter Rechtsanwalt. Im Jahr 1992 schloss er sich der Demokratischen Partei an, für die er 1997 Mitglied im Senat von Illinois wurde. Im Anschluss gehörte er von 2005 bis 2008 als Junior Senator für diesen US-Bundesstaat dem Senat der Vereinigten Staaten an W. Bei der Präsidentschaftswahl des Jahres 2008 errang er die Kandidatur seiner Partei und setzte sich dann gegen den Republikaner John McCain durch." ;
    TextAnnotation ta = tokenizer.createTextAnnotation(text);
    for(int i = 0; i < ta.getNumberOfSentences(); i++)
      System.out.println(ta.getSentence(i).getTokenizedText());

  }
}

代码示例来源:origin: CogComp/cogcomp-nlp

/**
 * Makes the tree objects. This creates one tree per sentence.
 */
protected void makeTrees() {
  safeInitializeTrees();
  for (int sentenceId = 0; sentenceId < this.getTextAnnotation().getNumberOfSentences(); sentenceId++) {
    Constituent root = this.getRootConstituent(sentenceId);
    if (root == null) {
      // throw new IllegalStateException(
      // "Unable to find the root constituent. "
      // + "Maybe the view is not restricted to a single sentence.");
      trees.set(sentenceId, null);
    } else
      trees.set(sentenceId, makeTree(root));
  }
  firstTree = false;
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-core-utilities

/**
 * Makes the tree objects. This creates one tree per sentence.
 */
protected void makeTrees() {
  safeInitializeTrees();
  for (int sentenceId = 0; sentenceId < this.getTextAnnotation().getNumberOfSentences(); sentenceId++) {
    Constituent root = this.getRootConstituent(sentenceId);
    if (root == null) {
      // throw new IllegalStateException(
      // "Unable to find the root constituent. "
      // + "Maybe the view is not restricted to a single sentence.");
      trees.set(sentenceId, null);
    } else
      trees.set(sentenceId, makeTree(root));
  }
  firstTree = false;
}

代码示例来源:origin: CogComp/cogcomp-nlp

public static void main(String[] args) {
    String text = "  An aifi   Barack Hussain Obama ranar.... 4 ga watan Oguster na shekara ta 1961 a birnin n Honolulu dake yankin Hawai a ƙasar Amurika. Tun yana ɗan shekaru biyu da aihuwa iyayensa suka rabu, ya cigaba da zama tare da ma´aifiyarsa. Ubansa musulmi ƙan kasar Kenya a nahiyar Afirka, ya bar Amurika bayan ya rabu da matarsa ba´amurka inda ya koma gida Kenya, ya kuma zama minister a cikin gwamnatin shugaban ƙasa na farko, wato Jomo Keniyatta, kamin Allah ya amshi ransa, a shekara ta 1982 a cikin haɗarin mota.";
    WhiteSpaceTokenizer t = new WhiteSpaceTokenizer();
    TextAnnotation ta = t.getTextAnnotation(text);
    for(int i = 0; i < ta.getNumberOfSentences(); i++)
      System.out.println(ta.getSentence(i).getText());
//        SpanLabelView view = (SpanLabelView)ta.getView(ViewNames.TOKENS);
//        System.out.println(view.getConstituents().size());
//        for(Constituent c: view.getConstituents()){
//            System.out.println(c.getSurfaceForm());
//
//        }
//        System.out.println("#sen "+ta.getNumberOfSentences());
//        System.out.println(ta.getText());
//        System.out.println(ta.getTokensInSpan(3,4)[0]);
//        System.out.println(ta.getTokensInSpan(9,10)[0]);

  }

代码示例来源:origin: edu.illinois.cs.cogcomp/wikipediaAPI-multilingual

public static void main(String[] args) {
    String text = "  An aifi   Barack Hussain Obama ranar.... 4 ga watan Oguster na shekara ta 1961 a birnin n Honolulu dake yankin Hawai a ƙasar Amurika. Tun yana ɗan shekaru biyu da aihuwa iyayensa suka rabu, ya cigaba da zama tare da ma´aifiyarsa. Ubansa musulmi ƙan kasar Kenya a nahiyar Afirka, ya bar Amurika bayan ya rabu da matarsa ba´amurka inda ya koma gida Kenya, ya kuma zama minister a cikin gwamnatin shugaban ƙasa na farko, wato Jomo Keniyatta, kamin Allah ya amshi ransa, a shekara ta 1982 a cikin haɗarin mota.";
    WhiteSpaceTokenizer t = new WhiteSpaceTokenizer();
    TextAnnotation ta = t.getTextAnnotation(text);
    for(int i = 0; i < ta.getNumberOfSentences(); i++)
      System.out.println(ta.getSentence(i).getText());
//        SpanLabelView view = (SpanLabelView)ta.getView(ViewNames.TOKENS);
//        System.out.println(view.getConstituents().size());
//        for(Constituent c: view.getConstituents()){
//            System.out.println(c.getSurfaceForm());
//
//        }
//        System.out.println("#sen "+ta.getNumberOfSentences());
//        System.out.println(ta.getText());
//        System.out.println(ta.getTokensInSpan(3,4)[0]);
//        System.out.println(ta.getTokensInSpan(9,10)[0]);

  }

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-srl

private String[] getParse(TextAnnotation ta) {
  String[] parse = new String[ta.size()];
  for (int sentenceId = 0; sentenceId < ta.getNumberOfSentences(); sentenceId++) {

代码示例来源:origin: CogComp/cogcomp-nlp

/**
 * given a {@link TextAnnotation} for a sentence with annotations, map its annotations into a
 * TextAnnotation object for a longer text containing that sentence.
 * @param sentenceTa annotated TextAnnotation for sentence
 * @param textTa TextAnnotation for longer text containing sentence, without annotations for that sentence
 * @param sentenceId index of the sentence in the longer text
 */
static public void mapSentenceAnnotationsToText(TextAnnotation sentenceTa, TextAnnotation textTa, int sentenceId ) {
  assert(sentenceId < textTa.getNumberOfSentences());
  assert(sentenceTa.getText().equals(textTa.getSentence(sentenceId).getText()));
  int start = textTa.getSentence(sentenceId).getStartSpan();
  int end = textTa.getSentence(sentenceId).getEndSpan();
  copyViewsFromTo(sentenceTa, textTa, start, end, start);
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-core-utilities

/**
 * given a {@link TextAnnotation} for a sentence with annotations, map its annotations into a
 * TextAnnotation object for a longer text containing that sentence.
 * @param sentenceTa annotated TextAnnotation for sentence
 * @param textTa TextAnnotation for longer text containing sentence, without annotations for that sentence
 * @param sentenceId index of the sentence in the longer text
 */
static public void mapSentenceAnnotationsToText(TextAnnotation sentenceTa, TextAnnotation textTa, int sentenceId ) {
  assert(sentenceId < textTa.getNumberOfSentences());
  assert(sentenceTa.getText().equals(textTa.getSentence(sentenceId).getText()));
  int start = textTa.getSentence(sentenceId).getStartSpan();
  int end = textTa.getSentence(sentenceId).getEndSpan();
  copyViewsFromTo(sentenceTa, textTa, start, end, start);
}

代码示例来源:origin: CogComp/cogcomp-nlp

@Override
public void addView(TextAnnotation ta) {
  TokenLabelView posView = new TokenLabelView(ViewNames.POS, "ParsePOS", ta, 1.0);
  int tokenId = 0;
  for (int sentenceId = 0; sentenceId < ta.getNumberOfSentences(); sentenceId++) {
    Tree<String> parseTree = ((TreeView) (ta.getView(parseViewName))).getTree(sentenceId);
    parseTree = ParseUtils.snipNullNodes(parseTree);
    parseTree = ParseUtils.stripFunctionTags(parseTree);
    if (parseTree.getYield().size() != ta.getSentence(sentenceId).size()) {
      Sentence s = ta.getSentence(sentenceId);
      System.err.println(":"+s+":");
      List<Tree<String>> tree = parseTree.getYield();
      System.err.println("-"+tree+"-");
      throw new IllegalStateException("Parse tree size != ta.size()");
    }
    for (Tree<String> y : parseTree.getYield()) {
      posView.addTokenLabel(tokenId++, y.getParent().getLabel(), 1.0);
    }
  }
  ta.addView(getViewName(), posView);
  // return posView;
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-core-utilities

@Override
public void addView(TextAnnotation ta) {
  TokenLabelView posView = new TokenLabelView(ViewNames.POS, "ParsePOS", ta, 1.0);
  int tokenId = 0;
  for (int sentenceId = 0; sentenceId < ta.getNumberOfSentences(); sentenceId++) {
    Tree<String> parseTree = ((TreeView) (ta.getView(parseViewName))).getTree(sentenceId);
    parseTree = ParseUtils.snipNullNodes(parseTree);
    parseTree = ParseUtils.stripFunctionTags(parseTree);
    if (parseTree.getYield().size() != ta.getSentence(sentenceId).size()) {
      Sentence s = ta.getSentence(sentenceId);
      System.err.println(":"+s+":");
      List<Tree<String>> tree = parseTree.getYield();
      System.err.println("-"+tree+"-");
      throw new IllegalStateException("Parse tree size != ta.size()");
    }
    for (Tree<String> y : parseTree.getYield()) {
      posView.addTokenLabel(tokenId++, y.getParent().getLabel(), 1.0);
    }
  }
  ta.addView(getViewName(), posView);
  // return posView;
}

代码示例来源:origin: CogComp/cogcomp-nlp

@Override
public void addView(TextAnnotation ta) {
  TokenLabelView posView = new TokenLabelView(ViewNames.POS, "ParsePOS", ta, 1.0);
  int tokenId = 0;
  for (int sentenceId = 0; sentenceId < ta.getNumberOfSentences(); sentenceId++) {
    Tree<String> parseTree = ((TreeView) (ta.getView(parseViewName))).getTree(sentenceId);
    parseTree = ParseUtils.snipNullNodes(parseTree);
    parseTree = ParseUtils.stripFunctionTags(parseTree);
    if (parseTree.getYield().size() != ta.getSentence(sentenceId).size())
      throw new IllegalStateException("Parse tree size != ta.size()");
    for (Tree<String> y : parseTree.getYield()) {
      posView.addTokenLabel(tokenId++, y.getParent().getLabel(), 1.0);
    }
  }
  ta.addView(getViewName(), posView);
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-edison

@Override
public void addView(TextAnnotation ta) {
  TokenLabelView posView = new TokenLabelView(ViewNames.POS, "ParsePOS", ta, 1.0);
  int tokenId = 0;
  for (int sentenceId = 0; sentenceId < ta.getNumberOfSentences(); sentenceId++) {
    Tree<String> parseTree = ((TreeView) (ta.getView(parseViewName))).getTree(sentenceId);
    parseTree = ParseUtils.snipNullNodes(parseTree);
    parseTree = ParseUtils.stripFunctionTags(parseTree);
    if (parseTree.getYield().size() != ta.getSentence(sentenceId).size())
      throw new IllegalStateException("Parse tree size != ta.size()");
    for (Tree<String> y : parseTree.getYield()) {
      posView.addTokenLabel(tokenId++, y.getParent().getLabel(), 1.0);
    }
  }
  ta.addView(getViewName(), posView);
}

代码示例来源:origin: CogComp/cogcomp-nlp

@Override
  protected void addView(TextAnnotation ta) throws AnnotatorException {
    assert ta.hasView(ViewNames.SENTENCE): "Sentences view didn't find . . . ";
    List<Constituent> sentences = ta.getView(ViewNames.SENTENCE).getConstituents();
    View vu = new View(viewName, "ClausIEAnnotator", ta, 1.0);
    assert sentences.size() == ta.getNumberOfSentences();
    for(Constituent sent : sentences) {
      String[] clausieResults = ClausieSplitter.split(sent.getSurfaceForm());
      Constituent sentenceCons = new Constituent("sent-" + sent.getSentenceId(), viewName, ta, sent.getStartSpan(), sent.getEndSpan());
      int propId = 0;
      for(String clausieSent : clausieResults) {
        sentenceCons.addAttribute("clauseIe:" + propId, clausieSent);
        propId++;
      }
      vu.addConstituent(sentenceCons);
    }
    ta.addView(viewName, vu);
  }
}

相关文章