/** * return the next annotation object. Don't forget to increment currentAnnotationId. * * @return an annotation object. */ @Override public XmlTextAnnotation next() { String data; try { data = LineIO.slurp(currentfile); } catch (FileNotFoundException e1) { this.badFiles.add(this.currentfile); return null; } catch (Throwable e1) { e1.printStackTrace(); return null; } try { XmlTextAnnotation ta = nextAnnotation(data, currentfile); return ta; } catch (AnnotatorException e) { e.printStackTrace(); throw new IllegalStateException(e); } }
/** * return the next annotation object. Don't forget to increment currentAnnotationId. * * @return an annotation object. */ @Override public XmlTextAnnotation next() { String data; try { data = LineIO.slurp(currentfile); } catch (FileNotFoundException e1) { this.badFiles.add(this.currentfile); return null; } catch (Throwable e1) { e1.printStackTrace(); return null; } try { XmlTextAnnotation ta = nextAnnotation(data, currentfile); return ta; } catch (AnnotatorException e) { e.printStackTrace(); throw new IllegalStateException(e); } }
public void RunPipelineWithCorpusReader(AnnotationReader reader) { Iterator<TextAnnotation> iter = reader.iterator(); boolean replaceExistingViews = false; while (iter.hasNext()) { TextAnnotation ta = iter.next(); try { ta = pipeline.annotateTextAnnotation(ta, replaceExistingViews); } catch (AnnotatorException e) { e.printStackTrace(); logger.error("failed to preprocess ta with id '" + ta.getId() + "'."); } logger.debug("processed file (assumed this is TextAnnotation docid): '" + ta.getId() + "'"); } }
public void RunPipelineWithCorpusReader(AnnotationReader reader) { Iterator<TextAnnotation> iter = reader.iterator(); boolean replaceExistingViews = false; while (iter.hasNext()) { TextAnnotation ta = iter.next(); try { ta = pipeline.annotateTextAnnotation(ta, replaceExistingViews); } catch (AnnotatorException e) { e.printStackTrace(); logger.error("failed to preprocess ta with id '" + ta.getId() + "'."); } logger.debug("processed file (assumed this is TextAnnotation docid): '" + ta.getId() + "'"); } }
ta = findNextTree(); } catch (AnnotatorException e) { e.printStackTrace(); throw new IllegalStateException(e);
ta = findNextTree(); } catch (AnnotatorException e) { e.printStackTrace(); throw new IllegalStateException(e);
private static void annotate(String filepath) throws IOException { DepAnnotator annotator = new DepAnnotator(); TextAnnotationBuilder taBuilder = new TokenizerTextAnnotationBuilder(new StatefulTokenizer(true, false)); Preprocessor preprocessor = new Preprocessor(); Files.lines(Paths.get(filepath)).forEach(line -> { TextAnnotation ta = taBuilder.createTextAnnotation(line); try { preprocessor.annotate(ta); annotator.addView(ta); System.out.println(ta.getView(annotator.getViewName()).toString()); } catch (AnnotatorException e) { e.printStackTrace(); } }); }
private static void annotate(String filepath) throws IOException { DepAnnotator annotator = new DepAnnotator(); TextAnnotationBuilder taBuilder = new TokenizerTextAnnotationBuilder(new StatefulTokenizer(true, false)); Preprocessor preprocessor = new Preprocessor(); Files.lines(Paths.get(filepath)).forEach(line -> { TextAnnotation ta = taBuilder.createTextAnnotation(line); try { preprocessor.annotate(ta); annotator.addView(ta); System.out.println(ta.getView(annotator.getViewName()).toString()); } catch (AnnotatorException e) { e.printStackTrace(); } }); }
System.exit(-1); } catch (AnnotatorException e) { e.printStackTrace(); logger.error("Error Annotating the Test Document with the Dataless View ... exiting"); System.exit(-1);
System.exit(-1); } catch (AnnotatorException e) { e.printStackTrace(); logger.error("Error Annotating the Test Document with the Dataless View ... exiting"); System.exit(-1);
System.exit(-1); } catch (AnnotatorException e) { e.printStackTrace(); logger.error("Error Annotating the Test Document with the Dataless View ... exiting"); System.exit(-1);
System.exit(-1); } catch (AnnotatorException e) { e.printStackTrace(); logger.error("Error Annotating the Test Document with the Dataless View ... exiting"); System.exit(-1);
/** * Process each sentence individually. This potentially allows for failure at an individual * sentence level, without failing for the whole text. THIS REQUIRES THAT ALL RELATIONS ARE * INTRA-SENTENCE. Any that are *not* will be omitted for the sentence-level processing. * * @param annotator Annotator to apply * @param textAnnotation TextAnnotation to augment * @return */ public void processBySentence(Annotator annotator, TextAnnotation textAnnotation) { logger.debug("in processBySentence()..."); for (int sentenceId = 0; sentenceId < textAnnotation.sentences().size(); ++sentenceId) { TextAnnotation sentTa = TextAnnotationUtilities.getSubTextAnnotation(textAnnotation, sentenceId); try { annotator.getView(sentTa); int start = textAnnotation.getSentence(sentenceId).getStartSpan(); int end = textAnnotation.getSentence(sentenceId).getEndSpan(); TextAnnotationUtilities.copyViewFromTo(annotator.getViewName(), sentTa, textAnnotation, start, end, start); } catch (AnnotatorException e) { e.printStackTrace(); } } return; }
/** * Process each sentence individually. This potentially allows for failure at an individual * sentence level, without failing for the whole text. THIS REQUIRES THAT ALL RELATIONS ARE * INTRA-SENTENCE. Any that are *not* will be omitted for the sentence-level processing. * * @param annotator Annotator to apply * @param textAnnotation TextAnnotation to augment * @return */ public void processBySentence(Annotator annotator, TextAnnotation textAnnotation) { logger.debug("in processBySentence()..."); for (int sentenceId = 0; sentenceId < textAnnotation.sentences().size(); ++sentenceId) { TextAnnotation sentTa = TextAnnotationUtilities.getSubTextAnnotation(textAnnotation, sentenceId); try { annotator.getView(sentTa); int start = textAnnotation.getSentence(sentenceId).getStartSpan(); int end = textAnnotation.getSentence(sentenceId).getEndSpan(); TextAnnotationUtilities.copyViewFromTo(annotator.getViewName(), sentTa, textAnnotation, start, end, start); } catch (AnnotatorException e) { e.printStackTrace(); } } return; }
@Override public Set<Feature> getWordFeatures(TextAnnotation ta, int wordPosition) throws EdisonException { lazyLoadClusters(brownClustersFile); if (!ta.hasView(viewGenerator.getViewName())) { synchronized (BrownClusterFeatureExtractor.class) { View view = null; try { view = viewGenerator.getView(ta); } catch (AnnotatorException e) { e.printStackTrace(); throw new EdisonException(e.getMessage()); } ta.addView(viewGenerator.getViewName(), view); } } SpanLabelView view = (SpanLabelView) ta.getView(viewGenerator.getViewName()); String word = ta.getToken(wordPosition); // What follows has a subtle bug: view.getLabel only gets the first // label for the word. A word can have multiple brown clusters though! // This has been fixed below. // String cluster = view.getLabel(wordPosition); // // return getBrownClusters(word, cluster); Set<Feature> features = new LinkedHashSet<>(); for (Constituent c : view.getConstituentsCoveringToken(wordPosition)) { String cluster = c.getLabel(); features.addAll(getBrownClusters(word, cluster)); } return features; }
@Override public Set<Feature> getWordFeatures(TextAnnotation ta, int wordPosition) throws EdisonException { lazyLoadClusters(brownClustersFile); if (!ta.hasView(viewGenerator.getViewName())) { synchronized (BrownClusterFeatureExtractor.class) { View view = null; try { view = viewGenerator.getView(ta); } catch (AnnotatorException e) { e.printStackTrace(); throw new EdisonException(e.getMessage()); } ta.addView(viewGenerator.getViewName(), view); } } SpanLabelView view = (SpanLabelView) ta.getView(viewGenerator.getViewName()); String word = ta.getToken(wordPosition); // What follows has a subtle bug: view.getLabel only gets the first // label for the word. A word can have multiple brown clusters though! // This has been fixed below. // String cluster = view.getLabel(wordPosition); // // return getBrownClusters(word, cluster); Set<Feature> features = new LinkedHashSet<>(); for (Constituent c : view.getConstituentsCoveringToken(wordPosition)) { String cluster = c.getLabel(); features.addAll(getBrownClusters(word, cluster)); } return features; }