use of org.eclipse.rdf4j.repository.sparql.SPARQLRepository in project inception by inception-project.
the class TestFixtures method isReachable.
public static boolean isReachable(String aUrl) {
if (UNREACHABLE_ENDPOINTS.contains(aUrl)) {
return false;
}
try {
URL url = new URL(aUrl + "?query=" + new URLCodec().encode("SELECT ?v WHERE { BIND (true AS ?v)}"));
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("HEAD");
con.setConnectTimeout(7_500);
con.setReadTimeout(7_500);
con.setRequestProperty("Content-Type", "application/sparql-query");
int status = con.getResponseCode();
if (status == HTTP_MOVED_TEMP || status == HTTP_MOVED_PERM) {
String location = con.getHeaderField("Location");
return isReachable(location);
}
} catch (Exception e) {
System.out.printf("[%s] Network-level check: %s%n", aUrl, e.getMessage());
UNREACHABLE_ENDPOINTS.add(aUrl);
return false;
}
SPARQLRepository r = new SPARQLRepository(aUrl);
r.setHttpClient(newPerThreadSslCheckingHttpClientBuilder().build());
r.init();
try (RepositoryConnection conn = r.getConnection()) {
TupleQuery query = conn.prepareTupleQuery("SELECT ?v WHERE { BIND (true AS ?v)}");
query.setMaxExecutionTime(5);
try (TupleQueryResult result = query.evaluate()) {
return true;
}
} catch (Exception e) {
System.out.printf("[%s] Repository-level check: %s%n", aUrl, e.getMessage());
// e.printStackTrace();
UNREACHABLE_ENDPOINTS.add(aUrl);
return false;
}
}
use of org.eclipse.rdf4j.repository.sparql.SPARQLRepository in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Remote_PathQL_GetFactTests method setUpBeforeClass.
/**
* Sets the up before class.
*
* @throws Exception the exception
*/
@BeforeAll
static void setUpBeforeClass() throws Exception {
// org.eclipse.rdf4j.repository.Repository workingRep = new SPARQLRepository("http://localhost:8080/rdf4j-server/repositories/calc2graph");
SPARQLRepository workingRep = new SPARQLRepository("http://localhost:8080/rdf4j-server/repositories/calc2graph");
// org.eclipse.rdf4j.repository.Repository workingRep = new HTTPRepository("http://localhost:8080/rdf4j-server","calc2graph");
// HTTPRepository workingRep = new HTTPRepository("http://localhost:8080/rdf4j-server","calc2graph");
Map<String, String> headers = new HashMap<String, String>();
headers.put("Accept", "text/plain");
workingRep.setAdditionalHttpHeaders(headers);
source = IntelligentGraphRepository.create(workingRep);
source.prefix("<http://inova8.com/calc2graph/def/>");
source.prefix("rdfs", "<http://www.w3.org/2000/01/rdf-schema#>");
}
use of org.eclipse.rdf4j.repository.sparql.SPARQLRepository in project com.inova8.intelligentgraph by peterjohnlawrence.
the class TrianglesFunction method evaluate.
/**
* Evaluate.
*
* @param valueFactory the value factory
* @param args the args
* @return the value
* @throws ValueExprEvaluationException the value expr evaluation exception
*/
@Override
public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException {
org.eclipse.rdf4j.repository.Repository rep = new SPARQLRepository(args[0].stringValue());
rep.init();
try (RepositoryConnection workingConn = workingRep.getConnection();
RepositoryConnection conn = rep.getConnection()) {
// SPARQLRepository updaterepository = new SPARQLRepository(args[0].stringValue()+"/statements");
// Update update =updaterepository.getConnection().prepareUpdate(QueryLanguage.SPARQL,"insert data{graph <http://test> {<http://exampleSub> <http://examplePred> <http://exampleObj> }}");
// update.execute();
String graphQueryString = "CONSTRUCT{?vertex <label:connect> ?neighbor.}\r\n" + "WHERE{\r\n" + "SELECT ?vertex ?neighbor\r\n" + "WHERE{{?vertex ?p ?neighbor.}\r\n" + " UNION{?neighbor ?p ?vertex.}FILTER(STR(?vertex) <STR(?neighbor))}\r\n" + "}";
GraphQueryResult graphResult = conn.prepareGraphQuery(graphQueryString).evaluate();
Resource graph = iri("ng:temp");
while (graphResult.hasNext()) {
Statement st = graphResult.next();
// ... do something with the resulting statement here.
workingConn.add(st, graph);
}
String queryString = "SELECT(COUNT(DISTINCT*) AS ?triangles)\r\n" + "WHERE{\r\n" + " {\r\n" + "GRAPH<ng:temp> {\r\n" + " ?x?p?y.\r\n" + " ?y?p?z.\r\n" + " ?x?p?z.\r\n" + " }\r\n" + " }\r\n" + "}";
TupleQuery query = workingConn.prepareTupleQuery(queryString);
try (TupleQueryResult result = query.evaluate()) {
// we just iterate over all solutions in the result...
while (result.hasNext()) {
BindingSet solution = result.next();
return valueFactory.createLiteral(((SimpleLiteral) solution.getValue("triangles")).intValue());
}
}
}
return null;
}
use of org.eclipse.rdf4j.repository.sparql.SPARQLRepository in project lyo by eclipse.
the class SparqlUtil method processQuery_sesame.
/**
* Send the given sparql update to the sparql update service using the
* sesame libraries
*
* @param query
* sparql update to be processeda
* @param serviceUrl
* sparql update endpoint for processing the sparql update
* @param user
* username for authentication if applicable
* @param pwd
* password for authentication if applicable
*/
public static void processQuery_sesame(String query, String serviceUrl, String user, String pwd) {
SPARQLRepository repo = new SPARQLRepository(serviceUrl);
repo.setUsernameAndPassword(user, pwd);
repo.initialize();
RepositoryConnection rc = repo.getConnection();
processQuery_sesame(query, rc);
}
use of org.eclipse.rdf4j.repository.sparql.SPARQLRepository in project AJAN-service by aantakli.
the class SparqlTripleDataBase method getInitializedRepository.
@Override
public Repository getInitializedRepository() {
Repository repository = new SPARQLRepository(sparqlEndpoint.toString(), sparqlUpdateEndpoint.toString());
repository.initialize();
return repository;
}
Aggregations