Làm thế nào tôi có thể lập trình có được cùng một phân tích phụ thuộc bằng cách sử dụng stanford corenlp như đã thấy trong bản demo trực tuyến?Làm cách nào để có được kết quả phân tích cú pháp phụ thuộc chính xác như bản trình diễn trực tuyến?
Tôi đang sử dụng gói corenlp để có được phân tích phụ thuộc cho câu sau đây.
Nhân viên chăm sóc sức khỏe thứ hai ở Texas xét nghiệm dương tính với Ebola, nhà chức trách nói.
tôi cố gắng để có được những phân tích cú pháp lập trình bằng cách sử dụng đoạn mã sau
Properties props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
String text = "Second healthcare worker in Texas tests positive for Ebola , authorities say ."; // Add your text here!
Annotation document = new Annotation(text);
pipeline.annotate(document);
String[] myStringArray = {"SentencesAnnotation"};
List<CoreMap> sentences = document.get(SentencesAnnotation.class);
for(CoreMap sentence: sentences) {
SemanticGraph dependencies = sentence.get(BasicDependenciesAnnotation.class);
IndexedWord root = dependencies.getFirstRoot();
System.out.printf("root(ROOT-0, %s-%d)%n", root.word(), root.index());
for (SemanticGraphEdge e : dependencies.edgeIterable()) {
System.out.printf ("%s(%s-%d, %s-%d)%n", e.getRelation().toString(), e.getGovernor().word(), e.getGovernor().index(), e.getDependent().word(), e.getDependent().index());
}
}
}
tôi nhận được đầu ra sau đây bằng cách sử dụng corenlp stanford 3.5.0 gói.
root(ROOT-0, worker-3)
amod(worker-3, Second-1)
nn(worker-3, healthcare-2)
prep(worker-3, in-4)
amod(worker-3, positive-7)
dep(worker-3, say-12)
pobj(in-4, tests-6)
nn(tests-6, Texas-5)
prep(positive-7, for-8)
pobj(for-8, ebola-9)
nsubj(say-12, authorities-11)
Nhưng bản trình diễn trực tuyến đưa ra một câu trả lời khác với dấu chấm trong từ phân tích cú pháp.
amod(worker-3, Second-1)
nn(worker-3, healthcare-2)
nsubj(tests-6, worker-3)
prep(worker-3, in-4)
pobj(in-4, Texas-5)
ccomp(say-12, tests-6)
acomp(tests-6, positive-7)
prep(positive-7, for-8)
pobj(for-8, Ebola-9)
nsubj(say-12, authorities-11)
root(ROOT-0, say-12)
Làm cách nào để giải quyết đầu ra của tôi phù hợp với demo trực tuyến?
Tôi tin rằng trình phân tích cú pháp là xác định. Hãy chắc chắn rằng bạn đang chạy cùng một phiên bản của CoreNLP như bản demo trực tuyến và bạn đang sử dụng cùng một mô hình. Bạn có thể phải gửi email cho nhóm Stanford và yêu cầu họ đang chạy phiên bản/mô hình nào trên trang web- không chắc chắn họ có thực sự đề cập đến điều này hay không. – mbatchkarov