Package org.apache.stanbol.enhancer.servicesapi

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


     * Tests if triples contained in parsed Metadata are also present within
     * the {@link ContentItem#getMetadata()} graph
     */
    @Test
    public void testParsedMetadata() throws IOException {
        ContentItem ci = contentItemFactory.createContentItem(TEST_CR, METADATA);
        assertNotNull(ci);
        assertEquals("The created ContentItem MUST contain parsed metadata",
            METADATA.size(), ci.getMetadata().size());
       
        ci = contentItemFactory.createContentItem(ID,TEST_CS, METADATA);
        assertNotNull(ci);
        assertEquals("The created ContentItem MUST contain parsed metadata",
            METADATA.size(), ci.getMetadata().size());

        ci = contentItemFactory.createContentItem(PREFIX,TEST_CS, METADATA);
        assertNotNull(ci);
        assertEquals("The created ContentItem MUST contain parsed metadata",
            METADATA.size(), ci.getMetadata().size());
    }
View Full Code Here


                                    @FormParam("format") String format,
                                    @FormParam("ajax") boolean buildAjaxview,
                                    @Context HttpHeaders headers) throws EnhancementException,
                                                                         IOException {
        log.info("enhance from From: " + content);
        ContentItem ci = ciFactory.createContentItem(new StringSource(content));
        if(!buildAjaxview){ //rewrite to a normal EnhancementRequest
            return enhanceFromData(ci, false, null, false, null, false, null, headers);
        } else { //enhance and build the AJAX response
            EnhancementException enhancementException;
            try {
View Full Code Here

        engine = null;
    }
   
    @Test
    public void testEngineDe() throws IOException, EngineException {
        ContentItem ci = ciFactory.createContentItem(new StringSource(de_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("de")));
        Assert.assertEquals("de", EnhancementEngineHelper.getLanguage(ci));
       
        //Add some Tokens with POS annotations to test the usage of
        //existing POS annotations by the lemmatizer
        Token verbrachten = at.addToken(de_verbStart,de_verbStart+de_verb.length());
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

    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

      return ciFactory.createContentItem(new UriRef(id), new StringSource(text));
    }

    @Test
    public void tesetBioText()  throws EngineException, IOException {
        ContentItem ci = wrapAsContentItem(BIO_DOMAIN_TEXT);
        try {
            zemantaEngine.computeEnhancements(ci);
        } catch (EngineException e) {
            RemoteServiceHelper.checkServiceUnavailable(e);
            return;
        }
        JenaSerializerProvider serializer = new JenaSerializerProvider();
        serializer.serialize(System.out, ci.getMetadata(), TURTLE);
        Map<UriRef,Resource> expectedValues = new HashMap<UriRef,Resource>();
        expectedValues.put(Properties.ENHANCER_EXTRACTED_FROM, ci.getUri());
        expectedValues.put(Properties.DC_CREATOR, LiteralFactory.getInstance().createTypedLiteral(
            zemantaEngine.getClass().getName()));
        //deactivate require fise:confidence values for fise:TextAnnotations, because
        //the one used to group the TopicAnnotations does not have a confidence value
        int textAnnoNum = validateAllTextAnnotations(ci.getMetadata(), BIO_DOMAIN_TEXT, expectedValues);
        log.info(textAnnoNum + " TextAnnotations found ...");
        //adding null as expected for confidence makes it a required property
        expectedValues.put(Properties.ENHANCER_CONFIDENCE, null);
        int entityAnnoNum = EnhancementStructureHelper.validateAllEntityAnnotations(ci.getMetadata(),expectedValues);
        log.info(entityAnnoNum + " EntityAnnotations found ...");
        int topicAnnoNum = EnhancementStructureHelper.validateAllTopicAnnotations(ci.getMetadata(),expectedValues);
        log.info(topicAnnoNum + " TopicAnnotations found ...");
    }
View Full Code Here

    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<UriRef,Resource> expectedValues = new HashMap<UriRef,Resource>();
        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);

    }
View Full Code Here

        in.close();
        LanguageDetectionEnhancementEngine langIdEngine = new LanguageDetectionEnhancementEngine();
        ComponentContext context =  new MockComponentContext();
        context.getProperties().put(EnhancementEngine.PROPERTY_NAME, "langdetect");
        langIdEngine.activate(context);
        ContentItem ci = ciFactory.createContentItem(new StringSource(text));
        langIdEngine.computeEnhancements(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(
            langIdEngine.getClass().getName()));
        int textAnnotationCount = validateAllTextAnnotations(ci.getMetadata(), text, expectedValues);
        assertTrue("A TextAnnotation is expected", textAnnotationCount > 0);
        //even through this tests do not validate detection quality
        //we expect the "en" is detected as best guess 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);

    }
View Full Code Here

            new NEREngineConfig()){};
    }

    public static ContentItem wrapAsContentItem(final String id,
            final String text, String language) throws IOException {
      ContentItem ci =  ciFactory.createContentItem(new UriRef(id),new StringSource(text));
      if(language != null){
          ci.getMetadata().add(new TripleImpl(ci.getUri(), DC_LANGUAGE, new PlainLiteralImpl(language)));
      }
      return ci;
    }
View Full Code Here

    }

    @Test
    public void testComputeEnhancements()
            throws EngineException, IOException {
        ContentItem ci = wrapAsContentItem("urn:test:content-item:single:sentence", SINGLE_SENTENCE,"en");
        nerEngine.computeEnhancements(ci);
        Map<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()));
        //adding null as expected for confidence makes it a required property
        expectedValues.put(Properties.ENHANCER_CONFIDENCE, null);
        MGraph g = ci.getMetadata();
        int textAnnotationCount = validateAllTextAnnotations(g,SINGLE_SENTENCE,expectedValues);
        assertEquals(3, textAnnotationCount);
    }
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.