Is it possible to parse a sentence using the Stanford Parser by passing a string and not an array of strings. This is the example they gave in their short tutorial (See Docs) :
Here's example:
import java.util.*;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.parser.lexparser.LexicalizedParser;
class ParserDemo {
public static void main(String[] args) {
LexicalizedParser lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz");
lp.setOptionFlags(new String[]{"-maxLength", "80", "-retainTmpSubcategories"});
String[] sent = { "This", "is", "an", "easy", "sentence", "." }; // This is the sentence to be parsed
List<CoreLabel> rawWords = Sentence.toCoreLabelList(sent);
Tree parse = lp.apply(rawWords);
parse.pennPrint();
System.out.println();
TreebankLanguagePack tlp = new PennTreebankLanguagePack();
GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
List<TypedDependency> tdl = gs.typedDependenciesCCprocessed();
System.out.println(tdl);
System.out.println();
}
}
I am trying to see if I can do this because I need to get sentences from a MySQL database and parse them directly as strings. I could tokezine the sentences and add the words, commas, and period to a String Array, However, to tokenize these sentences, I would have to use the Stanford Tokenizer , PTBTokenizer. The constructor of this tokenizer as listed here
(See Docs)
requires a "java.io.FileReader" Object, but I am not reading a file from directory. So I am wondering if there is a way to either Parse the sentence directly by passing a string, or if I can solve my problem by tokenizing the sentence without requiring a "java.io.FileReader" Object.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…