本文整理汇总了Java中org.languagetool.JLanguageTool.getAllRules方法的典型用法代码示例。如果您正苦于以下问题:Java JLanguageTool.getAllRules方法的具体用法?Java JLanguageTool.getAllRules怎么用?Java JLanguageTool.getAllRules使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.languagetool.JLanguageTool
的用法示例。
在下文中一共展示了JLanguageTool.getAllRules方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showOptions
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
void showOptions() {
final JLanguageTool langTool = getCurrentLanguageTool();
final List<Rule> rules = langTool.getAllRules();
final ConfigurationDialog configDialog = getCurrentConfigDialog();
configDialog.show(rules); // this blocks until OK/Cancel is clicked in
// the dialog
config.setDisabledRuleIds(configDialog.getDisabledRuleIds());
config.setEnabledRuleIds(configDialog.getEnabledRuleIds());
config.setDisabledCategoryNames(configDialog.getDisabledCategoryNames());
config.setMotherTongue(configDialog.getMotherTongue());
config.setRunServer(configDialog.getRunServer());
config.setServerPort(configDialog.getServerPort());
// Stop server, start new server if requested:
stopServer();
maybeStartServer();
}
示例2: showOptions
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void showOptions() {
final JLanguageTool langTool = ltSupport.getLanguageTool();
final List<Rule> rules = langTool.getAllRules();
final ConfigurationDialog configDialog = ltSupport.getCurrentConfigDialog();
configDialog.show(rules); // this blocks until OK/Cancel is clicked in the dialog
Configuration config = ltSupport.getConfig();
try { //save config - needed for the server
config.saveConfiguration(langTool.getLanguage());
} catch (IOException e) {
Tools.showError(e);
}
ltSupport.reloadConfig();
// Stop server, start new server if requested:
stopServer();
maybeStartServer();
}
示例3: validateRuleIds
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void validateRuleIds(Language lang, JLanguageTool languageTool) {
List<Rule> allRules = languageTool.getAllRules();
Set<String> ids = new HashSet<>();
Set<Class> ruleClasses = new HashSet<>();
Set<String> categoryIds = new HashSet<>();
for (Rule rule : allRules) {
assertIdUniqueness(ids, ruleClasses, lang, rule);
if (rule.getId().equalsIgnoreCase("ID")) {
System.err.println("WARNING: " + lang.getShortCodeWithCountryAndVariant() + " has a rule with id 'ID', this should probably be changed");
}
Category category = rule.getCategory();
if (category != null && category.getId() != null) {
String catId = category.getId().toString();
if (!catId.matches("[A-Z0-9_-]+") && !categoryIds.contains(catId)) {
System.err.println("WARNING: category id '" + catId + "' doesn't match expected regexp [A-Z0-9_-]+");
categoryIds.add(catId);
}
}
}
}
示例4: run
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
@Override
public void run() {
try {
JLanguageTool langTool = new JLanguageTool(docLanguage, config.getMotherTongue());
List<Rule> allRules = langTool.getAllRules();
for (Rule rule : allRules) {
if(rule.isOfficeDefaultOn()) rule.setDefaultOn();
else if(rule.isOfficeDefaultOff()) rule.setDefaultOff();
}
cfgDialog.show(allRules);
config.saveConfiguration(docLanguage);
if (mainThread != null) {
mainThread.resetDocument();
}
} catch (Throwable e) {
Main.showError(e);
}
}
示例5: showOptions
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void showOptions() {
JLanguageTool langTool = ltSupport.getLanguageTool();
List<Rule> rules = langTool.getAllRules();
ConfigurationDialog configDialog = getCurrentConfigDialog();
configDialog.show(rules); // this blocks until OK/Cancel is clicked in the dialog
Configuration config = ltSupport.getConfig();
try { //save config - needed for the server
config.saveConfiguration(langTool.getLanguage());
} catch (IOException e) {
Tools.showError(e);
}
ltSupport.reloadConfig();
// Stop server, start new server if requested:
stopServer();
maybeStartServer();
}
示例6: testJavaRules
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
@Test
public void testJavaRules() throws IOException {
Map<String,String> idsToClassName = new HashMap<>();
Set<Class> ruleClasses = new HashSet<>();
if (Languages.getWithDemoLanguage().size() <= 1) {
System.err.println("***************************************************************************");
System.err.println("WARNING: found only these languages - the tests might not be complete:");
System.err.println(Languages.getWithDemoLanguage());
System.err.println("***************************************************************************");
}
for (Language language : Languages.getWithDemoLanguage()) {
JLanguageTool lt = new JLanguageTool(language);
List<Rule> allRules = lt.getAllRules();
for (Rule rule : allRules) {
if (!(rule instanceof AbstractPatternRule)) {
assertIdUniqueness(idsToClassName, ruleClasses, language, rule);
assertIdValidity(language, rule);
assertTrue(rule.supportsLanguage(language));
testExamples(rule, lt);
}
}
}
}
示例7: setValueToRule
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void setValueToRule(String ruleID, int value, Language lang) {
if (lang == null) {
lang = language;
if (lang == null) {
return;
}
}
JLanguageTool langTool = new JLanguageTool(lang, motherTongue);
List<Rule> allRules = langTool.getAllRules();
for (Rule rule : allRules) {
if (rule.getId().startsWith(ruleID)) {
rule.setDefaultValue(value);
break;
}
}
}
示例8: configureFromRules
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
/**
* @since 3.3
*/
public static void configureFromRules(JLanguageTool langTool, Configuration config) {
Set<String> disabledRules = config.getDisabledRuleIds();
if (disabledRules != null) {
for (String ruleId : disabledRules) {
langTool.disableRule(ruleId);
}
}
Set<String> disabledCategories = config.getDisabledCategoryNames();
if (disabledCategories != null) {
for (String categoryName : disabledCategories) {
langTool.disableCategory(new CategoryId(categoryName));
}
}
if(config.getEnabledRulesOnly()) {
for (Rule rule : langTool.getAllRules()) {
langTool.disableRule(rule.getId());
}
}
Set<String> enabledRules = config.getEnabledRuleIds();
if (enabledRules != null) {
for (String ruleName : enabledRules) {
langTool.enableRule(ruleName);
}
}
}
示例9: run
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void run(Language lang) throws IOException {
File basePath = new File("/lt/git/languagetool/languagetool-language-modules");
if (!basePath.exists()) {
throw new RuntimeException("basePath does not exist: " + basePath);
}
String langCode = lang.getShortCode();
File xml = new File(basePath, "/" + langCode + "/src/main/resources/org/languagetool/rules/" + langCode + "/grammar.xml");
List<String> xmlLines = IOUtils.readLines(new FileReader(xml));
JLanguageTool tool = new JLanguageTool(lang);
for (Rule rule : tool.getAllRules()) {
if (!(rule instanceof PatternRule)) {
continue;
}
List<IncorrectExample> incorrectExamples = rule.getIncorrectExamples();
for (IncorrectExample incorrectExample : incorrectExamples) {
checkCorrections(rule, incorrectExample, xmlLines, tool);
}
}
System.err.println("Added corrections: " + addedCorrectionsCount);
for (String xmlLine : xmlLines) {
System.out.println(xmlLine);
}
}
示例10: disableSpellingRules
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void disableSpellingRules(JLanguageTool languageTool) {
List<Rule> allRules = languageTool.getAllRules();
for (Rule rule : allRules) {
if (rule instanceof SpellingCheckRule) {
languageTool.disableRule(rule.getId());
}
}
}
示例11: getBaselineTime
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private static long getBaselineTime(JLanguageTool langTool, String text) throws IOException {
deactivateAllRules(langTool);
long baselineStartTime = System.currentTimeMillis();
langTool.check(text);
long baselineTime = System.currentTimeMillis() - baselineStartTime;
if (langTool.getAllActiveRules().size() > 0) {
throw new RuntimeException("Did not expect to get any pattern rules: " + langTool.getAllActiveRules().size());
}
for (Rule rule : langTool.getAllRules()) {
langTool.enableRule(rule.getId());
}
return baselineTime;
}
示例12: enableOnlySpecifiedRules
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void enableOnlySpecifiedRules(String[] ruleIds, JLanguageTool languageTool) {
for (Rule rule : languageTool.getAllRules()) {
languageTool.disableRule(rule.getId());
}
for (String ruleId : ruleIds) {
languageTool.enableRule(ruleId);
}
warnOnNonExistingRuleIds(ruleIds, languageTool);
System.out.println("Only these rules are enabled: " + Arrays.toString(ruleIds));
}
示例13: warnOnNonExistingRuleIds
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void warnOnNonExistingRuleIds(String[] ruleIds, JLanguageTool languageTool) {
for (String ruleId : ruleIds) {
boolean found = false;
for (Rule rule : languageTool.getAllRules()) {
if (rule.getId().equals(ruleId)) {
found = true;
break;
}
}
if (!found) {
System.out.println("WARNING: Could not find rule '" + ruleId + "'");
}
}
}
示例14: activateAdditionalCategories
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void activateAdditionalCategories(String[] additionalCategoryIds, JLanguageTool languageTool) {
if (additionalCategoryIds != null) {
for (String categoryId : additionalCategoryIds) {
for (Rule rule : languageTool.getAllRules()) {
CategoryId id = rule.getCategory().getId();
if (id != null && id.toString().equals(categoryId)) {
System.out.println("Activating " + rule.getId() + " in category " + categoryId);
languageTool.enableRule(rule.getId());
}
}
}
}
}
示例15: activateCategory
import org.languagetool.JLanguageTool; //导入方法依赖的package包/类
private void activateCategory(String categoryName, JLanguageTool langTool) {
for (Rule rule : langTool.getAllRules()) {
if (rule.getCategory().getName().equals(categoryName)) {
System.out.println("Activating " + rule.getId() + " in category " + categoryName);
langTool.enableRule(rule.getId());
}
}
}