这个thread包含了一个很好的例子,说明如何使用Stanfords CoreNLP库的包装器。这是我正在使用的exmaple:
from pycorenlp import StanfordCoreNLP
nlp = StanfordCoreNLP('http://localhost:9000')
res = nlp.annotate("I love you. I hate him. You are nice. He is dumb",
properties={
'annotators': 'sentiment',
'outputFormat': 'json',
'timeout': 1000,
})
for s in res["sentences"]:
print("%d: '%s': %s %s" % (
s["index"],
" ".join([t["word"] for t in s["tokens"]]),
s["sentimentValue"], s["sentiment"]))
假设我有+10000个句子,我想像这个例子一样分析。有没有可能并行处理这些和多线程呢?你知道吗
不确定这种方法。在java中,我使用corenlp和我想要使用的管道设置了singleton类。然后我在singleton上调用一个方法,多个线程使用同一个实例,这个方法需要几个句子,它会对它们进行注释,并对结果进行一些处理。所以这种类型的多线程确实有效。我已经这样做了几年,没有任何问题
你能重新考虑一下你的代码吗?所以设置你的管道,然后用你的线程池一次调用几个句子的annotate?不应该太费劲。你知道吗
希望这有道理。你知道吗
相关问题 更多 >
编程相关推荐