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


Java QueryFactory.create方法代码示例

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


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

示例1: getLabel

import org.apache.jena.query.QueryFactory; //导入方法依赖的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

示例2: getCount

import org.apache.jena.query.QueryFactory; //导入方法依赖的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.QueryFactory; //导入方法依赖的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: LocationMapperAccept

import org.apache.jena.query.QueryFactory; //导入方法依赖的package包/类
public LocationMapperAccept(final Model configurationModel) {
    Query q = QueryFactory.create("PREFIX lm: <http://jena.hpl.hp.com/2004/08/location-mapping#>"
            + "SELECT * WHERE {"
            + "[] lm:mapping ?e ."
            + "?e lm:name ?name ; lm:altName ?alt ."
            + "OPTIONAL { ?e lm:media ?media . } "
            + "}");
    QueryExecutionFactory.create(q, configurationModel).execSelect().forEachRemaining((result) -> {
        String name = null, altName = null, media = null;
        try {
            name = result.getLiteral("name").getString();
            altName = result.getLiteral("alt").getString();
            media = (result.getLiteral("media") == null ? null : result.getLiteral("media").getString());
            altLocations.put(new LookUpRequest(name, media), new LookUpRequest(altName, media));
        } catch (Exception ex) {
            log.warn("Error while reading mapping in configuration model for name " + name + ", alt " + altName + ", media " + media,ex);
        }
    });
}
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:20,代码来源:LocationMapperAccept.java

示例5: testBaseUri

import org.apache.jena.query.QueryFactory; //导入方法依赖的package包/类
@Test
public void testBaseUri() {

    MarkLogicDatasetGraph baseTest = getMarkLogicDatasetGraph();
    Dataset ds = DatasetFactory.wrap(baseTest);
    String query = "select ?o where { <r3> a ?o }";
    QueryExecution exec = QueryExecutionFactory.create(query, ds);
    ResultSet results = exec.execSelect();
    List<String> subjects = project(results, "o");
    assertEquals("No base, got back list of size 0", 0, subjects.size());

    Query q = QueryFactory.create(query, "http://example.org/");
    exec = QueryExecutionFactory.create(q, ds);
    results = exec.execSelect();
    subjects = project(results, "o");
    assertEquals("No base, got back list of size 1", 1, subjects.size());

}
 
开发者ID:marklogic,项目名称:marklogic-jena,代码行数:19,代码来源:MarkLogicQueryEngineTest.java

示例6: fixOntModel

import org.apache.jena.query.QueryFactory; //导入方法依赖的package包/类
public OntModel fixOntModel(OntModel ontModel)
    {
        if (ontModel == null) throw new IllegalArgumentException("Model cannot be null");
        
        OntModel fixedModel = ModelFactory.createOntologyModel(ontModel.getSpecification());
        Query fix = QueryFactory.create("CONSTRUCT\n" +
"{\n" +
"  ?s ?p ?o\n" +
"}\n" +
"WHERE\n" +
"{\n" +
"  ?s ?p ?o\n" +
"  FILTER (!(?p = <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> && ?o = <https://www.w3.org/ns/ldt#Constraint>))\n" +
"}");
        
        try (QueryExecution qex = QueryExecutionFactory.create(fix, ontModel))
        {
            fixedModel.add(qex.execConstruct());
        }
        
        return fixedModel;
    }
 
开发者ID:AtomGraph,项目名称:Processor,代码行数:23,代码来源:Validator.java

示例7: queryExecution

import org.apache.jena.query.QueryFactory; //导入方法依赖的package包/类
/**
 * creates a new object of QueryExecution
 * @param query query
 * @param graph graph
 * @param endpoint endpoint
 * @param model model
 * @return QueryExecution object
 */
public static QueryExecution queryExecution(String query, String graph, String endpoint, Model model) {
    ARQ.setNormalMode();
    Query sparqlQuery = QueryFactory.create(query, Syntax.syntaxARQ);
    QueryExecution qexec;

    // take care of graph issues. Only takes one graph. Seems like some sparql endpoint do
    // not like the FROM option.
    // it is important to
    if (model == null) {
        if (graph != null) {
            qexec = QueryExecutionFactory.sparqlService(endpoint, sparqlQuery, graph);
        } //
        else {
            qexec = QueryExecutionFactory.sparqlService(endpoint, sparqlQuery);
        }
    } else {
        logger.info("Query to Model...");
        qexec = QueryExecutionFactory.create(sparqlQuery, model);
    }

    return qexec;
}
 
开发者ID:dice-group,项目名称:LIMES,代码行数:31,代码来源:SPARQLHelper.java

示例8: addRolesFromModel

import org.apache.jena.query.QueryFactory; //导入方法依赖的package包/类
public void addRolesFromModel(Model model){
	String sparql = "PREFIX swc: <http://data.semanticweb.org/ns/swc/ontology#> "
			+ "SELECT ?role ?roletype "
			+ "WHERE{?role a swc:Chair . ?role a ?roletype . filter(?roletype != swc:Chair)}";
	Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
	QueryExecution queryExecution = QueryExecutionFactory.create(query, model);
	ResultSet resultSet = queryExecution.execSelect();
	
	Model tmp = ModelFactory.createDefaultModel();
	while(resultSet.hasNext()){
		QuerySolution querySolution = resultSet.next();
		Resource role = querySolution.getResource("role");
		Resource roleType = querySolution.getResource("roletype");
		tmp.add(role, RDF.type, roleType);
	}
	
	
	
	//ResultSetFormatter.out(System.out, resultSet);
	
}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:22,代码来源:RoleKB.java

示例9: create

import org.apache.jena.query.QueryFactory; //导入方法依赖的package包/类
public void create(Model model) {

		Property id = model
				.createProperty("http://www.ontologydesignpatterns.org/ont/eswc/ontology.owl#eswcId");

		String sparql = "SELECT ?person " + "WHERE{?person a <" + FOAF.Person
				+ ">}";
		Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
		QueryExecution queryExecution = QueryExecutionFactory.create(query,
				model);

		ResultSet resultSet = queryExecution.execSelect();
		for (int i = 1; resultSet.hasNext(); i++) {
			QuerySolution solution = resultSet.next();
			Resource person = solution.getResource("person");
			person.addLiteral(id,
					model.createTypedLiteral(i, XSDDatatype.XSDpositiveInteger));
		}
	}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:20,代码来源:AppIDCreator.java

示例10: getClasses

import org.apache.jena.query.QueryFactory; //导入方法依赖的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

示例11: getDepictionList

import org.apache.jena.query.QueryFactory; //导入方法依赖的package包/类
protected Set<String> getDepictionList(Model model) {

		Set<String> depictions = new HashSet<String>();
		String sparql = "PREFIX foaf: <" + FOAF.NS + "> "
				+ "SELECT ?depiction "
				+ "WHERE{?author foaf:depiction ?depiction}";

		Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
		QueryExecution queryExecution = QueryExecutionFactory.create(query,
				model);
		ResultSet resultSet = queryExecution.execSelect();

		while (resultSet.hasNext()) {
			depictions.add(resultSet.next().get("depiction").toString());
		}

		return depictions;
	}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:19,代码来源:DepictionGraphBuilder.java

示例12: getPublicModel

import org.apache.jena.query.QueryFactory; //导入方法依赖的package包/类
public Model getPublicModel() {
	String sparql = "PREFIX voting: <" + VotingSystemData.VOTE_NS + "> "
			+ "CONSTRUCT { " + "?x a voting:Vote . "
			+ "?x voting:sha1sum ?sha1sum . "
			+ "?paper a voting:EligibleForVotingPaper . "
			+ "?paper voting:paperOfTrack ?track . " 
			+ "?paper voting:id ?id . "
			+ "?paper <" + DC_11.title.getURI() + "> ?title " 
			+ "} " 
			+ "WHERE{ "
			+ "?x a voting:Vote . " + "?x voting:sha1sum ?sha1sum . "
			+ "?paper a voting:EligibleForVotingPaper . "
			+ "?paper voting:paperOfTrack ?track . "
			+ "?paper voting:id ?id . "
			+ "?paper <" + DC_11.title.getURI() + "> ?title "
			+ "}";
	Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
	QueryExecution queryExecution = QueryExecutionFactory.create(query,
			adminModel);
	return queryExecution.execConstruct();
}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:22,代码来源:VoteModel.java

示例13: getProperties

import org.apache.jena.query.QueryFactory; //导入方法依赖的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

示例14: getSenseLabel

import org.apache.jena.query.QueryFactory; //导入方法依赖的package包/类
@Override
public String getSenseLabel(QName ref) {
	ParameterizedSparqlString stmt = new ParameterizedSparqlString(
			"SELECT ?word WHERE {\n"
			+ "?sense wordnet-ontology:synset_member ?word\n"
			+ "}", model);
	stmt.setIri("sense", this.asRef(ref));
	final String sparql = stmt.toString();
	log.trace("getSenseLabel SPARQL: {}", sparql);
	Query verbTxQuery = QueryFactory.create(sparql);
	QueryExecution qexec = QueryExecutionFactory.create(verbTxQuery, wn31tdb);
	try {
		ResultSet rs = qexec.execSelect();
		for (; rs.hasNext(); ) {
			QuerySolution soln = rs.next();
			String wordLocalName = soln.get("word").asResource().getLocalName();
			return wordLocalName;
		}
		log.warn("No wordnet-ontology:synset_member for sense " + ref);
		return shortQName(ref);
	} finally {
		qexec.close();
	}
}
 
开发者ID:lumenrobot,项目名称:relex-id,代码行数:25,代码来源:RelEx.java

示例15: getSenseRdfsLabel

import org.apache.jena.query.QueryFactory; //导入方法依赖的package包/类
public String getSenseRdfsLabel(QName ref) {
	ParameterizedSparqlString stmt = new ParameterizedSparqlString(
			"SELECT ?label WHERE {\n"
			+ "?sense rdfs:label ?label\n"
			+ "}", model);
	stmt.setIri("sense", this.asRef(ref));
	final String sparql = stmt.toString();
	log.trace("getSenseLabel SPARQL: {}", sparql);
	Query verbTxQuery = QueryFactory.create(sparql);
	QueryExecution qexec = QueryExecutionFactory.create(verbTxQuery, wn31tdb);
	try {
		ResultSet rs = qexec.execSelect();
		for (; rs.hasNext(); ) {
			QuerySolution soln = rs.next();
			String translation = soln.get("label").asLiteral().getString();
			return translation;
		}
		log.warn("No rdfs:label for sense " + ref);
		return shortQName(ref);
	} finally {
		qexec.close();
	}
}
 
开发者ID:lumenrobot,项目名称:relex-id,代码行数:24,代码来源:RelEx.java


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