-
Notifications
You must be signed in to change notification settings - Fork 5
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 #65 from ncats/aw_a005_greektome
WIP: Need to treat these characters as “real” indexed ones.
- Loading branch information
Showing
5 changed files
with
103 additions
and
30 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
gsrs-spring-legacy-indexer/src/main/java/ix/core/search/text/IndexedTextEncoder.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,12 @@ | ||
package ix.core.search.text; | ||
|
||
public interface IndexedTextEncoder{ | ||
public String encode(String s); | ||
default IndexedTextEncoder combine(IndexedTextEncoder enc){ | ||
IndexedTextEncoder _this=this; | ||
return (s)->{ | ||
String e=_this.encode(s); | ||
return enc.encode(e); | ||
}; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
gsrs-spring-legacy-indexer/src/main/java/ix/core/search/text/StandardEncoding.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,30 @@ | ||
package ix.core.search.text; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
@Data | ||
public class StandardEncoding implements IndexedTextEncoder{ | ||
|
||
private String regex; | ||
private String replaceWith; | ||
private Pattern _pattern; | ||
|
||
public StandardEncoding() {} | ||
|
||
public StandardEncoding(String regex, String replaceWith) { | ||
this.regex = regex; | ||
this.replaceWith = replaceWith; | ||
_pattern=Pattern.compile(Pattern.quote(regex)); | ||
} | ||
|
||
@Override | ||
public String encode(String s){ | ||
if(_pattern==null){ | ||
_pattern=Pattern.compile(Pattern.quote(regex)); | ||
} | ||
s=_pattern.matcher(s).replaceAll(replaceWith); | ||
return s; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
gsrs-spring-legacy-indexer/src/main/java/ix/core/search/text/StandardEncodings.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,43 @@ | ||
package ix.core.search.text; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class StandardEncodings { | ||
|
||
private static final String LEVO_REGEX = "(-)"; | ||
private static final String DEXTRO_REGEX = "(+)"; | ||
private static final String RACEMIC_REGEX = "(+/-)"; | ||
private static final String RACEMIC_COMBO_REGEX = "±"; // Associated with RACEMIC_WORD | ||
|
||
public static final String LEVO_WORD = "LEVOROTATION"; | ||
public static final String RACEMIC_WORD = "RACEMICROTATION"; | ||
public static final String DEXTRO_WORD = "DEXTROROTATION"; | ||
|
||
private static final String REPLACEMENT_SOURCE_GREEK = "\u03B1;.ALPHA.;\u03B2;.BETA.;\u03B3;.GAMMA.;\u03B4;.DELTA.;\u03B5;.EPSILON.;\u03B6;.ZETA.;\u03B7;.ETA.;\u03B8;.THETA.;\u03B9;.IOTA.;\u03BA;.KAPPA.;\u03BB;.LAMBDA.;\u03BC;.MU.;\u03BD;.NU.;\u03BE;.XI.;\u03BF;.OMICRON.;\u03C0;.PI.;\u03C1;.RHO.;\u03C2;.SIGMA.;\u03C3;.SIGMA.;\u03C4;.TAU.;\u03C5;.UPSILON.;\u03C6;.PHI.;\u03C7;.CHI.;\u03C8;.PSI.;\u03C9;.OMEGA.;\u0391;.ALPHA.;\u0392;.BETA.;\u0393;.GAMMA.;\u0394;.DELTA.;\u0395;.EPSILON.;\u0396;.ZETA.;\u0397;.ETA.;\u0398;.THETA.;\u0399;.IOTA.;\u039A;.KAPPA.;\u039B;.LAMBDA.;\u039C;.MU.;\u039D;.NU.;\u039E;.XI.;\u039F;.OMICRON.;\u03A0;.PI.;\u03A1;.RHO.;\u03A3;.SIGMA.;\u03A4;.TAU.;\u03A5;.UPSILON.;\u03A6;.PHI.;\u03A7;.CHI.;\u03A8;.PSI.;\u03A9;.OMEGA."; | ||
// The uppercase and lowercase forms of the 24 letters are: Α α, Β β, Γ γ, Δ δ, Ε ε, Ζ ζ, Η η, Θ θ, Ι ι, Κ κ, Λ λ, Μ μ, Ν ν, Ξ ξ, Ο ο, Π π, Ρ ρ, Σ σ/ς, Τ τ, Υ υ, Φ φ, Χ χ, Ψ ψ, and Ω ω. | ||
|
||
private static StandardEncodings _INSTANCE; | ||
|
||
private List<StandardEncoding> encodings = new ArrayList<StandardEncoding>(); | ||
|
||
public List<StandardEncoding> getEncodings(){ return encodings; } | ||
|
||
public static StandardEncodings getInstance(){ | ||
if(_INSTANCE==null)_INSTANCE=new StandardEncodings(); | ||
return _INSTANCE; | ||
} | ||
|
||
StandardEncodings() { | ||
encodings.add(new StandardEncoding(LEVO_REGEX, LEVO_WORD)); | ||
encodings.add(new StandardEncoding(DEXTRO_REGEX, DEXTRO_WORD)); | ||
encodings.add(new StandardEncoding(RACEMIC_REGEX, RACEMIC_WORD)); | ||
encodings.add(new StandardEncoding(RACEMIC_REGEX, RACEMIC_WORD)); | ||
|
||
String[] replacementTokensGreek = REPLACEMENT_SOURCE_GREEK.split(";"); | ||
for (int i = 0; i < replacementTokensGreek.length; i = i + 2) { | ||
encodings.add(new StandardEncoding(replacementTokensGreek[i], replacementTokensGreek[i + 1])); | ||
} | ||
} | ||
} | ||
|
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