Package org.apache.stanbol.enhancer.servicesapi

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


    }

    @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


            metadataGraph = tcManager.createMGraph(uriRef);
        } catch (EntityAlreadyExistsException ex) {
            return null;
        }
        handler.put(new UriRef(id), MediaType.valueOf(contentType), content);
        ContentItem contentItem = new ClerezzaContentItem(new GraphNode(uriRef,
                cgProvider.getContentGraph()), new IndexedMGraph(metadataGraph), handler);
        return contentItem;
    }
View Full Code Here

        try {
            metadataGraph = tcManager.getMGraph(uriRef);
        } catch (NoSuchEntityException ex) {
            throw new IllegalArgumentException("Is not a content item");
        }
        ContentItem contentItem = new ClerezzaContentItem(new GraphNode(uriRef,
                cgProvider.getContentGraph()), metadataGraph, handler);
        //TODO add other contentParts
        return contentItem;
    }
View Full Code Here

     */
    protected abstract Blob createBlob(ContentSource source) throws IOException;
   
  @Test
  public void addingAndRetrieving()  throws IOException{
    ContentItem ci = createContentItem(contentSource);
    assertNotNull(ci);
    assertNotNull(ci.getUri());
    UriRef partUri = new UriRef("http://foo/");
    Date someObject = new Date();
    ci.addPart(partUri, someObject);
    ci.getMetadata().add(new TripleImpl(ci.getUri(), new UriRef("http://example.org/ontology#hasPart"), partUri));
        ci.getMetadata().add(new TripleImpl(partUri, new UriRef("http://example.org/ontology#isPartOf"),ci.getUri()));
    assertEquals(someObject, ci.getPart(partUri, Date.class));
    assertEquals(someObject, ci.getPart(1, Date.class));
    assertEquals(partUri, ci.getPartUri(1));
    assertEquals(new UriRef(ci.getUri().getUnicodeString()+"_main"), ci.getPartUri(0));
    try {
        ci.getPart(2, Object.class);
        assertTrue("Requesting non existance part MUST throw an NoSuchPartException", false);
    } catch (NoSuchPartException e) {/* expected*/}
        try {
            ci.getPart(new UriRef("http://foo/nonexisting"), Object.class);
            assertTrue("Requesting non existance part MUST throw an NoSuchPartException", false);
        } catch (NoSuchPartException e) {/* expected*/}
        try {
            ci.getPartUri(2);
            assertTrue("Requesting non existance part MUST throw an NoSuchPartException", false);
        } catch (NoSuchPartException e) {/* expected*/}
    //finally log the toString
    log.info("toString: {}",ci);
  }
View Full Code Here

        uri = RestUtil.nullify(uri);
        if (uri == null) {
            return RestUtil.createResponse(servletContext, Status.BAD_REQUEST, "Missing 'uri' parameter",
                headers);
        }
        ContentItem ci = solrStore.get(uri, indexName);
        if (ci == null) {
            return RestUtil.createResponse(servletContext, Status.NOT_FOUND, null, headers);
        }

        // handle smart redirection to browser view
View Full Code Here

        }
        if (uri == null) {
            return RestUtil.createResponse(servletContext, Status.BAD_REQUEST, "Missing 'uri' parameter",
                headers);
        }
        ContentItem ci = solrStore.get(uri, indexName);
        if (ci == null) {
            return RestUtil.createResponse(servletContext, Status.NOT_FOUND, null, headers);
        }
        if (type.equals("metadata")) {
            String fileName = URLEncoder.encode(uri, "utf-8") + "-metadata";
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            serializer.serialize(baos, ci.getMetadata(), format);
            InputStream is = new ByteArrayInputStream(baos.toByteArray());

            ResponseBuilder response = Response.ok((Object) is);
            response.header("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
            response.type("text/plain");
            addCORSOrigin(servletContext, response, headers);
            return response.build();
        } else if (type.equals("raw")) {
            String fileName = URLEncoder.encode(uri, "utf-8") + "-raw";
            ResponseBuilder response = Response.ok((Object) ci.getStream());
            response.header("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
            response.type(ci.getMimeType());
            addCORSOrigin(servletContext, response, headers);
            return response.build();
        } else {
            throw new WebApplicationException(404);
        }
View Full Code Here

        uri = RestUtil.nullify(uri);
        if (uri == null) {
            return RestUtil.createResponse(servletContext, Status.BAD_REQUEST, "Missing 'uri' parameter",
                headers);
        }
        ContentItem ci = solrStore.get(uri, indexName);
        if (ci == null) {
            return RestUtil.createResponse(servletContext, Status.NOT_FOUND, null, headers);
        }

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        serializer.serialize(out, ci.getMetadata(), format);
        ResponseBuilder rb = Response.ok(out.toString(), "text/plain");
        addCORSOrigin(servletContext, rb, headers);
        return rb.build();
    }
View Full Code Here

        uri = RestUtil.nullify(uri);
        if (uri == null) {
            return RestUtil.createResponse(servletContext, Status.BAD_REQUEST, "Missing 'uri' parameter",
                headers);
        }
        ContentItem ci = solrStore.get(uri, indexName);
        if (ci == null) {
            return RestUtil.createResponse(servletContext, Status.NOT_FOUND, null, headers);
        }
        ResponseBuilder rb = Response.ok(ci.getStream(), ci.getMimeType());
        addCORSOrigin(servletContext, rb, headers);
        return rb.build();
    }
View Full Code Here

                                              String chain,
                                              HttpHeaders headers) throws EngineException,
                                                                  URISyntaxException,
                                                                  StoreException {

        ContentItem ci = solrStore.create(content, uri, title, mediaType.toString());
        solrStore.enhanceAndPut(ci, indexName, chain);
        if (useExplicitRedirect) {
            // use an redirect to point browsers to newly created content
            ResponseBuilder rb = Response.seeOther(makeRedirectionURI(ci.getUri().getUnicodeString()));
            addCORSOrigin(servletContext, rb, headers);
            return rb.build();
        } else {
            ResponseBuilder rb = Response.created(makeRedirectionURI(ci.getUri().getUnicodeString()));
            addCORSOrigin(servletContext, rb, headers);
            return rb.build();
        }
    }
View Full Code Here

        uri = RestUtil.nullify(uri);
        if (uri == null) {
            return RestUtil.createResponse(servletContext, Status.BAD_REQUEST, "Missing 'uri' parameter",
                headers);
        }
        ContentItem ci = solrStore.get(uri, indexName);
        if (ci == null) {
            return RestUtil.createResponse(servletContext, Status.NOT_FOUND, null, headers);
        }
        solrStore.deleteById(uri, indexName);
        return RestUtil.createResponse(servletContext, Status.OK, null, headers);
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.