如何使用语言工具创建用于拼写检查的词典?我不是Java程序员,这是我第一次看到LT。
发布于 2016-05-24 11:23:13
你好,这是我的经验,在创建一个字典,用于拼写检查的语言工具!希望你喜欢它。
第1部分:如何创建字典
你需要:
·一个包含字典的.txt文件
·一个.info文件,指定如何设置LT输出文件的信息(它已经存在于LT目录中)。
·LanguageTool独立版本
·Java 8
在本节结束时,您将拥有:
·.dict文件,即带有字典的用于LT的可读形式的文件
其中:
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)
a.将HunspellNoSuggestionRule中的YourLanguage.java更改为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)
);
}在\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;
}
}使用命令行转到\languagetool-master\并编写: Mvn包
看看你在\languagetool-master\languagetool-standalone\target\LanguageTool-3.4-SNAPSHOT\LanguageTool-3.4-SNAPSHOT.中的结果
发布于 2019-11-09 22:32:49
作为另一种解决方案,我创建了一个GUI程序,以使@KeyPi回答的更容易。你可以找到它,这里。
https://stackoverflow.com/questions/37412145
复制相似问题