您好,这是我使用语言工具创建拼写检查词典的经验!希望你喜欢它。
Part 1: 如何创建字典
你需要:
• 包含字典的.txt 文件
• 一个.info 文件,指定如何设置LT 输出文件的信息(它已存在于LT 目录中)。
• LanguageTool 独立版本
Java 8
在本节结束时,您将获得:
• .dict 文件,即包含 LT 可读格式的词典的文件
- 安装 LT 的最新版本:https://languagetool.org/download/snapshots/?C=M;O=D https://languagetool.org/download/snapshots/?C=M;O=D
- 确保您的 .txt 具有正确的格式 (a) 和编码 (b):
A。 1字标准线
b. UTF8编码
- 在命令行中写入:
A。 java -cp languagetool.jar org.languagetool.tools.SpellDictionaryBuilder fr_FR -i字典文件的路径 -info .info 文件的路径 -o 输出文件的路径
where:
我。 fr_FR是与字典的语言相关的代码
二. –i 这是输入文件的参数(你的.txt)
三. –info 是与字典相关的.info文件的参数。您可以按照以下说明创建它(http://wiki.languagetool.org/hunspell-support http://wiki.languagetool.org/hunspell-support- “配置词典”部分)或使用 \org\languagetool\resource\yourlanguage 中已有的 .info(如果存在)
四. -o 该参数用于指定您希望保存 .dict 输出文件的位置
Part 2: 如何在 LT 上集成词典进行拼写检查
你需要:
JDK 1.8(http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
• Maven(https://maven.apache.org/download.cgi https://maven.apache.org/download.cgi)
• Java IDE(JetBrains、Eclipse 等)
• .info 文件 + .dict 文件(参见第 1 部分)
• GitHub LanguageTool 项目(https://github.com/languagetool-org/languagetool https://github.com/languagetool-org/languagetool)
- 设置 JDK 和 Maven bin 路径(更多信息:https://maven.apache.org/install.html https://maven.apache.org/install.html)
- 将第 1 部分创建的 .info 和 .dict 文件复制到 \languagetool-master\languagetool-language-modules\YourLanguage\src\main\resources\org\languagetool\resource\YourLanguage\hunspell
- 使用 IDE 打开名为字典语言的 java 文件(例如 French.java):
A。将 YourLanguage.java 中的 HunspellNoSuggestionRule 更改为 MorfologikYourLanguageSpellerRule
@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)
);
}
b.在 \languagetool-master\languagetool-language-modules\YourLanguage\src\main\java\org\languagetool\rules\YourLanguage 中创建新的 MorfologikYourLanguageSpellerRule.java :
/* 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;
}
}
C。使用命令行转到 \languagetool-master\ 并写入: Mvn package
d.在 \languagetool-master\languagetool-standalone\target\LanguageTool-3.4-SNAPSHOT\LanguageTool-3.4-SNAPSHOT 中查看结果。