本文整理匯總了Java中com.hp.hpl.jena.query.QuerySolution.contains方法的典型用法代碼示例。如果您正苦於以下問題:Java QuerySolution.contains方法的具體用法?Java QuerySolution.contains怎麽用?Java QuerySolution.contains使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.query.QuerySolution
的用法示例。
在下文中一共展示了QuerySolution.contains方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: _query
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
private void _query() throws UnregisteredInstanceException {
SearchServiceFromSparql s = (SearchServiceFromSparql)_service;
String q = Queries.buildSimpleQuery(_osddBGP, s.getURI(), ((QueryableSource)s.getDataSource()));
ResultSet rs = ((QueryableSource)s.getDataSource()).sparqlSelect(q);
if (rs.hasNext()) {
QuerySolution qs = rs.next();
if (qs.contains("o")) {
_osdd = Utils.parseLiteral(qs.get("o").toString());
} else {
throw new UnregisteredInstanceException("OpenSearchService at URI (" + s.getURI() + ") is missing a pointer to its OpenSearch description document.");
}
} else {
throw new UnregisteredInstanceException("OpenSearchService at URI (" + s.getURI() + ") is missing a pointer to its OpenSearch description document.");
}
}
示例2: _getWidgetsFromInputs
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
private String[] _getWidgetsFromInputs(String klass, String parameter, String output) {
Set<String> widgets = new HashSet<>();
for (DataSource source : _sources) {
if (QueryableSource.class.isAssignableFrom(source.getClass())) {
ResultSet rs = ((QueryableSource)source).sparqlSelect(Queries.widgetsFromInputs(klass, parameter, output, null, ((QueryableSource)source)));
while (rs.hasNext()) {
QuerySolution qs = rs.next();
if (qs.contains("widget"))
widgets.add(qs.get("widget").toString());
}
}
}
String[] result = new String[widgets.size()];
widgets.toArray(result);
return result;
}
示例3: getSimpleSparqlJson
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
public static String getSimpleSparqlJson(ResultSet rs) {
JSONArray arr = new JSONArray();
while (rs.hasNext()) {
QuerySolution qs = rs.next();
Map<String,String> r = new HashMap<>();
for (String var : rs.getResultVars()) {
if (qs.contains(var) && qs.get(var).isLiteral()) {
r.put(var,qs.get(var).asLiteral().getValue().toString());
} else if (qs.contains(var) && qs.get(var).isResource()) {
r.put(var, qs.get(var).toString());
}
}
arr.put(r);
}
return arr.toString();
}
示例4: getFirstOrderResultsJson
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
public static String getFirstOrderResultsJson(ResultSet rs) {
JSONArray arr = new JSONArray();
arr.put(rs.getResultVars());
while (rs.hasNext()) {
QuerySolution qs = rs.next();
Map<String,String> r = new HashMap<>();
for (String var : rs.getResultVars()) {
if (qs.contains(var) && qs.get(var).isLiteral()) {
r.put(var,qs.get(var).asLiteral().getValue().toString());
} else if (qs.contains(var) && qs.get(var).isResource()) {
r.put(var, qs.get(var).toString());
}
}
arr.put(r);
}
return arr.toString();
}
示例5: 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()]);
}
示例6: getPagedFirstOrderResultsJson
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
public static String getPagedFirstOrderResultsJson(ResultSet rs, ResultSet count, Map<String,Collection<String>> inputs) {
JSONObject obj = new JSONObject();
JSONArray arr = new JSONArray();
arr.put(rs.getResultVars());
while (rs.hasNext()) {
QuerySolution qs = rs.next();
Map<String,String> r = new HashMap<>();
for (String var : rs.getResultVars()) {
if (qs.contains(var) && qs.get(var).isLiteral()) {
r.put(var,qs.get(var).asLiteral().getValue().toString());
} else if (qs.contains(var) && qs.get(var).isResource()) {
r.put(var, qs.get(var).toString());
}
}
arr.put(r);
}
try {
obj.put("results", arr);
obj.put("total", count.next().get("count").asLiteral().getValue().toString());
obj.put("limit", inputs.get(Ontology.opensearchCount));
obj.put("offset", inputs.get(Ontology.opensearchStartIndex));
} catch (JSONException e) {
//TODO: error handling
throw new RuntimeException(e);
}
return obj.toString();
}
示例7: testQueryBuilder
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
@Test
public void testQueryBuilder() {
Map<String,Collection<String>> map = new HashMap<>();
map.put(TEST_INPUT_FACET, Arrays.asList(TEST_INPUT_FACET_VALUE, TEST_INPUT_FACET_VALUE2));
String query = _facets.buildConnectedFacetQuery(TEST_CONNECTED_FACET, map);
ResultSet rs = _sparql.sparqlSelect(query);
boolean check = false;
while (rs.hasNext()) {
QuerySolution qs = rs.next();
if (qs.contains("id") && qs.get("id").toString().equals(TEST_RESULT)) check = true;
}
assertTrue(check);
}
示例8: getTestList
import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
@Parameters(name="{index}: {0}")
public static Collection<Object[]> getTestList() {
Model m = D2RQTestUtil.loadTurtle(MANIFEST_FILE);
IRI baseIRI = D2RQTestUtil.createIRI(m.getNsPrefixURI("base"));
String schema = D2RQTestUtil.getResourceURL(SCHEMA);
ResultSet rs = QueryExecutionFactory.create(TEST_CASE_LIST, m).execSelect();
List<Object[]> result = new ArrayList<Object[]>();
while (rs.hasNext()) {
QuerySolution qs = rs.next();
Resource file = qs.getResource("r2rml");
// if (!file.getLocalName().equals("duplicate-subject-map.ttl")) continue;
List<MessageExpectation> expectations = new ArrayList<MessageExpectation>();
QueryExecution qe = QueryExecutionFactory.create(TEST_CASE_DETAILS, m);
qe.setInitialBinding(qs);
ResultSet rs2 = qe.execSelect();
while (rs2.hasNext()) {
QuerySolution solution = rs2.next();
// Work around a SPARQL/ARQ weirdness where MAX() on an empty
// solution sequence creates a new all-empty solution
if (!solution.varNames().hasNext()) continue;
MessageExpectation expectation = new MessageExpectation(
Problem.valueOf(solution.getResource("problem").getLocalName()));
if (solution.contains("level")) {
expectation.expectLevel(Level.valueOf(solution.getResource("level").getLocalName()));
}
if (solution.contains("details") &&
solution.get("details").isLiteral() &&
solution.getLiteral("details").getBoolean()) {
expectation.expectDetails();
}
if (solution.contains("detailcode")) {
expectation.expectDetailCode(solution.getResource("detailcode").getLocalName());
}
if (solution.contains("subject")) {
expectation.expectSubject(solution.getResource("subject"));
}
if (solution.contains("predicate")) {
expectation.expectPredicate(solution.getResource("predicate").as(Property.class));
}
if (solution.contains("object")) {
expectation.expectObject(solution.get("object"));
}
expectations.add(expectation);
}
result.add(new Object[]{baseIRI.relativize(file.getURI()).toString(), file.getURI(), schema, expectations});
}
return result;
}