Package org.apache.stanbol.enhancer.servicesapi

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


     * 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


     * 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

   
    /** @inheritDoc */
    public Graph getGraph(EnhancementJobManager jobManager,
                          ContentItemFactory ciFactory) throws EnhancementException {
        if(graph == null) {
            ContentItem ci;
            try {
                ci = ciFactory.createContentItem(new StringSource(inputText));
            } catch (IOException e) {
                throw new IllegalStateException("Unable to create a ContentItem" +
                    "using '"+ciFactory.getClass().getSimpleName()+"'!",e);
            }
            if(chain == null){
                jobManager.enhanceContent(ci);
            } else { //parsing null as chain does not work!
                jobManager.enhanceContent(ci,chain);
            }
            graph = ci.getMetadata().getGraph();
        }
        return graph;
    }
View Full Code Here

    }

    @Override
    public List<String> tokenizeEntities(String queryTerm) {
        // obtain entities about query term through Enhancer
        ContentItem ci = null;
        boolean error = false;
        try {
            ci = ciFactory.createContentItem(new StringSource(queryTerm));
            enhancementJobManager.enhanceContent(ci);
        } catch (UnsupportedEncodingException e) {
            log.error("Failed to get bytes of query term: {}", queryTerm, e);
            error = true;
        } catch (EnhancementException e) {
            log.error("Failed to get enmancements for the query term: {}", queryTerm, e);
            error = true;
        } catch (IOException e) {
            log.error(
                "Failed to create a ContentItem by using " + ciFactory.getClass().getSimpleName() + "!", e);
            error = true;
        }

        List<String> tokenizedTerms = new ArrayList<String>();
        if (error || ci == null || ci.getMetadata() == null) {
            tokenizedTerms.add(queryTerm);
        } else {
            // traverse selected text assertions
            MGraph queryTermMetadata = ci.getMetadata();
            Iterator<Triple> textAnnotations = queryTermMetadata.filter(null,
                Properties.ENHANCER_SELECTED_TEXT, null);
            while (textAnnotations.hasNext()) {
                Resource r = textAnnotations.next().getObject();
                String selectedText = "";
View Full Code Here

    @Test
    public void testContentWithAdditionalMetadata() throws IOException, LDPathParseException {
        byte[] content = "text content".getBytes();
        UriRef uri = ContentItemHelper.makeDefaultUrn(content);

        ContentItem contentItem = ciFactory.createContentItem(uri, new ByteArraySource(content,
                "text/plain; charset=UTF-8"));

        TripleCollection tc = new SimpleMGraph();
        TypedLiteral literal = LiteralFactory.getInstance().createTypedLiteral("Michael Jackson");
        UriRef subject = new UriRef("dummyUri");
        tc.add(new TripleImpl(subject, new UriRef("http://xmlns.com/foaf/0.1/givenName"), literal));
        contentItem.addPart(new UriRef(uri.getUnicodeString() + "_additionalMetadata"), tc);

        ContentItemBackend ciBackend = new ContentItemBackend(contentItem, true);
        LDPath<Resource> ldPath = new LDPath<Resource>(ciBackend, EnhancerLDPath.getConfig());
        Collection<Resource> result = ldPath.pathQuery(subject, "foaf:givenName", null);
View Full Code Here

        } else {
            uri = new UriRef(id);
        }
        log.debug("Created ContentItem with id:{} and uri:{}", id, uri);
        final MGraph g = new IndexedMGraph();
        ContentItem ci = null;
        try {
            ci = ciFactory.createContentItem(uri, new ByteArraySource(content, contentType), g);
        } catch (IOException e) {
            log.error("Failed to create contentitem with uri: {}", uri.getUnicodeString());
            throw new StoreException(String.format("Failed to create contentitem with uri: %s",
                uri.getUnicodeString()));
        }
        if (title != null && !title.trim().isEmpty()) {
            ci.addPart(TITLE_URI, title.trim());
        }
        return ci;
    }
View Full Code Here

            while (tripleItr.hasNext()) {
                Triple triple = tripleItr.next();
                metadata.add(triple);
            }
        }
        ContentItem ci = null;
        try {
            ci = ciFactory
                    .createContentItem(new UriRef(id), new ByteArraySource(content, mimeType), metadata);
        } catch (IOException e) {
            log.error("Failed to create contentitem with uri: {}", id);
View Full Code Here

        super("content");
    }
   
    @Override
    public Collection<Resource> apply(ContentItemBackend backend, Collection<Resource>... args) throws IllegalArgumentException {
        ContentItem ci = ((ContentItemBackend)backend).getContentItem();
//        Collection<Resource> contexts = args[0];
        Set<String> mimeTypes;
        if(args == null || args.length < 1){
            mimeTypes = null;
        } else {
//TODO: Wait for ld-path to parse the context
//      http://code.google.com/p/ldpath/issues/detail?id=7
//                //1. check if the first parameter is the context
//                if(!args[0].isEmpty() && backend.isURI(args[0].iterator().next())){
//                    contexts = args[0];
//                    if(args.length > 1){ // cut the context from the args
//                        Collection<Resource>[] tmp = new Collection[args.length-1];
//                        System.arraycopy(args, 0, tmp, 0, tmp.length);
//                        args = tmp;
//                    } else {
//                        args = new Collection[]{};
//                    }
//                } else { //use the ContentItem as context
//                    contexts = java.util.Collections.singleton((Resource)ci.getUri());
//                }
            mimeTypes = new HashSet<String>();
            for(Iterator<Resource> params = concat(args).iterator();params.hasNext();){
                Resource param = params.next();
                String mediaTypeString = backend.stringValue(param);
                try {
                    mimeTypes.add(parseMimeType(mediaTypeString).get(null));
                } catch (IllegalArgumentException e) {
                    log.warn(String.format("Invalid mediaType '%s' (based on RFC 2046) parsed!",
                        mediaTypeString),e);
                }
            }
        }
        Collection<Resource> result;
        Blob blob;
        if(mimeTypes == null || mimeTypes.isEmpty()){
            blob = ci.getBlob();
        } else {
            Entry<UriRef,Blob> entry = ContentItemHelper.getBlob(ci, mimeTypes);
            blob = entry != null ? entry.getValue() : null;
        }
        if(blob == null){
           result = java.util.Collections.emptySet();
        } else {
            String charset = blob.getParameter().get("charset");
            try {
                if(charset != null){
                    result = java.util.Collections.singleton(
                        backend.createLiteral(IOUtils.toString(blob.getStream(), charset)));
                } else { //binary content
                    byte[] data = IOUtils.toByteArray(blob.getStream());
                    result = java.util.Collections.singleton(
                        (Resource)lf.createTypedLiteral(data));
                }
            } catch (IOException e) {
                throw new IllegalStateException("Unable to read contents from Blob '"
                    + blob.getMimeType()+"' of ContentItem "+ci.getUri(),e);
            }
        }
        return result;
    }
View Full Code Here

     * content and
     * @return
     * @throws IOException
     */
    private ContentItem initContentItem() throws IOException {
        ContentItem ci = ciFactory.createContentItem(
            new UriRef("urn:iks-project:enhancer:text:content-item:person"),
            new StringSource(CONTEXT));
        //add three text annotations to be consumed by this test
        getTextAnnotation(ci, PERSON, CONTEXT, DBPEDIA_PERSON);
        getTextAnnotation(ci, ORGANISATION, CONTEXT, DBPEDIA_ORGANISATION);
        getTextAnnotation(ci, PLACE, CONTEXT, DBPEDIA_PLACE);
        //add the language
        ci.getMetadata().add(new TripleImpl(ci.getUri(), Properties.DC_LANGUAGE, new PlainLiteralImpl("en")));
        return ci;
    }
View Full Code Here

    }

    @Test
    public void testEntityLinkingEnhancementEngine() throws Exception{
        //create a content item
        ContentItem ci = initContentItem();
        NamedEntityTaggingEngine entityLinkingEngine = initEngine(true, true, true);
        //perform the computation of the enhancements
        entityLinkingEngine.computeEnhancements(ci);
        int entityAnnotationCount = validateAllEntityAnnotations(entityLinkingEngine, ci);
        assertEquals(3, entityAnnotationCount);
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.