@Test void testGenerateRules() { EntityType targetRefEntityType = createCategoricalRefEntityType("HOP_HYPERTENSION"); Entity targetEntity1 = new DynamicEntity( targetRefEntityType, of("code", 0, "label", "Never had high blood pressure ")); Entity targetEntity2 = new DynamicEntity( targetRefEntityType, of("code", 1, "label", "Ever had high blood pressure ")); Entity targetEntity3 = new DynamicEntity(targetRefEntityType, of("code", 9, "label", "Missing")); Mockito.when(dataService.findAll(targetRefEntityType.getId())) .thenReturn(Stream.of(targetEntity1, targetEntity2, targetEntity3)); targetAttribute = attrMetaFactory.create().setName("History of Hypertension").setDataType(CATEGORICAL); targetAttribute.setRefEntity(targetRefEntityType); EntityType sourceRefEntityType = createCategoricalRefEntityType("High_blood_pressure_ref"); Entity sourceEntity1 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "yes")); Entity sourceEntity2 = new DynamicEntity(targetRefEntityType, of("code", 2, "label", "no")); Entity sourceEntity3 = new DynamicEntity(targetRefEntityType, of("code", 3, "label", "I do not know")); Mockito.when(dataService.findAll(sourceRefEntityType.getId())) .thenReturn(Stream.of(sourceEntity1, sourceEntity2, sourceEntity3)); sourceAttribute = attrMetaFactory.create().setName("High_blood_pressure").setDataType(CATEGORICAL); sourceAttribute.setRefEntity(sourceRefEntityType); String generatedAlgorithm = categoryAlgorithmGenerator.generate( targetAttribute, singletonList(sourceAttribute), targetEntityType, sourceEntityType); String expectedAlgorithm = "$('High_blood_pressure').map({\"1\":\"1\",\"2\":\"0\",\"3\":\"9\"}, null, null).value();"; assertEquals(expectedAlgorithm, generatedAlgorithm); }
@Override public String generate( Attribute targetAttribute, List<Attribute> sourceAttributes, EntityType targetEntityType, EntityType sourceEntityType) { String mapAlgorithm = null; if (!sourceAttributes.isEmpty()) { Attribute firstSourceAttribute = sourceAttributes.get(0); List<Category> targetCategories = convertToCategory(targetAttribute); List<Category> sourceCategories = convertToCategory(firstSourceAttribute); if (isFrequencyCategory(targetCategories) && isFrequencyCategory(sourceCategories)) { mapAlgorithm = mapCategories( firstSourceAttribute, targetCategories, sourceCategories, frequencyCategoryMapper); } else { mapAlgorithm = mapCategories( firstSourceAttribute, targetCategories, sourceCategories, lexicalCategoryMapper); } } return mapAlgorithm; }
OneToOneCategoryAlgorithmGenerator extends AbstractCategoryAlgorithmGenerator { @Override public String generate( Attribute targetAttribute, List<Attribute> sourceAttributes, EntityType targetEntityType, EntityType sourceEntityType) { String mapAlgorithm = null; if (!sourceAttributes.isEmpty()) { Attribute firstSourceAttribute = sourceAttributes.get(0); List<Category> targetCategories = convertToCategory(targetAttribute); List<Category> sourceCategories = convertToCategory(firstSourceAttribute); if (isFrequencyCategory(targetCategories) && isFrequencyCategory(sourceCategories)) { mapAlgorithm = mapCategories( firstSourceAttribute, targetCategories, sourceCategories, frequencyCategoryMapper); } else { mapAlgorithm = mapCategories( firstSourceAttribute, targetCategories, sourceCategories, lexicalCategoryMapper); } } return mapAlgorithm; } }
OneToOneCategoryAlgorithmGenerator extends AbstractCategoryAlgorithmGenerator { @Override public String generate( Attribute targetAttribute, List<Attribute> sourceAttributes, EntityType targetEntityType, EntityType sourceEntityType) { String mapAlgorithm = null; if (!sourceAttributes.isEmpty()) { Attribute firstSourceAttribute = sourceAttributes.get(0); List<Category> targetCategories = convertToCategory(targetAttribute); List<Category> sourceCategories = convertToCategory(firstSourceAttribute); if (isFrequencyCategory(targetCategories) && isFrequencyCategory(sourceCategories)) { mapAlgorithm = mapCategories( firstSourceAttribute, targetCategories, sourceCategories, frequencyCategoryMapper); } else { mapAlgorithm = mapCategories( firstSourceAttribute, targetCategories, sourceCategories, lexicalCategoryMapper); } } return mapAlgorithm; } OneToOneCategoryAlgorithmGenerator(DataService dataService); }
OneToOneCategoryAlgorithmGenerator extends AbstractCategoryAlgorithmGenerator { @Override public String generate( Attribute targetAttribute, List<Attribute> sourceAttributes, EntityType targetEntityType, EntityType sourceEntityType) { String mapAlgorithm = null; if (!sourceAttributes.isEmpty()) { Attribute firstSourceAttribute = sourceAttributes.get(0); List<Category> targetCategories = convertToCategory(targetAttribute); List<Category> sourceCategories = convertToCategory(firstSourceAttribute); if (isFrequencyCategory(targetCategories) && isFrequencyCategory(sourceCategories)) { mapAlgorithm = mapCategories( firstSourceAttribute, targetCategories, sourceCategories, frequencyCategoryMapper); } else { mapAlgorithm = mapCategories( firstSourceAttribute, targetCategories, sourceCategories, lexicalCategoryMapper); } } return mapAlgorithm; } OneToOneCategoryAlgorithmGenerator(DataService dataService); @Override boolean isSuitable(Attribute targetAttribute, List<Attribute> sourceAttributes); @Override String generate(
      Attribute targetAttribute,
      List<Attribute> sourceAttributes,
      EntityType targetEntityType,
      EntityType sourceEntityType); }
OneToOneCategoryAlgorithmGenerator extends AbstractCategoryAlgorithmGenerator { @Override public String generate( Attribute targetAttribute, List<Attribute> sourceAttributes, EntityType targetEntityType, EntityType sourceEntityType) { String mapAlgorithm = null; if (!sourceAttributes.isEmpty()) { Attribute firstSourceAttribute = sourceAttributes.get(0); List<Category> targetCategories = convertToCategory(targetAttribute); List<Category> sourceCategories = convertToCategory(firstSourceAttribute); if (isFrequencyCategory(targetCategories) && isFrequencyCategory(sourceCategories)) { mapAlgorithm = mapCategories( firstSourceAttribute, targetCategories, sourceCategories, frequencyCategoryMapper); } else { mapAlgorithm = mapCategories( firstSourceAttribute, targetCategories, sourceCategories, lexicalCategoryMapper); } } return mapAlgorithm; } OneToOneCategoryAlgorithmGenerator(DataService dataService); @Override boolean isSuitable(Attribute targetAttribute, List<Attribute> sourceAttributes); @Override String generate(
      Attribute targetAttribute,
      List<Attribute> sourceAttributes,
      EntityType targetEntityType,
      EntityType sourceEntityType);  }