我想从Twitter的API添加流数据,以我的管道,并对其进行批注。
我知道如何从阅读器添加静态数据的管道,但我怎么能与数据流实现的呢?有没有办法将外部数据添加到JCAS对象?
流媒体功能:
this.twitterStream.addListener(new StatusListener() {
public void onStatus(Status status) {
//get data from here to collectionReader
}
}
收集读者:
@Override
public void initialize(UimaContext context) throws ResourceInitializationException{
super.initialize(context);
}
@Override
public Progress[] getProgress() {
//return progress of the stream. necessary?
}
@Override
public boolean hasNext() throws IOException, CollectionException {
//return should always be false since the stream has no end
return false;
}
@Override
public void getNext(JCas jcas) throws IOException, CollectionException {
//get next element of the stream
}
数据应该从API函数将CollectionReader被传递,所以我可以在注释器注释的数据。
基本上,你跳过读者,而是自己创建的案件,并将它们传递到管道。
这是一个示例UIMA / uimaFIT Groovy脚本不使用读取器和代替数据直接传递到管道。
@Grab(group='de.tudarmstadt.ukp.dkpro.core',
module='de.tudarmstadt.ukp.dkpro.core.opennlp-asl',
version='1.5.0')
import static org.apache.uima.fit.pipeline.SimplePipeline.*;
import static org.apache.uima.fit.util.JCasUtil.*;
import static org.apache.uima.fit.factory.AnalysisEngineFactory.*;
import org.apache.uima.fit.factory.JCasFactory;
import de.tudarmstadt.ukp.dkpro.core.opennlp.*;
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.*;
import de.tudarmstadt.ukp.dkpro.core.api.syntax.type.*;
def jcas = JCasFactory.createJCas();
jcas.documentText = "This is a test";
jcas.documentLanguage = "en";
runPipeline(jcas,
createEngineDescription(OpenNlpSegmenter),
createEngineDescription(OpenNlpPosTagger),
createEngineDescription(OpenNlpParser,
OpenNlpParser.PARAM_WRITE_PENN_TREE, true));
select(jcas, Token).each { println "${it.coveredText} ${it.pos.posValue}" }
select(jcas, PennTree).each { println it.pennTree }
注意:这个脚本是不是性能在所有优化。在生产场景中,你会用例的游泳池(因为创建一个CAS是一种昂贵的,通常他们都重复使用)和你使用createEngine(...)
传递之前runPipeline(...)
或致电process(...)
它实例化管道,否则你倒是得到了不少的开销实例的所有管道组件每个文档。
来源:https://dkpro.github.io/dkpro-core/groovy/recipes/opennlp-postag-no-reader/