private Annotator getParser() { if(parserProcessor == null){ parserProcessor = StanfordCoreNLP.getExistingAnnotator("parse"); if (parserProcessor == null) { Properties emptyProperties = new Properties(); parserProcessor = new ParserAnnotator("coref.parse.md", emptyProperties); } assert(parserProcessor != null); } return parserProcessor; }
String[] flags = convertFlagsToArray(props.getProperty(annotatorName + ".flags")); this.parser = loadModel(model, VERBOSE, flags); this.maxSentenceLength = PropertiesUtils.getInt(props, annotatorName + ".maxlen", -1);
try { final List<ParserConstraint> constraints = sentence.get(ParserAnnotations.ConstraintAnnotation.class); trees = doOneSentence(constraints, words); } catch (RuntimeInterruptedException e) { if (VERBOSE) { doOneFailedSentence(annotation, sentence); } else { finishSentence(sentence, trees);
public ParserAnnotator(String parserLoc, boolean verbose, int maxSent, String[] flags) { this(loadModel(parserLoc, verbose, flags), verbose, maxSent); }
try { final List<ParserConstraint> constraints = sentence.get(ParserAnnotations.ConstraintAnnotation.class); tree = doOneSentence(constraints, words); } catch (RuntimeInterruptedException e) { if (VERBOSE) {
Annotation document = new Annotation(sentences); posAnnotator.annotate(document); parseAnnotator.annotate(document); sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
public ParserAnnotator(String parserLoc, boolean verbose, int maxSent, String[] flags) { this(loadModel(parserLoc, verbose, flags), verbose, maxSent); }
@Override public void annotate(Annotation annotation) { if (annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) { if (nThreads != 1 || maxParseTime > 0) { MulticoreWrapper<CoreMap, CoreMap> wrapper = new MulticoreWrapper<CoreMap, CoreMap>(nThreads, new ParserAnnotatorProcessor()); if (maxParseTime > 0) { wrapper.setMaxBlockTime(maxParseTime); } for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) { wrapper.put(sentence); while (wrapper.peek()) { wrapper.poll(); } } wrapper.join(); while (wrapper.peek()) { wrapper.poll(); } } else { // parse a tree for each sentence for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) { doOneSentence(sentence); } } } else { throw new RuntimeException("unable to find sentences in: " + annotation); } }
Annotation document = new Annotation(sentences); posAnnotator.annotate(document); parseAnnotator.annotate(document); sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
/** * Annotate parse trees * * @param properties Properties that control the behavior of the parser. It use "parse.x" properties. * @return A ParserAnnotator */ public Annotator parse(Properties properties) { String parserType = properties.getProperty("parse.type", "stanford"); String maxLenStr = properties.getProperty("parse.maxlen"); if (parserType.equalsIgnoreCase("stanford")) { return new ParserAnnotator("parse", properties); } else if (parserType.equalsIgnoreCase("charniak")) { String model = properties.getProperty("parse.model"); String parserExecutable = properties.getProperty("parse.executable"); if (model == null || parserExecutable == null) { throw new RuntimeException("Both parse.model and parse.executable properties must be specified if parse.type=charniak"); } int maxLen = 399; if (maxLenStr != null) { maxLen = Integer.parseInt(maxLenStr); } return new CharniakParserAnnotator(model, parserExecutable, false, maxLen); } else { throw new RuntimeException("Unknown parser type: " + parserType + " (currently supported: stanford and charniak)"); } }
String[] flags = convertFlagsToArray(props.getProperty(annotatorName + ".flags")); this.parser = loadModel(model, VERBOSE, flags); this.maxSentenceLength = PropertiesUtils.getInt(props, annotatorName + ".maxlen", -1);
public ParserAnnotator(String parserLoc, boolean verbose, int maxSent, String[] flags) { this(loadModel(parserLoc, verbose, flags), verbose, maxSent); }
try { final List<ParserConstraint> constraints = sentence.get(ParserAnnotations.ConstraintAnnotation.class); trees = doOneSentence(constraints, words); } catch (RuntimeInterruptedException e) { if (VERBOSE) { doOneFailedSentence(annotation, sentence); } else { finishSentence(sentence, trees);
Annotation document = new Annotation(sentences); posAnnotator.annotate(document); parseAnnotator.annotate(document); sentences = document.get(CoreAnnotations.SentencesAnnotation.class); if (sentences.get(0).get(TreeCoreAnnotations.TreeAnnotation.class).nodeString().equals("X")) {
private Annotator getParser() { if(parserProcessor == null){ Annotator parser = StanfordCoreNLP.getExistingAnnotator("parse"); if (parser == null) { Properties emptyProperties = new Properties(); parser = new ParserAnnotator("coref.parse.md", emptyProperties); } if (parser == null) { // TODO: these assertions rule out the possibility of alternately named parse/pos annotators throw new AssertionError("Failed to get parser - this should not be possible"); } if (parser.requires().contains(CoreAnnotations.PartOfSpeechAnnotation.class)) { Annotator tagger = StanfordCoreNLP.getExistingAnnotator("pos"); if (tagger == null) { throw new AssertionError("Parser required tagger, but failed to find the pos annotator"); } List<Annotator> annotators = Generics.newArrayList(); annotators.add(tagger); annotators.add(parser); parserProcessor = new AnnotationPipeline(annotators); } else { parserProcessor = parser; } } return parserProcessor; }
String[] flags = convertFlagsToArray(props.getProperty(annotatorName + ".flags")); this.parser = loadModel(model, VERBOSE, flags); this.maxSentenceLength = PropertiesUtils.getInt(props, annotatorName + ".maxlen", -1);
public ParserAnnotator(String parserLoc, boolean verbose, int maxSent, String[] flags) { this(loadModel(parserLoc, verbose, flags), verbose, maxSent); }
Annotation document = new Annotation(sentences); posAnnotator.annotate(document); parseAnnotator.annotate(document); sentences = document.get(CoreAnnotations.SentencesAnnotation.class); if (sentences.get(0).get(TreeCoreAnnotations.TreeAnnotation.class).nodeString().equals("X")) {
ap.addAnnotator(new ParserAnnotator(verbose, -1));
private Annotator getParser() { if(parserProcessor == null){ parserProcessor = StanfordCoreNLP.getExistingAnnotator("parse"); if (parserProcessor == null) { Properties emptyProperties = new Properties(); parserProcessor = new ParserAnnotator("coref.parse.md", emptyProperties); } assert(parserProcessor != null); } return parserProcessor; }