本文整理汇总了Java中org.languagetool.JLanguageTool类的典型用法代码示例。如果您正苦于以下问题:Java JLanguageTool类的具体用法?Java JLanguageTool怎么用?Java JLanguageTool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JLanguageTool类属于org.languagetool包,在下文中一共展示了JLanguageTool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.languagetool.JLanguageTool; //导入依赖的package包/类
public static void main(String[] args) {
System.out.println("start...");
try {
JLanguageTool langTool = new JLanguageTool(Language.ENGLISH);
langTool.activateDefaultPatternRules();
List<RuleMatch> matches = langTool.check("A sentence "
+ "with a error in the Hitchhiker's Guide tot he Galaxy");
for (RuleMatch match : matches) {
System.out.println("Potential error at line "
+ match.getEndLine() + ", column " + match.getColumn()
+ ": " + match.getMessage());
System.out.println("Suggested correction: "
+ match.getSuggestedReplacements());
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("finished.");
}
示例2: hideToTray
import org.languagetool.JLanguageTool; //导入依赖的package包/类
void hideToTray() {
if (!isInTray) {
final java.awt.SystemTray tray = java.awt.SystemTray
.getSystemTray();
final Image img = Toolkit.getDefaultToolkit().getImage(
JLanguageTool.getDataBroker().getFromResourceDirAsUrl(
LangToolMain.SYSTEM_TRAY_ICON_NAME));
final PopupMenu popup = makePopupMenu();
try {
final java.awt.TrayIcon trayIcon = new java.awt.TrayIcon(img,
"tooltip", popup);
trayIcon.addMouseListener(new TrayActionListener());
trayIcon.setToolTip(SYSTEM_TRAY_TOOLTIP);
tray.add(trayIcon);
} catch (final AWTException e1) {
// thrown if there's no system tray
Tools.showError(e1);
}
}
isInTray = true;
frame.setVisible(false);
}
示例3: 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();
}
示例4: 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();
}
示例5: hideToTray
import org.languagetool.JLanguageTool; //导入依赖的package包/类
private void hideToTray() {
if (!isInTray) {
final SystemTray tray = SystemTray.getSystemTray();
final String iconPath = tray.getTrayIconSize().height > 16 ? TRAY_ICON : TRAY_SMALL_ICON;
final URL iconUrl = JLanguageTool.getDataBroker().getFromResourceDirAsUrl(iconPath);
final Image img = Toolkit.getDefaultToolkit().getImage(iconUrl);
final PopupMenu popup = makePopupMenu();
try {
trayIcon = new TrayIcon(img, TRAY_TOOLTIP, popup);
trayIcon.addMouseListener(new TrayActionListener());
setTrayIcon();
tray.add(trayIcon);
} catch (AWTException e1) {
Tools.showError(e1);
}
}
isInTray = true;
frame.setVisible(false);
}
示例6: setTrayIcon
import org.languagetool.JLanguageTool; //导入依赖的package包/类
private void setTrayIcon() {
if (trayIcon != null) {
final SystemTray tray = SystemTray.getSystemTray();
final boolean httpServerRunning = httpServer != null && httpServer.isRunning();
final boolean smallTray = tray.getTrayIconSize().height <= 16;
final String iconPath;
if (httpServerRunning) {
trayIcon.setToolTip(messages.getString("tray_tooltip_server_running"));
iconPath = smallTray ? TRAY_SMALL_SERVER_ICON : TRAY_SERVER_ICON;
} else {
trayIcon.setToolTip(TRAY_TOOLTIP);
iconPath = smallTray ? TRAY_SMALL_ICON : TRAY_ICON;
}
final URL iconUrl = JLanguageTool.getDataBroker().getFromResourceDirAsUrl(iconPath);
final Image img = Toolkit.getDefaultToolkit().getImage(iconUrl);
trayIcon.setImage(img);
}
}
示例7: initWordTagger
import org.languagetool.JLanguageTool; //导入依赖的package包/类
private WordTagger initWordTagger() {
MorfologikTagger morfologikTagger = new MorfologikTagger(dictionary);
try {
String manualRemovalFileName = getManualRemovalsFileName();
ManualTagger removalTagger = null;
if (manualRemovalFileName != null) {
try (InputStream stream = JLanguageTool.getDataBroker().getFromResourceDirAsStream(manualRemovalFileName)) {
removalTagger = new ManualTagger(stream);
}
}
String manualAdditionFileName = getManualAdditionsFileName();
if (manualAdditionFileName != null) {
try (InputStream stream = JLanguageTool.getDataBroker().getFromResourceDirAsStream(manualAdditionFileName)) {
ManualTagger manualTagger = new ManualTagger(stream);
return new CombiningTagger(morfologikTagger, manualTagger, removalTagger, overwriteWithManualTagger());
}
} else {
return morfologikTagger;
}
} catch (IOException e) {
throw new RuntimeException("Could not load manual tagger data from " + getManualAdditionsFileName(), e);
}
}
示例8: lazyInit
import org.languagetool.JLanguageTool; //导入依赖的package包/类
private void lazyInit() throws IOException {
if (manualTagger != null) {
return;
}
// A manual tagger is used for closed words. Closed words are the small
// limited set of words in Esperanto which have no standard ending, as
// opposed to open words which are unlimited in numbers and which follow
// strict rules for their suffixes.
try (InputStream stream = JLanguageTool.getDataBroker().getFromResourceDirAsStream("/eo/manual-tagger.txt")) {
manualTagger = new ManualTagger(stream);
}
// Load set of transitive and intransitive verbs. Files don't contain
// verbs with suffix -iĝ or -ig since transitivity is obvious for those verbs.
// They also don't contain verbs with prefixes mal-, ek-, re-, mis- fi- and
// suffixes -ad, -aĉ, -et, -eg since these affixes never alter transitivity.
setTransitiveVerbs = loadWords(JLanguageTool.getDataBroker().getFromRulesDirAsStream("/eo/verb-tr.txt"));
setIntransitiveVerbs = loadWords(JLanguageTool.getDataBroker().getFromRulesDirAsStream("/eo/verb-ntr.txt"));
setNonParticiple = loadWords(JLanguageTool.getDataBroker().getFromRulesDirAsStream("/eo/root-ant-at.txt"));
}
示例9: main
import org.languagetool.JLanguageTool; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
List<Language> realLanguages = Languages.get();
System.out.println("This example will test a short string with all languages known to LanguageTool.");
System.out.println("It's just a test to make sure there's at least no crash.");
System.out.println("Using LanguageTool " + JLanguageTool.VERSION + " (" + JLanguageTool.BUILD_DATE + ")");
System.out.println("Supported languages: " + realLanguages.size());
for (Language language : realLanguages) {
JLanguageTool langTool = new JLanguageTool(language);
String input = "And the the";
List<RuleMatch> result = langTool.check(input);
System.out.println("Checking '" + input + "' with " + language + ":");
for (RuleMatch ruleMatch : result) {
System.out.println(" " + ruleMatch);
}
}
}
示例10: testRule
import org.languagetool.JLanguageTool; //导入依赖的package包/类
@Test
public void testRule() throws IOException {
SimpleGrammarEkavianReplaceRule rule = new SimpleGrammarEkavianReplaceRule(TestTools.getEnglishMessages());
RuleMatch[] matches;
JLanguageTool langTool = new JLanguageTool(new Serbian());
// correct sentences:
matches = rule.match(langTool.getAnalyzedSentence("Данас је диван дан."));
assertEquals(0, matches.length);
// incorrect sentences:
matches = rule.match(langTool.getAnalyzedSentence("Син је вишљи од оца."));
assertEquals(1, matches.length);
assertEquals(1, matches[0].getSuggestedReplacements().size());
assertEquals(Arrays.asList("виши"), matches[0].getSuggestedReplacements());
matches = rule.match(langTool.getAnalyzedSentence("У то оправдано сумљам."));
assertEquals(1, matches.length);
assertEquals(1, matches[0].getSuggestedReplacements().size());
assertEquals(Arrays.asList("сумњам"), matches[0].getSuggestedReplacements());
}
示例11: loadWords
import org.languagetool.JLanguageTool; //导入依赖的package包/类
/**
* Load replacement rules from a utf-8 file in the classpath.
*/
public Map<String, List<String>> loadWords(String path) {
InputStream stream = JLanguageTool.getDataBroker().getFromRulesDirAsStream(path);
Map<String, List<String>> map = new HashMap<>();
try (Scanner scanner = new Scanner(stream, "utf-8")) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.isEmpty() || line.charAt(0) == '#') { // # = comment
continue;
}
String[] parts = line.split("=");
if (parts.length != 2) {
throw new RuntimeException("Could not load simple replacement data from: " + path + ". " +
"Error in line '" + line + "', expected format 'word=replacement'");
}
String[] wrongForms = parts[0].split("\\|");
List<String> replacements = Arrays.asList(parts[1].split("\\|"));
for (String wrongForm : wrongForms) {
map.put(wrongForm, replacements);
}
}
}
return Collections.unmodifiableMap(map);
}
示例12: 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);
}
}
示例13: testCorrect
import org.languagetool.JLanguageTool; //导入依赖的package包/类
@Test
public void testCorrect() throws IOException, ParserConfigurationException, SAXException {
JLanguageTool tool = new JLanguageTool(new Polish());
tool.setCleanOverlappingMatches(false);
String correct = Tools.correctText("To jest całkowicie prawidłowe zdanie.", tool);
assertEquals("To jest całkowicie prawidłowe zdanie.", correct);
correct = Tools.correctText("To jest jest problem.", tool);
assertEquals("To jest problem.", correct);
// more sentences, need to apply more suggestions > 1 in subsequent sentences
correct = Tools.correctText("To jest jest problem. Ale to już już nie jest problem.", tool);
assertEquals("To jest problem. Ale to już nie jest problem.", correct);
correct = Tools.correctText("To jest jest problem. Ale to już już nie jest problem. Tak sie nie robi. W tym zdaniu brakuje przecinka bo go zapomniałem.", tool);
assertEquals("To jest problem. Ale to już nie jest problem. Tak się nie robi. W tym zdaniu brakuje przecinka, bo go zapomniałem.", correct);
}
示例14: getSpeller
import org.languagetool.JLanguageTool; //导入依赖的package包/类
@Nullable
private static MorfologikMultiSpeller getSpeller(Language language) {
if (!language.getShortCode().equals(Locale.GERMAN.getLanguage())) {
throw new RuntimeException("Language is not a variant of German: " + language);
}
try {
String morfoFile = "/de/hunspell/de_" + language.getCountries()[0] + ".dict";
if (JLanguageTool.getDataBroker().resourceExists(morfoFile)) {
// spell data will not exist in LibreOffice/OpenOffice context
String path = "/de/hunspell/spelling.txt";
try (InputStream stream = JLanguageTool.getDataBroker().getFromResourceDirAsStream(path);
BufferedReader br = new BufferedReader(new InputStreamReader(stream, "utf-8"))) {
return new MorfologikMultiSpeller(morfoFile, new ExpandingReader(br), path, MAX_EDIT_DISTANCE);
}
} else {
return null;
}
} catch (IOException e) {
throw new RuntimeException("Could not set up morfologik spell checker", e);
}
}
示例15: getTokensForSentenceStart
import org.languagetool.JLanguageTool; //导入依赖的package包/类
private List<PatternToken> getTokensForSentenceStart(String[] parts) {
List<PatternToken> ucPatternTokens = new ArrayList<>();
int j = 0;
for (String part : parts) {
if (j == 0) {
// at sentence start, we also need to accept a phrase that starts with an uppercase char:
String uppercased = StringTools.uppercaseFirstChar(part);
ucPatternTokens.add(new PatternTokenBuilder().posRegex(JLanguageTool.SENTENCE_START_TAGNAME).build());
ucPatternTokens.add(new PatternTokenBuilder().csToken(uppercased).build());
} else {
ucPatternTokens.add(new PatternTokenBuilder().csToken(part).build());
}
j++;
}
return ucPatternTokens;
}