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


Java QueryFactory类代码示例

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


QueryFactory类属于org.apache.jena.query包,在下文中一共展示了QueryFactory类的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: creatingAgentsFor

import org.apache.jena.query.QueryFactory; //导入依赖的package包/类
private static List<RDFNode> creatingAgentsFor(Resource r) {
	logger.fine("Finding creator of " + r);
	String queryStr = sparqlPrefixes + "SELECT ?agent WHERE { \n" + " { \n"
			+ "  ?r dct:creator [ \n" + "	    rdfs:member ?agent \n"
			+ "  ] \n" + " } UNION { \n" + "   ?r dct:creator ?agent .\n "
			+ "   FILTER NOT EXISTS { ?agent rdfs:member ?member } \n"
			+ " } \n" + "} \n";
	logger.finer(QueryFactory.create(queryStr).toString());
	QueryExecution qexec = QueryExecutionFactory.create(queryStr,
			r.getModel());
	QuerySolutionMap binding = new QuerySolutionMap();
	binding.add("r", r);
	qexec.setInitialBinding(binding);
	ResultSet select = qexec.execSelect();
	List<RDFNode> agents = new ArrayList<>();

	while (select.hasNext()) {
		RDFNode agent = select.next().get("agent");
		logger.fine("Found: " + agent);
		agents.add(agent);
	}
	return agents;
}
 
开发者ID:apache,项目名称:incubator-taverna-language,代码行数:24,代码来源:CombineManifest.java

示例8: mboxForAgent

import org.apache.jena.query.QueryFactory; //导入依赖的package包/类
private static Resource mboxForAgent(Resource agentResource) {
	logger.fine("Finding mbox of " + agentResource);
	String queryStr = sparqlPrefixes + "SELECT ?mbox WHERE { \n"
			+ "		{ ?agent foaf:mbox ?mbox } \n" + "	UNION  \n"
			+ "		{ ?agent vcard:hasEmail ?mbox } \n" + "	UNION  \n"
			+ "		{ ?agent vcard:email ?email .  \n"
			+ "       BIND(IRI(CONCAT(\"mbox:\", ?email)) AS ?mbox) \n" // legacy
			+ "	    } \n" + "} \n";
	logger.finer(QueryFactory.create(queryStr).toString());
	QueryExecution qexec = QueryExecutionFactory.create(queryStr,
			agentResource.getModel());
	QuerySolutionMap binding = new QuerySolutionMap();
	binding.add("agent", agentResource);
	qexec.setInitialBinding(binding);
	ResultSet select = qexec.execSelect();
	if (select.hasNext()) {
		Resource mbox = select.next().getResource("mbox");
		logger.fine("Found mbox: " + mbox);
		return mbox;
	}
	logger.fine("mbox not found");
	return null;
}
 
开发者ID:apache,项目名称:incubator-taverna-language,代码行数:24,代码来源:CombineManifest.java

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

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

示例11: getSummaries

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

示例12: list

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

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

示例14: buildRDF

import org.apache.jena.query.QueryFactory; //导入依赖的package包/类
@Override
public Model buildRDF(File directory) {
	Model modelout = ModelFactory.createDefaultModel();
	Model model = ModelFactory.createDefaultModel();

	try {
		model.read(new FileInputStream(directory), null, "RDF/XML");
	} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

	if (!model.isEmpty()) {
		String sparql = "PREFIX foaf: <" + FOAF.NS + "> "
				+ "CONSTRUCT {?author foaf:depiction ?depiction} "
				+ "WHERE{?author foaf:depiction ?depiction}";

		Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
		QueryExecution queryExecution = QueryExecutionFactory.create(query,
				model);
		modelout = queryExecution.execConstruct();
	}
	return modelout;
}
 
开发者ID:AnLiGentile,项目名称:cLODg,代码行数:25,代码来源:DepictionGraphBuilder.java

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


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