- Add the Codota plugin to your IDE and get smart completions
private void myMethod () {SimpleDateFormat s =
String pattern;new SimpleDateFormat(pattern)
String template;Locale locale;new SimpleDateFormat(template, locale)
new SimpleDateFormat()
- Smart code suggestions by Codota
}
/** * 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); } } }
/** * 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); } } }
@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(); }
@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(); }
/** * 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); }
/** * 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); }
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()); } }
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()); } }
/** * 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; }
/** * 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; }
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]); }
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]); }
private String[] getParse(TextAnnotation ta) { String[] parse = new String[ta.size()]; for (int sentenceId = 0; sentenceId < ta.getNumberOfSentences(); sentenceId++) {
/** * 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); }
/** * 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); }
@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; }
@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; }
@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); }
@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); }
@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); } }