Search in sources :

Example 56 with ContentItem

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);
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) EntityLinkerConfig(org.apache.stanbol.enhancer.engines.entitylinking.config.EntityLinkerConfig) TextProcessingConfig(org.apache.stanbol.enhancer.engines.entitylinking.config.TextProcessingConfig) PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) HashMap(java.util.HashMap) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) StringSource(org.apache.stanbol.enhancer.servicesapi.impl.StringSource) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) ContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem) Test(org.junit.Test)

Example 57 with ContentItem

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);
}
Also used : ContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem) Test(org.junit.Test)

Example 58 with ContentItem

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);
}
Also used : ContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem) Test(org.junit.Test)

Example 59 with ContentItem

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());
}
Also used : SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) ContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem) Test(org.junit.Test)

Example 60 with ContentItem

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));
}
Also used : SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) ContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem) Test(org.junit.Test)

Aggregations

ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)73 Test (org.junit.Test)62 IRI (org.apache.clerezza.commons.rdf.IRI)46 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)18 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)18 HashMap (java.util.HashMap)15 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)15 Blob (org.apache.stanbol.enhancer.servicesapi.Blob)15 StringSource (org.apache.stanbol.enhancer.servicesapi.impl.StringSource)13 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)12 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)11 Graph (org.apache.clerezza.commons.rdf.Graph)8 Date (java.util.Date)6 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)6 Hashtable (java.util.Hashtable)5 AnalysedText (org.apache.stanbol.enhancer.nlp.model.AnalysedText)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 MediaType (javax.ws.rs.core.MediaType)3 Triple (org.apache.clerezza.commons.rdf.Triple)3