首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在LanguageTool中,如何创建字典并将其用于拼写检查?

在LanguageTool中,如何创建字典并将其用于拼写检查?
EN

Stack Overflow用户
提问于 2016-05-24 11:23:13
回答 2查看 2.1K关注 0票数 5

如何使用语言工具创建用于拼写检查的词典?我不是Java程序员,这是我第一次看到LT。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-05-24 11:23:13

你好,这是我的经验,在创建一个字典,用于拼写检查的语言工具!希望你喜欢它。

第1部分:如何创建字典

你需要:

·一个包含字典的.txt文件

·一个.info文件,指定如何设置LT输出文件的信息(它已经存在于LT目录中)。

·LanguageTool独立版本

·Java 8

在本节结束时,您将拥有:

·.dict文件,即带有字典的用于LT的可读形式的文件

  1. 安装LT:https://languagetool.org/download/snapshots/?C=M;O=D的最后一个版本
  2. 确保您的.txt以正确的格式(a)和编码(b):a. 1字等号b. UTF8编码。
  3. 在命令行中写:A.java -cp languagetool.jar org.languagetool.tools.SpellDictionaryBuilder fr_FR -i路径的字典文件-info路径的.info文件-o路径的输出文件

其中:

i. fr_FR是与字典语言相关的代码。

二、-i,它是输入文件的参数(您的.txt)

三、-info--它是与字典相关的.info文件的参数。您可以按照以下说明(http://wiki.languagetool.org/hunspell-support -“配置字典”部分)创建它,或者使用已经存在的.info -如果在org\languagetool\.info中使用

四.-o--它是指定要保存.dict输出文件的位置的参数

第2部分:如何在LT上集成字典用于拼写检查

你需要:

·JDK 1.8 (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)

·Maven (https://maven.apache.org/download.cgi)

·Java (JetBrains、Eclipse等)

·.info文件+ .dict文件(参见part1)

·GitHub LanguageTool项目(https://github.com/languagetool-org/languagetool)

  1. 设置JDK和Maven bin路径(更多信息:https://maven.apache.org/install.html)
  2. 复制\languagetool-master\languagetool-language-modules\YourLanguage\src\main\resources\org\languagetool\resource\YourLanguage\hunspell中在part1上创建的.info和.dict文件
  3. 用IDE打开作为字典语言的java文件(用于ex )。French.java):

a.将HunspellNoSuggestionRule中的YourLanguage.java更改为MorfologikYourLanguageSpellerRule

代码语言:javascript
复制
 @Override
  public List<Rule> getRelevantRules(ResourceBundle messages) throws IOException {
    return Arrays.asList(
new CommaWhitespaceRule(messages),
new DoublePunctuationRule(messages),
new GenericUnpairedBracketsRule(messages,
Arrays.asList("[", "(", "{" /*"«", "‘"*/),
Arrays.asList("]", ")", "}"
/*"»", French dialog can contain multiple sentences. */
/*"’" used in "d’arm" and many other words */)),
new MorfologikYourLanguageSpellerRule(messages, this),
new UppercaseSentenceStartRule(messages, this),
new MultipleWhitespaceRule(messages, this),
new SentenceWhitespaceRule(messages),
// specific to French:
new CompoundRule(messages),
new QuestionWhitespaceRule(messages)
);
}

在\languagetool-master\languagetool-language-modules\YourLanguage\src\main\java\org\languagetool\rules\YourLanguage中创建新的MorfologikYourLanguageSpellerRule.java:

代码语言:javascript
复制
/* LanguageTool, a natural language style checker
 * Copyright (C) 2012 Marcin Miłkowski (http://www.languagetool.org)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 * USA
 */

package org.languagetool.rules.fr;

import java.io.IOException;
import java.util.ResourceBundle;

import org.languagetool.Language;
import org.languagetool.rules.spelling.morfologik.MorfologikSpellerRule;

public final class MorfologikYourLanguageSpellerRule extends MorfologikSpellerRule {

    public static final String RULE_ID = "MORFOLOGIK_RULE_CODEOFYOURLANGUAGE"; /* for ex. Fr_FR for French */

    private static final String RESOURCE_FILENAME = "PATH TO YOUR .DICT FILE";

    public MorfologikFrenchSpellerRule(ResourceBundle messages,
                                      Language language) throws IOException {
    super(messages, language);
  }

    @Override
    public String getFileName() {
        return RESOURCE_FILENAME;
    }

    @Override
    public String getId() {
        return RULE_ID;
    }
}

使用命令行转到\languagetool-master\并编写: Mvn包

看看你在\languagetool-master\languagetool-standalone\target\LanguageTool-3.4-SNAPSHOT\LanguageTool-3.4-SNAPSHOT.中的结果

票数 5
EN

Stack Overflow用户

发布于 2019-11-09 22:32:49

作为另一种解决方案,我创建了一个GUI程序,以使@KeyPi回答的更容易。你可以找到它,这里

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37412145

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档