Codota Logo
TextAnnotation.getNumberOfSentences
Code IndexAdd Codota to your IDE (free)

How to use
getNumberOfSentences
method
in
edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation

Best Java code snippets using edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation.getNumberOfSentences (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
SimpleDateFormat s =
  • Codota IconString pattern;new SimpleDateFormat(pattern)
  • Codota IconString template;Locale locale;new SimpleDateFormat(template, locale)
  • Codota Iconnew SimpleDateFormat()
  • Smart code suggestions by Codota
}
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);
  }
}
edu.illinois.cs.cogcomp.core.datastructures.textannotationTextAnnotationgetNumberOfSentences

Popular methods of TextAnnotation

  • addView
  • getView
  • hasView
  • getText
  • getId
  • getSentence
  • getTokens
  • getToken
  • size
  • getTokenIdFromCharacterOffset
    Get the position of token that corresponds to the character offset that is passed as a parameter. Th
  • getAvailableViews
  • <init>
  • getAvailableViews,
  • <init>,
  • getSentenceId,
  • getTokenizedText,
  • getCorpusId,
  • getSentenceFromToken,
  • getTokensInSpan,
  • sentences,
  • addAttribute

Popular in Java

  • Updating database using SQL prepared statement
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • notifyDataSetChanged (ArrayAdapter)
  • findViewById (Activity)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • HashMap (java.util)
    HashMap is an implementation of Map. All optional operations are supported.All elements are permitte
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • JTextField (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now