本文整理匯總了Java中com.hp.hpl.jena.query.QuerySolution.getResource方法的典型用法代碼示例。如果您正苦於以下問題:Java QuerySolution.getResource方法的具體用法?Java QuerySolution.getResource怎麽用?Java QuerySolution.getResource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.query.QuerySolution
的用法示例。
在下文中一共展示了QuerySolution.getResource方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAgentUri
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
public Resource getAgentUri(VirtGraph graphOrgs, String vatId) {
Resource agentUri = null;
String queryUri = "PREFIX gr: <http://purl.org/goodrelations/v1#> " +
"SELECT ?org ?vatId " +
"FROM <" + QueryConfiguration.queryGraphOrganizations + "> " +
"WHERE { " +
"?org gr:vatID ?vatId . " +
"FILTER ( ?vatId = \"" + vatId + "\"^^<http://www.w3.org/2001/XMLSchema#string> ) " +
"}";
VirtuosoQueryExecution vqeUri = VirtuosoQueryExecutionFactory.create(queryUri, graphOrgs);
ResultSet resultsUri = vqeUri.execSelect();
if (resultsUri.hasNext()) {
QuerySolution result = resultsUri.nextSolution();
agentUri = result.getResource("org");
}
vqeUri.close();
return agentUri;
}
示例2: getAgentUriNoVat
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
public Resource getAgentUriNoVat(VirtGraph graphOrgs, String vatId) {
Resource agentUri = null;
String queryUri = "PREFIX gr: <http://purl.org/goodrelations/v1#> " +
"SELECT DISTINCT ?org " +
"FROM <" + QueryConfiguration.queryGraphOrganizations + "> " +
"WHERE { " +
"?org rdf:type foaf:Organization . " +
"FILTER (STR(?org) = \"http://linkedeconomy.org/resource/Organization/" + vatId + "\") . " +
"}";
VirtuosoQueryExecution vqeUri = VirtuosoQueryExecutionFactory.create(queryUri, graphOrgs);
ResultSet resultsUri = vqeUri.execSelect();
if (resultsUri.hasNext()) {
QuerySolution result = resultsUri.nextSolution();
agentUri = result.getResource("org");
}
vqeUri.close();
return agentUri;
}
示例3: getTestListFromManifest
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
public static Collection<Object[]> getTestListFromManifest(String manifestFileURL) {
// We'd like to use FileManager.loadModel() but it doesn't work on jar: URLs
// Model m = FileManager.get().loadModel(manifestFileURL);
Model m = ModelFactory.createDefaultModel();
m.read(manifestFileURL, "TURTLE");
IRI baseIRI = D2RQTestUtil.createIRI(m.getNsPrefixURI("base"));
ResultSet rs = QueryExecutionFactory.create(TEST_CASE_LIST, m).execSelect();
List<Object[]> result = new ArrayList<Object[]>();
while (rs.hasNext()) {
QuerySolution qs = rs.next();
Resource mapping = qs.getResource("mapping");
Resource schema = qs.getResource("schema");
// if (!mapping.getLocalName().equals("constant-object.ttl")) continue;
QueryExecution qe = QueryExecutionFactory.create(TEST_CASE_TRIPLES, m);
qe.setInitialBinding(qs);
Model expectedTriples = qe.execConstruct();
result.add(new Object[]{baseIRI.relativize(mapping.getURI()).toString(), mapping.getURI(),
schema.getURI(), expectedTriples});
}
return result;
}
示例4: getTestLists
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
@Parameters(name="{index}: {0}")
public static Collection<Object[]> getTestLists() {
Model m = D2RQTestUtil.loadTurtle(MANIFEST_FILE);
IRI baseIRI = D2RQTestUtil.createIRI(m.getNsPrefixURI("base"));
ResultSet rs = QueryExecutionFactory.create(TEST_CASE_LIST, m).execSelect();
List<Object[]> result = new ArrayList<Object[]>();
while (rs.hasNext()) {
QuerySolution qs = rs.next();
Resource testCase = qs.getResource("case");
// if (!case.getLocalName().equals("expression")) continue;
QueryExecution qe = QueryExecutionFactory.create(TEST_CASE_TRIPLES, m);
qe.setInitialBinding(qs);
Model expectedTriples = qe.execConstruct();
result.add(new Object[]{
baseIRI.relativize(testCase.getURI()).toString(),
qs.getLiteral("sql").getLexicalForm(),
expectedTriples});
}
return result;
}
示例5: getTypesFromSPARQL
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
private Set<String> getTypesFromSPARQL(String sparqlQueryString) {
Query query = QueryFactory.create(sparqlQueryString);
QueryExecution qexec = QueryExecutionFactory.sparqlService(this.endpoint, query);
Set<String> types = new HashSet<>();
ResultSet results = qexec.execSelect();
while(results.hasNext()) {
QuerySolution qs = results.next();
Resource type = qs.getResource("?type");
types.add(type.getURI());
}
qexec.close();
return types;
}
示例6: getResourcesToLink
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
/**
* It executes a SELECT SPARQL query on the SPARQL endpoint, to get
* the URIs of the resources to use to discover links towards external datasets.
*
* @param sparqlEndpointURI the SPARQL endpoint URI.
* @param graphName the graphName, null in case of default graph.
* @param user the user name for the SPARQl endpoint.
* @param password the password for the SPARQl endpoint.
* @param query the query to use to look for the resources.
* @param offset causes the solutions generated to start after the
* specified number of solutions.
* @param limit upper bound on the number of solutions returned.
* @return a list of the matched URIs.
* @since 2.0
*/
public ResourceToLink[] getResourcesToLink(final String sparqlEndpointURI, final String user, final String password, final String sparql, final Integer offset, final Integer limit) {
final ArrayList<ResourceToLink> resourcesList = new ArrayList<ResourceToLink>();
final String query = sparql + " OFFSET " + offset + " LIMIT " + limit;
// Execute the query and obtain results
final ResultSet results = rdfstoreDAO.executeSelect(sparqlEndpointURI, user, password, query);
if (results != null){
while (results.hasNext())
{
final QuerySolution soln = results.nextSolution() ;
final Resource res = soln.getResource("res");
final String resURI = res.getURI();
final String textToSearch = soln.getLiteral("text").getString();
final ResourceToLink resToLink = new ResourceToLink(textToSearch, resURI);
resourcesList.add(resToLink);
}
}
if (resourcesList.isEmpty()) {
return new ResourceToLink[0];
}
return (ResourceToLink[]) resourcesList.toArray(new ResourceToLink[resourcesList.size()]);
}
示例7: inferPropertyNames
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
private static void inferPropertyNames(final Model model) {
final Model names = ModelFactory.createDefaultModel();
try (QueryExecution qx = createQuery(model, getQuery("/sparql/nameless-properties.rq"))) {
final ResultSet rs = qx.execSelect();
while (rs.hasNext()) {
final QuerySolution qs = rs.next();
final Resource p = qs.getResource("property");
final Resource t = qs.getResource("type");
names.add(p, Ontology.hasName, t.getURI());
}
}
model.add(names);
}
示例8: retrieveObjectProperties
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
/**
* @see KnowledgeBaseConnector#objectProperties
*/
private void retrieveObjectProperties() {
objectProperties = new HashSet<String>();
String query = "SELECT DISTINCT ?t WHERE { ?t a owl:ObjectProperty }";
try {
QueryExecution qexec = getQueryExec(query);
ResultSet results = qexec.execSelect();
while (results.hasNext()) {
QuerySolution sol = results.next();
Resource objectProperty = sol.getResource("?t");
objectProperties.add(objectProperty.getURI());
}
qexec.close();
log.info("Found " + objectProperties.size() + " object properties for endpoint " + sparqlEndpoint);
} catch (Exception e) {
log.error("Error retrieving list of object properties: ", e);
}
}
示例9: getUsage
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
private List<Statement> getUsage(Property property, Model model){
List<Statement> stmts = new ArrayList<Statement>();
String sparql = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
+ "PREFIX owl: <http://www.w3.org/2002/07/owl#> "
+ "SELECT DISTINCT ?concept "
+ "WHERE{"
+ " {<" + property.getURI() + "> rdfs:domain ?concept} "
+ " UNION "
+ " { "
+ " ?concept rdfs:subClassOf|owl:equivalentClass ?restriction . "
+ " ?restriction a owl:Restriction; "
+ " owl:onProperty <" + property.getURI() + "> "
+ " } "
+ "}";
Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
QueryExecution queryExecution = QueryExecutionFactory.create(query, model);
ResultSet resultSet = queryExecution.execSelect();
while(resultSet.hasNext()){
QuerySolution querySolution = resultSet.next();
Resource concept = querySolution.getResource("concept");
stmts.add(new StatementImpl(property, usage, concept));
}
return stmts;
}
示例10: getDiscoveredLinks
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
/**
* It executes a SELECT SPARQL query on the SPARQL endpoint,
* to get the discovered links.
*
* @param sparqlEndpointURI the SPARQL endpoint URI.
* @param graphName the graphName, null in case of default graph.
* @param user the user name for the SPARQl endpoint.
* @param password the password for the SPARQl endpoint.
* @param offset causes the solutions generated to start after
* the specified number of solutions.
* @param limit upper bound on the number of solutions returned.
* @return a list of triples with the discovered links.
* @since 2.0
*/
public Triple[] getDiscoveredLinks(final String sparqlEndpointURI, final String graphName, final String user, final String password, final int offset, final int limit) {
final String query = "select * FROM <" + graphName + "> " +
"where {?source ?rel ?target }" +
" ORDER BY ?source ?target" +
" OFFSET " + offset + " LIMIT " + limit;
ArrayList<Triple> linksList = new ArrayList<Triple>();
try {
// Execute the query and obtain results
final QueryExecution qexec = QueryExecutionFactory.sparqlService(
sparqlEndpointURI,
QueryFactory.create(query),
auth(sparqlEndpointURI, user, password));
qexec.setTimeout(2000, 5000);
final ResultSet results = qexec.execSelect() ;
while (results.hasNext())
{
final QuerySolution soln = results.nextSolution() ;
final Resource sourceResType = soln.getResource("source");
final Resource targetResType = soln.getResource("target");
final Resource relResType = soln.getResource("rel");
final Triple triple = new Triple(sourceResType.asNode(), relResType.asNode(), targetResType.asNode());
linksList.add(triple);
}
qexec.close() ;
} catch (Exception exception) {
LOGGER.error(MessageCatalog._00035_SPARQL_FAILED, exception, query);
}
if (linksList.isEmpty()) {
return new Triple[0];
}
return (Triple[]) linksList.toArray(new Triple[linksList.size()]);
}
示例11: getAmbiguousDiscoveredLinks
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
/**
* It executes a SELECT SPARQL query on the SPARQL endpoint,
* to get the ambiguous discovered links.
*
* @param sparqlEndpointURI the SPARQL endpoint URI.
* @param graphName the graphName, null in case of default graph.
* @param user the user name for the SPARQl endpoint.
* @param password the password for the SPARQl endpoint.
* @param offset causes the solutions generated to start after
* the specified number of solutions.
* @param limit upper bound on the number of solutions returned.
* @return a list of {@link eu.aliada.shared.rdfstore.AmbiguousLink} with the ambiguous discovered links.
* @since 2.0
*/
public AmbiguousLink[] getAmbiguousDiscoveredLinks(final String sparqlEndpointURI, final String graphName, final String user, final String password, final int offset, final int limit) {
final String query = "SELECT ?localRes ?extResBegin (COUNT(?localRes) AS ?count) FROM <" + graphName + "> " +
" WHERE {?localRes ?rel ?extRes ." +
" BIND( str(?extRes) as ?extResStr )." +
" BIND( SUBSTR(?extResStr, 1,14) AS ?extResBegin)" +
" }" +
" GROUP BY ?localRes ?extResBegin" +
" HAVING (COUNT(?localRes) > 1)" +
" ORDER BY ?localRes" +
" OFFSET " + offset + " LIMIT " + limit;
ArrayList<AmbiguousLink> ambiguousLinksList = new ArrayList<AmbiguousLink>();
try {
// Execute the query and obtain results
final QueryExecution qexec = QueryExecutionFactory.sparqlService(
sparqlEndpointURI,
QueryFactory.create(query),
auth(sparqlEndpointURI, user, password));
qexec.setTimeout(2000, 5000);
final ResultSet results = qexec.execSelect() ;
while (results.hasNext())
{
final QuerySolution soln = results.nextSolution() ;
final Resource localRes = soln.getResource("localRes");
final String extResBegin = soln.getLiteral("extResBegin").getString();
final AmbiguousLink ambiguousLink = new AmbiguousLink();
ambiguousLink.setSourceURI(localRes.getURI());
getSourceURIAmbiguousLinks(ambiguousLink, localRes, extResBegin, sparqlEndpointURI, graphName, user, password);
ambiguousLinksList.add(ambiguousLink);
}
qexec.close() ;
} catch (Exception exception) {
LOGGER.error(MessageCatalog._00035_SPARQL_FAILED, exception, query);
}
if (ambiguousLinksList.isEmpty()) {
return new AmbiguousLink[0];
}
return (AmbiguousLink[]) ambiguousLinksList.toArray(new AmbiguousLink[ambiguousLinksList.size()]);
}
示例12: getSourceURIAmbiguousLinks
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
/**
* It executes a SELECT SPARQL query on the SPARQL endpoint,
* to get the ambiguous discovered links of a source URI.
*
* @param ambiguousLink a {@link eu.aliada.shared.rdfstore.AmbiguousLink} that contains the source URI.
* @param localRes the source resource of the link.
* @param extResBegin the beginning string of the target link.
* @param sparqlEndpointURI the SPARQL endpoint URI.
* @param graphName the graphName, null in case of default graph.
* @param user the user name for the SPARQl endpoint.
* @param password the password for the SPARQl endpoint.
* @param offset causes the solutions generated to start after
* the specified number of solutions.
* @param limit upper bound on the number of solutions returned.
* @since 2.0
*/
public void getSourceURIAmbiguousLinks(final AmbiguousLink ambiguousLink, final Resource localRes, final String extResBegin, final String sparqlEndpointURI, final String graphName, final String user, final String password) {
final String query = "SELECT ?rel ?extRes FROM <" + graphName + "> " +
" WHERE {<" + ambiguousLink.getSourceURI() + "> ?rel ?extRes ." +
" FILTER regex(?extRes, \"^" + extResBegin + "\", \"i\")" +
" }";
try {
// Execute the query and obtain results
final QueryExecution qexec = QueryExecutionFactory.sparqlService(
sparqlEndpointURI,
QueryFactory.create(query),
auth(sparqlEndpointURI, user, password));
qexec.setTimeout(2000, 5000);
final ResultSet results = qexec.execSelect() ;
while (results.hasNext())
{
final QuerySolution soln = results.nextSolution() ;
final Resource extRes = soln.getResource("extRes");
final Resource relResType = soln.getResource("rel");
final Triple triple = new Triple(localRes.asNode(), relResType.asNode(), extRes.asNode());
ambiguousLink.addLink(triple);
}
qexec.close() ;
} catch (Exception exception) {
LOGGER.error(MessageCatalog._00035_SPARQL_FAILED, exception, query);
}
}
示例13: getResources
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
/**
* It executes a SELECT SPARQL query on the SPARQL endpoint,
* to get the resources specified in the query argument.
*
* @param query the query to execute to get the resources.
* @param sparqlEndpointURI the SPARQL endpoint URI.
* @param user the user name for the SPARQl endpoint.
* @param password the password for the SPARQl endpoint.
* @param offset causes the solutions generated to start after
* the specified number of solutions.
* @param limit upper bound on the number of solutions returned.
* @return a list of {@link eu.aliada.shared.rdfstore.RetrievedResource} with the resources.
* @since 2.0
*/
public RetrievedResource[] getResources(final String query, final String sparqlEndpointURI, final String user, final String password, final int offset, final int limit) {
final ArrayList<RetrievedResource> resList = new ArrayList<RetrievedResource>();
try {
// Execute the query and obtain results
final QueryExecution qexec = QueryExecutionFactory.sparqlService(
sparqlEndpointURI,
QueryFactory.create(query),
auth(sparqlEndpointURI, user, password));
qexec.setTimeout(2000, 5000);
final ResultSet results = qexec.execSelect() ;
while (results.hasNext())
{
final QuerySolution soln = results.nextSolution() ;
final Resource res = soln.getResource("res");
String name = "";
if(soln.contains("name")) {
name = soln.getLiteral("name").getString();
}
final RetrievedResource retrievedRes = new RetrievedResource(res.getURI(), name);
resList.add(retrievedRes);
}
qexec.close() ;
} catch (Exception exception) {
LOGGER.error(MessageCatalog._00035_SPARQL_FAILED, exception, query);
}
if (resList.isEmpty()) {
return new RetrievedResource[0];
}
return (RetrievedResource[]) resList.toArray(new RetrievedResource[resList.size()]);
}
示例14: countVotesForRegions
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
/**
* @param windowLength
* @param step
* @param detectingSensors
* @param distances
*/
private void countVotesForRegions(int windowLength, long step, HashMap<Resource, Double2D> detectingSensors,
HashMap<Resource, Double> distances) {
long initialTimestamp = step - windowLength / 2;
long finalTimestamp = step + windowLength / 2;
String query = "SELECT (?x as ?msg) WHERE { ?x a b2d2-wsn:ZigBeeMessage . ?x b2d2-wsn:isDetecting true . ?x b2d2-wsn:timestamp ?tmp FILTER (?tmp >= "
+ initialTimestamp + " && ?tmp <= " + finalTimestamp + ") }";
Query arqQuery = ARQFactory.get().createQuery(model, query);
QueryExecution qExe = QueryExecutionFactory.create(arqQuery, model);
ResultSet results = qExe.execSelect();
List<String> alreadyVoted = new ArrayList<String>();
while (results.hasNext()) {
QuerySolution result = results.next();
Resource resource = result.getResource("msg");
String sensorName = resource.getProperty(Vocabulary.isSentBy).getProperty(Vocabulary.name).getString();
if (!alreadyVoted.contains(sensorName)) {
alreadyVoted.add(sensorName);
Resource auxlocation = resource.getProperty(Vocabulary.isSentBy).getProperty(Vocabulary.locatedAt)
.getResource();
long auxX = auxlocation.getProperty(Vocabulary.longitude).getLong();
long auxY = auxlocation.getProperty(Vocabulary.latitude).getLong();
Double2D auxPosition = new Double2D(auxX, auxY);
for (Entry<Resource, Double2D> entry : detectingSensors.entrySet()) {
double distance = auxPosition.distance(entry.getValue());
if (distances.containsKey(entry.getKey())) {
double previous = distances.get(entry.getKey());
distances.put(entry.getKey(), previous + distance);
} else {
distances.put(entry.getKey(), distance);
}
}
}
}
}
示例15: ckeckLeadingZeros
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
private void ckeckLeadingZeros(SparqlifyDataset dataset)
throws NotImplementedException, SQLException {
// http://www.w3.org/TR/2003/WD-rdf-syntax-grammar-20030123/#rdf-ns-uri
String queryStr =
"Prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
"SELECT * { " +
"?s ?p ?o . " +
"FILTER(regex(str(?p), \"^http://www.w3.org/1999/02/22-rdf-syntax-ns#_0\")) " +
"}";
Query query = QueryFactory.create(queryStr);
QueryExecution qe;
if (dataset.isSparqlService() && dataset.getSparqlServiceUri()!=null) {
qe = QueryExecutionFactory.createServiceRequest(
dataset.getSparqlServiceUri(), query);
} else {
qe = QueryExecutionFactory.create(query, dataset);
}
ResultSet res = qe.execSelect();
List<Triple> leadingZeroTriples = new ArrayList<Triple>();
while(res.hasNext())
{
QuerySolution solution = res.nextSolution();
Resource subj = solution.getResource("s");
Resource pred = solution.getResource("p");
RDFNode obj = solution.get("o");
Triple leadingzeroTriple = new Triple(subj.asNode(), pred.asNode(), obj.asNode());
leadingZeroTriples.add(leadingzeroTriple);
}
qe.close();
for (Triple triple : leadingZeroTriples) {
Set<ViewQuad<ViewDefinition>> viewQuads = pinpointer.getViewCandidates(triple);
writeTripleMeasureToSink(leadingZeroVal, triple, viewQuads);
}
}