运行 stanford 交互式解析器(使用 stdin 和 stdout)或 运行 作为服务器
run stanford parser interactively (using stdin and stdout) or run it as a server
我发现当有新输入时重新启动解析器效率很低,所以我想 运行 交互解析器——从标准输入读取输入并将结果打印到标准输出。但是官网给出的指令Can I have the parser run as a filter?好像和options不兼容(比如-port
)。
我知道 CoreNLP 可以 运行 作为服务器,但它不能接收 POS 标记的文本作为输入,所以我不会使用它。
这是我正在尝试的:
class myThread(threading.Thread):
def __init__(self,inQueue,outQueue):
threading.Thread.__init__(self)
self.cmd=['java.exe',
'-mx4g',
'-cp','*',
'edu.stanford.nlp.parser.lexparser.LexicalizedParser',
'-model', 'edu/stanford/nlp/models/lexparser/chinesePCFG.ser.gz',
'-sentences', 'newline',
'-outputFormat', 'conll2007',
'-tokenized',
'-tagSeparator','/',
'-tokenizerFactory', 'edu.stanford.nlp.process.WhitespaceTokenizer',
'-tokenizerMethod', 'newCoreLabelTokenizerFactory',
'-encoding', 'utf8']
self.subp=subprocess.Popen(cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
self.inQueue=inQueue
self.outQueue=outQueue
def run(self):
while True:
rid,sentence=self.inQueue.get()
print(u"Receive sentence %s"%sentence)
sentence=sentence.replace("\n","")
self.subp.stdin.write((sentence+u'\n').encode('utf8'))
self.subp.stdin.flush()
print("start readline")
result=self.subp.stdout.readline()
print("end readline")
print(result)
self.outQueue.put((rid,result))
我认为您有点混淆了事情。 CoreNLP 和 Stanford Parser 都可以选择 运行 作为命令行过滤器,从 stdin 读取并写入 stdout。但是,只有CoreNLP单独提供了webservice的实现。
像port
这样的选项只对后者有意义。
所以,目前,我同意您有一个有效的用例(想要输入预先标记的文本),但目前没有网络服务支持它。最简单的方法是为解析器编写一个简单的 Web 服务实现。对我们来说,它可能会在某个时候发生,但目前还有许多其他优先事项。欢迎其他人写一个。 :)
我发现当有新输入时重新启动解析器效率很低,所以我想 运行 交互解析器——从标准输入读取输入并将结果打印到标准输出。但是官网给出的指令Can I have the parser run as a filter?好像和options不兼容(比如-port
)。
我知道 CoreNLP 可以 运行 作为服务器,但它不能接收 POS 标记的文本作为输入,所以我不会使用它。
这是我正在尝试的:
class myThread(threading.Thread):
def __init__(self,inQueue,outQueue):
threading.Thread.__init__(self)
self.cmd=['java.exe',
'-mx4g',
'-cp','*',
'edu.stanford.nlp.parser.lexparser.LexicalizedParser',
'-model', 'edu/stanford/nlp/models/lexparser/chinesePCFG.ser.gz',
'-sentences', 'newline',
'-outputFormat', 'conll2007',
'-tokenized',
'-tagSeparator','/',
'-tokenizerFactory', 'edu.stanford.nlp.process.WhitespaceTokenizer',
'-tokenizerMethod', 'newCoreLabelTokenizerFactory',
'-encoding', 'utf8']
self.subp=subprocess.Popen(cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
self.inQueue=inQueue
self.outQueue=outQueue
def run(self):
while True:
rid,sentence=self.inQueue.get()
print(u"Receive sentence %s"%sentence)
sentence=sentence.replace("\n","")
self.subp.stdin.write((sentence+u'\n').encode('utf8'))
self.subp.stdin.flush()
print("start readline")
result=self.subp.stdout.readline()
print("end readline")
print(result)
self.outQueue.put((rid,result))
我认为您有点混淆了事情。 CoreNLP 和 Stanford Parser 都可以选择 运行 作为命令行过滤器,从 stdin 读取并写入 stdout。但是,只有CoreNLP单独提供了webservice的实现。
像port
这样的选项只对后者有意义。
所以,目前,我同意您有一个有效的用例(想要输入预先标记的文本),但目前没有网络服务支持它。最简单的方法是为解析器编写一个简单的 Web 服务实现。对我们来说,它可能会在某个时候发生,但目前还有许多其他优先事项。欢迎其他人写一个。 :)