【问题标题】:Spell check and/or spell correction in Java [duplicate]Java中的拼写检查和/或拼写纠正[重复]
【发布时间】:2012-05-30 16:36:37
【问题描述】:

如何在 Java 应用程序中进行拼写检查和/或拼写更正?

【问题讨论】:

    标签: java nlp spell-checking languagetool


    【解决方案1】:

    Google 的拼写检查器http://code.google.com/p/google-api-spelling-java/

     SpellChecker checker = new SpellChecker();
    
     SpellResponse spellResponse = checker.check( "helloo worlrd" );
    
     for( SpellCorrection sc : spellResponse.getCorrections() )
        System.out.println( sc.getValue() );
    

    这很像当您使用 Gmail 或 Google 服务(例如 translate.google.com 或搜索)时,如果您有错别字,它会为您提供替代建议。

    后台发生了什么?

    SpellChecker 类将请求转换为 XML 并将其发送到 Google 的拼写检查服务。响应也是 XML 格式的,它 然后反序列化为简单的 POJO。

    对上面第一个示例的请求如下所示:

      <?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
      <spellrequest textalreadyclipped="0" ignoredigits="1" 
                              ignoreallcaps="1" ignoredups="0">
        <text>helloo worlrd</text>  
      </spellrequest>
    

    响应 XML 如下所示:

      <?xml version="1.0" encoding="UTF-8"?>  
      <spellresult error="0" clipped="0" charschecked="13">
         <c o="0" l="6" s="1">hello  Helli   hell    hallo   hullo</c>
         <c o="7" l="6" s="1">world  whorled wold    warlord would</c>  
      </spellresult>
    

    没试过。


    更新:
    谷歌可能已经开始为此收费。我没有时间编写代码来检查这一点。有人可以确认。就 Google 而言,他们似乎已经弃用了旧的 API,而使用了新的和付费的 API。

    参考:Google Translate API FAQ

    Translate API 的早期免费版本发生了什么变化?
    自 2011 年 12 月 1 日起,Google Translate API v1 不再可用,并已被 Google Translate API v2 取代。 Google Translate API v1 已于 2011 年 5 月 26 日正式弃用。决定弃用 API 并将其替换为付费服务是因为广泛滥用造成的巨大经济负担。

    【讨论】:

    • 这个谷歌解决方案不能离线工作?
    • 那还免费吗?谷歌现在想要钱来使用谷歌翻译 API。我猜他们真的在那边……
    【解决方案2】:

    您可以使用JOrtho。我之前在其中一个 swing 应用中使用过它。

    【讨论】:

      【解决方案3】:

      一个好的离线解决方案是Jazzy。试试这个example 并下载dictionary

      这是库的Maven dependency

      <dependency>
          <groupId>net.sf.jazzy</groupId>
          <artifactId>jazzy</artifactId>
          <version>0.5.2-rtext-1.4.1-2</version>
      </dependency>
      

      【讨论】:

      • 另一个例子可以找到here
      【解决方案4】:

      Languagetool 是可能适合的基于 Java 的拼写检查和校对软件。 见

      【讨论】:

        【解决方案5】:

        试试 Hunspell。它是拼写检查的标准。您可以使用 Java port of Hunspell,即 Hunspell-c+ JNA

        【讨论】:

          【解决方案6】:

          如果您想要一个简单且离线的解决方案,基于 Google 拼写校正器的 Peter Norvig explanation,请看这里:http://raelcunha.com/spell-correct.php

          【讨论】:

            猜你喜欢
            • 2017-08-27
            • 1970-01-01
            • 2012-03-04
            • 1970-01-01
            • 2013-08-09
            • 2019-07-02
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多