2011-11-28 25 views

回答

0

的tt4j頁用有用的代碼更新的開始:

import org.annolab.tt4j.*; 
import static java.util.Arrays.asList; 

public class Example { 
     public static void main(String[] args) throws Exception { 
       // Point TT4J to the TreeTagger installation directory. The executable is expected 
       // in the "bin" subdirectory - in this example at "/opt/treetagger/bin/tree-tagger" 
       System.setProperty("treetagger.home", "/opt/treetagger"); 
       TreeTaggerWrapper tt = new TreeTaggerWrapper<String>(); 
       try { 
         tt.setModel("/opt/treetagger/models/english.par:iso8859-1"); 
         tt.setHandler(new TokenHandler<String>() { 
           public void token(String token, String pos, String lemma) { 
             System.out.println(token + "\t" + pos + "\t" + lemma); 
           } 
         }); 
         tt.process(asList(new String[] { "This", "is", "a", "test", "." })); 
       } 
       finally { 
         tt.destroy(); 
       } 
     } 
} 

一個pom.xml(Maven的)這應該是足以讓它工作:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 

    <dependencies> 
    <dependency> 
    <groupId>org.annolab.tt4j</groupId> 
    <artifactId>org.annolab.tt4j</artifactId> 
    <version>1.1.0</version> 
     <type>jar</type> 
    </dependency> 
    </dependencies> 

    <modelVersion>4.0.0</modelVersion> 

    <groupId>gk2go</groupId> 
    <artifactId>gk</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>gk</name> 
    <url>http://maven.apache.org</url> 
</project> 

以上所有代碼都已經過修改,因此未進行原樣測試。