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


Java QueryExecutionFactory类代码示例

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


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

示例1: listVocabularies

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

import org.apache.jena.query.QueryExecutionFactory; //导入依赖的package包/类
public static List<String> listThingDescriptions(String query) {
List<String> tds = new ArrayList<>();
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);

try {
  String q = "SELECT DISTINCT ?g WHERE { GRAPH ?g { " + query + " FILTER NOT EXISTS { ?ontology a <http://www.w3.org/2002/07/owl#Ontology> } } }";
  try (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,代码行数:23,代码来源:ThingDescriptionUtils.java

示例5: getThingDescriptionIdFromUri

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

示例6: listThingDescriptionsUri

import org.apache.jena.query.QueryExecutionFactory; //导入依赖的package包/类
/**
  * Returns a list of the thing descriptions URIs.
  * @return a list of URIs stored in the database.
  */
 public static List<String> listThingDescriptionsUri() {

List<String> tds = new ArrayList<>();
String query = "?td <http://iot.linkeddata.es/def/wot#baseURI> ?uri";
  
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);

try {
  String q = "SELECT ?uri WHERE { GRAPH ?g_id { " + query + " }}";
  try (QueryExecution qexec = QueryExecutionFactory.create(q, dataset)) {
	ResultSet result = qexec.execSelect();
	while (result.hasNext()) { 
	tds.add(result.next().get("uri").toString());
	}
  }
catch (Exception e) {
  throw e;
}
} finally {
  dataset.end();
}

return tds;
 }
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:30,代码来源:ThingDescriptionUtils.java

示例7: getProperties

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

示例8: runSelectQuery

import org.apache.jena.query.QueryExecutionFactory; //导入依赖的package包/类
static ResultSet runSelectQuery(String queryString, String service, String... defaultGraphs) throws Exception {
    QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(service, queryString);
    qExec.addDefaultGraph(Constants.DBPEDIA_URL);
    if (defaultGraphs != null) {
        for (String defaultGraph : defaultGraphs) {
            qExec.addDefaultGraph(defaultGraph);
        }
    }
    qExec.addParam("timeout", Constants.TIMEOUT_VALUE); //100 sec
    ResultSet set = null;
    try {
        set = qExec.execSelect();
        set = ResultSetFactory.copyResults(set);
    } catch (Exception e) {
        QGenLogger.severe("Exception in SELECT\n" + queryString + "\n" + e.getMessage());
    } finally {
        qExec.close();
    }
    return set;
}
 
开发者ID:slidewiki,项目名称:auto-questions-service,代码行数:21,代码来源:SPARQLClient.java

示例9: getCount

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

示例10: queryData

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

示例11: LocationMapperAccept

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

示例12: testSelect

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

示例13: testRulesets

import org.apache.jena.query.QueryExecutionFactory; //导入依赖的package包/类
@Test
public void testRulesets() {
    MarkLogicDatasetGraph infTestDsg = getMarkLogicDatasetGraph();
    Dataset ds = DatasetFactory.wrap(infTestDsg);
    String query = "prefix : <http://example.org/> select ?o where { :r3 a ?o }";
    QueryExecution exec = QueryExecutionFactory.create(query, ds);
    ResultSet results = exec.execSelect();

    List<String> subjects = project(results, "o");
    assertEquals("No inference, got back list of size 1", 1,
            subjects.size());

    infTestDsg.withRulesets(SPARQLRuleset.RDFS);
    // MarkLogicQuery inferringQuery = MarkLogicQuery.create(query);
    // inferringQuery.setRulesets(SPARQLRuleset.RDFS);
    exec = QueryExecutionFactory.create(query, ds);
    results = exec.execSelect();
    subjects = project(results, "o");
    System.out.println(subjects);
    assertEquals("Using RDFs got back two class assertions", 2,
            subjects.size());

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

示例14: testBaseUri

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

示例15: testUpdateAction

import org.apache.jena.query.QueryExecutionFactory; //导入依赖的package包/类
@Test
public void testUpdateAction() {
    DatasetGraph gs = getMarkLogicDatasetGraph();
    UpdateRequest update = new UpdateRequest();
    update.add("INSERT DATA { <s2> <p1> <o1> }");
    update.add("DROP ALL")
            .add("CREATE GRAPH <http://example/update1>")
            .add("BASE <http://example.org/> INSERT DATA { GRAPH <http://example.org/update2> { <s1> <p1> <o1>  } }")
            .add("BASE <http://example.org/> INSERT DATA { GRAPH <http://example.org/update3> { <s1> <p1> <o1>  } }");

    UpdateAction.execute(update, gs);

    QueryExecution askQuery = QueryExecutionFactory
            .create("BASE <http://example.org/> ASK WHERE { GRAPH <update3> { <s1> <p1> <o1>  }}",
                    DatasetFactory.wrap(gs));
    assertTrue("update action must update database.", askQuery.execAsk());

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


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