use of org.molgenis.semanticmapper.algorithmgenerator.bean.Category in project molgenis by molgenis.
the class InternalAbstractCategoryRuleTest method testCreateNumericQualityIndicatorDoesNotThrowNPE.
@Test
public void testCreateNumericQualityIndicatorDoesNotThrowNPE() {
InternalAbstractCategoryRule rule = new NegativeCategoryRule();
Category target = mock(Category.class);
when(target.getLabel()).thenReturn("label1");
Category source = mock(Category.class);
when(source.getLabel()).thenReturn("label2");
rule.createCategoryMatchQuality(target, source);
}
use of org.molgenis.semanticmapper.algorithmgenerator.bean.Category in project molgenis by molgenis.
the class FrequencyCategoryMapper method findBestCategoryMatch.
public Category findBestCategoryMatch(Category sourceCategory, List<Category> targetCategories) {
Category bestTargetCategory = null;
double smallestFactor = -1;
for (Category targetCategory : targetCategories) {
Double convertFactor = convert(sourceCategory.getAmountWrapper(), targetCategory.getAmountWrapper());
if (convertFactor == null)
continue;
if (smallestFactor == -1) {
smallestFactor = convertFactor;
bestTargetCategory = targetCategory;
} else if (smallestFactor > convertFactor) {
smallestFactor = convertFactor;
bestTargetCategory = targetCategory;
}
}
return bestTargetCategory;
}
use of org.molgenis.semanticmapper.algorithmgenerator.bean.Category in project molgenis by molgenis.
the class LexicalCategoryMapper method findBestCategoryMatch.
public Category findBestCategoryMatch(Category sourceCategory, List<Category> targetCategories) {
String sourceCategoryLabel = sourceCategory.getLabel().toLowerCase();
Category bestCategory = null;
double bestNGramScore = -1;
for (Category targetCategory : targetCategories) {
String targetCategoryLabel = targetCategory.getLabel();
if (StringUtils.equalsIgnoreCase(sourceCategoryLabel, targetCategoryLabel)) {
return targetCategory;
}
double ngramScore = NGramDistanceAlgorithm.stringMatching(sourceCategoryLabel, targetCategoryLabel);
if (bestNGramScore == -1 || bestNGramScore < ngramScore) {
bestNGramScore = ngramScore;
bestCategory = targetCategory;
}
}
if (bestNGramScore < DEFAULT_THRESHOLD) {
Optional<?> findFirst = targetCategories.stream().map(targetCategory -> applyCustomRules(sourceCategory, targetCategory)).filter(Objects::nonNull).sorted().findFirst();
if (findFirst.isPresent() && findFirst.get() instanceof CategoryMatchQuality) {
bestCategory = ((CategoryMatchQuality<?>) findFirst.get()).getTargetCategory();
}
}
return bestCategory;
}
use of org.molgenis.semanticmapper.algorithmgenerator.bean.Category in project molgenis by molgenis.
the class LexicalCategoryMapperTest method findBestCategoryMatch.
@Test
public void findBestCategoryMatch() {
Category maleCategory = Category.create("0", "MALE");
Category femaleCategory = Category.create("1", "FEMALE");
List<Category> targetCategories1 = Lists.newArrayList(maleCategory, femaleCategory);
Assert.assertEquals(lexicalCategoryMapper.findBestCategoryMatch(Category.create("1", "male"), targetCategories1), maleCategory);
Assert.assertEquals(lexicalCategoryMapper.findBestCategoryMatch(Category.create("2", "female"), targetCategories1), femaleCategory);
Category neverStrokeCategory = Category.create("0", "Never had stroke");
Category hasStrokeCategory = Category.create("1", "Has has stroke");
List<Category> targetCategories2 = Lists.newArrayList(neverStrokeCategory, hasStrokeCategory);
Assert.assertEquals(lexicalCategoryMapper.findBestCategoryMatch(Category.create("1", "no"), targetCategories2), neverStrokeCategory);
Assert.assertEquals(lexicalCategoryMapper.findBestCategoryMatch(Category.create("1", "yes"), targetCategories2), hasStrokeCategory);
}
use of org.molgenis.semanticmapper.algorithmgenerator.bean.Category in project molgenis by molgenis.
the class OneToManyCategoryAlgorithmGenerator method generateWeightedMap.
public String generateWeightedMap(Attribute attribute) {
StringBuilder stringBuilder = new StringBuilder();
for (Category sourceCategory : convertToCategory(attribute)) {
AmountWrapper amountWrapper = sourceCategory.getAmountWrapper();
if (amountWrapper != null) {
if (stringBuilder.length() == 0) {
stringBuilder.append("$('").append(attribute.getName()).append("').map({");
}
double estimatedValue = amountWrapper.getAmount().getEstimatedValue();
stringBuilder.append("\"").append(sourceCategory.getCode()).append("\":").append(DECIMAL_FORMAT.format(estimatedValue)).append(",");
}
}
if (stringBuilder.length() > 0) {
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
stringBuilder.append("}, null, null).value()");
}
return stringBuilder.toString();
}
Aggregations