Package org.apache.stanbol.enhancer.servicesapi

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


        final FormFile file = body.getFormFileParameterValues("file")[0];
        final ContentSource contentSource = new ByteArraySource(
                file.getContent(),
                file.getMediaType().toString(),
                file.getFileName());
        final ContentItem contentItem = contentItemFactory.createContentItem(contentSource);
        if ((chainName == null) || chainName.trim().equals("")) {
            enhancementJobManager.enhanceContent(contentItem);
        } else {
            final Chain chain = chainManager.getChain(chainName);
            if (chain == null) {
                throw new RuntimeException("No chain by that name: "+chainName);
            }
            enhancementJobManager.enhanceContent(contentItem, chain);
        }
        //this contains the enhancement results
        final MGraph resultGraph = contentItem.getMetadata();
        //this is the IRI assigned to the subitted content
        final UriRef contentIri = contentItem.getUri();
        //this represent the submitted Content within the resultGraph
        final GraphNode node = new GraphNode(contentIri, resultGraph);
        //node is the "root" for rendering the results
        return new RdfViewable("Enhancements", node, MultiEnhancer.class);
    }
View Full Code Here


        linkerConfig.setRedirectProcessingMode(RedirectProcessingMode.FOLLOW);
        linkerConfig.setMinFoundTokens(2);//this is assumed by this test
        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<UriRef,Resource> expectedValues = new HashMap<UriRef,Resource>();
        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);
    }
View Full Code Here

        log.info(" ... created {} Entity references ", numLinks);

    }

    public static ContentItem getContentItem(final String id) throws IOException {
        ContentItem ci = ciFactory.createContentItem(new UriRef(id), new StringSource("Not used"));
        ci.getMetadata().addAll(testMetadata);
        return ci;
    }
View Full Code Here

     * Test {@link OfflineMode} functionality
     * @throws Exception
     */
    @Test
    public void testOfflineMode() throws Exception {
        ContentItem ci = getContentItem("urn:test:testOfflineMode");
        EntityDereferencer onlineDereferencer = new TestDereferencer(null){
          @Override
            public boolean supportsOfflineMode() {
                return false;
           
View Full Code Here

        Assert.assertEquals(engine.canEnhance(ci), EnhancementEngine.CANNOT_ENHANCE);
    }

    @Test
    public void testSyncDereferencing() throws Exception {
        ContentItem ci = getContentItem("urn:test:testSyncDereferencing");
        EntityDereferenceEngine engine = new EntityDereferenceEngine(syncDereferencer,
            new DereferenceEngineConfig("sync", false, false));
        Assert.assertNotEquals(engine.canEnhance(ci), EnhancementEngine.CANNOT_ENHANCE);
        engine.computeEnhancements(ci);
        validateDereferencedEntities(ci.getMetadata());
    }
View Full Code Here

        validateDereferencedEntities(ci.getMetadata());
    }

    @Test
    public void testAsyncDereferencing() throws Exception {
        ContentItem ci = getContentItem("urn:test:testSyncDereferencing");
        EntityDereferenceEngine engine = new EntityDereferenceEngine(asyncDereferencer,
            new DereferenceEngineConfig("async", false, false));
        Assert.assertNotEquals(engine.canEnhance(ci), EnhancementEngine.CANNOT_ENHANCE);
        engine.computeEnhancements(ci);
        validateDereferencedEntities(ci.getMetadata());
    }
View Full Code Here

    /**
     * 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 SimpleMGraph());
        assertNotNull(ci);
        assertNotNull(ci.getUri());
        assertTrue("The ID of the created ContentItem MUST start with the parsed prefix",
            ci.getUri().getUnicodeString().startsWith(PREFIX));
    }
View Full Code Here

    /**
     * Test that the parsed URI is used as ID of the ContentItem
     */
    @Test
    public void testURI() throws IOException {
        ContentItem ci = contentItemFactory.createContentItem(ID, TEST_CS);
        assertNotNull(ci);
        assertNotNull(ci.getUri());
        assertTrue("The ID of the created ContentItem MUST be equals to the parsed ID",
            ci.getUri().equals(ID));
       
        ci = contentItemFactory.createContentItem(ID, TEST_CS,new SimpleMGraph());
        assertNotNull(ci);
        assertNotNull(ci.getUri());
        assertTrue("The ID of the created ContentItem MUST be equals to the parsed ID",
            ci.getUri().equals(ID));
    }
View Full Code Here

     * Test the generation of valid IDs if no or <code>null</code> is parsed
     * as id
     */
    @Test
    public void testDefaultId() throws IOException {
        ContentItem ci = contentItemFactory.createContentItem(TEST_CS);
        assertNotNull(ci);
        assertNotNull(ci.getUri());
        ci = contentItemFactory.createContentItem((UriRef)null,TEST_CS);
        assertNotNull(ci);
        assertNotNull(ci.getUri());
        ci = contentItemFactory.createContentItem((UriRef)null,TEST_CS, new SimpleMGraph());
        assertNotNull(ci);
        assertNotNull(ci.getUri());
    }
View Full Code Here

     * 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 SimpleMGraph());
        assertNotNull(ci);
        assertNotNull(ci.getUri());
        assertEquals(TEST_CR.getReference(),ci.getUri().getUnicodeString());
    }
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.