-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
43 changed files
with
713 additions
and
95 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
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
40 changes: 40 additions & 0 deletions
40
src/main/java/org/snomed/snowstormlite/config/LanguageCharacterFoldingConfiguration.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,40 @@ | ||
package org.snomed.snowstormlite.config; | ||
|
||
import java.util.*; | ||
|
||
public class LanguageCharacterFoldingConfiguration { | ||
|
||
private final Map<String, String> charactersNotFolded = new HashMap<>(); | ||
private Map<String, Set<Character>> charactersNotFoldedSets; | ||
|
||
public Map<String, String> getCharactersNotFolded() { | ||
return charactersNotFolded; | ||
} | ||
|
||
public Map<String, Set<Character>> getCharactersNotFoldedSets() { | ||
if (charactersNotFoldedSets == null) { | ||
charactersNotFoldedSets = buildMap(); | ||
} | ||
return charactersNotFoldedSets; | ||
} | ||
|
||
public Set<Character> getCharactersNotFolded(String lang) { | ||
return getCharactersNotFoldedSets().getOrDefault(lang, Collections.emptySet()); | ||
} | ||
|
||
private synchronized Map<String, Set<Character>> buildMap() { | ||
Map<String, Set<Character>> notFoldedSets = new HashMap<>(); | ||
for (Map.Entry<String, String> entry : charactersNotFolded.entrySet()) { | ||
notFoldedSets.put(entry.getKey(), toCharSet(entry.getValue())); | ||
} | ||
return notFoldedSets; | ||
} | ||
|
||
private Set<Character> toCharSet(String s) { | ||
Set<Character> set = new HashSet<>(); | ||
for (char c : s.toCharArray()) { | ||
set.add(c); | ||
} | ||
return set; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/org/snomed/snowstormlite/config/LanguageDialectAliasConfiguration.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,76 @@ | ||
package org.snomed.snowstormlite.config; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.snomed.snowstormlite.domain.LanguageDialect; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class LanguageDialectAliasConfiguration { | ||
|
||
private static LanguageDialectAliasConfiguration singleton; | ||
|
||
private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
private final Map<String, String> config = new HashMap<>(); | ||
|
||
private Map<String, DialectConfiguration> dialects; | ||
|
||
// Used by Spring to fill the properties | ||
public Map<String, String> getConfig() { | ||
return config; | ||
} | ||
|
||
@PostConstruct | ||
private void init() { | ||
Map<String, DialectConfiguration> dialects = new HashMap<>(); | ||
for (String key : config.keySet()) { | ||
String dialectCode = key.substring(key.lastIndexOf(".") + 1).toLowerCase(); | ||
long languageRefsetId = Long.parseLong(config.get(key)); | ||
dialects.put(dialectCode, new DialectConfiguration(dialectCode, languageRefsetId)); | ||
logger.info("Known dialect " + dialectCode + " - refset: " + languageRefsetId); | ||
} | ||
this.dialects = Collections.unmodifiableMap(dialects); | ||
singleton = this; | ||
} | ||
|
||
public static LanguageDialectAliasConfiguration instance() { | ||
return singleton; | ||
} | ||
|
||
public Long findRefsetForDialect(String dialectCode) { | ||
if (dialects.containsKey(dialectCode)) { | ||
return dialects.get(dialectCode).languageRefsetId; | ||
} | ||
return null; | ||
} | ||
|
||
public LanguageDialect getLanguageDialect(String dialectCode) { | ||
//Do we know about this language code? | ||
dialectCode = dialectCode.toLowerCase(); | ||
if (dialects.containsKey(dialectCode)) { | ||
String lang = dialectCode.split("-")[0]; | ||
Long refsetId = findRefsetForDialect(dialectCode); | ||
return new LanguageDialect(lang, refsetId); | ||
} | ||
return new LanguageDialect(dialectCode); | ||
} | ||
|
||
public void report() { | ||
logger.info(dialects.size() + " known dialects configured"); | ||
} | ||
|
||
public static class DialectConfiguration { | ||
String dialectCode; | ||
Long languageRefsetId; | ||
|
||
DialectConfiguration(String dialectCode, Long languageRefsetId) { | ||
this.dialectCode = dialectCode; | ||
this.languageRefsetId = languageRefsetId; | ||
} | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/snomed/snowstormlite/config/ServiceConfiguration.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,22 @@ | ||
package org.snomed.snowstormlite.config; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class ServiceConfiguration { | ||
|
||
@Bean | ||
@ConfigurationProperties(prefix = "search.language") | ||
public LanguageCharacterFoldingConfiguration languageCharacterFoldingConfiguration() { | ||
return new LanguageCharacterFoldingConfiguration(); | ||
} | ||
|
||
@Bean | ||
@ConfigurationProperties(prefix = "search.dialect") | ||
public LanguageDialectAliasConfiguration languageDialectAliasConfiguration() { | ||
return new LanguageDialectAliasConfiguration(); | ||
} | ||
|
||
} |
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
72 changes: 72 additions & 0 deletions
72
src/main/java/org/snomed/snowstormlite/domain/LanguageDialect.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,72 @@ | ||
package org.snomed.snowstormlite.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class LanguageDialect { | ||
|
||
private String languageCode; | ||
private Long languageReferenceSet; | ||
|
||
public LanguageDialect() { } | ||
|
||
public LanguageDialect(String languageCode) { | ||
this.languageCode = languageCode; | ||
} | ||
|
||
public LanguageDialect(String languageCode, Long languageReferenceSet) { | ||
this.languageCode = languageCode; | ||
this.languageReferenceSet = languageReferenceSet; | ||
} | ||
|
||
public String getLanguageCode() { | ||
return languageCode; | ||
} | ||
|
||
public Long getLanguageReferenceSet() { | ||
return languageReferenceSet; | ||
} | ||
|
||
public static List<String> toLanguageCodes(List<LanguageDialect> languageDialects) { | ||
List<String> languageCodes = new ArrayList<>(); | ||
if (languageDialects != null) { | ||
for (LanguageDialect languageDialect : languageDialects) { | ||
String code = languageDialect.getLanguageCode(); | ||
if (code != null && !code.isEmpty()) { | ||
languageCodes.add(code); | ||
} | ||
} | ||
} | ||
return languageCodes; | ||
} | ||
|
||
public String toString() { | ||
String str = ""; | ||
if (languageCode != null) { | ||
str = languageCode; | ||
if (languageReferenceSet != null) { | ||
str += " - "; | ||
} | ||
} | ||
|
||
if (languageReferenceSet != null) { | ||
str += languageReferenceSet; | ||
} | ||
return str; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
LanguageDialect that = (LanguageDialect) o; | ||
return languageCode.equals(that.languageCode) && | ||
Objects.equals(languageReferenceSet, that.languageReferenceSet); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(languageCode, languageReferenceSet); | ||
} | ||
} |
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
Oops, something went wrong.