Skip to content

Commit e697437

Browse files
update the use of DictionaryFactory.create in tests
1 parent 0cbd390 commit e697437

11 files changed

+34
-34
lines changed

src/test/java/com/worksap/nlp/sudachi/JapaneseDictionaryTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class JapaneseDictionaryTest {
7777
@Test
7878
fun instantiateConfigWithoutCharDef() {
7979
val config = setupMinimumConfig()
80-
val jdict = DictionaryFactory().create(config)
80+
val jdict = Dictionary.load(config)
8181

8282
assertNotNull(jdict)
8383
assertNotNull(jdict.tokenizer())
@@ -87,7 +87,7 @@ class JapaneseDictionaryTest {
8787
@Test
8888
fun throwExceptionOnDictionaryUsageAfterClose() {
8989
val config = setupMinimumConfig()
90-
val jdict = DictionaryFactory().create(config)
90+
val jdict = Dictionary.load(config)
9191
jdict.close()
9292

9393
assertFailsWith(IllegalStateException::class) { jdict.tokenizer() }
@@ -96,7 +96,7 @@ class JapaneseDictionaryTest {
9696
@Test
9797
fun throwExceptionOnTokenizerUsageAfterClose() {
9898
val config = setupMinimumConfig()
99-
val jdict = DictionaryFactory().create(config)
99+
val jdict = Dictionary.load(config)
100100
val tok = jdict.tokenizer()
101101
jdict.close()
102102

@@ -189,7 +189,7 @@ abc,1,1,4675,AbC,名詞,普通名詞,一般,*,*,*,エービーシー,,,,,""")
189189
.clearUserDictionaries()
190190
.systemDictionary(sdict)
191191
.addUserDictionary(udict)
192-
val mdict = DictionaryFactory().create(cfg)
192+
val mdict = Dictionary.load(cfg)
193193

194194
val found = mdict.lookup("ABC")
195195
assertEquals(4, found.size)

src/test/java/com/worksap/nlp/sudachi/JapaneseTokenizerMaskTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022 Works Applications Co., Ltd.
2+
* Copyright (c) 2022-2024 Works Applications Co., Ltd.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,7 +40,7 @@ class JapaneseTokenizerMaskTest {
4040
cfg0.addOovProviderPlugin(CaptureOtherWords::class.java)
4141
cfg0.addOovProviderPlugin(SimpleOovProviderPlugin::class.java)
4242
val cfg = cfg0.withFallback(TestDictionary.user0Cfg())
43-
val dic = DictionaryFactory().create(cfg) as JapaneseDictionary
43+
val dic = Dictionary.load(cfg) as JapaneseDictionary
4444
val tokenizer = dic.tokenizer()
4545

4646
assertEquals(2, dic.oovProviderPlugins.size)
@@ -61,7 +61,7 @@ class JapaneseTokenizerMaskTest {
6161
fun correctMasksWithSecondProvider() {
6262
val cfg = TestDictionary.user0Cfg()
6363
cfg.addOovProviderPlugin(CaptureOtherWords::class.java)
64-
val dic = DictionaryFactory().create(cfg) as JapaneseDictionary
64+
val dic = Dictionary.load(cfg) as JapaneseDictionary
6565
val tokenizer = dic.tokenizer()
6666

6767
assertIs<SimpleOovProviderPlugin>(dic.oovProviderPlugins[0])

src/test/java/com/worksap/nlp/sudachi/JapaneseTokenizerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public void zeroLengthMorpheme() {
353353
@Test
354354
public void disableEmptyMorpheme() throws IOException {
355355
Config config = TestDictionary.INSTANCE.user1Cfg();
356-
dict = new DictionaryFactory().create(Config.empty().withFallback(config).allowEmptyMorpheme(false));
356+
dict = Dictionary.load(Config.empty().withFallback(config).allowEmptyMorpheme(false));
357357
tokenizer = (JapaneseTokenizer) dict.tokenizer();
358358

359359
List<Morpheme> s = tokenizer.tokenize("…");

src/test/java/com/worksap/nlp/sudachi/JoinNumericPluginTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017-2022 Works Applications Co., Ltd.
2+
* Copyright (c) 2017-2024 Works Applications Co., Ltd.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@ public class JoinNumericPluginTest {
3232
public void setUp() throws IOException {
3333
Config config = TestDictionary.INSTANCE.user0Cfg()
3434
.characterDefinition(getClass().getClassLoader().getResource("joinnumeric/char.def"));
35-
Dictionary dict = new DictionaryFactory().create(config);
35+
Dictionary dict = Dictionary.load(config);
3636
tokenizer = (JapaneseTokenizer) dict.tokenizer();
3737

3838
plugin = new JoinNumericPlugin();

src/test/java/com/worksap/nlp/sudachi/OovProviderPluginTest.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022 Works Applications Co., Ltd.
2+
* Copyright (c) 2022-2024 Works Applications Co., Ltd.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,7 +49,7 @@ class OovProviderPluginTest {
4949
val cfg = TestDictionary.user0Cfg()
5050
cfg.addOovProviderPlugin(FakeOovProvider::class.java)
5151
.addList("pos", "名詞", "普通名詞", "一般", "*", "*", "*")
52-
val inst = DictionaryFactory().create(cfg) as JapaneseDictionary
52+
val inst = Dictionary.load(cfg) as JapaneseDictionary
5353
val plugin = assertIs<FakeOovProvider>(inst.oovProviderPlugins.last())
5454
assertEquals(4, plugin.posId)
5555
}
@@ -60,7 +60,7 @@ class OovProviderPluginTest {
6060
cfg.addOovProviderPlugin(FakeOovProvider::class.java)
6161
.addList("pos", "名詞", "普通名詞", "一般", "*", "*", "new")
6262
.add(USER_POS, USER_POS_ALLOW)
63-
val inst = DictionaryFactory().create(cfg) as JapaneseDictionary
63+
val inst = Dictionary.load(cfg) as JapaneseDictionary
6464
val plugin = assertIs<FakeOovProvider>(inst.oovProviderPlugins.last())
6565
assertEquals(8, plugin.posId)
6666
}
@@ -71,15 +71,15 @@ class OovProviderPluginTest {
7171
cfg.addOovProviderPlugin(FakeOovProvider::class.java)
7272
.addList("pos", "名詞", "普通名詞", "一般", "*", "*", "*")
7373
.add(USER_POS, "test")
74-
assertFails { DictionaryFactory().create(cfg) }
74+
assertFails { Dictionary.load(cfg) }
7575
}
7676

7777
@Test
7878
fun failInvalidPos() {
7979
val cfg = TestDictionary.user0Cfg()
8080
cfg.addOovProviderPlugin(FakeOovProvider::class.java)
8181
.addList("pos", "名詞", "普通名詞", "一般", "*", "*", "test")
82-
assertFails { DictionaryFactory().create(cfg) }
82+
assertFails { Dictionary.load(cfg) }
8383
}
8484

8585
@Test
@@ -91,7 +91,7 @@ class OovProviderPluginTest {
9191
cfg.addOovProviderPlugin(FakeOovProvider::class.java)
9292
.addList("pos", "名詞", "普通名詞", "一般", "*", "*", "new")
9393
.add(USER_POS, USER_POS_ALLOW)
94-
val inst = DictionaryFactory().create(cfg) as JapaneseDictionary
94+
val inst = Dictionary.load(cfg) as JapaneseDictionary
9595
val oovPlugins = inst.oovProviderPlugins
9696
val p1 = assertIs<FakeOovProvider>(oovPlugins[oovPlugins.size - 2])
9797
assertEquals(8, p1.posId)
@@ -105,7 +105,7 @@ class OovProviderPluginTest {
105105
cfg.addOovProviderPlugin(FakeOovProvider::class.java)
106106
.addList("pos", "名詞", "普通名詞", "一般", "*", "*", "new")
107107
.add(USER_POS, USER_POS_ALLOW)
108-
val dict = DictionaryFactory().create(cfg) as JapaneseDictionary
108+
val dict = Dictionary.load(cfg) as JapaneseDictionary
109109
val plugin = assertIs<FakeOovProvider>(dict.oovProviderPlugins.last())
110110
assertEquals(8, plugin.posId)
111111
val tokinzer = dict.tokenizer()

src/test/java/com/worksap/nlp/sudachi/PosMatcherTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022 Works Applications Co., Ltd.
2+
* Copyright (c) 2022-2024 Works Applications Co., Ltd.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ import kotlin.test.*
2121

2222
class PosMatcherTest {
2323

24-
private val dic = DictionaryFactory().create(TestDictionary.user2Cfg()) as JapaneseDictionary
24+
private val dic = Dictionary.load(TestDictionary.user2Cfg()) as JapaneseDictionary
2525
private val tok = dic.tokenizer()
2626

2727
@Test

src/test/java/com/worksap/nlp/sudachi/RegexOovProviderTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022 Works Applications Co., Ltd.
2+
* Copyright (c) 2022-2024 Works Applications Co., Ltd.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ class RegexOovProviderTest {
3434
.addList("pos", "名詞", "普通名詞", "一般", "*", "*", "*")
3535
@Suppress("UNCHECKED_CAST") block(cfg, pluginCfg as Config.PluginConf<RegexOovProvider>)
3636
// prepend our OOV configuration to the main configuration
37-
return DictionaryFactory().create(cfg.withFallback(TestDictionary.user0Cfg())).tokenizer()
37+
return Dictionary.load(cfg.withFallback(TestDictionary.user0Cfg())).tokenizer()
3838
}
3939

4040
@Test

src/test/java/com/worksap/nlp/sudachi/TestDictionary.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017-2022 Works Applications Co., Ltd.
2+
* Copyright (c) 2017-2024 Works Applications Co., Ltd.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -67,11 +67,11 @@ object TestDictionary {
6767

6868
/** System only */
6969
fun user0(): JapaneseDictionary {
70-
return DictionaryFactory().create(user0Cfg()) as JapaneseDictionary
70+
return Dictionary.load(user0Cfg()) as JapaneseDictionary
7171
}
7272

7373
/** System + One User dictionary */
7474
fun user1(): JapaneseDictionary {
75-
return DictionaryFactory().create(user1Cfg()) as JapaneseDictionary
75+
return Dictionary.load(user1Cfg()) as JapaneseDictionary
7676
}
7777
}

src/test/java/com/worksap/nlp/sudachi/TextNormalizerTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import kotlin.test.*
2323
class TextNormalizerTest {
2424

2525
private val dic =
26-
DictionaryFactory()
27-
.create(TestDictionary.user2Cfg().characterDefinition(CharacterCategory.loadDefault()))
26+
Dictionary.load(
27+
TestDictionary.user2Cfg().characterDefinition(CharacterCategory.loadDefault()))
2828
as JapaneseDictionary
2929

3030
@Test

src/test/java/com/worksap/nlp/sudachi/UserDictionaryTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017-2022 Works Applications Co., Ltd.
2+
* Copyright (c) 2017-2024 Works Applications Co., Ltd.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@ public void fullUserDict() throws IOException {
3737
}
3838
config.addUserDictionary(instance.getUserDict2());
3939

40-
try (Dictionary dict = new DictionaryFactory().create(config)) {
40+
try (Dictionary dict = Dictionary.load(config)) {
4141
Tokenizer tokenizer = dict.tokenizer();
4242
List<Morpheme> morphs = tokenizer.tokenize("ぴさる");
4343
assertThat(morphs.size(), is(1));
@@ -54,14 +54,14 @@ public void openTooManyUserDict() throws IOException {
5454
for (int i = 0; i < 15; i++) {
5555
config.addUserDictionary(instance.getUserDict1());
5656
}
57-
new DictionaryFactory().create(config);
57+
Dictionary.load(config);
5858
}
5959

6060
@Test
6161
public void splitForUserDict() throws IOException {
6262
TestDictionary td = TestDictionary.INSTANCE;
6363
Config config = td.user0Cfg().addUserDictionary(td.getUserDict2()).addUserDictionary(td.getUserDict1());
64-
try (Dictionary dict = new DictionaryFactory().create(config)) {
64+
try (Dictionary dict = Dictionary.load(config)) {
6565
Tokenizer tokenizer = dict.tokenizer();
6666
List<Morpheme> morphs = tokenizer.tokenize("東京府");
6767
assertThat(morphs.size(), is(1));
@@ -76,7 +76,7 @@ public void splitForUserDict() throws IOException {
7676
@Test
7777
public void userDefinedPos() throws IOException {
7878
Config config = TestDictionary.INSTANCE.user2Cfg();
79-
try (Dictionary dict = new DictionaryFactory().create(config)) {
79+
try (Dictionary dict = Dictionary.load(config)) {
8080
Tokenizer tokenizer = dict.tokenizer();
8181
List<Morpheme> morphs = tokenizer.tokenize("すだちかぼす");
8282
assertThat(morphs.size(), is(2));
@@ -88,7 +88,7 @@ public void userDefinedPos() throws IOException {
8888

8989
TestDictionary td = TestDictionary.INSTANCE;
9090
config = td.user0Cfg().addUserDictionary(td.getUserDict2()).addUserDictionary(td.getUserDict1());
91-
try (Dictionary dict = new DictionaryFactory().create(config)) {
91+
try (Dictionary dict = Dictionary.load(config)) {
9292
Tokenizer tokenizer = dict.tokenizer();
9393
List<Morpheme> morphs = tokenizer.tokenize("すだちかぼす");
9494
assertThat(morphs.size(), is(2));

src/test/java/com/worksap/nlp/sudachi/dictionary/build/UserDicTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017-2022 Works Applications Co., Ltd.
2+
* Copyright (c) 2017-2024 Works Applications Co., Ltd.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -71,7 +71,7 @@ class TestDic {
7171
fun load(): Dictionary {
7272
val config = Config.fromClasspath(config).systemDictionary(systemDic)
7373
userDics.forEach { config.addUserDictionary(it) }
74-
return DictionaryFactory().create(config)
74+
return Dictionary.load(config)
7575
}
7676
}
7777

0 commit comments

Comments
 (0)