use of com.hp.hpl.jena.rdf.model.RDFNode in project goci by EBISPOT.
the class SparqlTemplate method query.
public <T> T query(String sparql, ResultSetMapper<T> rsm, Object... args) {
sparql = getPrefixString().concat(sparql);
Graph g = getJenaQueryExecutionService().getDefaultGraph();
Map<String, Object> bindingMap = new HashMap<String, Object>();
int i = 0;
for (Object o : args) {
String argName = "?_arg" + i++;
sparql = sparql.replaceFirst("\\?\\?", argName);
bindingMap.put(argName, o);
}
Query q1 = QueryFactory.create(sparql, Syntax.syntaxARQ);
QuerySolutionMap initialBinding = new QuerySolutionMap();
for (String argName : bindingMap.keySet()) {
Object argValue = bindingMap.get(argName);
RDFNode arg;
if (argValue instanceof URI) {
arg = new ResourceImpl(argValue.toString());
} else {
arg = getLiteralNode(argValue);
}
initialBinding.add(argName, arg);
}
ParameterizedSparqlString queryString = new ParameterizedSparqlString(q1.toString(), initialBinding);
QueryExecution execute = null;
try {
execute = getJenaQueryExecutionService().getQueryExecution(g, queryString.asQuery(), false);
ResultSet results = execute.execSelect();
return rsm.mapResultSet(results);
} catch (LodeException e) {
throw new SparqlQueryException("Failed to execute query '" + sparql + "'", e);
} finally {
if (execute != null) {
execute.close();
if (g != null) {
g.close();
}
}
}
}
use of com.hp.hpl.jena.rdf.model.RDFNode in project stanbol by apache.
the class JenaToOwlConvert method ResourceJenaToOwlAxiom.
// //////////////////////////////////////////////////////////////////////////////
/**
* This function converts every statments relative to a resource in an a set of OWLAxiom objects
*
* @param jenadata
* {A resource in the form (S,P,O), it could be any kind of resource (a class, a data property,
* an object property and an instance) except a litteral}
* @param format
* {The format of the ontology, i.e. "RDF/XML"}
* @return {A set of axiom in the form of Set<OWLAxiom>}
*/
public synchronized Set<OWLAxiom> ResourceJenaToOwlAxiom(Resource jenadata, String format) {
while (available == false) {
try {
wait();
} catch (InterruptedException e) {
System.err.println("ResourceJenaToOwlAxiom::: " + e);
}
}
available = false;
try {
OntModel model = ModelFactory.createOntologyModel();
StmtIterator prop = jenadata.listProperties();
while (prop.hasNext()) {
Statement stat = prop.nextStatement();
model.add(stat);
RDFNode obj = stat.getObject();
if (obj.isResource()) {
if (!obj.isURIResource()) {
StmtIterator aux = ((Resource) obj).listProperties();
while (aux.hasNext()) {
Statement stataux = aux.nextStatement();
model.add(stataux);
}
}
}
}
OWLOntology owlmodel = ModelJenaToOwlConvert(model, format);
available = true;
notifyAll();
return owlmodel.getAxioms();
} catch (Exception e) {
System.err.print("ResourceJenaToOwlAxiom::: ");
e.printStackTrace();
return null;
}
}
use of com.hp.hpl.jena.rdf.model.RDFNode in project lucene-skos by behas.
the class SKOSEngineImpl method indexObject.
private void indexObject(Resource skos_concept, Document conceptDoc, ObjectProperty property, String field) {
StmtIterator stmt_iter = skos_concept.listProperties(property);
while (stmt_iter.hasNext()) {
RDFNode concept = stmt_iter.nextStatement().getObject();
if (!concept.canAs(Resource.class)) {
logger.warn("Error when indexing relationship of concept " + skos_concept.getURI() + " .");
continue;
}
Resource resource = concept.as(Resource.class);
Field conceptField = new Field(field, resource.getURI(), TextField.TYPE_STORED);
conceptDoc.add(conceptField);
}
}
use of com.hp.hpl.jena.rdf.model.RDFNode in project wikidata-query-rdf by wikimedia.
the class BigdataStatementToJenaStatementMapper method map1.
@Override
public Statement map1(final BigdataStatement blzgStmt) {
final Resource s = convertToJenaResource(blzgStmt.getSubject());
final Property p = convertToJenaProperty(blzgStmt.getPredicate());
final RDFNode o = convertToJenaRDFNode(blzgStmt.getObject());
return ResourceFactory.createStatement(s, p, o);
}
use of com.hp.hpl.jena.rdf.model.RDFNode in project nextprot-api by calipho-sib.
the class RdfHelpServiceImpl method getDataFromSolutionVar.
private Object getDataFromSolutionVar(QuerySolution sol, String var, boolean useQuotes) {
RDFNode n = sol.get(var);
if (n == null)
return "";
RDFBasicVisitor rdfVisitor = new RDFBasicVisitor(sparqlDictionary.getSparqlPrefixes());
rdfVisitor.setSurroundLiteralStringWithQuotes(useQuotes);
return n.visitWith(rdfVisitor);
}
Aggregations