zoukankan      html  css  js  c++  java
  • 语法检查程序LanguageTool学习和使用笔记

    这是LanguageTool的官方语法规则说明,一定要仔细研究,学会这个语法,就可以自己编写语法检查规则了,这篇文档上说,编写这份语法检查文档,你甚至都不需要是一名程序员:

    http://wiki.languagetool.org/development-overview#toc3

    开源中国社区,为我们罗列了LanguageTool的版本发布列表:

    LanguageTool首页、文档和下载 - 语法检查程序 - 开源中国社区
    http://www.oschina.net/p/languagetool

    下面是一个中文版的LanguageTool测试页面:

    LanguageTool开源文体和语法校正软件
    中文官方页面:https://www.languagetool.org/zh/

    LanguageTool的JavaAPI调用示例代码:

    Java API - LanguageTool Wiki
    http://wiki.languagetool.org/java-api

    在编写代码的过程中,我们还会需要查看doc文档,学会一些方法的使用,链接如下:

    https://languagetool.org/development/api/

    languagetool中文语法校对xml规则定制方法 - 豆丁网
    http://www.docin.com/p-905900112.html

    LanguageTool语法校正规则库的开发 - 下载频道 - CSDN.NET
    http://download.csdn.net/detail/u011088871/5617583

    下面笔者对http://wiki.languagetool.org/development-overview#toc0这篇在线文档的翻译,希望能对看到这篇文章的你有帮助,我仅仅只是做了一些翻译,如果你的英文较好,建议直接看英文版。

    LanguageTool是一个开源的文体和语法校正的软件,包括对英语、中文、法语、德语、波兰语、荷兰语、罗马尼亚语等很多 其他语言的支持。

    new error detection rules 错误检测规则
    nutshell 概括
    detect 检测
    下载完,解压,然后打开LanguageTool-xx/org/languagetool/rules/en/grammar.xml这个文件。
    Typos 错别字、打字稿、 评写错误
    找到name="Possible Typo"这个节点(它就在开头),按照文档中说的,加上文档里的例子。

    incorrect 错误的,不正确的;不适当的;不真实的
    correct 改正;告诫;正确的

    在合适的目录下使用命令行 java -jar languagetool.jar 运行 languagetool.jar 这个jar文件。
    选择“英语(英国)”作为文本语言的类型(在窗口的左下角)。

    LanguageTool will now check your text and suggest bicycle as a replacement for foo bar, because that's what the rule which we just added says.
    LanguageTool 就会开始帮你检查,当LanguageTool发现“foo bar”一起出现的时候,它就会提示 应该使用“bicycle ”来替换“foo bar”,这正是由于我们刚刚添加了那一条自定义的规则。

    当然如果你不想自己直接编辑 XML 文档,你可以使用 LanguageTool 的在线编辑工具自行编辑。

    get a grasp on 把握
    understanding 理解明白

    internally 内部地;国内地;内在地
    check out 检验

    设置运行的内存。
    You can then build the code with mvn clean package or just run the tests with mvn clean test. Maven's default memory settings are often too low, so you will probably need to set your environment variable MAVEN_OPTS to:
    -Xmx512m -XX:MaxPermSize=256m

    下面我们来看一下 Language 运行的流程:
    Language checking process

    This is what LanguageTool does when it analyzes a text for errors:
    1、将文本分割成句子;
    The text is split into sentences
    2、将每个句子分割成单词;
    Each sentence is split into words

    3、每个word 都会被加上part-of-speech tag(s)词性标记,例如 cars 被标记为 复数名词( plural noun), talked 被标记为“简单动词过去式”。
    Each word is assigned its part-of-speech tag(s) (e.g. cars = plural noun, talked = simple past verb)
    4、然后分析文本开始匹配内置规则,另一部分规则从xml文件加载。
    The analyzed text is then matched against the built-in rules and against the rules loaded from the grammar.xml file

    【你需要记住的最重要的事情是 LanguageTool 的规则“描述的错误是什么样子”,而不是正确的句子应该长什么样。这和我们学习一门新的语言来说恰恰好相反。】
    The most important thing you need to keep in mind is that LanguageTool's rules describe what errors look like, not what correct sentences look like (this is the opposite of how you learn a new language).


    Adding new XML rules
    Most rules are contained in rules/xx/grammar.xml, whereas xx is a language code like en or de.
    pattern 模式

    A rule is basically a pattern which shows an error message to the user if the pattern matches.
    一个<rule>基于一个模式,当这个模式匹配的时候显示一个错误的 message 给用户。
    一个 模式(pattern)给出了 这个单词 或者 词性的标记(part-of-speech tags)。
    A pattern can address words or part-of-speech tags. Here are some examples of patterns that can be used in that file:

    (1)<token>think</token>
    匹配单词 think
    (2)<token>think</token> <token>about</token>
    匹配短语(phrase)think about,【you need to list each word separately as a token】。
    像下面这种写法就不会起作用:<token>think about</token>
    (3)<token regexp="yes">think|say</token>
    i.e. 也就是说
    the word think or the word say
    匹配单词 think 或者 单词say。编写这些简单规则的时候,你甚至可以不需要了解什么是“正则表达式”,但是如果you want to learn more about them you can try this tutorial(指南)。这个链接介绍了什么是正则表达式。
    笔者注:也就是说,LanguageTool也参考了或者就是用正则表达式作为匹配的语法。
    (4)<token postag="VB" />
    匹配一个基本形式的动词。
    a base form verb 一个基本形式动词
    【See resource/en/tagset.txt for a list of possible English part-of-speech tags.】
    找到下面的这个文件,到里面去看 词性标记 的写法。【【【这里需要有一张截图。】】】
    在D: oolsOpenSourceLanguageTool-2.6orglanguagetool esourceen (这个路径的前半部分是笔者电脑里面的路径,大家忽略哟)这个文件里面 tagset.txt 文件。
    (5)<token postag="V.*" postag_regexp="yes" />
    matches a word whose part-of-speech tag starts with V。
    backslash 反斜杠
    请注意到,对于 tags 而言,类似于 PRP$ ,你需要在 $ 之前使用 反斜杠,因为它在正则表达式里面有特殊的含义。
    【【【这里需要一张截图。】】】
    笔者注:加上反斜杠是为了实现转义。否则类似于 PRP$ 这种就会是另外的一个意思,而不是我们所期望的意思。
    Note that for tags with a special character like PRP$ you need to escape the $ with a backslash, as it has a special meaning in regular expressions: PRP$.
    (6)<token>cause</token> <token regexp="yes" negate="yes">and|to</token>
    matches the word “cause” followed by any word that is not “and” or “to”.
    只要 cause 后面不是跟着 and 或者 to ,就匹配,匹配的意思就是让LanguageTool认为是错误的,提示用户修改。
    (7)<token postag="SENT_START" /> <token>foobar</token>
    matches the word foobar only at the beginning of a sentence. The corresponding postag for the end of a sentence is SENT_END.
    只要是 以“foobar”开头的句子,就匹配。这里“匹配”的意思同上。


    A pattern's tokens are matched case-insensitively by default. This can be changed for the whole pattern or for a single token by setting case_sensitive="yes".
    case-insensitively 大小写
    如果你设置 case_sensitive="yes" 就可以改变 整个 pattern。

    Alternatively, case-sensitive matching can be turned on for single tokens by using (?-i) in regular expressions (ex: <token regexp="yes">(?-i)Bill</token> will match Bill but not bill).

    alternatively(非此即彼;二者择一地;作为一种选择)
    be turned on 被打开

    case_sensitive="yes" 这个设置被打开也可以通过在表达式里面写(?-i),这样就执行了严格的大小写匹配。
    笔者注:经过测试,默认情况下,即不设置 case_sensitive="yes" 的情况下,LanguageTool工具在执行匹配的时候忽略大小写。

    The basic elements of a rule

  • 相关阅读:
    11.json
    10.正则表达式
    9.面向对象、类
    bzoj 2878: [Noi2012]迷失游乐园
    bzoj 2727: [HNOI2012]双十字
    bzoj 3224: Tyvj 1728 普通平衡树
    bzoj 3932: [CQOI2015]任务查询系统
    bzoj 1997: [Hnoi2010]Planar
    4 Django简介
    3 web框架
  • 原文地址:https://www.cnblogs.com/liweiwei1419/p/4306411.html
Copyright © 2011-2022 走看看