本文整理匯總了Java中org.apache.jena.query.ResultSet類的典型用法代碼示例。如果您正苦於以下問題:Java ResultSet類的具體用法?Java ResultSet怎麽用?Java ResultSet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ResultSet類屬於org.apache.jena.query包,在下文中一共展示了ResultSet類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: listVocabularies
import org.apache.jena.query.ResultSet; //導入依賴的package包/類
public static Set<String> listVocabularies() {
Set<String> tds = new HashSet<>();
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT DISTINCT ?g WHERE { GRAPH ?g { ?o a <http://www.w3.org/2002/07/owl#Ontology> } }";
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
tds.add(result.next().get("g").asResource().getURI());
}
} catch (Exception e) {
throw e;
} finally {
dataset.end();
}
return tds;
}
示例2: getLabel
import org.apache.jena.query.ResultSet; //導入依賴的package包/類
/**
* Return the label for this object in the selected language
* @param language - the language for which the label is requested
* @return - the label in the requested language.
* @throws ModelException - thrown if there are multiple labels present for this object in this language
*/
public Label getLabel(Language language) throws ModelException {
String sparql = "SELECT ?label WHERE { ?objectURI rdfs:label ?label . FILTER(LANG(?label) = STR(?labelLanguage)) }";
ParameterizedSparqlString parameterizedSparql = new ParameterizedSparqlString(model);
parameterizedSparql.setCommandText(sparql);
parameterizedSparql.setParam("objectURI", resource);
parameterizedSparql.setParam("labelLanguage", model.createLiteral(language.getCode(), ""));
Query query = QueryFactory.create(parameterizedSparql.asQuery());
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet resultSet = qexec.execSelect();
if (!resultSet.hasNext()) return null;
QuerySolution querySolution = resultSet.next();
Label label = new Label(querySolution.getLiteral("label"));
if (!resultSet.hasNext()) return label;
throw new ModelException("%s has more than one label in language '%s'", resource.getURI(), language.getCode());
}
示例3: get
import org.apache.jena.query.ResultSet; //導入依賴的package包/類
@Override
public RESTResource get(URI uri, Map<String, String> parameters) throws RESTException {
RESTResource resource = new RESTResource(uri.toString(),this);
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT ?str WHERE { <" + uri + "> <" + DC.source + "> ?str }";
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
ResultSet result = qexec.execSelect();
if (result.hasNext()) {
resource.contentType = "application/ld+json";
resource.content = result.next().get("str").asLiteral().getLexicalForm();
} else {
throw new RESTException();
}
} finally {
dataset.end();
}
return resource;
}
示例4: listThingDescriptions
import org.apache.jena.query.ResultSet; //導入依賴的package包/類
public static List<String> listThingDescriptions(String query) {
List<String> tds = new ArrayList<>();
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT DISTINCT ?g WHERE { GRAPH ?g { " + query + " FILTER NOT EXISTS { ?ontology a <http://www.w3.org/2002/07/owl#Ontology> } } }";
try (QueryExecution qexec = QueryExecutionFactory.create(q, dataset)) {
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
tds.add(result.next().get("g").asResource().getURI());
}
}
catch (Exception e) {
throw e;
}
} finally {
dataset.end();
}
return tds;
}
示例5: getThingDescriptionIdFromUri
import org.apache.jena.query.ResultSet; //導入依賴的package包/類
/**
* Returns the ID of a thing description stored in the database given its URI.
* @param uri URI of the thing description we want to return.
* @return the ID of the thing description.
*/
public static String getThingDescriptionIdFromUri(String uri) {
String query = "?td <http://iot.linkeddata.es/def/wot#baseURI> <" + uri + ">";
String id = "NOT FOUND";
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT ?g_id WHERE { GRAPH ?g_id { " + query + " }}";
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
id = result.next().get("g_id").toString();
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
dataset.end();
}
return id;
}
示例6: listThingDescriptionsUri
import org.apache.jena.query.ResultSet; //導入依賴的package包/類
/**
* Returns a list of the thing descriptions URIs.
* @return a list of URIs stored in the database.
*/
public static List<String> listThingDescriptionsUri() {
List<String> tds = new ArrayList<>();
String query = "?td <http://iot.linkeddata.es/def/wot#baseURI> ?uri";
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT ?uri WHERE { GRAPH ?g_id { " + query + " }}";
try (QueryExecution qexec = QueryExecutionFactory.create(q, dataset)) {
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
tds.add(result.next().get("uri").toString());
}
}
catch (Exception e) {
throw e;
}
} finally {
dataset.end();
}
return tds;
}
示例7: getProperties
import org.apache.jena.query.ResultSet; //導入依賴的package包/類
private static List<Pair<String, String>> getProperties(String uri) {
List<Pair<String, String>> results = new ArrayList<>();
String sparqlQuery = "select ?r ?y where {<" + uri + "> ?r ?y}";
//System.out.println(sparqlQuery);
QueryExecution e = QueryExecutionFactory.sparqlService(ENDPOINT, sparqlQuery);
ResultSet rs = e.execSelect();
while (rs.hasNext()) {
QuerySolution nextSolution = rs.nextSolution();
RDFNode ynode = nextSolution.get("y");
if (ynode.isResource()) {
results.add(Pair.of(nextSolution.getResource("r").getURI(), nextSolution.getResource("y").getURI()));
} else {
results.add(Pair.of(nextSolution.getResource("r").getURI(), nextSolution.getLiteral("y").getString().replaceAll("\\n+", " ")));
}
}
e.close();
return results;
}
示例8: setPersonTypes
import org.apache.jena.query.ResultSet; //導入依賴的package包/類
public void setPersonTypes(Set<String> personTypes){
this.personTypes = personTypes;
//get the inferred sub types as well
if(useInference){
Set<String> inferredTypes = new HashSet<>();
String queryTemplate = "select ?sub where{?sub <http://www.w3.org/2000/01/rdf-schema#subClassOf>* <%s>.}";
for (String type : personTypes) {
String query = String.format(queryTemplate, type);
try(QueryExecution qe = qef.createQueryExecution(query)) {
ResultSet rs = qe.execSelect();
while(rs.hasNext()){
inferredTypes.add(rs.next().getResource("sub").getURI());
}
}
}
personTypes.addAll(inferredTypes);
}
}
示例9: isPerson
import org.apache.jena.query.ResultSet; //導入依賴的package包/類
private boolean isPerson(String uri){
if(personTypes.isEmpty()){
return true;
} else {
//g et types of URI
Set<String> types = new HashSet<>();
try {
String query = "SELECT ?type WHERE {<" + uri + "> a ?type.}";
try(QueryExecution qe = qef.createQueryExecution(query)) {
ResultSet rs = qe.execSelect();
while(rs.hasNext()){
types.add(rs.next().getResource("type").getURI());
}
}
} catch (Exception e) {
int code = ((QueryExceptionHTTP)e.getCause()).getResponseCode();
logger.warn("SPARQL query execution failed: " + code + " - " + HttpSC.getCode(code).getMessage());
}
// check for overlap between types of entity and person types
return !Sets.intersection(personTypes, types).isEmpty();
}
}
示例10: runSelectQuery
import org.apache.jena.query.ResultSet; //導入依賴的package包/類
static ResultSet runSelectQuery(String queryString, String service, String... defaultGraphs) throws Exception {
QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(service, queryString);
qExec.addDefaultGraph(Constants.DBPEDIA_URL);
if (defaultGraphs != null) {
for (String defaultGraph : defaultGraphs) {
qExec.addDefaultGraph(defaultGraph);
}
}
qExec.addParam("timeout", Constants.TIMEOUT_VALUE); //100 sec
ResultSet set = null;
try {
set = qExec.execSelect();
set = ResultSetFactory.copyResults(set);
} catch (Exception e) {
QGenLogger.severe("Exception in SELECT\n" + queryString + "\n" + e.getMessage());
} finally {
qExec.close();
}
return set;
}
示例11: getResultSetAsStringList
import org.apache.jena.query.ResultSet; //導入依賴的package包/類
static List<String> getResultSetAsStringList(ResultSet resultSet, String variableName, boolean literalRequired) {
List<String> resultStrings = new ArrayList<>();
RDFNode node;
if (resultSet != null) {
while (resultSet.hasNext()) {
QuerySolution result = resultSet.next();
if (result != null) {
node = result.get(variableName);
if (literalRequired) {
String literal = getStringLiteral(node);
if (literal != null) {
resultStrings.add(literal);
}
} else {
if (node != null) {
resultStrings.add(node.toString());
}
}
}
}
}
return resultStrings;
}
示例12: getLabelOfType
import org.apache.jena.query.ResultSet; //導入依賴的package包/類
static String getLabelOfType(String type) {
type = "<" + type + ">";
String queryString = Constants.PREFIX_RDFS + Constants.PREFIX_FOAF;
String variable = "name";
queryString += "SELECT ?" + variable + " FROM <http://dbpedia.org> WHERE {\n" +
"{" + type + " rdfs:label ?name .}\n" +
Constants.UNION +
"{" + type + " foaf:name ?name .}\n" +
" filter (langMatches(lang(?name), \"EN\")) ." +
"}";
ResultSet results = null;
try {
results = SPARQLClient.runSelectQuery(queryString, Constants.DBPEDIA_SPARQL_SERVICE);
} catch (Exception e) {
e.printStackTrace();
}
if (results != null) {
if (results.hasNext()) {
QuerySolution result = results.next();
return getStringLiteral(result.get(variable));
}
}
return null;
}
示例13: getLabelOfSpotlightType
import org.apache.jena.query.ResultSet; //導入依賴的package包/類
static String getLabelOfSpotlightType(String type) {
String nsAndType = getNsAndTypeForSpotlightType(type);
String queryString = Constants.PREFIX_RDFS + PREFIX_DBRES;
queryString += "SELECT ?name FROM <http://dbpedia.org> WHERE {\n" +
nsAndType + " rdfs:label ?name .\n" +
" filter (langMatches(lang(?name), \"EN\")) ." +
"}";
ResultSet results = null;
try {
results = SPARQLClient.runSelectQuery(queryString, Constants.DBPEDIA_SPARQL_SERVICE);
} catch (Exception e) {
e.printStackTrace();
}
List<String> resultList = new ArrayList<>();
addResultsToList(results, resultList, "name");
return resultList.get(0);
}
示例14: getTypeDepth
import org.apache.jena.query.ResultSet; //導入依賴的package包/類
static int getTypeDepth(String type) {
String queryString =
Constants.PREFIX_RDF + Constants.PREFIX_FOAF + Constants.PREFIX_RDFS +
"SELECT DISTINCT ?path FROM <http://dbpedia.org> WHERE {\n" +
"<" + type + "> rdfs:subClassOf* ?path . }";
ResultSet results;
int count = 0;
try {
results = SPARQLClient.runSelectQuery(queryString, Constants.DBPEDIA_SPARQL_SERVICE);
while (results.hasNext()) {
results.next();
count++;
}
} catch (Exception e) {
e.printStackTrace();
}
return count;
}
示例15: getCount
import org.apache.jena.query.ResultSet; //導入依賴的package包/類
public static int getCount(String q, Model m) {
Query query = QueryFactory.create(q);
QueryExecution queryExec = QueryExecutionFactory.create(query, m);
ResultSet rs = queryExec.execSelect();
String vName = "";
for (String v: rs.getResultVars()) {
if (v.contains("count")) {
vName = v;
break;
}
}
while (rs.hasNext()) {
QuerySolution s = rs.nextSolution();
Literal c = s.getLiteral(vName);
queryExec.close();
return c.getInt();
}
queryExec.close();
return 0;
}