如何在java代码

时间:2016-05-01 16:15:05

标签: java heideltime

我想在我的java代码中使用heideltime工具,所以我下载了heideltime-standalone,我导入了de.unihd.dbs.heideltime.standalone.jar以及stanford-postagger.jar。

这是代码:

String textFile ="مدى اسبوع";
HeidelTimeStandalone H = new HeidelTimeStandalone(Language.ARABIC,
                DocumentType.NEWS,
                OutputType.TIMEML,
                "/heideltime-standalone/config.props",
                POSTagger.STANFORDPOSTAGGER,true);
        String result = H.process(textFile,resultFormatter );
        System.out.print(result);

这是输出:

mai 01, 2016 5:09:54 PM de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone initialize
INFOS: HeidelTimeStandalone initialized with language arabic
mai 01, 2016 5:09:54 PM de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone readConfigFile
INFOS: trying to read in file /heideltime-standalone/config.props
May 01, 2016 5:09:56 PM de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone initialize
INFO: HeidelTime initialized
May 01, 2016 5:09:56 PM de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone initialize
INFO: JCas factory initialized
May 01, 2016 5:09:56 PM de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone process
INFO: Processing started
de.unihd.dbs.heideltime.standalone.exceptions.DocumentCreationTimeMissingException
    at de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone.provideDocumentCreationTime(HeidelTimeStandalone.java:304)
    at de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone.process(HeidelTimeStandalone.java:493)
    at de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone.process(HeidelTimeStandalone.java:427)
    at Arabic_Parser.main(Arabic_Parser.java:54)
May 01, 2016 5:09:56 PM de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone process
WARNING: Processing aborted due to errors
May 01, 2016 5:09:56 PM de.unihd.dbs.heideltime.standalone.HeidelTimeStandalone process
INFO: Result formatted
<?xml version="1.0"?>
<!DOCTYPE TimeML SYSTEM "TimeML.dtd">
<TimeML>
مدى اسبوع
</TimeML>

正如您所看到由于错误导致处理中止,请您帮我修复错误

1 个答案:

答案 0 :(得分:0)

你正在调用的HeidelTime

String result = H.process(textFile,resultFormatter );

in its doc comment

/**
 * Processes document with HeidelTime
 * 
 * @param document
 * @return Annotated document
 * @throws DocumentCreationTimeMissingException
 *             If document creation time is missing when processing a
 *             document of type {@link DocumentType#NEWS}. Use
 *             {@link #process(String, Date)} instead to provide document
 *             creation time!
 */
public String process(String document, ResultFormatter resultFormatter)
        throws DocumentCreationTimeMissingException {

如果你想用NEWS调用它,那么你也必须指定一个时间,作为文档和结果格式化程序之间的额外参数。