/** * append a single row of column format NE corpus from TextAnnotation ta corresponding to token index * tokenIndex to columnOutput * for now, assume only token info is present * * @param columnOutput * @param ta * @param tokenIndex */ private static void printRow(StringBuilder columnOutput, String label, TextAnnotation ta, int tokenIndex, int inSentenceOffset ) { // B-LOC 0 0 O O WASHINGTON x x 0 // O 0 1 O O -- x x 0 if ( tokenIndex < ta.size() ) { String token = ta.getToken(tokenIndex); columnOutput.append(label).append("\t").append("0").append( "\t" ).append(inSentenceOffset).append( "\t" ); columnOutput.append(OUT_TAG).append( "\t" ).append(OUT_TAG).append( "\t" ); columnOutput.append( token ).append("\t").append("x").append("\t").append("x"); columnOutput.append("\t").append("0").append(System.lineSeparator()); } else logger.warn( "out of range of token indexes: " + ta.getCorpusId() + " index " + tokenIndex ); }
/** * display a TextAnnotation object. * * @param ta_ * @return */ public String textAnnotationToString( TextAnnotation ta_ ) { String taString = "ID: " + ta_.getId() + "\n" + "Corpus ID: " + ta_.getCorpusId() + "\n"; taString += "Text: " + ta_.getText() + "\n"; Set< String > viewNames = ta_.getAvailableViews(); Iterator< String > it_viewName = viewNames.iterator(); while( it_viewName.hasNext() ) { String viewName = it_viewName.next(); View currentView = ta_.getView( viewName ); taString += "View " + viewName + ":\n"; taString += currentView.toString(); } taString += "\n\n----end " + ta_.getId() + "----\n\n"; return taString; }
annotationCache.addTextAnnotation(ta.getCorpusId(), ta); } catch (Exception e) { e.printStackTrace();
@Override public boolean addView(TextAnnotation textAnnotation, String viewName, ResourceManager runtimeAttributes) throws AnnotatorException { boolean isUpdated = false; if (ViewNames.SENTENCE.equals(viewName) || ViewNames.TOKENS.equals(viewName)) return false; if ( !textAnnotation.hasView( viewName ) || forceUpdate ) { isUpdated = true; if ( !viewProviders.containsKey(viewName) ) throw new AnnotatorException( "View '" + viewName + "' cannot be provided by this AnnotatorService." ); Annotator annotator = viewProviders.get( viewName ); for ( String prereqView : annotator.getRequiredViews() ) { addView( textAnnotation, prereqView, runtimeAttributes); } View v = annotator.getView(textAnnotation, runtimeAttributes); textAnnotation.addView( annotator.getViewName(), v ); } if (isUpdated && throwExceptionIfNotCached) throwNotCachedException(textAnnotation.getCorpusId(), textAnnotation.getId(), textAnnotation.getText()); return isUpdated; }
annotationCache.addTextAnnotation(ta.getCorpusId(), ta); } catch (Exception e) { e.printStackTrace();
@Override public boolean addView(TextAnnotation textAnnotation, String viewName, ResourceManager runtimeAttributes) throws AnnotatorException { boolean isUpdated = false; if (ViewNames.SENTENCE.equals(viewName) || ViewNames.TOKENS.equals(viewName)) return false; if ( !textAnnotation.hasView( viewName ) || forceUpdate ) { isUpdated = true; if ( !viewProviders.containsKey(viewName) ) throw new AnnotatorException( "View '" + viewName + "' cannot be provided by this AnnotatorService." ); Annotator annotator = viewProviders.get( viewName ); for ( String prereqView : annotator.getRequiredViews() ) { addView( textAnnotation, prereqView, runtimeAttributes); } View v = annotator.getView(textAnnotation, runtimeAttributes); textAnnotation.addView( annotator.getViewName(), v ); } if (isUpdated && throwExceptionIfNotCached) throwNotCachedException(textAnnotation.getCorpusId(), textAnnotation.getId(), textAnnotation.getText()); return isUpdated; }
writeString("corpusId", ta.getCorpusId(), json); writeString("id", ta.getId(), json); writeString("text", ta.getText(), json);
/** * DOES NOT CACHE THE ADDED VIEW!!! * * @param textAnnotation textAnnotation to be modified * @param viewName name of view to be added * @return 'true' if textAnnotation was modified * @throws AnnotatorException */ @Override public boolean addView(TextAnnotation textAnnotation, String viewName) throws AnnotatorException { boolean isUpdated = false; if (ViewNames.SENTENCE.equals(viewName) || ViewNames.TOKENS.equals(viewName)) return false; if ( !textAnnotation.hasView( viewName ) || forceUpdate ) { isUpdated = true; if ( !viewProviders.containsKey(viewName) ) throw new AnnotatorException( "View '" + viewName + "' cannot be provided by this AnnotatorService." ); Annotator annotator = viewProviders.get( viewName ); for ( String prereqView : annotator.getRequiredViews() ) { addView( textAnnotation, prereqView ); } View v = annotator.getView(textAnnotation); textAnnotation.addView( annotator.getViewName(), v ); } if (isUpdated && throwExceptionIfNotCached) throwNotCachedException(textAnnotation.getCorpusId(), textAnnotation.getId(), textAnnotation.getText()); return isUpdated; }
View nerView = ta.getView(reader.getMentionViewName()); CoNLL2002Writer.writeViewInCoNLL2003Format(nerView, ta, conllDir + "/" + ta.getCorpusId() + ".txt");
/** * DOES NOT CACHE THE ADDED VIEW!!! * * @param textAnnotation textAnnotation to be modified * @param viewName name of view to be added * @return 'true' if textAnnotation was modified * @throws AnnotatorException */ @Override public boolean addView(TextAnnotation textAnnotation, String viewName) throws AnnotatorException { boolean isUpdated = false; if (ViewNames.SENTENCE.equals(viewName) || ViewNames.TOKENS.equals(viewName)) return false; if ( !textAnnotation.hasView( viewName ) || forceUpdate ) { isUpdated = true; if ( !viewProviders.containsKey(viewName) ) throw new AnnotatorException( "View '" + viewName + "' cannot be provided by this AnnotatorService." ); Annotator annotator = viewProviders.get( viewName ); for ( String prereqView : annotator.getRequiredViews() ) { addView( textAnnotation, prereqView ); } View v = annotator.getView(textAnnotation); textAnnotation.addView( annotator.getViewName(), v ); } if (isUpdated && throwExceptionIfNotCached) throwNotCachedException(textAnnotation.getCorpusId(), textAnnotation.getId(), textAnnotation.getText()); return isUpdated; }
writeString("corpusId", ta.getCorpusId(), json); writeString("id", ta.getId(), json); writeString("text", ta.getText(), json);
View nerView = ta.getView(reader.getMentionViewName()); CoNLL2002Writer.writeViewInCoNLL2003Format(nerView, ta, conllDir + "/" + ta.getCorpusId() + ".txt");
@Override public boolean addView(TextAnnotation ta, String viewName) throws AnnotatorException { if (ViewNames.SENTENCE.equals(viewName) || ViewNames.TOKENS.equals(viewName)) return false; if (!viewProviders.containsKey(viewName)) throw new AnnotatorException("View " + viewName + " is not supported."); boolean isUpdated = false; if (ta.hasView(viewName)) return false; if (annotationCache != null && annotationCache.contains(ta)) { TextAnnotation taFromCache = annotationCache.getTextAnnotation(ta); if(taFromCache.getAvailableViews().contains(viewName)) { ta.addView(viewName, taFromCache.getView(viewName)); return false; } } Annotator annotator = viewProviders.get(viewName); for (String prereqView : annotator.getRequiredViews()) isUpdated = addView(ta, prereqView); ta.addView(annotator); if (annotationCache != null ) { if(annotationCache.contains(ta)) annotationCache.updateTextAnnotation(ta); else annotationCache.addTextAnnotation(ta.getCorpusId(), ta); } return isUpdated; }
String text = goldTa.getText(); TextAnnotation predTa = taBldr.createTextAnnotation(goldTa.getCorpusId() + "_PREDICTED", goldTa.getId(), text);
@Override public boolean addView(TextAnnotation ta, String viewName) throws AnnotatorException { if (ViewNames.SENTENCE.equals(viewName) || ViewNames.TOKENS.equals(viewName)) return false; if (!viewProviders.containsKey(viewName)) throw new AnnotatorException("View " + viewName + " is not supported."); boolean isUpdated = false; if (ta.hasView(viewName)) return false; if (annotationCache != null && annotationCache.contains(ta)) { TextAnnotation taFromCache = annotationCache.getTextAnnotation(ta); if(taFromCache.getAvailableViews().contains(viewName)) { ta.addView(viewName, taFromCache.getView(viewName)); return false; } } Annotator annotator = viewProviders.get(viewName); for (String prereqView : annotator.getRequiredViews()) isUpdated = addView(ta, prereqView); ta.addView(annotator); if (annotationCache != null ) { if(annotationCache.contains(ta)) annotationCache.updateTextAnnotation(ta); else annotationCache.addTextAnnotation(ta.getCorpusId(), ta); } return isUpdated; }
String text = goldTa.getText(); TextAnnotation predTa = taBldr.createTextAnnotation(goldTa.getCorpusId() + "_PREDICTED", goldTa.getId(), text);
throwNotCachedException(textAnnotation.getCorpusId(), textAnnotation.getId(), textAnnotation.getText()); return isUpdated;
throwNotCachedException(textAnnotation.getCorpusId(), textAnnotation.getId(), textAnnotation.getText()); return isUpdated;
taBuilder.setCorpusId(ta.getCorpusId()); taBuilder.setId(ta.getId()); taBuilder.setText(ta.getText());
taBuilder.setCorpusId(ta.getCorpusId()); taBuilder.setId(ta.getId()); taBuilder.setText(ta.getText());