2017-04-02 4 views
0

실제로 저는 Java를 사용하여 스페인어 텍스트에서 삼중 추출을 수행합니다. NP-VP-NP 양식의 세 쌍을 추출해야합니다. 저는 Stanford Parser CoreNLP v 3.7.0과 스페인어 모델 v 3.7.0도 사용하고 있습니다. 내 질문은 다음에, 스페인어 모델의 문장에서 NP 하위 트리와 VP 하위 트리를 추출하는 방법이 있습니까? 스페인 파서 트리 형태가 영어 형태와 다른 점을 알고 있습니다.스페인어 모델을 사용하여 스탠포드 파서에서 NP 및 VP 하위 트리를 얻는 방법

예 :

(ROOT (sentence (sn (spec (da0000 El)) (grup.nom (nc0s000 reino))) (grup.verb (vmm0000 canta) (sadv (spec (rg muy)) (grup.adv (rg bien))) (fp .)))

답변

1

당신은 당신이 모든 것을 가지고 있는지 확인하기 위해 주요 배포판을 사용하고 스페인 모델

(여기에 해당 : http://stanfordnlp.github.io/CoreNLP/download.html)

다운로드해야

package edu.stanford.nlp.examples; 

import edu.stanford.nlp.ling.*; 
import edu.stanford.nlp.pipeline.*; 
import edu.stanford.nlp.trees.*; 
import edu.stanford.nlp.trees.tregex.*; 
import edu.stanford.nlp.util.*; 

import java.util.*; 


public class TregexExample { 

    public static void main(String[] args) { 
    // set up pipeline 
    Properties props = StringUtils.argsToProperties("-props", "StanfordCoreNLP-spanish.properties"); 
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 
    // Spanish example 
    Annotation spanishDoc = new Annotation("...insert Spanish text..."); 
    pipeline.annotate(spanishDoc); 
    // get first sentence 
    CoreMap firstSentence = spanishDoc.get(CoreAnnotations.SentencesAnnotation.class).get(0); 
    Tree firstSentenceTree = firstSentence.get(TreeCoreAnnotations.TreeAnnotation.class); 
    // use Tregex to match 
    String nounPhrasePattern = "/grup\\.nom/"; 
    TregexPattern nounPhraseTregexPattern = TregexPattern.compile(nounPhrasePattern); 
    TregexMatcher nounPhraseTregexMatcher = nounPhraseTregexPattern.matcher(firstSentenceTree); 
    while (nounPhraseTregexMatcher.find()) { 
     nounPhraseTregexMatcher.getMatch().pennPrint(); 
    } 
    } 
} 
+0

감사합니다. nounPhrasePattern을 변경하는 동사 그룹과 동일한 작업을 수행해야합니까? –

+0

예 "/grup\\.verb/"로 변경하십시오. – StanfordNLPHelp

+0

완벽. 고마워. –