use of edu.stanford.nlp.parser.nndep.DependencyParser in project CoreNLP by stanfordnlp.
the class SceneGraphImageDependencyParser method main.
public static void main(String[] args) throws IOException {
DependencyParser parser = DependencyParser.loadFromModelFile(DependencyParser.DEFAULT_MODEL);
String filename = args[0];
BufferedReader reader = IOUtils.readerFromString(filename);
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
SceneGraphImage img = SceneGraphImage.readFromJSON(line);
if (img == null) {
continue;
}
for (SceneGraphImageRegion region : img.regions) {
if (region.tokens != null) {
region.gs = parser.predict(region.tokens);
}
}
System.out.println(img.toJSON());
}
}
use of edu.stanford.nlp.parser.nndep.DependencyParser in project CoreNLP by stanfordnlp.
the class TaggerParserPosTagCompatibilityITest method testTagSet4.
private static void testTagSet4(String[] lexParsers, String[] maxentTaggers, String[] srParsers, String[] nnDepParsers) {
// Choose a reference point to work from. We choose the first maxent tagger, since there must be one of those.
String refTaggerName = maxentTaggers[0];
MaxentTagger refTagger = new MaxentTagger(refTaggerName);
Set<String> tagSet = refTagger.tagSet();
tagSet.removeAll(tagsToIgnore);
for (String name : maxentTaggers) {
MaxentTagger tagger = new MaxentTagger(name);
Set<String> maxentTagSet = new HashSet<>(tagger.tagSet());
maxentTagSet.removeAll(tagsToIgnore);
assertEquals(refTaggerName + " vs. " + name + " tag set mismatch:\n" + "left - right: " + Sets.diff(tagSet, maxentTagSet) + "; right - left: " + Sets.diff(maxentTagSet, tagSet) + "\n", tagSet, maxentTagSet);
}
for (String name : lexParsers) {
LexicalizedParser lp = LexicalizedParser.loadModel(name);
Set<String> lexParserTagSet = new HashSet<>(lp.getLexicon().tagSet(lp.treebankLanguagePack().getBasicCategoryFunction()));
lexParserTagSet.removeAll(tagsToIgnore);
assertEquals(refTaggerName + " vs. " + name + " tag set mismatch:\n" + "left - right: " + Sets.diff(tagSet, lexParserTagSet) + "; right - left: " + Sets.diff(lexParserTagSet, tagSet) + "\n", tagSet, lexParserTagSet);
}
for (String name : srParsers) {
ShiftReduceParser srp = ShiftReduceParser.loadModel(name);
Set<String> srParserTagSet = new HashSet<>(srp.tagSet());
srParserTagSet.removeAll(tagsToIgnore);
assertEquals(refTaggerName + " vs. " + name + " tag set mismatch:\n" + "left - right: " + Sets.diff(tagSet, srParserTagSet) + "; right - left: " + Sets.diff(srParserTagSet, tagSet) + "\n", tagSet, srParserTagSet);
}
for (String name : nnDepParsers) {
DependencyParser dp = DependencyParser.loadFromModelFile(name);
Set<String> nnDepParserTagSet = new HashSet<String>(dp.getPosSet());
nnDepParserTagSet.removeAll(tagsToIgnore);
assertEquals(refTaggerName + " vs. " + name + " tag set mismatch:\n" + "left - right: " + Sets.diff(tagSet, nnDepParserTagSet) + "; right - left: " + Sets.diff(nnDepParserTagSet, tagSet) + "\n", tagSet, nnDepParserTagSet);
}
}
use of edu.stanford.nlp.parser.nndep.DependencyParser in project CoreNLP by stanfordnlp.
the class DependencyParserDemo method main.
public static void main(String[] args) {
String modelPath = DependencyParser.DEFAULT_MODEL;
String taggerPath = "edu/stanford/nlp/models/pos-tagger/english-left3words-distsim.tagger";
for (int argIndex = 0; argIndex < args.length; ) {
switch(args[argIndex]) {
case "-tagger":
taggerPath = args[argIndex + 1];
argIndex += 2;
break;
case "-model":
modelPath = args[argIndex + 1];
argIndex += 2;
break;
default:
throw new RuntimeException("Unknown argument " + args[argIndex]);
}
}
String text = "I can almost always tell when movies use fake dinosaurs.";
MaxentTagger tagger = new MaxentTagger(taggerPath);
DependencyParser parser = DependencyParser.loadFromModelFile(modelPath);
DocumentPreprocessor tokenizer = new DocumentPreprocessor(new StringReader(text));
for (List<HasWord> sentence : tokenizer) {
List<TaggedWord> tagged = tagger.tagSentence(sentence);
GrammaticalStructure gs = parser.predict(tagged);
// Print typed dependencies
log.info(gs);
}
}
Aggregations