1 package eu
.etaxonomy
.cdm
.api
.service
;
3 import java
.util
.ArrayList
;
6 public class NameServiceImplementBelen
{
7 private String tempInputName
;
8 private String tempDatabaseName
;
9 private String shortenedInputName
;
10 private String shortenedDatabaseName
;
12 // Phonetic changes performed ONLY on the initial characters of each String
14 public String
replaceInitialCharacter(String inp
) {
15 String input
=inp
.toLowerCase();
17 String
[][] phoneticChange
= {
18 {"ae","e"},{"cn","n"},{"ct","t"},{"cz","c"},
19 {"dj","d"},{"ea","e"},{"eu","u"},{"gn","n"},
20 {"kn","n"},{"mc","mac"},{"mn","n"},{"oe","e"},
21 {"qu","q"},{"ph","f"},{"ps","s"},{"pt","t"},
22 {"ts","s"},{"wr","r"},{"x","z"}
24 for (int i
= 0 ; i
< phoneticChange
.length
; i
++) {
25 if (input
.startsWith(phoneticChange
[i
][0])){
26 output
= input
.replaceFirst(phoneticChange
[i
][0], phoneticChange
[i
][1]);
34 // trim common characters between query and document
36 public List
<String
> trimCommonChar(String inputName
, String databaseName
) {
38 // trim common leading characters of query and document
40 int inputNameLength
= inputName
.length();
41 int databaseNameLength
= databaseName
.length();
42 int largestString
= Math
.max(inputNameLength
, databaseNameLength
);
45 for (i
= 0; i
< largestString
; i
++) {
46 if (i
>= inputNameLength
|| i
>= databaseNameLength
|| inputName
.charAt(i
) != databaseName
.charAt(i
)) {
47 // Stop iterating when the characters at the current position are not equal.
52 // Create temp names with common leading characters removed.
53 tempInputName
= inputName
.substring(i
);
54 tempDatabaseName
= databaseName
.substring(i
);
56 List
<String
> list
= new ArrayList
<>();
58 // trim common tailing characters between query and document
60 int restantInputNameLenght
= tempInputName
.length();
61 int restantDatabaseNameLenght
= tempDatabaseName
.length();
62 int shortestString
= Math
.min(restantInputNameLenght
, restantDatabaseNameLenght
);
64 for (int x
= 0; x
< shortestString
; x
++) {
65 if (tempInputName
.charAt(restantInputNameLenght
- x
- 1) != tempDatabaseName
66 .charAt(restantDatabaseNameLenght
- x
- 1)) {
69 shortenedInputName
= tempInputName
.substring(0, restantInputNameLenght
- x
- 1);
70 shortenedDatabaseName
= tempDatabaseName
.substring(0, restantDatabaseNameLenght
- x
- 1);
73 list
.add(shortenedInputName
+" "+ shortenedDatabaseName
);