我试图理解这个使用 Py4j 的代码。然而,每次我运行代码时,我都会遇到同样的错误。我的 Ubuntu 14.04 中安装了 py4j。jar 文件位于 usr/share/py4j 中。
代码是
from nltk.tokenize.punkt import PunktSentenceTokenizer, PunktParameters
from nltk.tokenize import wordpunct_tokenize , sent_tokenize
from py4j.java_gateway import JavaGateway
import nltk
from nltk.tree import Tree
import os.path
import parsers
LangPaths =os.path.realpath("/home/Downloads/Abstractive Summarizer/SumMe-master/Summarizer/langdetector/profiles/")
tltagger = nltk.data.load("taggers/english.pickle")
tlChunker = nltk.data.load("chunkers/maxent_ne_chunker/english_ace_binary.pickle")
enChunker = nltk.data.load("chunkers/maxent_ne_chunker/english_ace_multiclass.pickle")
punkt_param = PunktParameters() #creates an opening for tokenizer parameters.
punkt_param.abbrev_types = set(['gng','mr','mrs','dr','rep']) #abbreviations further accepted goes here
sentence_splitter = PunktSentenceTokenizer(punkt_param)
tokenized = ""
gateway = JavaGateway()
detector = gateway.entry_point
detector.init(LangPaths)
我得到的错误是
文件“/home/shiju/Downloads/Abstractive Summarizer/SumMe-master/Summarizer/preprocessor.py”,第 29 行,在detector.init(LangPaths)
__call_ answer = self.gateway_client.send_command(command) 中的文件“/usr/local/lib/python2.7/dist-packages/py4j/java_gateway.py”,第 811 行
文件“/usr/local/lib/python2.7/dist-packages/py4j/java_gateway.py”,第 624 行,在 send_command connection = self._get_connection()
文件“/usr/local/lib/python2.7/dist-packages/py4j/java_gateway.py”,第 579 行,在 _get_connection 连接 = self._create_connection() 文件“/usr/local/lib/python2.7/dist -packages/py4j/java_gateway.py”,第 585 行,在 _create_connection connection.start() 中
文件“/usr/local/lib/python2.7/dist-packages/py4j/java_gateway.py”,第 697 行,开始引发 Py4JNetworkError(msg, e) py4j.protocol.Py4JNetworkError:尝试连接时出错Java 服务器
我认为 Python 无法与 Java 应用程序连接