2

次の形式で txt ファイルに保存されているタグ付きの文のリストがあります。

We_PRP 've_VBP just_RB wrapped_VBN up_RP with_IN the_DT boys_NNS of_IN Block_NNP B_NNP

文を解析したいのですが、次のコードが見つかりました。

String filename = "tt.txt";
    // This option shows loading and sentence-segmenting and tokenizing
    // a file using DocumentPreprocessor.
    TreebankLanguagePack tlp = new PennTreebankLanguagePack();
    GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
    // You could also create a tokenizer here (as below) and pass it
    // to DocumentPreprocessor
    for (List<HasWord> sentence : new DocumentPreprocessor(filename)) {
        Tree parse = lp.apply(sentence);
        parse.pennPrint();
        System.out.println();

        GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
        Collection tdl = gs.typedDependenciesCCprocessed();
        System.out.println(tdl);
        System.out.println();
    }

解析結果は長く、問題はこの行 new DocumentPreprocessor(filename) にあるのではないかと思いました。実際に文を再タグ付けします。タグ付けステップをスキップする方法はありますか?

4

1 に答える 1

0

Parser FAQで答えを見つけることができます。試してみたところ、うまくいきました

// set up grammar and options as appropriate
LexicalizedParser lp = LexicalizedParser.loadModel(grammar, options);
String[] sent3 = { "It", "can", "can", "it", "." };
// Parser gets tag of second "can" wrong without help                    
String[] tag3 = { "PRP", "MD", "VB", "PRP", "." };                             
List sentence3 = new ArrayList();
for (int i = 0; i < sent3.length; i++) {
  sentence3.add(new TaggedWord(sent3[i], tag3[i]));
}
Tree parse = lp.parse(sentence3);
parse.pennPrint();
于 2014-02-25T06:31:03.323 に答える