【问题标题】:LanguageTool : words followed by word different fromLanguageTool : 单词后跟不同的单词
【发布时间】:2016-06-03 18:11:04
【问题描述】:

如何匹配一系列单词后跟一个不同于x 的单词?

例如,我如何匹配at the cost of 后跟与some 不同的单词?

我尝试了以下方法,但无济于事:

<rule id="AT_THE_COST_OF_!SOME" name="at the cost of !some">
<pattern>
<token>at</token>
<token>the</token>
<token>cost</token>
<token>of</token>
<token regexp="yes">/^((?!some).)*$</token>
</pattern>
<message>Did you mean <suggestion>at the cost of some \5</suggestion>?</message>
<example correction='at the cost of some efforts'>Yes, it comes 
<marker>at the cost of efforts</marker>.</example>
</rule>

【问题讨论】:

    标签: regex xml languagetool


    【解决方案1】:

    LanguageTool 适用于标记。使用 regexp 是一种特殊情况,如果使用 regexp,它们适用于单个标记(使用 pattern 时)。这将解决您的问题:

    <pattern>
        <token>at</token>
        <token>the</token>
        <token>cost</token>
        <token>of</token>
        <token><exception>some</exception></token>
    </pattern>
    

    要使用正则表达式,请使用&lt;regexp&gt;,如http://wiki.languagetool.org/development-overview#toc8 中所述。

    【讨论】:

    • 根据您的回答,可能完整的 LanguageTool 条目将是 &lt;rule id="AT_THE_COST_OF_!SOME" name="at the cost of !some"&gt; &lt;pattern&gt; &lt;token&gt;at&lt;/token&gt; &lt;token&gt;the&lt;/token&gt; &lt;token&gt;cost&lt;/token&gt; &lt;token&gt;of&lt;/token&gt; &lt;token&gt;&lt;exception&gt;some&lt;/exception&gt;&lt;/token&gt; &lt;/pattern&gt; &lt;message&gt;Did you mean &lt;suggestion&gt;at the cost of some \5&lt;/suggestion&gt;?&lt;/message&gt; &lt;example correction='at the cost of some efforts'&gt;Yes, it comes &lt;marker&gt;at the cost of efforts&lt;/marker&gt;.&lt;/example&gt; &lt;/rule&gt;
    【解决方案2】:

    传统的正则表达式也可以使用&lt;regexp&gt;标签代替&lt;token&gt;标签。 (但需要 LanguageTool 3.2 或更高版本才能使用&lt;regexp&gt;)。欲了解更多信息 - wiki

    &lt;regexp&gt;(at the cost of (?!some\b))\w+&lt;regexp&gt;

    匹配的模式:

    以某人为代价

    不惜一切代价

    模式被丢弃:

    牺牲一些

    请测试here

    【讨论】:

    • 谢谢。测试工作,但我仍在努力将其包含在 LanguageTool 中。特别是,当我将LanguageToolTexstudio 一起使用时,规则&lt;rule id="AT_THE_COST_OF_!SOME" name="at the cost of !some"&gt; &lt;pattern&gt; &lt;token regexp="yes"&gt;/(at the cost of (?!some\b))\w+/&lt;/token&gt; &lt;/pattern&gt; &lt;message&gt;Did you mean &lt;suggestion&gt;at the cost of some&lt;/suggestion&gt;?&lt;/message&gt; &lt;example correction='at the cost of some'&gt;Yes, it comes &lt;marker&gt;at the cost of efforts&lt;/marker&gt;.&lt;/example&gt; &lt;/rule&gt; 不起作用。知道我做错了什么吗?
    • 顺便说一句,理想情况下,我希望有一个规则允许建议更正 at the cost of some \w+ 的形式,即包括最初在 of 之后提出的词。
    • @MartinVanderLinden,我很高兴它有帮助。由于您知道要使用的正则表达式,因此我建议您发布一个新问题,其中包含您面临的问题以及新要求,以便您解决问题。
    • 使用跨越多个标记的正则表达式仅在使用 &lt;regexp&gt; 时有效,在使用 &lt;pattern&gt; 时无效。即使那样,/ 也不是正则表达式的一部分。 &lt;pattern&gt; 应该是首选。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-20
    • 2011-03-07
    • 1970-01-01
    • 2013-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多