Search in sources :

Example 31 with IndexedGraph

use of org.apache.stanbol.commons.indexedgraph.IndexedGraph in project stanbol by apache.

the class ClerezzaModelWriter method toRDF.

private Graph toRDF(Representation representation) {
    Graph graph = new IndexedGraph();
    addRDFTo(graph, representation);
    return graph;
}
Also used : IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) Graph(org.apache.clerezza.commons.rdf.Graph) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph)

Example 32 with IndexedGraph

use of org.apache.stanbol.commons.indexedgraph.IndexedGraph in project stanbol by apache.

the class ClerezzaModelWriter method toRDF.

private Graph toRDF(Entity entity) {
    Graph graph = new IndexedGraph();
    addRDFTo(graph, entity);
    return graph;
}
Also used : IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) Graph(org.apache.clerezza.commons.rdf.Graph) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph)

Example 33 with IndexedGraph

use of org.apache.stanbol.commons.indexedgraph.IndexedGraph in project stanbol by apache.

the class VirtuosoSearcher method find.

@Override
public final QueryResultList<Representation> find(FieldQuery parsedQuery) throws IOException {
    long start = System.currentTimeMillis();
    final SparqlFieldQuery query = SparqlFieldQueryFactory.getSparqlFieldQuery(parsedQuery);
    query.setSparqlEndpointType(SparqlEndpointTypeEnum.Virtuoso);
    String sparqlQuery = query.toSparqlConstruct();
    long initEnd = System.currentTimeMillis();
    log.info("  > InitTime: " + (initEnd - start));
    log.info("  > SPARQL query:\n" + sparqlQuery);
    InputStream in = SparqlEndpointUtils.sendSparqlRequest(getQueryUri(), sparqlQuery, SparqlSearcher.DEFAULT_RDF_CONTENT_TYPE);
    long queryEnd = System.currentTimeMillis();
    log.info("  > QueryTime: " + (queryEnd - initEnd));
    if (in != null) {
        Graph graph;
        Graph rdfData = parser.parse(in, SparqlSearcher.DEFAULT_RDF_CONTENT_TYPE, new IRI(getBaseUri()));
        if (rdfData instanceof Graph) {
            graph = (Graph) rdfData;
        } else {
            graph = new IndexedGraph(rdfData);
        }
        long parseEnd = System.currentTimeMillis();
        log.info("  > ParseTime: " + (parseEnd - queryEnd));
        return new RdfQueryResultList(query, graph);
    } else {
        return null;
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Graph(org.apache.clerezza.commons.rdf.Graph) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) RdfQueryResultList(org.apache.stanbol.entityhub.query.clerezza.RdfQueryResultList) InputStream(java.io.InputStream) SparqlFieldQuery(org.apache.stanbol.entityhub.query.sparql.SparqlFieldQuery) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph)

Example 34 with IndexedGraph

use of org.apache.stanbol.commons.indexedgraph.IndexedGraph in project stanbol by apache.

the class ClerezzaYard method find.

@Override
public final QueryResultList<Representation> find(FieldQuery parsedQuery) throws YardException, IllegalArgumentException {
    if (parsedQuery == null) {
        throw new IllegalArgumentException("The parsed query MUST NOT be NULL!");
    }
    final SparqlFieldQuery query = SparqlFieldQueryFactory.getSparqlFieldQuery(parsedQuery);
    int limit = QueryUtils.getLimit(query, getConfig().getDefaultQueryResultNumber(), getConfig().getMaxQueryResultNumber());
    Query sparqlQuery;
    //NOTE:
    // - use the endpoint type standard, because we do not know what type of
    //   SPARQL implementation is configured for Clerezza via OSGI
    String sparqlQueryString = SparqlQueryUtils.createSparqlConstructQuery(query, limit, EndpointTypeEnum.Standard);
    try {
        sparqlQuery = QueryParser.getInstance().parse(sparqlQueryString);
    } catch (ParseException e) {
        log.error("ParseException for SPARQL Query in findRepresentation");
        log.error("FieldQuery: " + query);
        log.error("SPARQL Query: " + sparqlQueryString);
        throw new YardException("Unable to parse SPARQL query generated for the parse FieldQuery", e);
    }
    Object resultObject = tcManager.executeSparqlQuery(sparqlQuery, graph);
    final Graph resultGraph;
    if (resultObject instanceof Graph) {
        resultGraph = (Graph) resultObject;
    } else if (resultObject instanceof ImmutableGraph) {
        resultGraph = new IndexedGraph();
        resultGraph.addAll((ImmutableGraph) resultObject);
    } else {
        log.error("Unable to create " + Graph.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);
        throw new YardException("Unable to process results of Query");
    }
    return new RdfQueryResultList(query, resultGraph);
}
Also used : YardException(org.apache.stanbol.entityhub.servicesapi.yard.YardException) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) Graph(org.apache.clerezza.commons.rdf.Graph) Query(org.apache.clerezza.rdf.core.sparql.query.Query) SparqlFieldQuery(org.apache.stanbol.entityhub.query.clerezza.SparqlFieldQuery) FieldQuery(org.apache.stanbol.entityhub.servicesapi.query.FieldQuery) SelectQuery(org.apache.clerezza.rdf.core.sparql.query.SelectQuery) RdfQueryResultList(org.apache.stanbol.entityhub.query.clerezza.RdfQueryResultList) SparqlFieldQuery(org.apache.stanbol.entityhub.query.clerezza.SparqlFieldQuery) ParseException(org.apache.clerezza.rdf.core.sparql.ParseException) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph)

Aggregations

IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)34 Graph (org.apache.clerezza.commons.rdf.Graph)27 IRI (org.apache.clerezza.commons.rdf.IRI)20 HashSet (java.util.HashSet)9 InputStream (java.io.InputStream)8 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)8 RdfValueFactory (org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory)8 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)8 Triple (org.apache.clerezza.commons.rdf.Triple)7 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)6 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)5 RdfQueryResultList (org.apache.stanbol.entityhub.query.clerezza.RdfQueryResultList)5 Test (org.junit.Test)5 EntityhubLDPath (org.apache.stanbol.entityhub.ldpath.EntityhubLDPath)4 RdfRepresentation (org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation)4 Entity (org.apache.stanbol.entityhub.servicesapi.model.Entity)4 BeforeClass (org.junit.BeforeClass)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)3