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


Java QueryExecution.close方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: runSelect

import org.apache.jena.query.QueryExecution; //导入方法依赖的package包/类
public static void runSelect(String q, Model m) {
    Query query = QueryFactory.create(q);
    QueryExecution queryExec = QueryExecutionFactory.create(query, m);
    ResultSet rs = queryExec.execSelect();
    System.out.println(ResultSetFormatter.asText(rs));
    queryExec.close();
}
 
开发者ID:albangaignard,项目名称:EDAMetrics,代码行数:8,代码来源:Queries.java

示例8: updateTest

import org.apache.jena.query.QueryExecution; //导入方法依赖的package包/类
public void updateTest() {
		// Add a new book to the collection
//		String service = "http://219.248.137.7:13030/icbms/update";
//		UpdateRequest ur = UpdateFactory
//				.create(""
//						+ "delete  { <http://www.pineone.com/campus/TemperatureObservationValue_LB0001> <http://data.nasa.gov/qudt/owl/qudt#hasNumericValue>  ?value . } "
//						+ "insert  { <http://www.pineone.com/campus/TemperatureObservationValue_LB0001> <http://data.nasa.gov/qudt/owl/qudt#hasNumericValue>  \"19\" . } " //<-- 19대신 여기 온도를 넣어주세
//						+ "WHERE   { <http://www.pineone.com/campus/TemperatureObservationValue_LB0001> <http://data.nasa.gov/qudt/owl/qudt#hasNumericValue> ?value . }");
//		UpdateProcessor up = UpdateExecutionFactory.createRemote(ur, service);
//		up.execute();

		// Query the collection, dump output
//		String service1 = "http://219.248.137.7:13030/icbms/";
//		QueryExecution qe = QueryExecutionFactory.sparqlService(service1,
//				"SELECT * WHERE {<http://www.pineone.com/campus/Student_S00001> ?r ?y} limit 20 ");
//
//		ResultSet results = qe.execSelect();
//		ResultSetFormatter.out(System.out, results);
//		qe.close();
		Model model = ModelFactory.createDefaultModel();
		Statement s = model.createStatement(model.createResource("ex:e1"),model.createProperty("ex:p1"), ResourceFactory.createTypedLiteral(new String("0.6")));
		model.add(s);
		String query = "select * {?s ?p ?o }";
		QueryExecution qe = QueryExecutionFactory.create(query, model);
		ResultSet results = qe.execSelect();
		ResultSetFormatter.out(System.out, results);
		qe.close();
	}
 
开发者ID:iotoasis,项目名称:SDA,代码行数:29,代码来源:Test.java

示例9: updateTest

import org.apache.jena.query.QueryExecution; //导入方法依赖的package包/类
public void updateTest() {
		// Add a new book to the collection
//		String service = "http://219.248.137.7:13030/icbms/update";
//		UpdateRequest ur = UpdateFactory
//				.create(""
//						+ "delete  { <http://www.iotoasis.org/TemperatureObservationValue_LB0001> <http://data.nasa.gov/qudt/owl/qudt#hasNumericValue>  ?value . } "
//						+ "insert  { <http://www.iotoasis.org/TemperatureObservationValue_LB0001> <http://data.nasa.gov/qudt/owl/qudt#hasNumericValue>  \"19\" . } " 
//						+ "WHERE   { <http://www.iotoasis.org/TemperatureObservationValue_LB0001> <http://data.nasa.gov/qudt/owl/qudt#hasNumericValue> ?value . }");
//		UpdateProcessor up = UpdateExecutionFactory.createRemote(ur, service);
//		up.execute();

		// Query the collection, dump output
//		String service1 = "http://219.248.137.7:13030/icbms/";
//		QueryExecution qe = QueryExecutionFactory.sparqlService(service1,
//				"SELECT * WHERE {<http://www.iotoasis.org/Student_S00001> ?r ?y} limit 20 ");
//
//		ResultSet results = qe.execSelect();
//		ResultSetFormatter.out(System.out, results); 
//		qe.close();
		Model model = ModelFactory.createDefaultModel();
		Statement s = model.createStatement(model.createResource("ex:e1"),model.createProperty("ex:p1"), ResourceFactory.createTypedLiteral(new String("0.6")));
		model.add(s);
		String query = "select * {?s ?p ?o }";
		QueryExecution qe = QueryExecutionFactory.create(query, model);
		ResultSet results = qe.execSelect();
		ResultSetFormatter.out(System.out, results);
		qe.close();
		
		// gooper
		if(! model.isClosed()) {
			model.close();
		}
		if(model != null) {
			model = null;
		}

	}
 
开发者ID:iotoasis,项目名称:SDA,代码行数:38,代码来源:Test.java

示例10: getDeviceInfo

import org.apache.jena.query.QueryExecution; //导入方法依赖的package包/类
public static String getDeviceInfo(String deviceUri) throws Exception {
	String serviceURI = Utils.getSdaProperty("com.pineone.icbms.sda.knowledgebase.dw.sparql.endpoint")+"/sparql";
	StringWriter out = new StringWriter();
	// 요기
	String query = getSparQlHeader() + "\n"+ "describe "+ deviceUri;

	QueryExecution qe = QueryExecutionFactory.sparqlService(serviceURI, query);
	Model model =   qe.execDescribe();
	qe.close();
	model.write(out,"RDF/XML");
	return out.toString();
}
 
开发者ID:iotoasis,项目名称:SDA,代码行数:13,代码来源:Utils.java

示例11: getDeviceInfo

import org.apache.jena.query.QueryExecution; //导入方法依赖的package包/类
public String  getDeviceInfo(String deviceUri) {
	StringWriter out = new StringWriter();
	String query = prefix + "\n"+ "describe "+ deviceUri;
	QueryExecution qe = QueryExecutionFactory.sparqlService(endpoint, query);
	Model model =   qe.execDescribe();
	qe.close();
	model.write(out,"RDF/XML");
	return out.toString();
}
 
开发者ID:iotoasis,项目名称:SDA,代码行数:10,代码来源:DeviceResource.java

示例12: queryData2

import org.apache.jena.query.QueryExecution; //导入方法依赖的package包/类
public static Boolean queryData2(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);
    List<String> answer = new ArrayList<String>();
    Boolean t = (qexec.execAsk());
    qexec.close();
    db.close();
    return t;
}
 
开发者ID:kunal15595,项目名称:smart-question-answering-nlp,代码行数:13,代码来源:Database.java

示例13: evidencesForFacts

import org.apache.jena.query.QueryExecution; //导入方法依赖的package包/类
/**
 * Given a set of triples extracted/generated from the result/answer of query gpad-basic.rq, we find matching evidence subgraphs. 
 * In other words, if there are no matching evidence (i.e. no bindings for evidence_type), we discard (basic) GPAD instance.
 * 
 * The parameter "facts" consists of triples <?subject, ?predicate, ?object> constructed from a binding of ?pr, ?rel, ?target in gpad_basic.rq. 
 * (The codes that constructing these triples are executed right before this method is called).
 * 
 * These triples are then decomposed into values used as the parameters/bindings for objects of the following patterns.
 * 		?axiom owl:annotatedSource   ?subject (i.e. ?pr in gpad_basic.rq) 
 * 		?axiom owl:annotatedProperty ?predicate (i.e., ?rel in gpad_basic.rq, which denotes qualifier in GPAD) 
 * 		?axiom owl:annotatedTarget    ?object (i.e., ?target in gpad_basic.rq)
 * 
 * If we find the bindings of ?axioms and the values of these bindings have some rdf:type triples, we proceed. (If not, we discard).
 * The bindings of the query gpad-relation-evidence-multiple.rq are then used for filling up fields in GPAD records/tuples.
 */
private Map<Triple, Set<GPADEvidence>> evidencesForFacts(Set<Triple> facts, Model model, String modelID) {
	Query query = QueryFactory.create(multipleEvidenceQuery);
	Var subject = Var.alloc("subject");
	Var predicate = Var.alloc("predicate");
	Var object = Var.alloc("object");
	List<Var> variables = new ArrayList<>();
	variables.add(subject);
	variables.add(predicate);
	variables.add(object);
	Stream<Binding> bindings = facts.stream().map(f -> createBinding(Pair.of(subject, f.getSubject()), Pair.of(predicate, f.getPredicate()), Pair.of(object, f.getObject())));
	query.setValuesDataBlock(variables, bindings.collect(Collectors.toList()));
	QueryExecution evidenceExecution = QueryExecutionFactory.create(query, model);
	ResultSet evidenceResults = evidenceExecution.execSelect();
	Map<Triple, Set<GPADEvidence>> allEvidences = facts.stream().collect(Collectors.toMap(Function.identity(), f -> new HashSet<GPADEvidence>()));
	while (evidenceResults.hasNext()) {
		QuerySolution eqs = evidenceResults.next();
		if (eqs.get("evidence_type") != null) {
			Triple statement = Triple.create(eqs.getResource("subject").asNode(), eqs.getResource("predicate").asNode(), eqs.getResource("object").asNode());
			IRI evidenceType = IRI.create(eqs.getResource("evidence_type").getURI());
			Optional<String> with = Optional.ofNullable(eqs.getLiteral("with")).map(l -> l.getLexicalForm());
			Set<Pair<String, String>> annotationAnnotations = new HashSet<>();
			annotationAnnotations.add(Pair.of("noctua-model-id", modelID));
			annotationAnnotations.addAll(getContributors(eqs).stream().map(c -> Pair.of("contributor", c)).collect(Collectors.toSet()));
			String date = eqs.getLiteral("date").getLexicalForm();
			String reference = eqs.getLiteral("source").getLexicalForm();
			allEvidences.get(statement).add(new GPADEvidence(evidenceType, reference, with, date, "GO_Noctua", annotationAnnotations, Optional.empty()));
		}
	}
	evidenceExecution.close();
	return allEvidences;
}
 
开发者ID:geneontology,项目名称:minerva,代码行数:47,代码来源:GPADSPARQLExport.java

示例14: queryService

import org.apache.jena.query.QueryExecution; //导入方法依赖的package包/类
/**
 * 
 * @param service
 * @param sparqlQueryString
 * @param solutionConcept
 *            the target concept to extract from the query, tye name should
 *            be the same as the name of the target variable in
 *            sparqlQueryString
 * @return the set of string from literal results
 */
public Set<String> queryService(String service, String sparqlQueryString,
		String solutionConcept) {
	Set<String> resulStrings = new HashSet<String>();

	Query query = QueryFactory.create(sparqlQueryString);

	QueryExecution qexec = QueryExecutionFactory.sparqlService(service,
			query);

	try {
		ResultSet results = qexec.execSelect();

		for (; results.hasNext();) {
			QuerySolution soln = results.nextSolution();

			Literal l;
			try {
				if (soln.get(solutionConcept).isLiteral()) {
					l = soln.getLiteral(solutionConcept);
					resulStrings.add(l.getString());
				} else {
					RDFNode u = soln.get(solutionConcept);
					resulStrings.add(u.toString());
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	} finally {
		qexec.close();
	}
	return resulStrings;
}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:45,代码来源:GenerateNameGraph.java

示例15: createNodes

import org.apache.jena.query.QueryExecution; //导入方法依赖的package包/类
public static Node createNodes(CsvTupler aCsvTupler, List<List<String>> csvRows, Model model, String query){

      try {
        // the query must have '?node' as a result
        if(model == null || query == null){
           return null;
        }		

        Query qry = QueryFactory.create(query);
        QueryExecution qe = QueryExecutionFactory.create(qry, model);
        ResultSet rs = qe.execSelect();

        List<Node> nodes = new ArrayList<Node>();

        while (rs.hasNext())
        {
            QuerySolution sol = rs.nextSolution();
            Resource res = sol.getResource("node");
            if (res.getProperty(RDF.type).getObject().asResource().getLocalName().equals("Node")) {
              nodes.add(new Node(aCsvTupler, csvRows, model, res));
            }
            else {
              System.out.println(res.getProperty(RDF.type).getObject().asResource().getURI());
              System.out.println(res.getProperty(RDF.type).getObject().asResource().getLocalName());
              return null;
            }
        }

        qe.close();

        Node root = buildTree(model, nodes);
        aCsvTupler.setNodes(nodes);
        if (setOffsets(root) == false)
          throw new Exception("Can't set row and columns offsets");

        if (setOffsetsRelativeTo(root) == false)
          throw new Exception("Can't set relative row and columns offsets");        

        return root;
        
      } catch (Exception e) {
        System.out.println(e);
        return null;
      }
    }
 
开发者ID:tag42git,项目名称:CsvTupler,代码行数:46,代码来源:NodeFactory.java


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