use of org.apache.stanbol.enhancer.servicesapi.ContentItem in project stanbol by apache.
the class EntityLinkingEngineTest method testEngine.
/**
* 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);
//this is assumed by this test
linkerConfig.setMinFoundTokens(2);
EntityLinkingEngine engine = new EntityLinkingEngine("dummy", searcher, new TextProcessingConfig(), linkerConfig, labelTokenizer);
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")));
//and add the AnalysedText instance used for this test
ci.addPart(AnalysedText.ANALYSED_TEXT_URI, TEST_ANALYSED_TEXT);
//compute the enhancements
engine.computeEnhancements(ci);
//validate the enhancement results
Map<IRI, RDFTerm> expectedValues = new HashMap<IRI, RDFTerm>();
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);
}
use of org.apache.stanbol.enhancer.servicesapi.ContentItem in project stanbol by apache.
the class TestEntityLinkingEnhancementEngine method testLocationLinking.
@Test
public void testLocationLinking() throws Exception {
//create a content item
ContentItem ci = initContentItem();
NamedEntityTaggingEngine entityLinkingEngine = initEngine(false, false, true);
//perform the computation of the enhancements
entityLinkingEngine.computeEnhancements(ci);
int entityAnnotationCount = validateAllEntityAnnotations(entityLinkingEngine, ci);
assertEquals(1, entityAnnotationCount);
}
use of org.apache.stanbol.enhancer.servicesapi.ContentItem in project stanbol by apache.
the class TestEntityLinkingEnhancementEngine method testOrganizationLinking.
@Test
public void testOrganizationLinking() throws Exception {
//create a content item
ContentItem ci = initContentItem();
NamedEntityTaggingEngine entityLinkingEngine = initEngine(false, true, false);
//perform the computation of the enhancements
entityLinkingEngine.computeEnhancements(ci);
int entityAnnotationCount = validateAllEntityAnnotations(entityLinkingEngine, ci);
assertEquals(1, entityAnnotationCount);
}
use of org.apache.stanbol.enhancer.servicesapi.ContentItem in project stanbol by apache.
the class ContentItemFactoryTest method testContentReferenceId.
/**
* Tests if the {@link ContentReference#getReference()} is used as ID for
* the contentItem
*/
@Test
public void testContentReferenceId() throws IOException {
ContentItem ci = contentItemFactory.createContentItem(TEST_CR);
assertNotNull(ci);
assertNotNull(ci.getUri());
assertEquals(TEST_CR.getReference(), ci.getUri().getUnicodeString());
contentItemFactory.createContentItem(TEST_CR, new SimpleGraph());
assertNotNull(ci);
assertNotNull(ci.getUri());
assertEquals(TEST_CR.getReference(), ci.getUri().getUnicodeString());
}
use of org.apache.stanbol.enhancer.servicesapi.ContentItem in project stanbol by apache.
the class ContentItemFactoryTest method testPrefix.
/**
* Test that the generated ID starts with the parsed prefix
*/
@Test
public void testPrefix() throws IOException {
ContentItem ci = contentItemFactory.createContentItem(PREFIX, TEST_CS);
assertNotNull(ci);
assertNotNull(ci.getUri());
assertTrue("The ID of the created ContentItem MUST start with the parsed prefix", ci.getUri().getUnicodeString().startsWith(PREFIX));
ci = contentItemFactory.createContentItem(PREFIX, TEST_CS, new SimpleGraph());
assertNotNull(ci);
assertNotNull(ci.getUri());
assertTrue("The ID of the created ContentItem MUST start with the parsed prefix", ci.getUri().getUnicodeString().startsWith(PREFIX));
}
Aggregations