1

我想创建自己的类Corr_tool,它继承自 class language_check.LanguageTool。但它给我带来了一堆错误。我想问一下,如果有一些我不知道的规则,因为对于其他导入的类,继承没有任何问题。

这是我的代码:

from language_check import LanguageTool

class Corr_tool(LanguageTool):
    def __init__(self):
        super().__init__(language='en-GB')

tool1 = Corr_tool()

错误如下所示:

in <module> tool1 = Correct_tool()
in __init__ super().__init__(language='en-GB')
in __init__ self._language = LanguageTag(language)
in __new__ return str.__new__(cls, cls._normalize(tag))
in _normalize for language in get_languages()}
in get_languages languages = LanguageTool._get_languages()
in _get_languages cls._start_server_if_needed()
in _get_languages ls._start_server_if_needed()
in _start_server_if_needed cls._start_server_on_free_port()
in _start_server_on_free_port cls._start_local_server()
in _start_local_server startupinfo=startupinfo
in __init__ restore_signals, start_new_session)
line 1155, in _execute_child startupinfo)
OSError: [WinError 87] The parameter is incorrect

我错过了什么吗?感谢您的任何解释或帮助。

编辑

当我使用此代码时:

from language_check import LanguageTool

tool1 = LanguageTool('en-GB')
text = u'A sentence with a error in the Hitchhiker’s Guide tot he Galaxy'
matches = tool1.check(text)
for match in matches:
    print(match)  

一切正常。但是当我尝试从这个类继承时,如果得到错误。我的Windows会有问题,这段代码不会也出现这个问题吗?

编辑 2

它让我疯狂。为什么这段代码工作得很好:

from language_check import LanguageTool

tmp_tool = LanguageTool('en-GB')

class Corr_tool(LanguageTool):
    def __init__(self, lang):
        super().__init__(language = lang)

tool = Corr_tool('en-GB')

但是这个不起作用(并抛出我已经在这里写过的错误):

from language_check import LanguageTool

class Corr_tool(LanguageTool):
    def __init__(self, lang):
        super().__init__(language = lang)

tool = Corr_tool('en-GB')
4

2 回答 2

0

该库似乎与 Windows 不兼容。OSError代码 ( 87) 涉及尝试通过分叉创建新进程(在 Windows 上不可用)。

您的选择是:

  • 将您的代码移植到兼容的平台。例如。GNU/Linux、OSX 或 BSD。
  • 寻找另一个图书馆
  • 说服您的库作者使该模块与 Windows 兼容。这似乎不太可能,因为此功能请求似乎是在 2015 年提出的,但仍未实施。
于 2018-10-20T14:19:02.687 回答
0
from language_check import LanguageTool

class Corr_tool(LanguageTool):
    def __init__(self):
        super().__init__(language='en-GB')

tool = Corr_tool()
text = u"A sentence with a error in the Hitchhiker's Guide tot he Galaxy"
matches = tool.check(text)
for match in matches:
    print(match)

没有错误

印刷 :

Line 1, column 17, Rule ID: EN_A_VS_AN
Message: Use 'an' instead of 'a' if the following word starts with a vowel sound, e.g. 'an article', 'an hour'
Suggestion: an
A sentence with a error in the Hitchhiker’s Guide tot he ...
                ^
Line 1, column 32, Rule ID: MORFOLOGIK_RULE_EN_GB
Message: Possible spelling mistake found
Suggestion: Hitch-hiker
A sentence with a error in the Hitchhiker’s Guide tot he Galaxy
                               ^^^^^^^^^^
Line 1, column 51, Rule ID: TOT_HE[1]
Message: Did you mean 'to the'?
Suggestion: to the
... with a error in the Hitchhiker’s Guide tot he Galaxy

看起来在 Windows 8 上使用 python v3.6.4、language_check v1.1 和 java 1.8 一切正常

于 2018-10-20T13:57:49.383 回答