Skip to content

Commit ca5ea5a

Browse files
add const for magics and fix
1 parent a598575 commit ca5ea5a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/main/java/com/worksap/nlp/elasticsearch/sudachi/ConfigAdapter.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,35 @@ class ConfigAdapter(anchor: PathAnchor, settings: Settings, env: Environment) {
5151

5252
companion object {
5353
const val PARAM_SPLIT_MODE_DEPRECATED = "mode"
54+
const val PARAM_SPLIT_MODE = "split_mode"
5455
const val PARAM_SETTINGS_PATH = "settings_path"
56+
const val PARAM_RESOURCES_PATH = "resources_path"
5557
const val PARAM_ADDITIONAL_SETTINGS = "additional_settings"
5658
const val PARAM_DISCARD_PUNCTUATION = "discard_punctuation"
5759

58-
private object SplitModeFlag : EnumFlag<SplitMode>("split_mode", SplitMode.C)
60+
const val DEFAULT_SETTINGS_FILENAME = "sudachi.json"
61+
const val DEFAULT_RESOURCE_PATH = "sudachi"
62+
63+
private object SplitModeFlag : EnumFlag<SplitMode>(PARAM_SPLIT_MODE, SplitMode.C)
5964

6065
@JvmStatic
6166
fun splitMode(settings: Settings): SplitMode {
6267
if (settings.get(PARAM_SPLIT_MODE_DEPRECATED, null) != null) {
6368
throw IllegalArgumentException(
64-
"Setting $PARAM_SPLIT_MODE_DEPRECATED is deprecated, use SudachiSplitFilter instead",
69+
"Setting $PARAM_SPLIT_MODE_DEPRECATED is deprecated, use $PARAM_SPLIT_MODE instead",
6570
)
6671
}
6772
return SplitModeFlag.get(settings)
6873
}
6974

7075
@JvmStatic
7176
fun resourcesPath(env: Environment, settings: Settings): Path {
72-
return env.configFile().resolve(settings.get("resources_path", "sudachi"))
77+
return env.configFile().resolve(settings.get(PARAM_RESOURCES_PATH, DEFAULT_RESOURCE_PATH))
7378
}
7479

7580
private fun readDefaultConfig(root: Path, baseAnchor: PathAnchor): Config {
7681
val anchor = PathAnchor.filesystem(root).andThen(baseAnchor)
77-
val resolved = root.resolve("sudachi.json")
82+
val resolved = root.resolve(DEFAULT_SETTINGS_FILENAME)
7883
val exists =
7984
try {
8085
resolved.exists()

src/main/java/com/worksap/nlp/elasticsearch/sudachi/index/SudachiTokenizerFactory.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ class SudachiTokenizerFactory(
5050
}
5151
}
5252

53-
private val mode = ConfigAdapter.splitMode(settings)
54-
5553
private val config = ConfigAdapter(service.anchor, settings, env)
54+
private val mode = config.mode
5655

5756
private val dictionary by lazy { service.forConfig(config.compiled) }
5857

0 commit comments

Comments
 (0)