【问题标题】:Detecting meaningless and/or grammatically incorrect sentence with LanguageTool使用 LanguageTool 检测无意义和/或语法错误的句子
【发布时间】:2012-10-22 17:19:41
【问题描述】:

我需要检查文本中的拼写和语法,所以我开始使用 LanguageTool API (Can be found here)。现在,当我编写他们提供的启动代码时,如下 -

JLanguageTool langTool = new JLanguageTool(Language.ENGLISH);
langTool.activateDefaultPatternRules();
List<RuleMatch> matches = langTool.check("Eat I rice" +
    "every day and go school to good as a boy");
for (RuleMatch match : matches) {
  System.out.println("Potential error at line " +
      match.getEndLine() + ", column " +
      match.getColumn() + ": " + match.getMessage());
  System.out.println("Suggested correction: " +
      match.getSuggestedReplacements());
}

我没有收到任何错误。对不起,如果我错了,但是“每天吃我的饭,像个男孩一样上学”这句话是正确的句子吗(语法上)?如果是,或者不是,那么有没有办法使用该工具检测此类句子(无意义和/或语法错误)?

【问题讨论】:

  • 我怀疑该工具理解文本并判断它是否无意义(语义方面)的能力。
  • 转到网站根目录(删除/development)并尝试一些句子。好像挺没用的
  • @nhahtdh,谢谢。还有其他 Java 工具可以作为建议吗?
  • 不,我以前没有使用过 NLP。

标签: java nlp grammar text-processing languagetool


【解决方案1】:

Languagetool 是基于规则的。显然,“每天吃我米饭,像个男孩一样上学”这句话还没有被任何规则所抓住。

http://wiki.languagetool.org/tips-and-tricks 有关于如何将用户定义的规则添加到 Languagetool 的信息。

以下是此类规则的示例:

<rule>
  <pattern>
    <token>
      <exception regexp="yes">(that|ha[ds]|will|must|could|can|should|would|does|did|may|might|t|let)</exception>
      <exception inflected="yes" regexp="yes">feel|hear|see|watch|prevent|help|stop|be</exception>
      <exception postag="C[CD]|IN|DT|MD|NNP|\." postag_regexp="yes"></exception>
      <exception scope="previous" postag="PRP$"/>
    </token>
    <token postag="NNP" regexp="yes">.{2,}<exception postag="JJ|CC|RP|DT|PRP\$?|NNPS|NNS|IN|RB|WRB|VBN" postag_regexp="yes"></exception></token>
    <marker>
      <token postag="VB|VBP" postag_regexp="yes" regexp="yes">\p{Lower}+<exception postag="VBN|VBD|JJ|IN|MD" postag_regexp="yes"></exception></token>
    </marker>
    <token postag="IN|DT" postag_regexp="yes"></token>
  </pattern>
  <message>The proper name in singular (<match no="2"></match>) must be used with a third-person verb: <suggestion><match no="3" postag="VBZ"></match></suggestion>.</message>
  <short>Grammatical problem</short>
  <example correction="walks" type="incorrect">Ann <marker>walk</marker> to the building.</example>
  <example type="correct">Bill <marker>walks</marker> to the building.</example>
  <example type="correct">Guinness <marker>walked</marker> to the building.</example>
  <example type="correct">Roosevelt and Hoover speak each other's lines.</example>
  <example type="correct">Boys are at higher risk for autism than girls.</example>
  <example type="correct">In reply, he said he was too old for this.</example>
  <example type="correct">I can see Bill looking through the window.</example>
  <example type="correct">Richard J. Hughes made his Morris County debut in his bid for the Democratic gubernatorial elections.</example>
  <example type="correct">... last night got its seven-concert Beethoven cycle at Carnegie Hall off to a good start.</example>
  <example type="correct">... and through knowing Him better to become happier and more effective people.</example>
  <!-- TODO: Fix false-positive: The library and Medical Center are to the north.-->
  <!-- The present Federal program of vocational education began in 1917. -->
</rule>

有一个在线规则编辑器可用

http://community.languagetool.org/ruleEditor2/

一个简单的解决方案是

<!-- English rule, 2014-09-19 --> 
<rule id="ID" name="EatI"> 
   <pattern> <token>Eat</token> <token>i</token> </pattern> 
   <message>Instead of <match no="2"/> <match no="1"/> it should be <match no="1"/> <match no="2"/></message> 
  <url>http://stackoverflow.com/questions/13016469/detecting-meaningless-and-or-grammatically-incorrect-sentence-with-languagetool/25933907#25933907</url> 
  <short>wrong order of verb and nown</short> 
  <example type='incorrect'><marker>Eat i</marker> rice</example> <example type='correct'>I eat rice</example> 
</rule>

当然这只会涵盖动词“Eat”——但我希望你能明白它是如何工作的......

【讨论】:

    猜你喜欢
    • 2020-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-28
    • 1970-01-01
    • 2014-07-24
    • 1970-01-01
    相关资源
    最近更新 更多