Package org.apache.stanbol.commons.indexedgraph

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


            uri = ContentItemHelper.makeDefaultUrn(content);
        } 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());
View Full Code Here


            log.error(msg, e);
            throw new StoreException(msg, e);
        }

        ResultSet resultSet = tcManager.executeSparqlQuery(selectQuery, this.getEnhancementGraph());
        MGraph metadata = new IndexedMGraph();
        while (resultSet.hasNext()) {
            SolutionMapping mapping = resultSet.next();
            UriRef ref = (UriRef) mapping.get("enhID");
            Iterator<Triple> tripleItr = this.getEnhancementGraph().filter(ref, null, null);
            while (tripleItr.hasNext()) {
                Triple triple = tripleItr.next();
                metadata.add(triple);
            }
        }
        ContentItem ci = null;
        try {
            ci = ciFactory
View Full Code Here

    public ContentItem create(String id, byte[] content, String mimeType) {
        UriRef uri = id == null ? ContentItemHelper.makeDefaultUrn(content)
                : new UriRef(id);
        log.debug("create ContentItem for id " + uri + " on TC Manager= "
                + tcProvider);
        final MGraph g = new IndexedMGraph();
        try {
            return ciFactory.createContentItem(uri, new ByteArraySource(content, mimeType), g);
        } catch (IOException e) {
            throw new IllegalStateException("IOException while creation of an in-memory" +
                "ContentItem (that should never happen)!",e);
View Full Code Here

    /**
     * @return an RDF/JSON descriptions of places for the word map widget
     */
    public String getPlacesAsJSON() throws ParseException, UnsupportedEncodingException {
        MGraph g = new IndexedMGraph();
        LiteralFactory lf = LiteralFactory.getInstance();
        MGraph metadata = contentItem.getMetadata();
        for (EntityExtractionSummary p : getPlaceOccurrences()) {
            EntitySuggestion bestGuess = p.getBestGuess();
            if (bestGuess == null) {
                continue;
            }
            UriRef uri = new UriRef(bestGuess.getUri());
            Iterator<Triple> latitudes = metadata.filter(uri, GEO_LAT, null);
            if (latitudes.hasNext()) {
                g.add(latitudes.next());
            }
            Iterator<Triple> longitutes = metadata.filter(uri, GEO_LONG, null);
            if (longitutes.hasNext()) {
                g.add(longitutes.next());
                g.add(new TripleImpl(uri, Properties.RDFS_LABEL, lf.createTypedLiteral(bestGuess.getLabel())));
            }
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        serializer.serialize(out, g, SupportedFormat.RDF_JSON);

View Full Code Here

        } 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

     * @param id the {@link UriRef} node representing the id of the Representation.
     * @param graph the Graph to extract the representation from
     * @return the extracted graph.
     */
    protected MGraph createRepresentationGraph(UriRef id, TripleCollection graph){
        return extractRepresentation(graph, new IndexedMGraph(), id, new HashSet<BNode>());
    }
View Full Code Here

        Object resultObject = tcManager.executeSparqlQuery(sparqlQuery, graph);
        final MGraph resultGraph;
        if(resultObject instanceof MGraph){
            resultGraph = (MGraph)resultObject;
        } else if(resultObject instanceof Graph){
            resultGraph = new IndexedMGraph();
            resultGraph.addAll((Graph)resultObject);
        } else {
            log.error("Unable to create "+MGraph.class+" instance for query reults of type "+resultObject.getClass()+" (this indicates that the used SPARQL Query was not of type CONSTRUCT)");
            log.error("FieldQuery: "+query);
            log.error("SPARQL Query: "+sparqlQueryString);
View Full Code Here

     * @throws LDPathParseException if the parsed LDPath program is invalid
     */
    private static MGraph executeLDPath(RDFBackend<Object> backend,
                                 String ldpath,
                                 Set<String> contexts ) throws LDPathParseException {
        MGraph data = new IndexedMGraph();
        RdfValueFactory vf = new RdfValueFactory(data);
        EntityhubLDPath ldPath = new EntityhubLDPath(backend,vf);
        Program<Object> program = ldPath.parseProgram(getReader(ldpath));
        if(log.isDebugEnabled()){
            log.debug("Execute on Context(s) '{}' LDPath program: \n{}",
View Full Code Here

                log.warn("Error while sending Request ",e);
                tracker.failed(request,content,executor);
                rtt = null;
                return;
            }
            IndexedMGraph graph = new IndexedMGraph();
            try {
                rdfParser.parse(graph,executor.getStream(), executor.getContentType().getMimeType());
            } catch (Exception e) {
                log.warn("Exception while parsing Enhancement Response",e);
                tracker.failed(request, content, executor);
                return;
            }
            Iterator<Triple> ciIt = graph.filter(null, Properties.ENHANCER_EXTRACTED_FROM, null);
            Assert.assertTrue("Enhancement Results do not caontain a single Enhancement",ciIt.hasNext());
            Resource contentItemUri = ciIt.next().getObject();
            Assert.assertTrue("ContentItem URI is not an UriRef but an instance of "
                    + contentItemUri.getClass().getSimpleName(), contentItemUri instanceof UriRef);
            tracker.succeed(request, (UriRef) contentItemUri, graph, rtt, executor.getContent().length());
View Full Code Here

        log.info("Id: {}", ci.getUri().getUnicodeString());
        log.info("Mime type: {}", ci.getMimeType());
    }

    private MGraph getAdditionalMetadataFromNode(ContentContext contentContext) {
        MGraph additionalMetadata = new IndexedMGraph();
        try {
            PropertyIterator it = contentContext.getNode().getProperties();
            while (it.hasNext()) {
                javax.jcr.Property p = it.nextProperty();
                if (!skipProperty(p)) {
                    if (!p.isMultiple()) {
                        additionalMetadata.add(new TripleImpl(new UriRef(contentContext.getIdentifier()),
                                new UriRef(p.getName()), LiteralFactory.getInstance().createTypedLiteral(
                                    JCRUtils.getTypedPropertyValue(p.getType(), p.getValue()))));
                    } else {
                        for (Value value : p.getValues()) {
                            Object typedValue = JCRUtils.getTypedPropertyValue(p.getType(), value);
                            additionalMetadata.add(new TripleImpl(new UriRef(contentContext.getIdentifier()),
                                    new UriRef(p.getName()), LiteralFactory.getInstance().createTypedLiteral(
                                        typedValue)));
                        }
                    }
                }
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.