OdinConfigurationProcessor { public String process() { Object loaded = yaml.load(configuration); Map<String, Object> map; if (loaded instanceof Map<?, ?>) { map = (Map<String, Object>) loaded; } else { map = new LinkedHashMap<>(); } addTaxonomy(map); addEntityRules(map); return yaml.dump(map); } OdinConfigurationProcessor(Collection<Object> taxonomy, String configuration); String process();  }
@Test public void canAddSimpleTaxonomy() { Collection<Object> taxonomy = new ArrayList<>(); taxonomy.add("Person"); OdinConfigurationProcessor ruleProcessor = new OdinConfigurationProcessor(taxonomy, ""); String processedRules = ruleProcessor.process(); assertTrue(processedRules.contains("taxonomy:\n- Person")); }
@Test public void addTypesIfTaxonomyDeclared() { Collection<Object> taxonomy = new ArrayList<>(); taxonomy.add("Person"); OdinConfigurationProcessor ruleProcessor = new OdinConfigurationProcessor(taxonomy, "taxonomy:\n- Entity\n\nrules:"); String processedRules = ruleProcessor.process(); assertTrue(processedRules.contains("- Entity")); assertTrue(processedRules.contains("- Person")); assertTrue(processedRules.contains("- name: ner-person")); }
@Test public void canAddComplexTaxonomy() { Collection<Object> taxonomy = new ArrayList<>(); taxonomy.add( ImmutableMap.of( "Entity", ImmutableList.of("Person", ImmutableMap.of("Location", ImmutableList.of("Point"))))); taxonomy.add(ImmutableMap.of("Other", ImmutableList.of("Tree"))); taxonomy.add("Event"); OdinConfigurationProcessor ruleProcessor = new OdinConfigurationProcessor(taxonomy, "rules:"); String processedRules = ruleProcessor.process(); assertTrue( processedRules, processedRules.contains( "taxonomy:\n- Entity:\n - Person\n - Location:\n - Point\n- Other:\n - Tree\n- Event")); }
@Test public void canAddEntityRule() { Collection<Object> taxonomy = new ArrayList<>(); taxonomy.add("Person"); OdinConfigurationProcessor ruleProcessor = new OdinConfigurationProcessor(taxonomy, "rules:"); String processedRules = ruleProcessor.process(); assertTrue( processedRules, processedRules.contains( "- name: ner-person\n" + " label: Person\n" + " priority: 1\n" + " type: token\n" + " pattern: '[entity=\"Person\"]+'")); }
@Test public void canAddNestedEntityRules() { Collection<Object> taxonomy = new ArrayList<>(); taxonomy.add( ImmutableMap.of( "Entity", ImmutableList.of("Person", ImmutableMap.of("Location", ImmutableList.of("Point"))))); taxonomy.add(ImmutableMap.of("Other", ImmutableList.of("Tree", "List"))); taxonomy.add("Event"); OdinConfigurationProcessor ruleProcessor = new OdinConfigurationProcessor(taxonomy, "rules:"); String processedRules = ruleProcessor.process(); assertTrue( processedRules, processedRules.contains( "- name: ner-person\n" + " label:\n" + " - Entity\n" + " - Person\n" + " priority: 1\n" + " type: token\n" + " pattern: '[entity=\"Person\"]+'")); assertTrue( processedRules, processedRules.contains( "- name: ner-point\n" + " label:\n" + " - Entity\n" + " - Location\n" + " - Point\n" + " priority: 1\n" + " type: token\n" + " pattern: '[entity=\"Point\"]+'")); assertTrue( processedRules, processedRules.contains( "- name: ner-event\n" + " label: Event\n" + " priority: 1\n" + " type: token\n" + " pattern: '[entity=\"Event\"]+'")); }
@Test public void canAddEntityRuleBeforeExistingRule() { Collection<Object> taxonomy = new ArrayList<>(); taxonomy.add("Person"); OdinConfigurationProcessor ruleProcessor = new OdinConfigurationProcessor(taxonomy, "rules:\n- name: test"); String processedRules = ruleProcessor.process(); assertTrue( processedRules, processedRules.contains( "- name: ner-person\n" + " label: Person\n" + " priority: 1\n" + " type: token\n" + " pattern: '[entity=\"Person\"]+'\n" + "- name: test")); }
@Test public void canAddEntityRuleBeforeExistingRules() { Collection<Object> taxonomy = new ArrayList<>(); taxonomy.add("Person"); OdinConfigurationProcessor ruleProcessor = new OdinConfigurationProcessor(taxonomy, "rules:\n- name: test\n- name: other"); String processedRules = ruleProcessor.process(); assertTrue( processedRules, processedRules.contains( "- name: ner-person\n" + " label: Person\n" + " priority: 1\n" + " type: token\n" + " pattern: '[entity=\"Person\"]+'\n" + "- name: test\n" + "- name: other")); }