/** * copy views from the relevant span from ta to newTA. If ta is smaller than newTA, map all constituents, * changing offsets according to the value 'offset'. * Otherwise, only map those constituents within the span sourceStartTokenIndex, sourceEndTokenIndex to newTA. * * @param ta * @param newTA * @param sourceStartTokenIndex * @param sourceEndTokenIndex * @param offset */ public static void copyViewsFromTo(TextAnnotation ta, TextAnnotation newTA, int sourceStartTokenIndex, int sourceEndTokenIndex, int offset) { for (String vuName : ta.getAvailableViews()) { if (ViewNames.TOKENS.equals(vuName) || ViewNames.SENTENCE.equals(vuName)) continue; copyViewFromTo(vuName, ta, newTA, sourceStartTokenIndex, sourceEndTokenIndex, offset); } }
/** * copy views from the relevant span from ta to newTA. If ta is smaller than newTA, map all constituents, * changing offsets according to the value 'offset'. * Otherwise, only map those constituents within the span sourceStartTokenIndex, sourceEndTokenIndex to newTA. * * @param ta * @param newTA * @param sourceStartTokenIndex * @param sourceEndTokenIndex * @param offset */ public static void copyViewsFromTo(TextAnnotation ta, TextAnnotation newTA, int sourceStartTokenIndex, int sourceEndTokenIndex, int offset) { for (String vuName : ta.getAvailableViews()) { if (ViewNames.TOKENS.equals(vuName) || ViewNames.SENTENCE.equals(vuName)) continue; copyViewFromTo(vuName, ta, newTA, sourceStartTokenIndex, sourceEndTokenIndex, offset); } }
public static String printTextAnnotation(TextAnnotation ta ) throws IOException { StringBuilder bldr = new StringBuilder(); bldr.append( "TextAnnotation for text: " ); bldr.append( ta.getText() ); for ( String vName: ta.getAvailableViews() ) { bldr.append(printView( ta.getView( vName ))); } return bldr.toString(); }
public static String printTextAnnotation(TextAnnotation ta ) throws IOException { StringBuilder bldr = new StringBuilder(); bldr.append( "TextAnnotation for text: " ); bldr.append( ta.getText() ); for ( String vName: ta.getAvailableViews() ) { bldr.append(printView( ta.getView( vName ))); } return bldr.toString(); }
static public void printTextAnnotation(PrintStream out, TextAnnotation ta) { out.println("TextAnnotation with id: " + ta.getId()); String rawText = ta.getText(); out.println("Raw Text: " + rawText); out.println(getLineFill()); out.println("TextAnnotation Views:"); for (String name : ta.getAvailableViews()) { out.println("View Name: " + name); out.println(ta.getView(name).toString()); out.println(getLineFill()); } }
static public void printTextAnnotation(PrintStream out, TextAnnotation ta) { out.println("TextAnnotation with id: " + ta.getId()); String rawText = ta.getText(); out.println("Raw Text: " + rawText); out.println(getLineFill()); out.println("TextAnnotation Views:"); for (String name : ta.getAvailableViews()) { out.println("View Name: " + name); out.println(ta.getView(name).toString()); out.println(getLineFill()); } }
@Override public TextAnnotation createAnnotatedTextAnnotation(String corpusId, String textId, String text) throws AnnotatorException { TextAnnotation ta = createBasicTextAnnotation(corpusId, textId, text); if (annotationCache != null && annotationCache.contains(ta)) { ta = annotationCache.getTextAnnotation(ta); // clone the views HashSet<String> views = new HashSet<>(viewProviders.keySet()); views.removeAll(ta.getAvailableViews()); if(views.size() == 0) { // it contains the required views; otherwise continue return ta; } } for (String viewName : viewProviders.keySet()) addView(ta, viewName); return ta; }
@Override public TextAnnotation createAnnotatedTextAnnotation(String corpusId, String textId, String text, Tokenizer.Tokenization tokenization) throws AnnotatorException { TextAnnotation ta = createBasicTextAnnotation(corpusId, textId, text, tokenization); if (annotationCache != null && annotationCache.contains(ta)) { ta = annotationCache.getTextAnnotation(ta); // clone the views HashSet<String> views = new HashSet<>(viewProviders.keySet()); views.removeAll(ta.getAvailableViews()); if(views.size() == 0) { // it contains the required views; otherwise continue return ta; } } for (String viewName : viewProviders.keySet()) addView(ta, viewName); return ta; }
@Override public TextAnnotation createAnnotatedTextAnnotation(String corpusId, String textId, String text) throws AnnotatorException { TextAnnotation ta = createBasicTextAnnotation(corpusId, textId, text); if (annotationCache != null && annotationCache.contains(ta)) { ta = annotationCache.getTextAnnotation(ta); // clone the views HashSet<String> views = new HashSet<>(viewProviders.keySet()); views.removeAll(ta.getAvailableViews()); if(views.size() == 0) { // it contains the required views; otherwise continue return ta; } } for (String viewName : viewProviders.keySet()) addView(ta, viewName); return ta; }
@Override public TextAnnotation createAnnotatedTextAnnotation(String corpusId, String textId, String text, Tokenizer.Tokenization tokenization) throws AnnotatorException { TextAnnotation ta = createBasicTextAnnotation(corpusId, textId, text, tokenization); if (annotationCache != null && annotationCache.contains(ta)) { ta = annotationCache.getTextAnnotation(ta); // clone the views HashSet<String> views = new HashSet<>(viewProviders.keySet()); views.removeAll(ta.getAvailableViews()); if(views.size() == 0) { // it contains the required views; otherwise continue return ta; } } for (String viewName : viewProviders.keySet()) addView(ta, viewName); return ta; }
@Override public TextAnnotation createAnnotatedTextAnnotation(String corpusId, String textId, String text, Set<String> viewNames) throws AnnotatorException { TextAnnotation ta = createBasicTextAnnotation(corpusId, textId, text); if (annotationCache != null && annotationCache.contains(ta)) { ta = annotationCache.getTextAnnotation(ta); // clone the views HashSet<String> views = new HashSet<>(viewProviders.keySet()); views.removeAll(ta.getAvailableViews()); if(views.size() == 0) { // it contains the required views; otherwise continue return ta; } } for (String viewName : viewNames) addView(ta, viewName); return ta; }
@Override public TextAnnotation createAnnotatedTextAnnotation(String corpusId, String textId, String text, Set<String> viewNames) throws AnnotatorException { TextAnnotation ta = createBasicTextAnnotation(corpusId, textId, text); if (annotationCache != null && annotationCache.contains(ta)) { ta = annotationCache.getTextAnnotation(ta); // clone the views HashSet<String> views = new HashSet<>(viewProviders.keySet()); views.removeAll(ta.getAvailableViews()); if(views.size() == 0) { // it contains the required views; otherwise continue return ta; } } for (String viewName : viewNames) addView(ta, viewName); return ta; }
@Override public TextAnnotation createAnnotatedTextAnnotation(String corpusId, String textId, String text, Tokenizer.Tokenization tokenization, Set<String> viewNames) throws AnnotatorException { TextAnnotation ta = createBasicTextAnnotation(corpusId, textId, text, tokenization); if (annotationCache != null && annotationCache.contains(ta)) { ta = annotationCache.getTextAnnotation(ta); // clone the views HashSet<String> views = new HashSet<>(viewProviders.keySet()); views.removeAll(ta.getAvailableViews()); if(views.size() == 0) { // it contains the required views; otherwise continue return ta; } } for (String viewName : viewNames) addView(ta, viewName); return ta; }
@Override public TextAnnotation createAnnotatedTextAnnotation(String corpusId, String textId, String text, Tokenizer.Tokenization tokenization, Set<String> viewNames) throws AnnotatorException { TextAnnotation ta = createBasicTextAnnotation(corpusId, textId, text, tokenization); if (annotationCache != null && annotationCache.contains(ta)) { ta = annotationCache.getTextAnnotation(ta); // clone the views HashSet<String> views = new HashSet<>(viewProviders.keySet()); views.removeAll(ta.getAvailableViews()); if(views.size() == 0) { // it contains the required views; otherwise continue return ta; } } for (String viewName : viewNames) addView(ta, viewName); return ta; }
public static void main(String[] args) { ServerClientAnnotator annotator = new ServerClientAnnotator(); String sentA = "This is the best sentence ever."; annotator.setUrl("http://austen.cs.illinois.edu", "8080"); annotator.setViews(ViewNames.POS, ViewNames.LEMMA); annotator.useCaching(); try { TextAnnotation ta = annotator.annotate(sentA); logger.info(ta.getAvailableViews().toString()); } catch (Exception e) { e.printStackTrace(); } } }
public static void main(String[] args) { ServerClientAnnotator annotator = new ServerClientAnnotator(); String sentA = "This is the best sentence ever."; annotator.setUrl("http://austen.cs.illinois.edu", "8080"); annotator.setViews(ViewNames.POS, ViewNames.LEMMA); annotator.useCaching(); try { TextAnnotation ta = annotator.annotate(sentA); logger.info(ta.getAvailableViews().toString()); } catch (Exception e) { e.printStackTrace(); } } }
@Override public TextAnnotation createAnnotatedTextAnnotation(String corpusId, String textId, String text, Set<String> viewsToAnnotate) throws AnnotatorException { TextAnnotation ta = createBasicTextAnnotation(corpusId, textId, text); // if it already contains its, return it. if (!forceUpdate && !disableCache && annotationCache.contains(ta)) { TextAnnotation taFromCache = annotationCache.getTextAnnotation(ta); boolean containsAll = true; for(String vu : viewsToAnnotate) { if(!taFromCache.getAvailableViews().contains(vu)) { containsAll = false; break; } } if(containsAll) return taFromCache; } return addViewsAndCache(ta, viewsToAnnotate, false); }
@Override public TextAnnotation createAnnotatedTextAnnotation(String corpusId, String textId, String text, Set<String> viewsToAnnotate) throws AnnotatorException { TextAnnotation ta = createBasicTextAnnotation(corpusId, textId, text); // if it already contains its, return it. if (!forceUpdate && !disableCache && annotationCache.contains(ta)) { TextAnnotation taFromCache = annotationCache.getTextAnnotation(ta); boolean containsAll = true; for(String vu : viewsToAnnotate) { if(!taFromCache.getAvailableViews().contains(vu)) { containsAll = false; break; } } if(containsAll) return taFromCache; } return addViewsAndCache(ta, viewsToAnnotate, false); }
@Override protected void addView(TextAnnotation ta) throws AnnotatorException { SpanLabelView view = new SpanLabelView(ViewNames.QUESTION_TYPE, ViewNames.QUESTION_TYPE, ta, 1.0); assert ta.getAvailableViews().contains(ViewNames.SHALLOW_PARSE) && ta.getAvailableViews().contains(ViewNames.NER_CONLL) && ta.getAvailableViews().contains(ViewNames.NER_ONTONOTES): "the annotator does not have the required views "; String fineLabel = fine.discreteValue(ta); Double fineLabelScore = fine.scores(ta).getScore(fineLabel).score; String coarseLabel = coarse.discreteValue(ta); Double coarseLabelScore = coarse.scores(ta).getScore(coarseLabel).score; Constituent cFine = new Constituent(fineLabel, fineLabelScore, ViewNames.QUESTION_TYPE, ta, 0, ta.getTokens().length); Constituent cCoarse = new Constituent(coarseLabel, coarseLabelScore, ViewNames.QUESTION_TYPE, ta, 0, ta.getTokens().length); view.addConstituent(cCoarse); view.addConstituent(cFine); ta.addView(ViewNames.QUESTION_TYPE, view); } }
@Override protected void addView(TextAnnotation ta) throws AnnotatorException { SpanLabelView view = new SpanLabelView(ViewNames.QUESTION_TYPE, ViewNames.QUESTION_TYPE, ta, 1.0); assert ta.getAvailableViews().contains(ViewNames.SHALLOW_PARSE) && ta.getAvailableViews().contains(ViewNames.NER_CONLL) && ta.getAvailableViews().contains(ViewNames.NER_ONTONOTES): "the annotator does not have the required views "; String fineLabel = fine.discreteValue(ta); Double fineLabelScore = fine.scores(ta).getScore(fineLabel).score; String coarseLabel = coarse.discreteValue(ta); Double coarseLabelScore = coarse.scores(ta).getScore(coarseLabel).score; Constituent cFine = new Constituent(fineLabel, fineLabelScore, ViewNames.QUESTION_TYPE, ta, 0, ta.getTokens().length); Constituent cCoarse = new Constituent(coarseLabel, coarseLabelScore, ViewNames.QUESTION_TYPE, ta, 0, ta.getTokens().length); view.addConstituent(cCoarse); view.addConstituent(cFine); ta.addView(ViewNames.QUESTION_TYPE, view); } }