/**
  * This tests if the Enhancements created by the Engine confirm to the rules defined for the
  * Stanbol Enhancement Structure.
  *
  * @throws IOException
  * @throws EngineException
  */
 @Test
 public void testEngine() throws IOException, EngineException {
   EntityLinkerConfig linkerConfig = new EntityLinkerConfig();
   linkerConfig.setRedirectProcessingMode(RedirectProcessingMode.FOLLOW);
   KeywordLinkingEngine engine =
       KeywordLinkingEngine.createInstance(
           openNLP, searcher, new TextAnalyzerConfig(), linkerConfig);
   engine.referencedSiteName = TEST_REFERENCED_SITE_NAME;
   ContentItem ci = ciFactory.createContentItem(new StringSource(TEST_TEXT));
   // tells the engine that this is an English text
   ci.getMetadata().add(new TripleImpl(ci.getUri(), DC_LANGUAGE, new PlainLiteralImpl("en")));
   // compute the enhancements
   engine.computeEnhancements(ci);
   // validate the enhancement results
   Map<UriRef, Resource> expectedValues = new HashMap<UriRef, Resource>();
   expectedValues.put(ENHANCER_EXTRACTED_FROM, ci.getUri());
   expectedValues.put(
       DC_CREATOR, LiteralFactory.getInstance().createTypedLiteral(engine.getClass().getName()));
   // adding null as expected for confidence makes it a required property
   expectedValues.put(Properties.ENHANCER_CONFIDENCE, null);
   // validate create fise:TextAnnotations
   int numTextAnnotations =
       validateAllTextAnnotations(ci.getMetadata(), TEST_TEXT, expectedValues);
   assertEquals("Four fise:TextAnnotations are expected by this Test", 4, numTextAnnotations);
   // validate create fise:EntityAnnotations
   int numEntityAnnotations = validateAllEntityAnnotations(ci, expectedValues);
   assertEquals("Five fise:EntityAnnotations are expected by this Test", 5, numEntityAnnotations);
 }
 /**
  * This tests the EntityLinker functionality (if the expected Entities are linked)
  *
  * @throws Exception
  */
 @Test
 public void testTaxonomyLinker() throws Exception {
   OpenNlpAnalysedContentFactory acf =
       OpenNlpAnalysedContentFactory.getInstance(openNLP, new TextAnalyzerConfig());
   EntityLinkerConfig config = new EntityLinkerConfig();
   config.setRedirectProcessingMode(RedirectProcessingMode.FOLLOW);
   EntityLinker linker = new EntityLinker(acf.create(TEST_TEXT, "en"), searcher, config);
   linker.process();
   Map<String, List<String>> expectedResults = new HashMap<String, List<String>>();
   expectedResults.put(
       "Patrick Marshall", new ArrayList<String>(Arrays.asList("urn:test:PatrickMarshall")));
   expectedResults.put(
       "geologist",
       new ArrayList<String>(
           Arrays.asList("urn:test:redirect:Geologist"))); // the redirected entity
   expectedResults.put("New Zealand", new ArrayList<String>(Arrays.asList("urn:test:NewZealand")));
   expectedResults.put(
       "University of Otago",
       new ArrayList<String>(
           Arrays.asList("urn:test:UniversityOfOtago", "urn:test:UniversityOfOtago_Texas")));
   for (LinkedEntity linkedEntity : linker.getLinkedEntities().values()) {
     List<String> expectedSuggestions = expectedResults.remove(linkedEntity.getSelectedText());
     assertNotNull(
         "LinkedEntity "
             + linkedEntity.getSelectedText()
             + "is not an expected Result (or was found twice)",
         expectedSuggestions);
     linkedEntity.getSuggestions().iterator();
     assertEquals(
         "Number of suggestions "
             + linkedEntity.getSuggestions().size()
             + " != number of expected suggestions "
             + expectedSuggestions.size()
             + "for selection "
             + linkedEntity.getSelectedText(),
         linkedEntity.getSuggestions().size(),
         expectedSuggestions.size());
     double score = linkedEntity.getScore();
     for (int i = 0; i < expectedSuggestions.size(); i++) {
       Suggestion suggestion = linkedEntity.getSuggestions().get(i);
       assertEquals(
           "Expecced Suggestion at Rank "
               + i
               + " expected: "
               + expectedSuggestions.get(i)
               + " suggestion: "
               + suggestion.getRepresentation().getId(),
           expectedSuggestions.get(i),
           suggestion.getRepresentation().getId());
       assertTrue(
           "Score of suggestion "
               + i
               + "("
               + suggestion.getScore()
               + " > as of the previous one ("
               + score
               + ")",
           score >= suggestion.getScore());
       score = suggestion.getScore();
     }
   }
 }