我正在使用 languageTool 和 python。但是当我想进行很长的文本或大量文本时,它非常慢。我一直在看建议机制有多长,我实际上不需要任何建议,我只对rule_id和类别感兴趣。
有人知道如何关闭此建议机制以获得一些处理能力吗?
查看源代码:看起来最接近的参数是 -a
,但这只是为了启用建议的自动应用,而不是禁用建议。它是开源的,因此您可以自己编辑它并创建一个参数。
parser.add_argument("file",
help="plain text file or “-” for stdin")
parser.add_argument("-c", "--encoding",
help="input encoding")
parser.add_argument("-l", "--language", metavar="CODE",
help="language code of the input or “auto”")
parser.add_argument("-m", "--mother-tongue", metavar="CODE",
help="language code of your first language")
parser.add_argument("-d", "--disable", metavar="RULES", type=get_rules,
action=RulesAction, default=set(),
help="list of rule IDs to be disabled")
parser.add_argument("-e", "--enable", metavar="RULES", type=get_rules,
action=RulesAction, default=set(),
help="list of rule IDs to be enabled")
parser.add_argument("--api", action="store_true",
help="print results as XML")
parser.add_argument("--version", action="version",
version="LanguageTool {} ({})"
.format(language_tool.get_version(),
language_tool.get_build_date()),
help="show LanguageTool version and build date")
parser.add_argument("-a", "--apply", action="store_true",
help="automatically apply suggestions if available")
parser.add_argument("-s", "--spell-check-off", dest="spell_check",
action="store_false",
help="disable spell-checking rules")
return parser.parse_args() parser.add_argument("file",
help="plain text file or “-” for stdin")
parser.add_argument("-c", "--encoding",
help="input encoding")
parser.add_argument("-l", "--language", metavar="CODE",
help="language code of the input or “auto”")
parser.add_argument("-m", "--mother-tongue", metavar="CODE",
help="language code of your first language")
parser.add_argument("-d", "--disable", metavar="RULES", type=get_rules,
action=RulesAction, default=set(),
help="list of rule IDs to be disabled")
parser.add_argument("-e", "--enable", metavar="RULES", type=get_rules,
action=RulesAction, default=set(),
help="list of rule IDs to be enabled")
parser.add_argument("--api", action="store_true",
help="print results as XML")
parser.add_argument("--version", action="version",
version="LanguageTool {} ({})"
.format(language_tool.get_version(),
language_tool.get_build_date()),
help="show LanguageTool version and build date")
parser.add_argument("-a", "--apply", action="store_true",
help="automatically apply suggestions if available")
parser.add_argument("-s", "--spell-check-off", dest="spell_check",
action="store_false",
help="disable spell-checking rules")
return parser.parse_args()
如果有人仍然想知道,language-tool-python
有配置选项maxSpellingSuggestions
.
但是,尽管0
默认值(并且在初始化工具时将其设置为 0
后注意到相同的行为),但我注意到当此参数实际设置为 1
时,代码运行速度明显更快(几乎快 2 倍)。
初始化示例:
import language_tool_python
language_tool = language_tool_python.LanguageTool('en-US', config={'maxSpellingSuggestions': 1})