2014-12-06 69 views
5

我想自動識別文檔流中的日期,從這個意義上說,我想使用由開源項目Heideltime提供的代碼,可在此處獲得(https://code.google.com/p/heideltime/)。我安裝了Heideltime套件(不是獨立版本),現在我想知道如何引用它並在我的Java項目中調用它。我已經添加了一個dependecy到Heideltime我的pom.xml裏面:如何在Java項目中使用HeidelTime時間標記器?

<dependency> 
     <groupId>de.unihd.dbs</groupId> 
     <artifactId>heideltime</artifactId> 
     <version>1.7</version> 
    </dependency> 

但我不知道如何從這個源項目中的類調入我自己的項目。我爲兩者都使用Maven。以前使用過的人可能會給我一個建議或建議嗎?非常感謝!

回答

0

這個庫還沒有在Maven中央倉庫中。 (您可以在這個search.maven.org網站查看。)

在您的項目中使用庫。您應該下載JAR文件並將其安裝在本地。請參閱此問題答案:How to add local jar files in maven project?

然後,您可以使用導入包並使用您的項目中的功能。

1

heideltime-kit本身就是一個Maven項目。因此,您可以將heideltime-kit項目添加爲依賴項。 (在Netbeans中,右鍵單擊依賴關係, - >添加依賴關係 - >打開項目(確保項目是首先打開的) - > HeidelTime)

然後將config.props文件移動到項目的src/main /資源文件夾。在config.props中設置treetagger的路徑。

就使用類而言,您需要使用POSTagger.TREETAGGER作爲posTagger參數和硬編碼路徑創建HeidelTimeStandalone實例(請參閱de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone.java)到你的src/main/resources/config.props文件中作爲configPath參數。 例如,

heidelTime = new HeidelTimeStandalone(Language.ENGLISH, 
             DocumentType.COLLOQUIAL, 
             OutputType.TIMEML, 
             "path/to/config.props", 
             POSTagger.TREETAGGER, true); 

然後使用HeidelTime處理文本,你可以簡單地調用處理功能:

String result = heidelTime.process(text, date); 
0

添加到從jgloves的回覆,你可能有興趣來解析Heideltime結果字符串轉換成Java對象表示。以下代碼將Uima-XML表示轉換爲Timex3對象。

HeidelTimeStandalone time = new HeidelTimeStandalone(Language.GERMAN, DocumentType.SCIENTIFIC, OutputType.XMI, "config.props", POSTagger.STANFORDPOSTAGGER); 
    String xmiRepresentation = time.process(document, documentCreationTime); //Apply Heideltime and get the XML-UIMA representation  
    JCas cas = jcasFactory.createJCas(); 

    for(FSIterator<Annotation> it= cas.getAnnotationIndex(Timex3.type).iterator(); it.hasNext();){ 
      System.out.printkn(it.next); 
    } 
相關問題