use of org.eclipse.rdf4j.repository.sparql.SPARQLRepository in project com.inova8.intelligentgraph by peterjohnlawrence.
the class DegreeDistributionTupleFunction method evaluate.
/**
* Evaluate.
*
* @param valueFactory the value factory
* @param args the args
* @return the closeable iteration{@code<? extends list<? extends value>, query evaluation exception>}
* @throws QueryEvaluationException the query evaluation exception
*/
@Override
public CloseableIteration<? extends List<? extends Value>, QueryEvaluationException> evaluate(ValueFactory valueFactory, Value... args) throws QueryEvaluationException {
org.eclipse.rdf4j.repository.Repository rep = new SPARQLRepository(args[0].stringValue());
rep.init();
conn = rep.getConnection();
String queryString = "SELECT ?degree (COUNT(?degree) AS ?count)\r\n" + "WHERE{\r\n" + " {SELECT(COUNT(?n)AS?degree)\r\n" + " WHERE{\r\n" + " {?n?out_edge?out}\r\n" + " UNION\r\n" + " {?in?in_edge?n}\r\n" + " }GROUP BY ?n}}\r\n" + "GROUP BY ?degree";
TupleQuery query = conn.prepareTupleQuery(queryString);
Collection<BindingSet> results = new ArrayList<BindingSet>();
try (TupleQueryResult result = query.evaluate()) {
while (result.hasNext()) {
results.add(result.next());
}
}
return new ConvertingIteration<BindingSet, List<Value>, QueryEvaluationException>(new CloseableIteratorIteration<>(results.iterator())) {
@Override
protected List<Value> convert(BindingSet bindings) throws QueryEvaluationException {
List<Value> results = new ArrayList<>();
for (String bindingName : bindings.getBindingNames()) {
results.add(bindings.getValue(bindingName));
}
return results;
}
};
}
use of org.eclipse.rdf4j.repository.sparql.SPARQLRepository in project lyo by eclipse.
the class SparqlUtil method getRepoConnection.
/**
* return the repo connection object in order to be able to use the sesame
* client libraries
*
* @param queryEndpoint
* the sparl query endpoint
* @param user
* username for authentication if applicable
* @param pwd
* password for authentication if applicable
* @return
*/
public static RepositoryConnection getRepoConnection(String queryEndpoint, String user, String pwd) {
SPARQLRepository repo = new SPARQLRepository(queryEndpoint);
if (user != null && pwd != null && !user.isEmpty() && !pwd.isEmpty()) {
repo.setUsernameAndPassword("okacimi", "nohheis4ae");
}
repo.initialize();
try {
RepositoryConnection conn = repo.getConnection();
if (conn == null) {
logger.error("error getting sparql repo connection !");
}
return conn;
} catch (Exception e) {
logger.error("error getting sparql repo connection !", e);
return null;
}
}
use of org.eclipse.rdf4j.repository.sparql.SPARQLRepository in project AJAN-service by aantakli.
the class BTUtil method getInitializedRepository.
public static Repository getInitializedRepository(final AgentTaskInformation metadata, final URI url) throws URISyntaxException, QueryEvaluationException {
Repository repo;
if (url.equals(new URI(AJANVocabulary.AGENT_KNOWLEDGE.toString()))) {
repo = metadata.getAgentBeliefs().initialize();
} else if (url.equals(new URI(AJANVocabulary.EXECUTION_KNOWLEDGE.toString()))) {
repo = metadata.getExecutionBeliefs().initialize();
} else if (url.equals(new URI(AJANVocabulary.BEHAVIOR_KNOWLEDGE.toString()))) {
repo = metadata.getBehaviorTDB().getInitializedRepository();
} else if (url.equals(new URI(AJANVocabulary.SERVICE_KNOWLEDGE.toString()))) {
repo = metadata.getServiceTDB().getInitializedRepository();
} else if (url.equals(new URI(AJANVocabulary.DOMAIN_KNOWLEDGE.toString()))) {
repo = metadata.getDomainTDB().getInitializedRepository();
} else {
// -----------------------------------------------------------------
// TODO: General Repository desription for SPARQL + Update Endpoints
// -----------------------------------------------------------------
repo = new SPARQLRepository(url.toString(), url.toString());
repo.initialize();
}
return repo;
}
use of org.eclipse.rdf4j.repository.sparql.SPARQLRepository in project AJAN-service by aantakli.
the class StateLoader method getInitializedRepository.
private static Repository getInitializedRepository(final URI url, AgentTaskInformation taskInfos) throws URISyntaxException, QueryEvaluationException {
Repository repo;
if (url.equals(new URI(AJANVocabulary.AGENT_KNOWLEDGE.toString()))) {
repo = taskInfos.getAgentBeliefs().getInitializedRepository();
} else {
repo = new SPARQLRepository(url.toString());
repo.initialize();
}
return repo;
}
use of org.eclipse.rdf4j.repository.sparql.SPARQLRepository in project amazon-neptune-tools by awslabs.
the class NeptuneSparqlClient method executeGraphQuery.
public void executeGraphQuery(String sparql, RdfTargetConfig targetConfig) throws IOException {
SPARQLRepository repository = chooseRepository();
try (RepositoryConnection connection = repository.getConnection();
OutputWriter outputWriter = targetConfig.createOutputWriter()) {
RDFWriter writer = targetConfig.createRDFWriter(outputWriter);
connection.prepareGraphQuery(sparql).evaluate(new GraphQueryHandler(writer));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations