Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String[] getConfusion(String correct, String incorrect){
- if(damerauLevenshteinDistance(correct, incorrect) != 1){
- return new String[]{"", ""};
- }
- if(correct.length() == incorrect.length()){
- for(int i = 0; i < correct.length(); i++){
- if(correct.charAt(i) == incorrect.charAt(i)){
- continue;
- }else{
- if(i == correct.length() - 1 && correct.charAt(i) != incorrect.charAt(i)){
- return new String[]{"" + incorrect.charAt(i), "" + correct.charAt(i)}; //Substitution
- }else if(i < correct.length() - 1 && correct.charAt(i) != incorrect.charAt(i)){
- if(correct.charAt(i) == incorrect.charAt(i+1) && incorrect.charAt(i) == correct.charAt(i+1)){
- return new String[]{"" + incorrect.charAt(i) + incorrect.charAt(i+1),
- "" + correct.charAt(i) + correct.charAt(i+1)}; //Transposition
- }else{
- return new String[]{"" + incorrect.charAt(i), "" + correct.charAt(i)}; //Subtitution
- }
- }
- }
- }
- }else if(correct.length() > incorrect.length()){ //Deletion
- for(int i = 0; i < incorrect.length(); i++){
- if(correct.charAt(i) == incorrect.charAt(i)){
- continue;
- }else{
- if(i == 0){
- return new String[]{"" + incorrect.charAt(i), "" + correct.charAt(i) + correct.charAt(i + 1),
- " ", "" + correct.charAt(i)};
- }else{
- return new String[]{"" + incorrect.charAt(i-1), "" + correct.charAt(i-1) + correct.charAt(i),
- "" + incorrect.charAt(i), "" + correct.charAt(i) + correct.charAt(i+1)};
- }
- }
- }
- return new String[]{"" + incorrect.charAt(incorrect.length()), "" + correct.charAt(incorrect.length()) + correct.charAt(incorrect.length() + 1),
- " ", "" + correct.charAt(incorrect.length() + 1)};
- }else{ //Insertion
- for(int i = 0; i < correct.length(); i++){
- if(correct.charAt(i) == incorrect.charAt(i)){
- continue;
- }else{
- if(i == 0){
- return new String[]{"" + incorrect.charAt(i), " ",
- "" + incorrect.charAt(i) + incorrect.charAt(i+1), "" + correct.charAt(i)};
- }else{
- return new String[]{"" + incorrect.charAt(i) + incorrect.charAt(i+1), "" + correct.charAt(i),
- "" + incorrect.charAt(i-1) + incorrect.charAt(i), "" + correct.charAt(i-1)};
- }
- }
- }
- return new String[]{"" + incorrect.charAt(incorrect.length()), " ",
- "" + incorrect.charAt(incorrect.length() - 1) + incorrect.charAt(incorrect.length()), "" + correct.charAt(correct.length())};
- }
- return new String[2];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement