Skip to content

Instantly share code, notes, and snippets.

@Jonty800
Created October 30, 2015 11:49
Show Gist options
  • Save Jonty800/f720de304505556c508f to your computer and use it in GitHub Desktop.
Save Jonty800/f720de304505556c508f to your computer and use it in GitHub Desktop.
private String[] ignoredWords = new String[] {
"eda"
};
/**
* Compares two strings.
* Each string is stripped of all invalid chars (Allowing letters and numbers only)
*
* @param newsResult The news result string
* @param currentArticle The article string
* @return A "Worth" value, based on the matches found
*/
int compareStrings(String newsResult, String currentArticle) {
if (newsResult == null || currentArticle == null) return 0;
//Strip everything but space, letter and number
newsResult = newsResult.replaceAll("[^a-zA-Z0-9\\s]", "");
currentArticle = currentArticle.replaceAll("[^a-zA-Z0-9\\s]", "");
int totalWorth = 0;
//Split each string into words array
String[] splitA = newsResult.split(" ");
String[] splitB = currentArticle.split(" ");
//Iterate through words
for (String a_: splitA) {
//if the string is an abbreviation OR is bigger than 5 in length and is not ignored
if (((isUpper(a_) && a_.length() >= 2) || (a_.length() >= 5)) && !isIgnored(a_.toLowerCase())) {
//Then compare it to b_
for (String b_: splitB) {
//It is a match if equalsIgnoreCase is true
if (a_.equalsIgnoreCase(b_)) {
totalWorth++;
}
}
}
}
return totalWorth; //return value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment