Package org.apache.stanbol.enhancer.servicesapi

Examples of org.apache.stanbol.enhancer.servicesapi.ContentItem


    }

    @Test
    public void testPersonLinking() throws Exception{
        //create a content item
        ContentItem ci = initContentItem();
        NamedEntityTaggingEngine entityLinkingEngine = initEngine(true, false, false);
        //perform the computation of the enhancements
        entityLinkingEngine.computeEnhancements(ci);
        int entityAnnotationCount = validateAllEntityAnnotations(entityLinkingEngine, ci);
        assertEquals(1, entityAnnotationCount);
View Full Code Here


    }

    @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);
View Full Code Here

    }
   
    @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);
View Full Code Here

    public static ContentItem wrapAsContentItem(final String text) throws IOException {
        return ciFactory.createContentItem(new StringSource(text));
    }
   
    private void testInput(String txt,String lang) throws EngineException, IOException{
      ContentItem ci = wrapAsContentItem(txt);
    try {
        //add a simple triple to statically define the language of the test content
        ci.getMetadata().add(new TripleImpl(ci.getUri(), DC_LANGUAGE, new PlainLiteralImpl(lang)));
      nerEngine.computeEnhancements(ci);

      TestUtils.logEnhancements(ci);
     
      HashMap<UriRef,Resource> expectedValues = new HashMap<UriRef,Resource>();
      expectedValues.put(Properties.ENHANCER_EXTRACTED_FROM, ci.getUri());
      expectedValues.put(Properties.DC_CREATOR, LiteralFactory.getInstance().createTypedLiteral(
          nerEngine.getClass().getName()));
      int textAnnoNum = validateAllTextAnnotations(ci.getMetadata(), txt, expectedValues);
          log.info(textAnnoNum + " TextAnnotations found ...");
          int entityAnnoNum = EnhancementStructureHelper.validateAllEntityAnnotations(ci.getMetadata(),expectedValues);
          log.info(entityAnnoNum + " EntityAnnotations found ...");
    } catch (EngineException e) {
            RemoteServiceHelper.checkServiceUnavailable(e);
    }
    }
View Full Code Here

  public static ContentItem wrapAsContentItem(final String text) throws IOException {
    return ciFactory.createContentItem(new StringSource(text));
  }

  private void testInput(String txt, String lang) throws EngineException, IOException {
    ContentItem ci = wrapAsContentItem(txt);
    try {
      // add a simple triple to statically define the language of the test content
      ci.getMetadata().add(new TripleImpl(ci.getUri(), DC_LANGUAGE, new PlainLiteralImpl(lang)));
      sentimentAnalysisEngine.computeEnhancements(ci);

      TestUtils.logEnhancements(ci);

      HashMap<UriRef, Resource> expectedValues = new HashMap<UriRef, Resource>();
      expectedValues.put(Properties.ENHANCER_EXTRACTED_FROM, ci.getUri());
      expectedValues.put(Properties.DC_CREATOR, LiteralFactory.getInstance().createTypedLiteral(sentimentAnalysisEngine.getClass().getName()));
      expectedValues.put(DC_TYPE, CeliConstants.SENTIMENT_EXPRESSION);
      int textAnnoNum = validateAllTextAnnotations(ci.getMetadata(), txt, expectedValues);
      log.info(textAnnoNum + " TextAnnotations found ...");
      assertTrue("2 sentiment expressions should be recognized in: "+txt,textAnnoNum==2);
      int entityAnnoNum = EnhancementStructureHelper.validateAllEntityAnnotations(ci.getMetadata(), expectedValues);
      assertTrue("0 entity annotations should be recognized in: "+txt,entityAnnoNum==0);
    } catch (EngineException e) {
      RemoteServiceHelper.checkServiceUnavailable(e);
    }
  }
View Full Code Here

    return ciFactory.createContentItem(new StringSource(text));
  }

  @Test
  public void tesetEngine() throws Exception {
    ContentItem ci = wrapAsContentItem(TEXT);
    try {
          //add a simple triple to statically define the language of the test
            //content
            ci.getMetadata().add(new TripleImpl(ci.getUri(), DC_LANGUAGE, new PlainLiteralImpl("fr")));
            //unit test should not depend on each other (if possible)
            //CeliLanguageIdentifierEnhancementEngineTest.addEnanchements(ci);
         
      classificationEngine.computeEnhancements(ci);

          TestUtils.logEnhancements(ci);
           HashMap<UriRef,Resource> expectedValues = new HashMap<UriRef,Resource>();
              expectedValues.put(Properties.ENHANCER_EXTRACTED_FROM, ci.getUri());
              expectedValues.put(Properties.DC_CREATOR, LiteralFactory.getInstance().createTypedLiteral(
                  classificationEngine.getClass().getName()));

      int textAnnoNum = EnhancementStructureHelper.validateAllTextAnnotations(ci.getMetadata(), TEXT,expectedValues);
      assertEquals("Only a single fise:TextAnnotation is expeted", 1, textAnnoNum);
      int numTopicAnnotations = validateAllTopicAnnotations(ci.getMetadata()  , expectedValues);
      assertTrue("No TpocisAnnotations found", numTopicAnnotations > 0);
    } catch (EngineException e) {
            RemoteServiceHelper.checkServiceUnavailable(e);
            return;
        }
View Full Code Here

        engine = null;
    }
   
    @Test
    public void testEngine() throws IOException, EngineException {
        ContentItem ci = ciFactory.createContentItem(new StringSource(text));
        Assert.assertNotNull(ci);
        AnalysedText at = atFactory.createAnalysedText(ci, ci.getBlob());
        Assert.assertNotNull(at);
        ci.getMetadata().add(new TripleImpl(ci.getUri(), DC_LANGUAGE, new PlainLiteralImpl("it")));
        Assert.assertEquals("it", EnhancementEngineHelper.getLanguage(ci));
       
        Assert.assertEquals("Can not enhance Test ContentItem", EnhancementEngine.ENHANCE_ASYNC,engine.canEnhance(ci));
        //compute the enhancements
        try {
View Full Code Here

    return ciFactory.createContentItem(new StringSource(text));
  }

  @Test
  public void tesetEngine() throws Exception {
    ContentItem ci = wrapAsContentItem(TEXT);
    try {
      langIdentifier.computeEnhancements(ci);

          TestUtils.logEnhancements(ci);
     
      HashMap<UriRef,Resource> expectedValues = new HashMap<UriRef,Resource>();
          expectedValues.put(Properties.ENHANCER_EXTRACTED_FROM, ci.getUri());
          expectedValues.put(Properties.DC_CREATOR, LiteralFactory.getInstance().createTypedLiteral(
              langIdentifier.getClass().getName()));
          int numTextAnnotations = validateAllTextAnnotations(ci.getMetadata(), TEXT, expectedValues);
          assertEquals("A single TextAnnotation is expected by this Test", 1,numTextAnnotations);
          //even through this tests do not validate service quality but rather
          //the correct integration of the CELI service as EnhancementEngine
          //we expect the "fr" is detected for the parsed text
          assertEquals("The detected language for text '"+TEXT+"' MUST BE 'fr'","fr",EnhancementEngineHelper.getLanguage(ci));

          int entityAnnoNum = validateAllEntityAnnotations(ci.getMetadata(), expectedValues);
          assertEquals("No EntityAnnotations are expected",0, entityAnnoNum);
    } catch (EngineException e) {
            RemoteServiceHelper.checkServiceUnavailable(e);
    }
  }
View Full Code Here

    }

   
  @Test
  public void testEngine() throws Exception {
    ContentItem ci = wrapAsContentItem(TEXT);
   
        //add a simple triple to statically define the language of the test
        //content
        ci.getMetadata().add(new TripleImpl(ci.getUri(), DC_LANGUAGE, new PlainLiteralImpl("it")));
        //unit test should not depend on each other (if possible)
        //CeliLanguageIdentifierEnhancementEngineTest.addEnanchements(ci);
        CeliLemmatizerEnhancementEngine morphoAnalysisEngine = initEngine(false);
        try {
      morphoAnalysisEngine.computeEnhancements(ci);
        } catch (EngineException e) {
            RemoteServiceHelper.checkServiceUnavailable(e);
            return;
        }

    TestUtils.logEnhancements(ci);
    //validate enhancement
        HashMap<UriRef,Resource> expectedValues = new HashMap<UriRef,Resource>();
        expectedValues.put(Properties.ENHANCER_EXTRACTED_FROM, ci.getUri());
        expectedValues.put(Properties.DC_CREATOR, LiteralFactory.getInstance().createTypedLiteral(
            morphoAnalysisEngine.getClass().getName()));
        Iterator<Triple> lemmaTextAnnotationIterator = ci.getMetadata().filter(null, RDF_TYPE, ENHANCER_TEXTANNOTATION);
        assertTrue("A TextAnnotation is expected by this Test", lemmaTextAnnotationIterator.hasNext());
        NonLiteral lemmaTextAnnotation = lemmaTextAnnotationIterator.next().getSubject();
        assertTrue("TextAnnoations MUST BE UriRefs!",lemmaTextAnnotation instanceof UriRef);
        assertFalse("Only a single TextAnnotation is expected by this Test", lemmaTextAnnotationIterator.hasNext());
        //validate the enhancement metadata
        validateEnhancement(ci.getMetadata(), (UriRef)lemmaTextAnnotation, expectedValues);
        //validate the lemma form TextAnnotation
        int lemmaForms = validateLemmaFormProperty(ci.getMetadata(), lemmaTextAnnotation,"it");
        assertTrue("Only a single LemmaForm property is expected if '"+ MORPHOLOGICAL_ANALYSIS+"=false'",lemmaForms == 1);
        shutdownEngine(morphoAnalysisEngine);
  }
View Full Code Here


 
    @Test
    public void testCompleteMorphoAnalysis() throws Exception {
        ContentItem ci = wrapAsContentItem(TERM);
        //add a simple triple to statically define the language of the test
        //content
        ci.getMetadata().add(new TripleImpl(ci.getUri(), DC_LANGUAGE, new PlainLiteralImpl("it")));

        CeliLemmatizerEnhancementEngine morphoAnalysisEngine = initEngine(true);
        try {
            morphoAnalysisEngine.computeEnhancements(ci);
        } catch (EngineException e) {
            RemoteServiceHelper.checkServiceUnavailable(e);
            return;
        }

        TestUtils.logEnhancements(ci);
        //validate enhancements
        HashMap<UriRef,Resource> expectedValues = new HashMap<UriRef,Resource>();
        expectedValues.put(Properties.ENHANCER_EXTRACTED_FROM, ci.getUri());
        expectedValues.put(Properties.DC_CREATOR, LiteralFactory.getInstance().createTypedLiteral(
            morphoAnalysisEngine.getClass().getName()));

        Iterator<Triple> textAnnotationIterator = ci.getMetadata().filter(null,
        RDF_TYPE, ENHANCER_TEXTANNOTATION);
        // test if a textAnnotation is present
        //assertTrue(textAnnotationIterator.hasNext());
        //  -> this might be used to test that there are no TextAnnotations
        int textAnnotationCount = 0;
        while (textAnnotationIterator.hasNext()) {
            UriRef textAnnotation = (UriRef) textAnnotationIterator.next().getSubject();
            // test if selected Text is added
            validateTextAnnotation(ci.getMetadata(), textAnnotation,TERM,expectedValues);
            textAnnotationCount++;
            //perform additional tests for "hasMorphologicalFeature" and "hasLemmaForm"
            validateMorphoFeatureProperty(ci.getMetadata(),textAnnotation);
        }
        log.info("{} TextAnnotations found and validated ...",textAnnotationCount);
        int entityAnnoNum = validateAllEntityAnnotations(ci.getMetadata(), expectedValues);
        //no EntityAnnotations expected
        Assert.assertEquals("No EntityAnnotations expected by this test", 0, entityAnnoNum);        shutdownEngine(morphoAnalysisEngine);
    }
View Full Code Here

TOP

Related Classes of org.apache.stanbol.enhancer.servicesapi.ContentItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.