Package org.apache.stanbol.commons.indexedgraph

Examples of org.apache.stanbol.commons.indexedgraph.IndexedMGraph


            TripleCollection rdfData = parser.parse(in, SparqlSearcher.DEFAULT_RDF_CONTENT_TYPE, new UriRef(
                    getBaseUri()));
            if (rdfData instanceof MGraph) {
                graph = (MGraph) rdfData;
            } else {
                graph = new IndexedMGraph(rdfData);
            }
            long parseEnd = System.currentTimeMillis();
            log.info("  > ParseTime: " + (parseEnd - queryEnd));
            return new RdfQueryResultList(query, graph);
        } else {
View Full Code Here


            TripleCollection rdfData = parser.parse(in, DEFAULT_RDF_CONTENT_TYPE,
                new UriRef(getBaseUri()));
            if(rdfData instanceof MGraph){
                graph = (MGraph) rdfData;
            } else {
                graph = new IndexedMGraph(rdfData);
            }
            long parseEnd = System.currentTimeMillis();
            log.debug("  > ParseTime: "+(parseEnd-queryEnd));
            return new RdfQueryResultList(query, graph);
        } else {
View Full Code Here

        contentItem.getLock().writeLock().lock();
        try {
            try {
                executionMetadata = contentItem.getPart(CHAIN_EXECUTION, MGraph.class);
            } catch (NoSuchPartException e) {
                executionMetadata = new IndexedMGraph();
                contentItem.addPart(CHAIN_EXECUTION, executionMetadata);
            }
        } finally {
            contentItem.getLock().writeLock().unlock();
        }
View Full Code Here

        String format = SupportedFormat.RDF_XML;
        InputStream in = dereference(uri, format);
        long queryEnd = System.currentTimeMillis();
        log.debug("  > DereferenceTime: {}",(queryEnd-start));
        if(in != null){
            MGraph rdfData = new IndexedMGraph(parser.parse(in, format,new UriRef(getBaseUri())));
            long parseEnd = System.currentTimeMillis();
            log.debug("  > ParseTime: {}",(parseEnd-queryEnd));
            return valueFactory.createRdfRepresentation(new UriRef(uri), rdfData);
        } else {
            return null;
View Full Code Here

        final String resourcePath = uriInfo.getAbsolutePath().toString();
        //The URI at which this service was accessed accessed, this will be the
        //central serviceUri in the response
        final UriRef serviceUri = new UriRef(resourcePath);
        //the in memory graph to which the triples for the response are added
        final MGraph responseGraph = new IndexedMGraph();
        //A union graph containing both the response specif triples as well
        //as the log-graph
        final UnionMGraph resultGraph = new UnionMGraph(responseGraph, getRequestLogGraph());
        //This GraphNode represents the service within our result graph
        final GraphNode node = new GraphNode(serviceUri, resultGraph);
View Full Code Here

                        //the metadata may define the ID for the contentItem
                        //only used if not parsed as query param
                        if(contentItemId == null && fis.getName() != null && !fis.getName().isEmpty()){
                            contentItemId = new UriRef(fis.getName());
                        }
                        metadata = new IndexedMGraph();
                        try {
                            getParser().parse(metadata, fis.openStream(), fis.getContentType());
                        } catch (Exception e) {
                            throw new WebApplicationException(e,
                                Response.status(Response.Status.BAD_REQUEST)
                                .entity(String.format("Unable to parse Metadata " +
                                    "from Multipart MIME part '%s' (" +
                                    "contentItem: %s| contentType: %s)",
                                    fis.getFieldName(),fis.getName(),fis.getContentType()))
                                .build());
                        }
                    } else if(fis.getFieldName().equals("content")){
                        contentItem = createContentItem(contentItemId, metadata, fis, parsedContentIds);
                    } else if(fis.getFieldName().equals("properties") ||
                            fis.getFieldName().equals(ENHANCEMENT_PROPERTIES_URI.getUnicodeString())){
                        //parse the enhancementProperties
                        if(contentItem == null){
                            throw new WebApplicationException(
                                Response.status(Response.Status.BAD_REQUEST)
                                .entity("Multipart MIME parts for " +
                                    "EnhancementProperties MUST BE after the " +
                                    "MIME parts for 'metadata' AND 'content'")
                                .build());
                        }
                        MediaType propMediaType = MediaType.valueOf(fis.getContentType());
                        if(!APPLICATION_JSON_TYPE.isCompatible(propMediaType)){
                            throw new WebApplicationException(
                                Response.status(Response.Status.BAD_REQUEST)
                                .entity("EnhancementProperties (Multipart MIME parts" +
                                    "with the name '"+fis.getFieldName()+"') MUST " +
                                    "BE encoded as 'appicaltion/json' (encountered: '" +
                                    fis.getContentType()+"')!")
                                .build());
                        }
                        String propCharset = propMediaType.getParameters().get("charset");
                        if(propCharset == null){
                            propCharset = "UTF-8";
                        }
                        Map<String,Object> enhancementProperties = getEnhancementProperties(contentItem);
                        try {
                            enhancementProperties.putAll(toMap(new JSONObject(
                                IOUtils.toString(fis.openStream(),propCharset))));
                        } catch (JSONException e) {
                            throw new WebApplicationException(e,
                                Response.status(Response.Status.BAD_REQUEST)
                                .entity("Unable to parse EnhancementProperties from" +
                                    "Multipart MIME parts with the name 'properties'!")
                                .build());
                        }
                       
                    } else { //additional metadata as serialised RDF
                        if(contentItem == null){
                            throw new WebApplicationException(
                                Response.status(Response.Status.BAD_REQUEST)
                                .entity("Multipart MIME parts for additional " +
                                    "contentParts MUST BE after the MIME " +
                                    "parts for 'metadata' AND 'content'")
                                .build());
                        }
                        if(fis.getFieldName() == null || fis.getFieldName().isEmpty()){
                            throw new WebApplicationException(
                                Response.status(Response.Status.BAD_REQUEST)
                                .entity("Multipart MIME parts representing " +
                                    "ContentParts for additional RDF metadata" +
                                    "MUST define the contentParts URI as" +
                                    "'name' of the MIME part!").build());
                        }
                        MGraph graph = new IndexedMGraph();
                        try {
                            getParser().parse(graph, fis.openStream(), fis.getContentType());
                        } catch (Exception e) {
                            throw new WebApplicationException(e,
                                Response.status(Response.Status.BAD_REQUEST)
View Full Code Here

        return recipesGraph;
    }
   
    @Activate
    protected void activate(BundleContext context) {
        recipesGraph = new IndexedMGraph();
        context.addBundleListener(this);
        for (Bundle b : context.getBundles()) {
            if (b.getState() == Bundle.ACTIVE) {
                loadRecipesData(b);
            }
View Full Code Here

    private LDPath<Resource> ldpath;
    @BeforeClass
    public static void readTestData() throws IOException {
        ParsingProvider parser = new JenaParserProvider();
        //NOTE(rw): the new third parameter is the base URI used to resolve relative paths
        graph = new IndexedMGraph();
        InputStream in = ClerezzaBackendTest.class.getClassLoader().getResourceAsStream("testdata.rdf.zip");
        assertNotNull(in);
        ZipInputStream zipIn = new ZipInputStream(new BufferedInputStream(in));
        InputStream uncloseable = new UncloseableStream(zipIn);
        ZipEntry entry;
View Full Code Here

     * @param headers the http headers of the request
     * @return the response
     */
    private Response executeLDPathQuery(FieldQuery query, String ldpathProgramString, MediaType mediaType, HttpHeaders headers) {
        QueryResultList<Representation> result;
        ValueFactory vf = new RdfValueFactory(new IndexedMGraph());
        SiteBackend backend = new SiteBackend(site,vf);
        EntityhubLDPath ldPath = new EntityhubLDPath(backend,vf);
        //copy the selected fields, because we might need to delete some during
        //the preparation phase
        Set<String> selectedFields = new HashSet<String>(query.getSelectedFields());
View Full Code Here

       } else if(isSupported(content.getMediaType())){ //from RDF serialisation
            RdfValueFactory valueFactory = RdfValueFactory.getInstance();
            Map<String,Representation> representations = new HashMap<String,Representation>();
            Set<NonLiteral> processed = new HashSet<NonLiteral>();
            Parser parser = ContextHelper.getServiceFromContext(Parser.class, servletContext);
            MGraph graph = new IndexedMGraph();
            try {
                parser.parse(graph,content.getEntityStream(), content.getMediaType().toString());
            } catch (UnsupportedParsingFormatException e) {
                //String acceptedMediaType = httpHeaders.getFirst("Accept");
                //throw an internal server Error, because we check in
                //isReadable(..) for supported types and still we get here a
                //unsupported format -> therefore it looks like an configuration
                //error the server (e.g. a missing Bundle with the required bundle)
                String message = "Unable to create the Parser for the supported format"
                    +content.getMediaType()+" ("+e+")";
                log.error(message,e);
                throw new WebApplicationException(
                    Response.status(Status.INTERNAL_SERVER_ERROR).
                    entity(message).
                    header(HttpHeaders.ACCEPT, acceptedMediaType).build());
            } catch (Exception e){
                String message = "Unable to create the Parser for the supported format "
                    +content.getMediaType()+" ("+e+")";
                log.error(message,e);
                throw new WebApplicationException(
                    Response.status(Status.INTERNAL_SERVER_ERROR).
                    entity(message).
                    header(HttpHeaders.ACCEPT, acceptedMediaType).build());
               
            }
            for(Iterator<Triple> st = graph.iterator();st.hasNext();){
                NonLiteral resource = st.next().getSubject();
                if(resource instanceof UriRef && processed.add(resource)){
                    //build a new representation
                    representations.put(((UriRef)resource).getUnicodeString(),
                        valueFactory.createRdfRepresentation((UriRef)resource, graph));
View Full Code Here

TOP

Related Classes of org.apache.stanbol.commons.indexedgraph.IndexedMGraph

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.