我写了一个烧瓶应用程序使用锅炉管提取内容。最初我编写了样板文件作为脚本来提取网站内容,但是当我试图与我的api集成时,JVM在执行boilerpeextractor时崩溃了。这是我得到的错误https://github.com/misja/python-boilerpipe/issues/17 我还在github上提出了一个问题
from boilerpipe.extract import Extractor
import unicodedata
class ExtractingContent:
@classmethod
def processingContent(self,sourceUrl,extractorType="DefaultExtractor"):
extractor = Extractor(extractor=extractorType, url=sourceUrl)
extractedText = extractor.getText()
if extractedText:
toNormalString = unicodedata.normalize('NFKD',extractedText).encode('ascii','ignore')
json_data = json.loads({"content": toNormalString, "url": sourceUrl , "status": "success", "publisher_id": "XXXXX", "content_count": str(len(toNormalString)) })
return json_data
else:
json_data = json.dumps({"response": {"message": "No data found", "url": sourceUrl , "status": "success", "content_count": "empty" }})
return json.loads(json_data)
这是上面的脚本,我试图集成到使用Flask restful、sqlachemy、psql的flaskapi中。我也更新了我的java,但没有修复问题.Java版本
^{pr2}$任何帮助都将不胜感激
谢谢
(我在https://github.com/misja/python-boilerpipe/issues/17中所写内容的副本)
好的,我重现了这个错误:调用JVM的线程没有附加到它,因此对JVM内部的调用失败。 这个bug来自锅炉管(见下文)。在
首先,monkey patching:在stackoverflow上发布的代码中,您只需在创建提取器之前添加以下代码:
关于锅炉管道:第50行的
boilerpipe/extractor/__init__.py
中的检查if threading.activeCount() > 1
是错误的。 调用线程必须始终连接到JVM,即使只有一个。在相关问题 更多 >
编程相关推荐