python - chaquopy 中的语言检查工具
问题描述
我正在使用这个文件来检查 Android 应用程序中文档的语法,但它在语言工具中给了我错误消息。我正在使用 tool = language_check.LanguageTool('en-US')
工具来检查语法。下面给出的错误消息图像
import language_check
from nltk.tokenize import sent_tokenize
matches=list()
def main(location):
# matches.clear()
mistake=0
path=location
uploaded_sentence=open(path).read()
#uploaded_sentence=path
tool = language_check.LanguageTool('en-US')
sent_text = sent_tokenize(uploaded_sentence)
for sent in sent_text:
#first letter of the sentence is capital
doc=sent.capitalize()
matches=(tool.check(doc))
# print(len(matches))
print(sent ,"\n"," mistakes that are in this sentence = ",len(matches),'\n')
print("type of the mistake that is done","\n ",matches,'\n')
# one of the method for the count grammar mistakes here
# if the mistakes are more than one or one it add only 1
# if len(matches)!=0:
# mistake=mistake+1
# the other method for the grammar mistake count
# here if the mistakes are more than one or one it will add the number of the mistakes
if (len(matches))>0:
mistake=mistake+(len(matches))
print("total number of the mistakes that are done =",mistake)
return(mistake)
解决方案
来自https://github.com/chaquo/chaquopy/issues/397:
language_check 通过在单独的 Java 进程中运行 LanguageTool JAR 并通过管道与其通信来工作。不幸的是,Android 设备不附带 Java 可执行文件或任何其他执行 JAR 的方式,因此 language_check 无法在没有重大更改的情况下在 Android 上运行。
另一种解决方案可能是将 LanguageTool JAR 下载到项目的 libs 目录中,这样它将与您的其余 Java 代码一起编译到您的应用程序中。然后,您可以直接从 Java 调用它,或者使用Chaquopy Python API从 Python 调用它。
有关更多详细信息,请参阅language_check 源代码和LanguageTool 文档。
推荐阅读
- data-structures - 红黑与 2-3-4 树的实际性能,特别是考虑缓存性能?
- python - 当我知道它在陆地上时,为什么底图会在陆地上绘制这个纬度和经度?
- sql - 使用函数从另一个表创建连接表
- google-maps - 如何使用 GMaps 或 Bing Maps API 确定给定 LAT/LONG 位置的流量密度?
- android - 升级 Jetpack Navigation 会导致其他库的编译错误
- go - 我不能使用交叉编译器
- javascript - 如何为数组中存在的所有相同日期提供相同的日期数
- regex - 正则表达式帮助 - 匹配数字或字符串结尾
- css - rem 单位不影响 Chrome 中的 DIV - 最小字体大小设置的副作用
- c - 如何将 [5][5] 数组的指针传递给需要同一数组的双指针的函数?