Search in sources :

Example 1 with LangIdEnhancementEngine

use of org.apache.stanbol.enhancer.engines.langid.LangIdEnhancementEngine in project stanbol by apache.

the class LangIdEngineTest method testEngine.

/**
 * Test the engine and validates the created enhancements
 * @throws EngineException
 * @throws IOException
 * @throws ConfigurationException
 */
@Test
public void testEngine() throws EngineException, IOException, ConfigurationException {
    LangIdEnhancementEngine langIdEngine = new LangIdEnhancementEngine();
    ComponentContext context = new MockComponentContext();
    context.getProperties().put(EnhancementEngine.PROPERTY_NAME, "langid");
    langIdEngine.activate(context);
    ContentItem ci = ciFactory.createContentItem(new StringSource(text));
    langIdEngine.computeEnhancements(ci);
    HashMap<IRI, RDFTerm> expectedValues = new HashMap<IRI, RDFTerm>();
    expectedValues.put(Properties.ENHANCER_EXTRACTED_FROM, ci.getUri());
    expectedValues.put(Properties.DC_CREATOR, LiteralFactory.getInstance().createTypedLiteral(langIdEngine.getClass().getName()));
    int textAnnotationCount = validateAllTextAnnotations(ci.getMetadata(), text, expectedValues);
    assertEquals("A single TextAnnotation is expected", 1, textAnnotationCount);
    // even through this tests do not validate service quality but rather
    // the correct integration of the CELI service as EnhancementEngine
    // we expect the "en" is detected for the parsed text
    assertEquals("The detected language for text '" + text + "' MUST BE 'en'", "en", EnhancementEngineHelper.getLanguage(ci));
    int entityAnnoNum = validateAllEntityAnnotations(ci.getMetadata(), expectedValues);
    assertEquals("No EntityAnnotations are expected", 0, entityAnnoNum);
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) LangIdEnhancementEngine(org.apache.stanbol.enhancer.engines.langid.LangIdEnhancementEngine) ComponentContext(org.osgi.service.component.ComponentContext) HashMap(java.util.HashMap) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) StringSource(org.apache.stanbol.enhancer.servicesapi.impl.StringSource) ContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 IRI (org.apache.clerezza.commons.rdf.IRI)1 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)1 LangIdEnhancementEngine (org.apache.stanbol.enhancer.engines.langid.LangIdEnhancementEngine)1 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)1 StringSource (org.apache.stanbol.enhancer.servicesapi.impl.StringSource)1 Test (org.junit.Test)1 ComponentContext (org.osgi.service.component.ComponentContext)1