Skip to content

Commit

Permalink
check etymology
Browse files Browse the repository at this point in the history
  • Loading branch information
qicz committed Jul 13, 2021
1 parent 6d7187c commit 2d6a813
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
*/
package org.wltea.analyzer.configuration;

import org.apache.http.util.Asserts;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Assertions;
import org.elasticsearch.SpecialPermission;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.PathUtils;
Expand All @@ -25,6 +27,7 @@
import java.nio.file.Path;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Objects;

public class Configuration {

Expand Down Expand Up @@ -54,6 +57,9 @@ public Configuration(Environment env, Settings settings) {
this.enableRemoteDict = "true".equals(settings.get("enable_remote_dict", "true"));
// 词源
String etymology = settings.get("etymology", RemoteDictionaryEtymology.DEFAULT.getEtymology());
RemoteDictionaryEtymology settingEtymology = RemoteDictionaryEtymology.newEtymology(etymology);
String message = String.format("the etymology '%s' config is invalid, just support 'redis','mysql','http'.", etymology);
Asserts.check(Objects.nonNull(settingEtymology), message);
// 领域
String domain = settings.get("domain", "default-domain");
logger.info("new configuration for domain {} etymology {}", domain, etymology);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import lombok.Getter;

import java.util.stream.Stream;

/**
* RemoteDictionaryEtymology
*
Expand All @@ -23,4 +25,9 @@ public enum RemoteDictionaryEtymology {
RemoteDictionaryEtymology(String etymology) {
this.etymology = etymology;
}

public static RemoteDictionaryEtymology newEtymology(String etymology) {
return Stream.of(values()).filter(e -> e.etymology.equals(etymology)).findFirst().orElse(null
);
}
}

0 comments on commit 2d6a813

Please sign in to comment.