-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06768e9
commit 10e7c9f
Showing
7 changed files
with
244 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
Copyright 2012-2022 Michael Pozhidaev <[email protected]> | ||
This file is part of LUWRAIN. | ||
LUWRAIN is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public | ||
License as published by the Free Software Foundation; either | ||
version 3 of the License, or (at your option) any later version. | ||
LUWRAIN 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 | ||
General Public License for more details. | ||
*/ | ||
|
||
package org.luwrain.nlp; | ||
|
||
import org.luwrain.nlp.ru.spell.*; | ||
|
||
public final class SpellCheckerFactory | ||
{ | ||
static private RuSpellChecker ru = null; | ||
|
||
public SpellChecker newChecker(String lang) | ||
{ | ||
switch(lang.toUpperCase()) | ||
{ | ||
case "RU": { | ||
if (ru == null) | ||
ru = new RuSpellChecker(); | ||
return ru; | ||
} | ||
default: | ||
throw new IllegalArgumentException("Unknown language: " + lang); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Copyright 2012-2022 Michael Pozhidaev <[email protected]> | ||
This file is part of LUWRAIN. | ||
LUWRAIN is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public | ||
License as published by the Free Software Foundation; either | ||
version 3 of the License, or (at your option) any later version. | ||
LUWRAIN 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 | ||
General Public License for more details. | ||
*/ | ||
|
||
package org.luwrain.nlp.ru.spell; | ||
|
||
import org.languagetool.rules.*; | ||
|
||
import org.luwrain.nlp.*; | ||
|
||
final class Problem implements SpellProblem | ||
{ | ||
private final String message, shortMessage; | ||
|
||
Problem(RuleMatch match) | ||
{ | ||
this.message = match.getMessage(); | ||
this.shortMessage = match.getShortMessage(); | ||
/* | ||
List<SuggestedReplacement> repl = r.getSuggestedReplacementObjects(); | ||
for(SuggestedReplacement rr: repl) | ||
System.out.println(rr); | ||
*/ | ||
} | ||
|
||
@Override public String getComment() { return message; } | ||
@Override public String getShortComment(){ return shortMessage; } | ||
@Override public int getStart(){ return 0; } | ||
@Override public int getEnd(){ return 0;} | ||
|
||
@Override public String toString() | ||
{ | ||
return message; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/org/luwrain/nlp/ru/spell/RuSpellChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2012-2022 Michael Pozhidaev <[email protected]> | ||
This file is part of LUWRAIN. | ||
LUWRAIN is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public | ||
License as published by the Free Software Foundation; either | ||
version 3 of the License, or (at your option) any later version. | ||
LUWRAIN 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 | ||
General Public License for more details. | ||
*/ | ||
|
||
package org.luwrain.nlp.ru.spell; | ||
|
||
import java.util.*; | ||
import java.io.*; | ||
|
||
import org.languagetool.*; | ||
import org.languagetool.language.*; | ||
import org.languagetool.rules.*; | ||
import org.languagetool.rules.spelling.*; | ||
|
||
import org.luwrain.core.*; | ||
import org.luwrain.nlp.*; | ||
|
||
public final class RuSpellChecker implements SpellChecker | ||
{ | ||
final JLanguageTool langTool; | ||
|
||
public RuSpellChecker() | ||
{ | ||
this.langTool = new JLanguageTool(new Russian()); | ||
} | ||
|
||
@Override public List<SpellProblem> check(String text) | ||
{ | ||
final List<SpellProblem> res = new ArrayList<>(); | ||
try { | ||
final List<RuleMatch> m = langTool.check(text); | ||
System.out.println("match " + m.size()); | ||
for(RuleMatch mm: m) | ||
res.add(new Problem(mm)); | ||
return res; | ||
} | ||
catch(IOException e) | ||
{ | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright 2012-2022 Michael Pozhidaev <[email protected]> | ||
This file is part of LUWRAIN. | ||
LUWRAIN is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public | ||
License as published by the Free Software Foundation; either | ||
version 3 of the License, or (at your option) any later version. | ||
LUWRAIN 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 | ||
General Public License for more details. | ||
*/ | ||
|
||
package org.luwrain.nlp; | ||
|
||
import org.junit.*; | ||
|
||
import org.luwrain.core.*; | ||
|
||
public class SpellTextTest extends Assert | ||
{ | ||
private SpellChecker checker = null; | ||
|
||
@Test public void main() | ||
{ | ||
} | ||
|
||
@Before public void create() | ||
{ | ||
checker = new SpellCheckerFactory().newChecker("ru"); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/test/java/org/luwrain/io/nlp/ru/spell/RuSpellCheckerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
Copyright 2012-2022 Michael Pozhidaev <[email protected]> | ||
This file is part of LUWRAIN. | ||
LUWRAIN is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public | ||
License as published by the Free Software Foundation; either | ||
version 3 of the License, or (at your option) any later version. | ||
LUWRAIN 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 | ||
General Public License for more details. | ||
*/ | ||
|
||
|
||
package org.luwrain.nlp.ru.spell; | ||
|
||
//https://languagetool.org/development/api/org/languagetool/rules/spelling/SpellingCheckRule.html | ||
|
||
|
||
import java.io.*; | ||
import java.net.*; | ||
|
||
import org.junit.*; | ||
|
||
import org.luwrain.core.*; | ||
|
||
public class RuSpellCheckerTest extends Assert | ||
{ | ||
private RuSpellChecker c = null; | ||
|
||
@Test public void main() | ||
{ | ||
} | ||
|
||
@Before public void create() | ||
{ | ||
c = new RuSpellChecker(); | ||
} | ||
} |