private static String annotateText(AnnotatorService finalPipeline, String text, String views, Logger logger) throws AnnotatorException { if (views == null || text == null) { return "The parameters 'text' and/or 'views' are not specified. Here is a sample input: \n ?text=\"This is a sample sentence. I'm happy.\"&views=POS,NER"; } else { logger.info("------------------------------"); logger.info("Text: " + text); logger.info("Views to add: " + views); String[] viewsInArray = views.split(","); logger.info("Adding the basic annotations . . . "); TextAnnotation ta = finalPipeline.createBasicTextAnnotation("", "", text); for (String vuName : viewsInArray) { logger.info("Adding the view: ->" + vuName.trim() + "<-"); try { finalPipeline.addView(ta, vuName.trim()); } catch (Exception e) { e.printStackTrace(); } printMemoryDetails(logger); } logger.info("Done adding the views. Deserializing the view now."); String output = SerializationHelper.serializeToJson(ta); logger.info("Done. Sending the result back. "); return output; } }
/** * Add the required views to the {@link TextAnnotation}. * * @param ta The {@link TextAnnotation} to be annotated * @return Whether new views were added */ public boolean annotate(TextAnnotation ta) throws AnnotatorException { boolean addedViews = false; for (String view : annotator.getAvailableViews()) { if (ta.hasView(view)) continue; annotator.addView(ta, view); addedViews = true; } return addedViews; } }
private void addViewsFromAnnotatorService(TextAnnotation ta) throws AnnotatorException { if (CommaProperties.getInstance().useCurator()) { annotatorService.addView(ta, ViewNames.POS); annotatorService.addView(ta, ViewNames.NER_CONLL); annotatorService.addView(ta, ViewNames.SHALLOW_PARSE); annotatorService.addView(ta, ViewNames.PARSE_STANFORD); annotatorService.addView(ta, ViewNames.SRL_VERB); annotatorService.addView(ta, ViewNames.SRL_NOM); annotatorService.addView(ta, ViewNames.SRL_PREP); } else { ta.addView(pos); ta.addView(nerConll); ta.addView(shallowParser); ta.addView(parser); } } }
public TextAnnotation preProcessText(String text) throws Exception { TextAnnotation ta; ta = annotator.createBasicTextAnnotation("", "", text); addViews(ta); return ta; }
for (String view : pipeline.getAvailableViews()) { viewsString += ", " + view;
viewProviders.put(annotator.getViewName(), annotator); return new AnnotatorService(taBuilder, viewProviders, rm);
public TextAnnotation preProcessText(TextAnnotation ta) throws Exception { if (useCurator) { annotator.addView(ta, ViewNames.POS); annotator.addView(ta, ViewNames.LEMMA); annotator.addView(ta, ViewNames.SHALLOW_PARSE); annotator.addView(ta, ViewNames.NER_CONLL); } else { ta.addView(pos); ta.addView(ner); ta.addView(lemma); ta.addView(chunker); } return ta; } }
public TextAnnotation preProcessText(String text) throws Exception { TextAnnotation ta; if (useCurator) { ta = annotator.createBasicTextAnnotation("", "", text); } else { ta = taBuilder.createTextAnnotation(text); } return preProcessText(ta); }
for(String view : pipeline.getAvailableViews()) { viewsString += ", " + view;
private static String annotateText(AnnotatorService finalPipeline, String text, String views, Logger logger) throws AnnotatorException { if (views == null || text == null) { return "The parameters 'text' and/or 'views' are not specified. Here is a sample input: \n ?text=\"This is a sample sentence. I'm happy.\"&views=POS,NER"; } else { logger.info("------------------------------"); logger.info("Text: " + text); logger.info("Views to add: " + views); String[] viewsInArray = views.split(","); logger.info("Adding the basic annotations . . . "); TextAnnotation ta = finalPipeline.createBasicTextAnnotation("", "", text); for (String vuName : viewsInArray) { logger.info("Adding the view: ->" + vuName.trim() + "<-"); try { finalPipeline.addView(ta, vuName.trim()); } catch (Exception e) { e.printStackTrace(); } printMemoryDetails(logger); } logger.info("Done adding the views. Deserializing the view now."); String output = SerializationHelper.serializeToJson(ta); logger.info("Done. Sending the result back. "); return output; } }
public TextAnnotation preProcessText(TextAnnotation ta) throws Exception { if (useCurator) { annotator.addView(ta, ViewNames.POS); annotator.addView(ta, ViewNames.LEMMA); annotator.addView(ta, ViewNames.SHALLOW_PARSE); annotator.addView(ta, ViewNames.NER_CONLL); } else { ta.addView(pos); ta.addView(ner); ta.addView(lemma); ta.addView(chunker); } return ta; } }
/** * Add the required views to the {@link TextAnnotation}. * * @param ta The {@link TextAnnotation} to be annotated * @return Whether new views were added */ public boolean annotate(TextAnnotation ta) throws AnnotatorException { boolean addedViews = false; for (String view : annotator.getAvailableViews()) { if (ta.hasView(view)) continue; annotator.addView(ta, view); addedViews = true; } return addedViews; } }
public TextAnnotation preProcessText(String text) throws Exception { TextAnnotation ta; if (useCurator) { ta = annotator.createBasicTextAnnotation("", "", text); } else { ta = taBuilder.createTextAnnotation(text); } return preProcessText(ta); }
for (String view : pipeline.getAvailableViews()) { viewsString += ", " + view;
private static String annotateText(AnnotatorService finalPipeline, String text, String views, Logger logger) throws AnnotatorException { if (views == null || text == null) { return "The parameters 'text' and/or 'views' are not specified. Here is a sample input: \n ?text=\"This is a sample sentence. I'm happy.\"&views=POS,NER"; } else { logger.info("------------------------------"); logger.info("Text: " + text); logger.info("Views to add: " + views); String[] viewsInArray = views.split(","); logger.info("Adding the basic annotations . . . "); TextAnnotation ta = finalPipeline.createBasicTextAnnotation("", "", text); for (String vuName : viewsInArray) { logger.info("Adding the view: ->" + vuName.trim() + "<-"); try { finalPipeline.addView(ta, vuName.trim()); } catch (Exception e) { e.printStackTrace(); } printMemoryDetails(logger); } logger.info("Done adding the views. Deserializing the view now."); String output = SerializationHelper.serializeToJson(ta); logger.info("Done. Sending the result back. "); return output; } }
private void addViewsFromAnnotatorService(TextAnnotation ta) throws AnnotatorException { if (CommaProperties.getInstance().useCurator()) { annotatorService.addView(ta, ViewNames.POS); annotatorService.addView(ta, ViewNames.NER_CONLL); annotatorService.addView(ta, ViewNames.SHALLOW_PARSE); annotatorService.addView(ta, ViewNames.PARSE_STANFORD); annotatorService.addView(ta, ViewNames.SRL_VERB); annotatorService.addView(ta, ViewNames.SRL_NOM); annotatorService.addView(ta, ViewNames.SRL_PREP); } else { ta.addView(pos); ta.addView(nerConll); ta.addView(shallowParser); ta.addView(parser); } } }
for(String view : pipeline.getAvailableViews()) { viewsString += ", " + view;
private static String annotateText(AnnotatorService finalPipeline, String text, String views, Logger logger) throws AnnotatorException { if (views == null || text == null) { return "The parameters 'text' and/or 'views' are not specified. Here is a sample input: \n ?text=\"This is a sample sentence. I'm happy.\"&views=POS,NER"; } else { logger.info("------------------------------"); logger.info("Text: " + text); logger.info("Views to add: " + views); String[] viewsInArray = views.split(","); logger.info("Adding the basic annotations . . . "); TextAnnotation ta = finalPipeline.createBasicTextAnnotation("", "", text); for (String vuName : viewsInArray) { logger.info("Adding the view: ->" + vuName.trim() + "<-"); try { finalPipeline.addView(ta, vuName.trim()); } catch (Exception e) { e.printStackTrace(); } printMemoryDetails(logger); } logger.info("Done adding the views. Deserializing the view now."); String output = SerializationHelper.serializeToJson(ta); logger.info("Done. Sending the result back. "); return output; } }
/** * Add the required views to the {@link TextAnnotation}. The views are specified in * {@link PreprocessorConfigurator#VIEWS_TO_ADD}. * * @param ta The {@link TextAnnotation} to be annotated */ public void annotate(TextAnnotation ta) throws AnnotatorException { for (String view : rm.getCommaSeparatedValues(PreprocessorConfigurator.VIEWS_TO_ADD)) { if (ta.hasView(view)) continue; annotator.addView(ta, view); } } }
public static void main (String[] args) throws Exception { /*Load data*/ byte[] encoded = Files.readAllBytes(Paths.get(args[0])); String text = new String(encoded, StandardCharsets.UTF_8); /*Create textannotation*/ AnnotatorService annotator = CuratorFactory.buildCuratorClient(); TextAnnotation ta = annotator.createBasicTextAnnotation("corpus", "id", text); /*Add part-of-speech*/ annotator.addView(ta, ViewNames.POS); /*ChunkerAnnotator*/ ChunkerAnnotator ca = new ChunkerAnnotator(true); ca.initialize(new ChunkerConfigurator().getDefaultConfig()); ca.addView(ta); /*Output to file*/ List<String> lines = new ArrayList<>(); lines.add(ta.getView(ViewNames.SHALLOW_PARSE).toString()); lines.add(ta.getView(ViewNames.POS).toString()); Path file = Paths.get(args[1]); Files.write(file,lines, Charset.forName("UTF-8")); } }