当前位置: 首页>>代码示例>>Java>>正文


Java QueryExecution.execSelect方法代码示例

本文整理汇总了Java中org.apache.jena.query.QueryExecution.execSelect方法的典型用法代码示例。如果您正苦于以下问题:Java QueryExecution.execSelect方法的具体用法?Java QueryExecution.execSelect怎么用?Java QueryExecution.execSelect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.jena.query.QueryExecution的用法示例。


在下文中一共展示了QueryExecution.execSelect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: listVocabularies

import org.apache.jena.query.QueryExecution; //导入方法依赖的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;
}
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:21,代码来源:VocabularyUtils.java

示例2: getLabel

import org.apache.jena.query.QueryExecution; //导入方法依赖的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());
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:28,代码来源:ObjectWithURI.java

示例3: get

import org.apache.jena.query.QueryExecution; //导入方法依赖的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;
}
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:25,代码来源:ThingDescriptionHandler.java

示例4: getThingDescriptionIdFromUri

import org.apache.jena.query.QueryExecution; //导入方法依赖的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;
 }
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:30,代码来源:ThingDescriptionUtils.java

示例5: getProperties

import org.apache.jena.query.QueryExecution; //导入方法依赖的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;
}
 
开发者ID:swapUniba,项目名称:lodrecsys_eswc2017tutorial,代码行数:19,代码来源:DownloadLodProperties.java

示例6: getCount

import org.apache.jena.query.QueryExecution; //导入方法依赖的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;
}
 
开发者ID:albangaignard,项目名称:EDAMetrics,代码行数:22,代码来源:Queries.java

示例7: queryData

import org.apache.jena.query.QueryExecution; //导入方法依赖的package包/类
public static List<String> queryData(String query){
	Dataset db = TDBFactory.createDataset("temp/dataset");
	db.begin(ReadWrite.READ);
    Model model = db.getDefaultModel();
    Query q = QueryFactory.create(query);
    QueryExecution qexec = QueryExecutionFactory.create(query, model);
    ResultSet results = qexec.execSelect();
    List<String> answer = new ArrayList<String>();
    while(results.hasNext()){
    	QuerySolution t = results.nextSolution();
    	RDFNode x  = t.get("x");
    	String s = x.toString();
	System.out.println(s);
    	answer.add(s.substring(7));
    }
    qexec.close();
    db.close();
    return answer;
}
 
开发者ID:kunal15595,项目名称:smart-question-answering-nlp,代码行数:20,代码来源:Database.java

示例8: getTriples

import org.apache.jena.query.QueryExecution; //导入方法依赖的package包/类
/**
 * Gets all triples for resource r and property p. If outgoing is true it
 * returns all triples with <r,p,o>, else <s,p,r>
 *
 * @param r
 *            the resource
 * @param p
 *            the property
 * @param outgoing
 *            whether to get outgoing or ingoing triples
 * @return A set of triples
 */
public Set<Triple> getTriples(Resource r, Property p, boolean outgoing) {
	Set<Triple> result = new HashSet<Triple>();
	try {
		String q;
		if (outgoing) {
			q = "SELECT ?o where { <" + r.getURI() + "> <" + p.getURI() + "> ?o." + "?o rdfs:label []}";
		} else {
			q = "SELECT ?o where { ?o <" + p.getURI() + "> <" + r.getURI() + ">." + "?o rdfs:label []}";
		}
		q += " LIMIT " + maxShownValuesPerProperty + 1;
		QueryExecution qe = qef.createQueryExecution(q);
		ResultSet results = qe.execSelect();
		if (results.hasNext()) {
			while (results.hasNext()) {
				RDFNode n = results.next().get("o");
				result.add(Triple.create(r.asNode(), p.asNode(), n.asNode()));
			}
		}
		qe.close();
	} catch (Exception e) {
		e.printStackTrace();
	}
	return result;
}
 
开发者ID:dice-group,项目名称:BENGAL,代码行数:37,代码来源:Verbalizer.java

示例9: getMostSpecificType

import org.apache.jena.query.QueryExecution; //导入方法依赖的package包/类
/**
 * Returns the most specific type of a given individual.
 * 
 * @param ind
 * @return
 */
private OWLClass getMostSpecificType(OWLIndividual ind) {
	logger.debug("Getting the most specific type of " + ind);
	String query = String.format("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
			+ "select distinct ?type where {" + " <%s> a ?type ." + "?type rdfs:label []."
			// + "?type a owl:Class ." // too strict, thus currently omitted
			+ "filter not exists {?subtype ^a <%s> ; rdfs:subClassOf ?type .filter(?subtype != ?type)}}",
			ind.toStringID(), ind.toStringID());
	SortedSet<OWLClass> types = new TreeSet<OWLClass>();

	QueryExecution qe = qef.createQueryExecution(query);
	ResultSet rs = qe.execSelect();
	while (rs.hasNext()) {
		QuerySolution qs = rs.next();
		if (qs.get("type").isURIResource()) {
			types.add(new OWLClassImpl(IRI.create(qs.getResource("type").getURI())));
		}
	}
	qe.close();

	// of more than one type exists, we have to choose one
	// TODO

	return types.first();
}
 
开发者ID:dice-group,项目名称:BENGAL,代码行数:31,代码来源:Verbalizer.java

示例10: getProperties

import org.apache.jena.query.QueryExecution; //导入方法依赖的package包/类
/**
* Retrieves all nodes from the endpoint that are classes.
   * @param endpoint
* @param classExpression
* @param model
* @return Set of all nodes that are classes
   */
  private Set<Node> getProperties(String endpoint, String classExpression, Model model) {
      Set<Node> result = new HashSet<Node>();
      try {
          String query = "SELECT DISTINCT ?p WHERE { ?s ?p ?y. ?s a <" + classExpression + "> }";
          Query sparqlQuery = QueryFactory.create(query);
          QueryExecution qexec;
          if(model == null)
          	qexec = QueryExecutionFactory.sparqlService(endpoint, sparqlQuery);
          else
          	qexec = QueryExecutionFactory.create(sparqlQuery, model);
          ResultSet results = qexec.execSelect();
          while (results.hasNext()) {
              QuerySolution soln = results.nextSolution();
              result.add(soln.get("p").asNode());
          }
      } catch (Exception e) {
          logger.warn("Error while processing classes");
      }
      return result;
  }
 
开发者ID:dice-group,项目名称:LIMES,代码行数:28,代码来源:LabelBasedPropertyMapper.java

示例11: generateIndividual

import org.apache.jena.query.QueryExecution; //导入方法依赖的package包/类
@Override
public void generateIndividual(VirtualEntity virtualEntity) {

    Model model = createIndividual(new VirtualEntity());
    
    String id = UUID.randomUUID().toString();
    System.out.println(String.format("Adding %s", id));
    UpdateProcessor upp = UpdateExecutionFactory.createRemote(
            UpdateFactory.create(String.format(UPDATE_TEMPLATE, id)),
            "http://localhost:3030/pswot/update");
    upp.execute();
    //Query the collection, dump output
    QueryExecution qe = QueryExecutionFactory.sparqlService(
            "http://localhost:3030/pswot/query",
            "SELECT * WHERE {?x ?r ?y}");
    ResultSet results = qe.execSelect();
    ResultSetFormatter.out(System.out, results);
    qe.close();

}
 
开发者ID:nailtonvieira,项目名称:cloudsemanticwot,代码行数:21,代码来源:DataConnectorImpl.java

示例12: getClasses

import org.apache.jena.query.QueryExecution; //导入方法依赖的package包/类
/**
 * Retrieves all nodes from the endpoint that are classes
 *
 * @param endpoint
 * @return Set of all nodes that are classes
 */
private Set<Node> getClasses(String endpoint, Model model) {
    Set<Node> result = new HashSet<Node>();
    try {
        String query = "SELECT DISTINCT ?y WHERE { ?s a ?y }";
        Query sparqlQuery = QueryFactory.create(query);
        QueryExecution qexec;
        if(model == null)
        	qexec = QueryExecutionFactory.sparqlService(endpoint, sparqlQuery);
        else
        	qexec = QueryExecutionFactory.create(sparqlQuery, model);
        ResultSet results = qexec.execSelect();
        while (results.hasNext()) {
            QuerySolution soln = results.nextSolution();
            result.add(soln.get("y").asNode());
        }
    } catch (Exception e) {
        logger.warn("Error while processing classes");
    }
    return result;
}
 
开发者ID:dice-group,项目名称:LIMES,代码行数:27,代码来源:LabelBasedClassMapper.java

示例13: getSummaries

import org.apache.jena.query.QueryExecution; //导入方法依赖的package包/类
/**
 * generates the map of paperId - paperTitle
 * 
 * @param model
 * @return
 */
public Map<String, String> getSummaries(Model[] models) {

	Map<String, String> titlesMap = new HashMap<String, String>();
	for (Model model : models) {
	    if(model != null){
   			String sparql = "PREFIX ical: <http://www.w3.org/2002/12/cal/icaltzd#> "
   					+ "SELECT ?event ?summary "
   					+ "WHERE{"
   					+ "    ?event ical:summary ?summary" + "}";
   			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 paper = querySolution.getResource("event");
   				Literal title = querySolution.getLiteral("summary");
   				String titleString = title.getLexicalForm().replaceAll(" +",
   						" ");
   				titlesMap.put(paper.getURI(), titleString);
   			}
	    }
	}
	return titlesMap;
}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:32,代码来源:CalendarAlignerWithSessions.java

示例14: testSelect

import org.apache.jena.query.QueryExecution; //导入方法依赖的package包/类
@Test
public void testSelect() {
    QueryExecution qe = QueryExecutionFactory.create(
            "select ?s ?p ?o where { ?s ?p ?o}", ds);
    ResultSet results = qe.execSelect();
    // System.out.println(ResultSetFormatter.asText(results));
    while (results.hasNext()) {
        QuerySolution qs = results.next();
        assertTrue(qs.contains("s"));
        assertTrue(qs.contains("p"));
        assertTrue(qs.contains("o"));
    }
}
 
开发者ID:marklogic,项目名称:marklogic-jena,代码行数:14,代码来源:MarkLogicQueryEngineTest.java

示例15: list

import org.apache.jena.query.QueryExecution; //导入方法依赖的package包/类
public void list(Model model) {
	String sparql = "PREFIX foaf: <" + FOAF.NS + "> "
			+ "SELECT ?lastName ?person " + "WHERE{ "
			+ "    ?person a foaf:Person . "
			+ "    ?person foaf:lastName ?lastName . "
			+ "    ?person1 a foaf:Person . "
			+ "    ?person1 foaf:lastName ?lastName1 . "
			+ "    FILTER(?person != ?person1) . "
			+ "    FILTER(STR(?lastName) = STR(?lastName1)) . " + "}"
			+ "ORDER BY ?lastName";
	Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
	QueryExecution queryExecution = QueryExecutionFactory.create(query,
			model);

	ResultSet resultSet = queryExecution.execSelect();
	ResultSetFormatter.out(System.out, resultSet);
}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:18,代码来源:DuplicatePerson.java


注:本文中的org.apache.jena.query.QueryExecution.execSelect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。