-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from yj-jtakagi/bugfix
fix bugs
- Loading branch information
Showing
8 changed files
with
214 additions
and
4 deletions.
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,2 @@ | ||
target/ | ||
.idea/ |
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,6 @@ | ||
# Changelog | ||
|
||
## [1.0.0] - 2019-09-11 | ||
### Fixed | ||
- 一部の記号がトークナイズの際にエラー原因になる問題の修正 | ||
- 元号などの合字が正規化前に Vespa によって取り除かれる問題の修正 |
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
32 changes: 32 additions & 0 deletions
32
src/main/java/jp/co/yahoo/vespa/language/lib/kuromoji/KuromojiCharacterClasses.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,32 @@ | ||
package jp.co.yahoo.vespa.language.lib.kuromoji; | ||
|
||
import com.yahoo.language.process.CharacterClasses; | ||
|
||
import java.text.Normalizer; | ||
|
||
public class KuromojiCharacterClasses extends CharacterClasses { | ||
@Override | ||
public boolean isLetter(int c) { | ||
// see https://github.com/vespa-engine/vespa/blob/master/linguistics/src/main/java/com/yahoo/language/process/CharacterClasses.java | ||
if (java.lang.Character.isLetter(c)) return true; | ||
if (Character.isDigit(c) && ! isLatin(c)) return true; | ||
|
||
if (c == '\u3008' || c == '\u3009' || c == '\u300a' || c == '\u300b' || | ||
c == '\u300c' || c == '\u300d' || c == '\u300e' || | ||
c == '\u300f' || c == '\u3010' || c == '\u3011') { | ||
return true; | ||
} | ||
int type = java.lang.Character.getType(c); | ||
if (type == java.lang.Character.NON_SPACING_MARK || | ||
type == java.lang.Character.COMBINING_SPACING_MARK || | ||
type == java.lang.Character.ENCLOSING_MARK) { | ||
return true; | ||
} else if (type == Character.OTHER_SYMBOL) { | ||
// OTHER_SYMBOL contains Gengo(Era), letter enclosed within a circle, etc | ||
String norm = Normalizer.normalize(String.valueOf((char)c), Normalizer.Form.NFKC); | ||
if (c == norm.charAt(0)) return false; | ||
return isLetterOrDigit(norm.charAt(0)); | ||
} | ||
return false; | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
src/test/java/jp/co/yahoo/vespa/language/lib/kuromoji/GramSplitterTest.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,44 @@ | ||
package jp.co.yahoo.vespa.language.lib.kuromoji; | ||
|
||
import com.yahoo.language.lib.kuromoji.KuromojiConfig; | ||
import com.yahoo.language.process.GramSplitter; | ||
import com.yahoo.vespa.configdefinition.SpecialtokensConfig; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class GramSplitterTest { | ||
private static final GramSplitter gramSplitter; | ||
|
||
static { | ||
GramSplitter splitter = null; | ||
try { | ||
splitter = new KuromojiLinguistics(new KuromojiConfig(new KuromojiConfig.Builder()), | ||
new SpecialtokensConfig(new SpecialtokensConfig.Builder())).getGramSplitter(); | ||
} catch (IOException e) { | ||
} finally { | ||
gramSplitter = splitter; | ||
} | ||
} | ||
|
||
@Test | ||
public void testWithSymbols() { | ||
assertGramSplit("㍻最後の㍉㌔", 2, "[㍻最, 最後, 後の, の㍉, ㍉㌔]"); | ||
} | ||
|
||
@Test | ||
public void testWithWhiteSpace() { | ||
assertGramSplit("㍻最後 の ㍉㌔", 2, "[㍻最, 最後, の, ㍉㌔]"); | ||
} | ||
|
||
@Test | ||
public void testWithIgnoreSymbol() { | ||
assertGramSplit("㍻最後の©㍉㌔", 2, "[㍻最, 最後, 後の, ㍉㌔]"); | ||
} | ||
|
||
private void assertGramSplit(String input, int gramSize, String expected) { | ||
assertEquals(gramSplitter.split(input, gramSize).toExtractedList().toString(), expected); | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
src/test/java/jp/co/yahoo/vespa/language/lib/kuromoji/KuromojiCharacterClassesTest.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,120 @@ | ||
package jp.co.yahoo.vespa.language.lib.kuromoji; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class KuromojiCharacterClassesTest { | ||
@Test | ||
public void testSpecialChars() { | ||
KuromojiCharacterClasses characterClasses = new KuromojiCharacterClasses(); | ||
// is letter | ||
assertTrue(characterClasses.isLetter('㍻')); | ||
assertTrue(characterClasses.isLetter('㍉')); | ||
assertTrue(characterClasses.isLetter('㊑')); | ||
// isLetterOrDigit is also true | ||
assertTrue(characterClasses.isLetterOrDigit('㍻')); | ||
assertTrue(characterClasses.isLetterOrDigit('㍉')); | ||
// is noise | ||
assertFalse(characterClasses.isLetter('〒')); | ||
assertFalse(characterClasses.isLetter('©'));; | ||
} | ||
|
||
@Test | ||
public void testQuotes() { | ||
KuromojiCharacterClasses characterClasses = new KuromojiCharacterClasses(); | ||
// quote is not letter | ||
// please see https://github.com/vespa-engine/vespa/blob/master/container-search/src/main/java/com/yahoo/prelude/query/parser/Tokenizer.java | ||
assertFalse(characterClasses.isLetter('"')); | ||
assertFalse(characterClasses.isLetter('\u201C')); | ||
assertFalse(characterClasses.isLetter('\u201D')); | ||
assertFalse(characterClasses.isLetter('\u201E')); | ||
assertFalse(characterClasses.isLetter('\u201F')); | ||
assertFalse(characterClasses.isLetter('\u2039')); | ||
assertFalse(characterClasses.isLetter('\u203A')); | ||
assertFalse(characterClasses.isLetter('\u00AB')); | ||
assertFalse(characterClasses.isLetter('\u00BB')); | ||
assertFalse(characterClasses.isLetter('\u301D')); | ||
assertFalse(characterClasses.isLetter('\u301E')); | ||
assertFalse(characterClasses.isLetter('\u301F')); | ||
assertFalse(characterClasses.isLetter('\uFF02')); | ||
} | ||
|
||
@Test | ||
public void testSigns() { | ||
KuromojiCharacterClasses characterClasses = new KuromojiCharacterClasses(); | ||
// +- is not letter | ||
// please see https://github.com/vespa-engine/vespa/blob/master/container-search/src/main/java/com/yahoo/prelude/query/parser/Tokenizer.java | ||
assertFalse(characterClasses.isLetter('-')); | ||
assertFalse(characterClasses.isLetter('\uFF0D')); | ||
assertFalse(characterClasses.isLetter('+')); | ||
assertFalse(characterClasses.isLetter('\uFF0B')); | ||
} | ||
|
||
@Test | ||
public void testPunctuations() { | ||
KuromojiCharacterClasses characterClasses = new KuromojiCharacterClasses(); | ||
// .,:; is not letter | ||
// please see https://github.com/vespa-engine/vespa/blob/master/container-search/src/main/java/com/yahoo/prelude/query/parser/Tokenizer.java | ||
assertFalse(characterClasses.isLetter('.')); | ||
assertFalse(characterClasses.isLetter('\uFF0E')); | ||
assertFalse(characterClasses.isLetter(',')); | ||
assertFalse(characterClasses.isLetter('\uFF0C')); | ||
assertFalse(characterClasses.isLetter(':')); | ||
assertFalse(characterClasses.isLetter('\uFF1A')); | ||
assertFalse(characterClasses.isLetter(';')); | ||
assertFalse(characterClasses.isLetter('\uFF1E')); | ||
} | ||
|
||
@Test | ||
public void testBrace() { | ||
KuromojiCharacterClasses characterClasses = new KuromojiCharacterClasses(); | ||
// () is not letter | ||
// please see https://github.com/vespa-engine/vespa/blob/master/container-search/src/main/java/com/yahoo/prelude/query/parser/Tokenizer.java | ||
assertFalse(characterClasses.isLetter('(')); | ||
assertFalse(characterClasses.isLetter('\uFF08')); | ||
assertFalse(characterClasses.isLetter(')')); | ||
assertFalse(characterClasses.isLetter('\uFF09')); | ||
} | ||
|
||
@Test | ||
public void testBracket() { | ||
KuromojiCharacterClasses characterClasses = new KuromojiCharacterClasses(); | ||
// [] is not letter | ||
// please see https://github.com/vespa-engine/vespa/blob/master/container-search/src/main/java/com/yahoo/prelude/query/parser/Tokenizer.java | ||
assertFalse(characterClasses.isLetter('[')); | ||
assertFalse(characterClasses.isLetter('\uFF3D')); | ||
assertFalse(characterClasses.isLetter(']')); | ||
assertFalse(characterClasses.isLetter('\uFF1B')); | ||
} | ||
|
||
@Test | ||
public void testGraterSmaller() { | ||
KuromojiCharacterClasses characterClasses = new KuromojiCharacterClasses(); | ||
// <> is not letter | ||
// please see https://github.com/vespa-engine/vespa/blob/master/container-search/src/main/java/com/yahoo/prelude/query/parser/Tokenizer.java | ||
assertFalse(characterClasses.isLetter('<')); | ||
assertFalse(characterClasses.isLetter('\uFF1E')); | ||
assertFalse(characterClasses.isLetter('>')); | ||
assertFalse(characterClasses.isLetter('\uFF1C')); | ||
} | ||
|
||
@Test | ||
public void testSimbols() { | ||
KuromojiCharacterClasses characterClasses = new KuromojiCharacterClasses(); | ||
// !_^*$ is not letter | ||
// please see https://github.com/vespa-engine/vespa/blob/master/container-search/src/main/java/com/yahoo/prelude/query/parser/Tokenizer.java | ||
assertFalse(characterClasses.isLetter('!')); | ||
assertFalse(characterClasses.isLetter('\uFF01')); | ||
assertFalse(characterClasses.isLetter('_')); | ||
assertFalse(characterClasses.isLetter('\uFF3F')); | ||
assertFalse(characterClasses.isLetter('^')); | ||
assertFalse(characterClasses.isLetter('\uFF3E')); | ||
assertFalse(characterClasses.isLetter('*')); | ||
assertFalse(characterClasses.isLetter('\uFF0A')); | ||
assertFalse(characterClasses.isLetter('$')); | ||
assertFalse(characterClasses.isLetter('\uFF04')); | ||
} | ||
|
||
} |