Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

java - How to pick out a the subject, predicate, and object and adjectives in a sentence

I want to extract the subject, predicate, and object of a sentence and find out which adjectives go to the subject, predicate, or object with Stanford CoreNLP in java code.

I have tried to use the dependency parser to solve this by finding the dependency index, checking the dependency tag if it equals amod, then adding it to an ArrayList, but with this method sometimes the adjective's dependency tag is not amod and is nmod, and other tags may come up.

With determining the object and predicate, I have used a similar method as above. I have checked if it is det, and if it is any other tags that mean it is a predicate or object. However, sometimes different tags come up and it is not efficient to have to parse every tag that somewhat means it is a predicate pointing to the object.

So my question is, how to I get the subject, predicate, and object of a sentence and each's adjectives but not need to check each tag?

For the above mentioned attempts, I have used Stanford CoreNLP Simple API, but I am OK with the standard API if it is truly needed.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should try out the openie annotator which will find (subject, predicate, object) triples.

example command:

java -Xmx5g edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner,depparse,coref,natlog,openie -file basic-example.txt -outputFormat text

example:

The tall man ate the delicious pizza.

example output:

1.0     man     ate     pizza
1.0     man     ate     delicious pizza
1.0     tall man        ate     pizza
1.0     tall man        ate     delicious pizza

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...