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;
}
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;
}
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;
}
}
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);
}
Aggregations