我想在一個java項目中使用https://code.google.com/p/heideltime/。該代碼「適合UIMA管道」,這是我根本不瞭解的。 UIMA看起來像是設計用於解決大量我沒有的問題,所以我只想獲得運行該代碼所需的最少量的UIMA。如果我想使用單個UIMA相關庫,是否需要重寫我的整個Java項目?
有一個簡單的例子,我可以運行一個簡單的UIMA程序嗎?
我添加
<dependency>
<groupId>org.uimafit</groupId>
<artifactId>uimafit</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.uima</groupId>
<artifactId>uimaj-core</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.uima</groupId>
<artifactId>uimaj-tools</artifactId>
<version>2.4.0</version>
</dependency>
到我的pom.xml,但由於某種原因,行家仍然不會編譯如下:
import org.apache.uima.jcas.JCas;
import org.apache.uima.util.Level;
import org.uimafit.component.JCasAnnotator_ImplBase;
import org.uimafit.descriptor.ConfigurationParameter;
import org.uimafit.descriptor.TypeCapability;
import org.uimafit.examples.tutorial.type.RoomNumber;
public class RoomNumberAnnotatorPipeline {
public static void main(String[] args) throws Exception {
String text = "The meeting was moved from Yorktown 01-144 to Hawthorne 1S-W33.";
TypeSystemDescription tsd = createTypeSystemDescription("org.uimafit.examples.tutorial.type.RoomNumber");
JCas jCas = createJCas(tsd);
// jCas.setDocumentText(text);
// AnalysisEngine analysisEngine = createPrimitive(RoomNumberAnnotator.class, tsd);
// analysisEngine.process(jCas);
//
// for (RoomNumber roomNumber : select(jCas, RoomNumber.class)) {
// System.out.println(roomNumber.getCoveredText() + "\tbuilding = "
// + roomNumber.getBuilding());
// }
}
}
[ERROR] symbol : class TypeSystemDescription
[ERROR] location: class com.stackoverflow.RoomNumberAnnotatorPipeline
UIMA是莫名其妙的依賴關係更充實比典型的java庫?僅僅從Maven Central中拉出UIMA並開始在我現有的代碼中使用他們的類是不夠的?
好吧,我不知怎麼把這個例子中的工作(我不知道它是什麼,我仍然感到困惑爲什麼它不工作之前)我仍然不能夠使用heideltime:
package org.ryan;
import static org.uimafit.factory.AnalysisEngineFactory.createPrimitive;
import static org.uimafit.factory.JCasFactory.createJCas;
import static org.uimafit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription;
import static org.uimafit.util.JCasUtil.select;
import org.apache.uima.UIMAException;
import org.apache.uima.analysis_engine.AnalysisEngine;
import org.apache.uima.jcas.JCas;
import org.apache.uima.resource.metadata.TypeSystemDescription;
import org.uimafit.examples.tutorial.ex1.RoomNumberAnnotator;
import org.uimafit.examples.tutorial.type.RoomNumber;
/**
* Hello world!
*
*/
public class UIMAWTF
{
public static void main(String[] args) throws UIMAException
{
String text = "The meeting was moved from Yorktown 01-144 to Hawthorne 1S-W33. Today is May 5, 2013.";
TypeSystemDescription tsd = createTypeSystemDescription("org.uimafit.examples.tutorial.type.RoomNumber");
JCas jCas = createJCas(tsd);
jCas.setDocumentText(text);
AnalysisEngine analysisEngine = createPrimitive(RoomNumberAnnotator.class, tsd);
analysisEngine.process(jCas);
for (RoomNumber roomNumber : select(jCas, RoomNumber.class)) {
System.out.println(roomNumber.getCoveredText() + "\tbuilding = "
+ roomNumber.getBuilding());
}
}
}
編輯 現在嘗試:
HeidelTimeStandalone hts_sci = new HeidelTimeStandalone(Language.ENGLISH, DocumentType.NEWS, OutputType.TIMEML);//, configPath);
dates = hts_sci.process("19-Nov-2013", new Date(2012,01,05), new TimeMLResultFormatter());
System.out.println(dates);
獲取:
Jul 3, 2013 2:02:41 PM de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone initialize
INFO: HeidelTimeStandalone initialized with language english
Jul 3, 2013 2:02:41 PM de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone readConfigFile
INFO: trying to read in file config.props
java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:61)
at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
at de.unihd.dbs.uima.annotator.heideltime.resources.GenericResourceManager.readResourcesFromDirectory(GenericResourceManager.java:45)
at de.unihd.dbs.uima.annotator.heideltime.resources.NormalizationManager.<init>(NormalizationManager.java:58)
at de.unihd.dbs.uima.annotator.heideltime.resources.NormalizationManager.getInstance(NormalizationManager.java:73)
at de.unihd.dbs.uima.annotator.heideltime.HeidelTime.initialize(HeidelTime.java:143)
at de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone.initialize(HeidelTimeStandalone.java:153)
at de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone.<init>(HeidelTimeStandalone.java:128)
at de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone.<init>(HeidelTimeStandalone.java:112)
at com.hrl.issl.osi.date.LocalHeidelTime.main(LocalHeidelTime.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:662)
Jul 3, 2013 2:02:41 PM de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone initialize
WARNING: HeidelTime could not be initialized
java.lang.NullPointerException
at org.apache.uima.util.XMLInputSource.<init>(XMLInputSource.java:118)
at de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone.initialize(HeidelTimeStandalone.java:163)
at de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone.<init>(HeidelTimeStandalone.java:128)
at de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone.<init>(HeidelTimeStandalone.java:112)
at com.hrl.issl.osi.date.LocalHeidelTime.main(LocalHeidelTime.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:662)
Jul 3, 2013 2:02:41 PM de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone initialize
WARNING: JCas factory could not be initialized
>出於某種原因,maven仍然不會編譯這個: 怎麼樣一些錯誤日誌? – cljk
對,現在在那裏。 – dranxo
TypeSystemDescription沒有導入 - 是同一個包中的類嗎? – cljk