@Test public void voteMatch_MANY_ORG_NAMES__ENOUGH_COMMON_WORDS__WITH_REGARD_TO_ORG() { resetOrgNames("Technical University in Poznan", "University of Toronto", "University of Warsaw"); whenFilterCharsThen(affOrgName, "Department Chemistry University Toronto"); whenFilterCharsThen("University of Toronto", "University Toronto"); whenFilterCharsThen("University of Warsaw", "University Warsaw"); whenFilterCharsThen("Technical University in Poznan", "Technical University Poznan"); when(commonSimilarWordCalculator.calcSimilarWordRatio(newArrayList("University", "Toronto"), newArrayList("Department", "Chemistry", "University", "Toronto"))) .thenReturn(MIN_COMMON_WORDS_RATIO - 0.01); when(commonSimilarWordCalculator.calcSimilarWordRatio(newArrayList("University", "Warsaw"), newArrayList("Department", "Chemistry", "University", "Toronto"))) .thenReturn(MIN_COMMON_WORDS_RATIO + 0.01); when(commonSimilarWordCalculator.calcSimilarWordRatio(newArrayList("Technical", "University", "Poznan"), newArrayList("Department", "Chemistry", "University", "Toronto"))) .thenReturn(MIN_COMMON_WORDS_RATIO - 0.01); assertTrue(voter.voteMatch(affiliation, organization)); }
@Override public boolean voteMatch(AffMatchAffiliation affiliation, AffMatchOrganization organization) { String filteredAffName = stringFilter.filterCharsAndShortWords(affiliation.getOrganizationName(), charsToFilter, wordToRemoveMaxLength); if (StringUtils.isEmpty(filteredAffName)) { return false; } List<String> affWords = ImmutableList.copyOf(StringUtils.split(filteredAffName)); for (String orgName : getOrgNamesFunction.apply(organization)) { String filteredOrgName = stringFilter.filterCharsAndShortWords(orgName, charsToFilter, wordToRemoveMaxLength); if (StringUtils.isEmpty(filteredOrgName)) { continue; } List<String> orgWords = ImmutableList.copyOf(StringUtils.split(filteredOrgName)); if (isProperNumberOfSimilarWords(affWords, orgWords)) { return true; } } return false; }
CommonWordsVoter extends AbstractAffOrgMatchVoter { @Override public boolean voteMatch(AffMatchAffiliation affiliation, AffMatchOrganization organization) { String filteredAffName = stringFilter.filterCharsAndShortWords(affiliation.getOrganizationName(), charsToFilter, wordToRemoveMaxLength); if (StringUtils.isEmpty(filteredAffName)) { return false; } List<String> affWords = ImmutableList.copyOf(StringUtils.split(filteredAffName)); for (String orgName : getOrgNamesFunction.apply(organization)) { String filteredOrgName = stringFilter.filterCharsAndShortWords(orgName, charsToFilter, wordToRemoveMaxLength); if (StringUtils.isEmpty(filteredOrgName)) { continue; } List<String> orgWords = ImmutableList.copyOf(StringUtils.split(filteredOrgName)); if (isProperNumberOfSimilarWords(affWords, orgWords)) { return true; } } return false; } }
CommonWordsVoter extends AbstractAffOrgMatchVoter { @Override public boolean voteMatch(AffMatchAffiliation affiliation, AffMatchOrganization organization) { String filteredAffName = stringFilter.filterCharsAndShortWords(affiliation.getOrganizationName(), charsToFilter, wordToRemoveMaxLength); if (StringUtils.isEmpty(filteredAffName)) { return false; } List<String> affWords = ImmutableList.copyOf(StringUtils.split(filteredAffName)); for (String orgName : getOrgNamesFunction.apply(organization)) { String filteredOrgName = stringFilter.filterCharsAndShortWords(orgName, charsToFilter, wordToRemoveMaxLength); if (StringUtils.isEmpty(filteredOrgName)) { continue; } List<String> orgWords = ImmutableList.copyOf(StringUtils.split(filteredOrgName)); if (isProperNumberOfSimilarWords(affWords, orgWords)) { return true; } } return false; } CommonWordsVoter(List<Character> charsToFilter, int wordToRemoveMaxLength, double minCommonWordsRatio, RatioRelation ratioRelation); }
CommonWordsVoter extends AbstractAffOrgMatchVoter { @Override public boolean voteMatch(AffMatchAffiliation affiliation, AffMatchOrganization organization) { String filteredAffName = stringFilter.filterCharsAndShortWords(affiliation.getOrganizationName(), charsToFilter, wordToRemoveMaxLength); if (StringUtils.isEmpty(filteredAffName)) { return false; } List<String> affWords = ImmutableList.copyOf(StringUtils.split(filteredAffName)); for (String orgName : getOrgNamesFunction.apply(organization)) { String filteredOrgName = stringFilter.filterCharsAndShortWords(orgName, charsToFilter, wordToRemoveMaxLength); if (StringUtils.isEmpty(filteredOrgName)) { continue; } List<String> orgWords = ImmutableList.copyOf(StringUtils.split(filteredOrgName)); if (isProperNumberOfSimilarWords(affWords, orgWords)) { return true; } } return false; } CommonWordsVoter(List<Character> charsToFilter, int wordToRemoveMaxLength, double minCommonWordsRatio, RatioRelation ratioRelation); @Override boolean voteMatch(AffMatchAffiliation affiliation, AffMatchOrganization organization); void setGetOrgNamesFunction(Function<AffMatchOrganization, List<String>> getOrgNamesFunction); void setCommonSimilarWordCalculator(CommonSimilarWordCalculator commonSimilarWordCalculator); void setRatioRelation(RatioRelation ratioRelation); @Override String toString(); }
CommonWordsVoter extends AbstractAffOrgMatchVoter { @Override public boolean voteMatch(AffMatchAffiliation affiliation, AffMatchOrganization organization) { String filteredAffName = stringFilter.filterCharsAndShortWords(affiliation.getOrganizationName(), charsToFilter, wordToRemoveMaxLength); if (StringUtils.isEmpty(filteredAffName)) { return false; } List<String> affWords = ImmutableList.copyOf(StringUtils.split(filteredAffName)); for (String orgName : getOrgNamesFunction.apply(organization)) { String filteredOrgName = stringFilter.filterCharsAndShortWords(orgName, charsToFilter, wordToRemoveMaxLength); if (StringUtils.isEmpty(filteredOrgName)) { continue; } List<String> orgWords = ImmutableList.copyOf(StringUtils.split(filteredOrgName)); if (isProperNumberOfSimilarWords(affWords, orgWords)) { return true; } } return false; } CommonWordsVoter(List<Character> charsToFilter, int wordToRemoveMaxLength, double minCommonWordsRatio, RatioRelation ratioRelation); @Override boolean voteMatch(AffMatchAffiliation affiliation, AffMatchOrganization organization); void setGetOrgNamesFunction(Function<AffMatchOrganization, List<String>> getOrgNamesFunction); void setCommonSimilarWordCalculator(CommonSimilarWordCalculator commonSimilarWordCalculator); void setRatioRelation(RatioRelation ratioRelation); @Override String toString();  }