當我解析一個包含左右方括號的句子時,解析速度要比包含左右括號和默認normalizeOtherBrackets值的句子慢很多且不同保持真實(我會說20秒vs ParserAnnotator運行3秒)。如果這是屬性而不是設置爲false,則括號與括號的解析時間相當可比,但解析樹仍然非常不同。對於帶有括號的文本的真實值,POS是-LRB,而POS是CD,但是在每種情況下樹的一般子結構都是相同的。解決流水中概念上處理方括號vs括號的方法
對於我的語料庫,括號絕大部分是爲了「澄清先行詞」,如this site中所述。然而,PRN短語級別的標籤存在於圓括號中,而不是用於方括號,所以即使它們在句子中具有接近於相同的功能,樹的形成本質上也是不同的。
因此,請解釋解析時間如此不同以及如何才能獲得適當的解析?顯然,一個簡單的方法是將括號替換爲parens,但這似乎不是一個令人滿意的解決方案。有什麼設置可以爲我提供一些解脫嗎?這是我的代碼:
private void execute() {
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner");
props.setProperty("tokenize.options", "normalizeOtherBrackets=false");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
// create an empty Annotation just with the given text
Annotation document = new Annotation(text);
// run all Annotators on this text
pipeline.annotate(document);
// these are all the sentences in this document
// a CoreMap is essentially a Map that uses class objects as keys and has values with custom types
List<CoreMap> sentences = document.get(SentencesAnnotation.class);
long start = System.nanoTime();
ParserAnnotator pa = new ParserAnnotator(DefaultPaths.DEFAULT_PARSER_MODEL, false, 60, new String[0]);
pa.annotate(document);
long end = System.nanoTime();
System.out.println((end - start)/1000000 + " ms");
for(CoreMap sentence: sentences) {
System.out.println(sentence);
Tree cm = sentence.get(TreeAnnotation.class);
cm.pennPrint();
List<CoreLabel> cm2 = sentence.get(TokensAnnotation.class);
for (CoreLabel c : cm2) {
System.out.println(c);
}
}
}
謝謝,這可以幫助我解決很多問題。現在我將開始工作並嘗試一些關於我的語料庫的建議。 – demongolem