Java Code Examples for edu.stanford.nlp.pipeline.Annotation#set()
The following examples show how to use
edu.stanford.nlp.pipeline.Annotation#set() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FeatureSet.java From winter with Apache License 2.0 | 6 votes |
/** * Prepares the check for a temporal expression. * * @param cell * Holds the columnĀ“s cell * @param pipeline * Used for temporal expressions. * @param result * Holds the intermediate result before executing this operation. * @return Holds the intermediate result after executing this operation. */ private int prepareSUTParser(String cell, AnnotationPipeline pipeline, int result) { if ((!cell.trim().isEmpty()) && (!cell.trim().equals("-") && !cell.trim().equals("--") && !cell.trim().equals("---") && !cell.trim().equals("n/a") && !cell.trim().equals("N/A") && !cell.trim().equals("(n/a)") && !cell.trim().equals("Unknown") && !cell.trim().equals("unknown") && !cell.trim().equals("?") && !cell.trim().equals("??") && !cell.trim().equals(".") && !cell.trim().equals("null") && !cell.trim().equals("NULL") && !cell.trim().equals("Null"))) { Annotation annotation = new Annotation(cell); annotation.set(CoreAnnotations.DocDateAnnotation.class, "2013-07-14"); pipeline.annotate(annotation); List<CoreMap> timexAnnsAll = annotation .get(TimeAnnotations.TimexAnnotations.class); if (timexAnnsAll != null) if (!timexAnnsAll.isEmpty()) result++; } return result; }
Example 2
Source File: CoreNLPHelper.java From Heracles with GNU General Public License v3.0 | 4 votes |
public static Annotation reconstructStanfordAnnotations(Span sentenceSpan, HashMap<Integer, Word> wordIndex, boolean useWordOrderInsteadOfOffset){ String originalText = sentenceSpan.getAnnotation("text", String.class); Annotation a = new Annotation(originalText); a.set(TextAnnotation.class, originalText); //a.set(DocIDAnnotation.class, "document"); List<CoreMap> sentenceAnnotations = new ArrayList<CoreMap>(); a.set(SentencesAnnotation.class, sentenceAnnotations); List<CoreLabel> tokenAnnotations = new ArrayList<CoreLabel>(); a.set(TokensAnnotation.class, tokenAnnotations); ArrayCoreMap sentenceAnnotation = new ArrayCoreMap(); sentenceAnnotations.add(sentenceAnnotation); // int startOffset = sentenceSpan.first().getStartOffset(); for (Word w : sentenceSpan){ CoreLabel c = new CoreLabel(); c.set(TextAnnotation.class, w.getWord()); c.set(OriginalTextAnnotation.class, w.getWord()); c.set(ValueAnnotation.class, w.getWord()); c.set(CharacterOffsetBeginAnnotation.class, w.getStartOffset()); c.set(CharacterOffsetEndAnnotation.class, w.getEndOffset()); c.set(IndexAnnotation.class, w.getOrder()+1); // c.setIndex(w.getOrder()); c.set(SentenceIndexAnnotation.class, 0); // c.setSentIndex(0); c.set(DocIDAnnotation.class, "document"); c.setDocID("document"); if (w.hasAnnotation("pos")) c.set(PartOfSpeechAnnotation.class, w.getAnnotation("pos",String.class)); if (w.hasAnnotation("lemma")) c.set(LemmaAnnotation.class, w.getAnnotation("lemma", String.class)); if (w.hasAnnotation("nerLabel")) c.set(NamedEntityTagAnnotation.class, w.getAnnotation("nerLabel", String.class)); if (w.hasAnnotation("nerValue")) c.set(NormalizedNamedEntityTagAnnotation.class, w.getAnnotation("nerValue", String.class)); tokenAnnotations.add(c); if (useWordOrderInsteadOfOffset){ wordIndex.put(w.getOrder(), w); } else { wordIndex.put(w.getStartOffset(), w); } } //essential sentence annotation: TokensAnnotation sentenceAnnotation.set(TokensAnnotation.class, tokenAnnotations); //essential sentence annotation: TextAnnotation sentenceAnnotation.set(TextAnnotation.class, originalText); //essential sentence annotation: SentenceIndexAnnotation sentenceAnnotation.set(SentenceIndexAnnotation.class, 0); sentenceAnnotation.set(CharacterOffsetBeginAnnotation.class, 0); sentenceAnnotation.set(CharacterOffsetEndAnnotation.class, sentenceSpan.last().getEndOffset()); sentenceAnnotation.set(TokenBeginAnnotation.class, 0); sentenceAnnotation.set(TokenEndAnnotation.class, sentenceSpan.last().getOrder()); return a; }
Example 3
Source File: ReadabilityAnnotator.java From tint with GNU General Public License v3.0 | 4 votes |
/** * Given an Annotation, perform a task on this Annotation. * * @param annotation */ @Override public void annotate(Annotation annotation) { Readability readability = null; if (className != null) { try { Class<? extends Readability> obj = (Class<? extends Readability>) Class.forName(className); Constructor<? extends Readability> constructor = obj.getConstructor(Properties.class, Properties.class, Annotation.class); readability = constructor.newInstance(globalProperties, localProperties, annotation); } catch (Exception e) { LOGGER.error(e.getMessage()); } } if (readability == null) { if (language == null) { LOGGER.warn("Language variable is not defined, readability will be empty"); return; } switch (language) { case "it": readability = new ItalianStandardReadability(globalProperties, localProperties, annotation); break; case "es": readability = new SpanishStandardReadability(globalProperties, localProperties, annotation); break; case "en": readability = new EnglishStandardReadability(globalProperties, localProperties, annotation); break; case "gl": readability = new GalicianStandardReadability(globalProperties, localProperties, annotation); break; // default: // readability = new EnglishReadability(); } } if (readability == null) { return; } List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class); int tokenCount = 0; readability.setSentenceCount(sentences.size()); for (CoreMap sentence : sentences) { int sentenceID = sentence.get(CoreAnnotations.SentenceIndexAnnotation.class); int wordsNow = readability.getWordCount(); for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) { readability.addWord(token); tokenCount++; } int words = readability.getWordCount() - wordsNow; if (words > maxSentenceLength) { readability.addTooLongSentence(sentenceID); } } readability.setTokenCount(tokenCount); readability.finalizeReadability(); annotation.set(ReadabilityAnnotations.ReadabilityAnnotation.class, readability); }