本文整理汇总了Java中com.hp.hpl.jena.query.Query类的典型用法代码示例。如果您正苦于以下问题:Java Query类的具体用法?Java Query怎么用?Java Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Query类属于com.hp.hpl.jena.query包,在下文中一共展示了Query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkContainment
import com.hp.hpl.jena.query.Query; //导入依赖的package包/类
public static boolean checkContainment(CompanyModel c){
String queryString =
"ASK" +
// check whether any manager is an employee in any other department
"{?dept1" + " <" + c.MANAGER + "> " + "?manager" + ". " +
" ?dept2" + " <" + c.EMPLOYEES + "> " + "?employees1" + ". " +
" ?employees1" + " <" + RDFS.member + "> " + "?employee1" + ". " +
" FILTER (?manager = ?employee1) " +
// check whether any employee occurs more than once
" ?dept3 " + " <" + c.EMPLOYEES + "> " + "?employees2" + ". " +
" ?employees2" + " <" + RDFS.member + "> " + "?employee2" + ". " +
" FILTER (?employee1 = ?employee2)" +
// check whether any department occurs more than once
" ?upperDept1" + " <" + c.DEPTS + "> " + "?dept4" + ". " +
" ?upperDept2" + " <" + c.DEPTS + "> " + "?dept5" + ". " +
" FILTER (?dept4 = ?dept5) " +
"}";
Query query = QueryFactory.create(queryString);
QueryExecution qe = QueryExecutionFactory.create(query, c.getModel());
boolean out = qe.execAsk();
qe.close();
return !out;
}
示例2: expandSubClasses
import com.hp.hpl.jena.query.Query; //导入依赖的package包/类
private List<Statement> expandSubClasses(Model model){
List<Statement> stmts = new ArrayList<Statement>();
String sparql = "PREFIX rdfs: <" + RDFS.getURI() + ">"
+ "SELECT DISTINCT ?class ?synonym "
+ "WHERE { "
+ "?class rdfs:subClassOf+ ?subClass . "
+ "?subClass <" + synonym + "> ?synonym"
+ "}";
Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
QueryExecution queryExecution = QueryExecutionFactory.create(query, model);
ResultSet resultSet = queryExecution.execSelect();
resultSet.forEachRemaining(querySolution -> {
stmts.add(new StatementImpl(querySolution.getResource("class"), synonym, querySolution.getLiteral("synonym")));
});
return stmts;
}
示例3: expandSubProperties
import com.hp.hpl.jena.query.Query; //导入依赖的package包/类
private List<Statement> expandSubProperties(Model model){
List<Statement> stmts = new ArrayList<Statement>();
String sparql = "PREFIX rdfs: <" + RDFS.getURI() + ">"
+ "SELECT DISTINCT ?property ?synonym "
+ "WHERE { "
+ "?property rdfs:subPropertyOf+ ?subProperty . "
+ "?subProperty <" + synonym + "> ?synonym"
+ "}";
Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
QueryExecution queryExecution = QueryExecutionFactory.create(query, model);
ResultSet resultSet = queryExecution.execSelect();
resultSet.forEachRemaining(querySolution -> {
stmts.add(new StatementImpl(querySolution.getResource("property"), synonym, querySolution.getLiteral("synonym")));
});
return stmts;
}
示例4: getOrderArg
import com.hp.hpl.jena.query.Query; //导入依赖的package包/类
private String getOrderArg(SortCondition condition) {
String orderArg = condition.getExpression().getVarName();
int direction = condition.getDirection();
switch(direction) {
case Query.ORDER_ASCENDING: {
orderArg += " ASC";
break;
}
case Query.ORDER_DESCENDING: {
orderArg += " DESC";
break;
}
case Query.ORDER_DEFAULT: {
break;
}
}
return orderArg;
}
示例5: main
import com.hp.hpl.jena.query.Query; //导入依赖的package包/类
public static void main(String[] args) {
ModelD2RQ m = new ModelD2RQ("file:doc/example/mapping-iswc.ttl");
String sparql =
"PREFIX dc: <http://purl.org/dc/elements/1.1/>" +
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>" +
"SELECT ?paperTitle ?authorName WHERE {" +
" ?paper dc:title ?paperTitle . " +
" ?paper dc:creator ?author ." +
" ?author foaf:name ?authorName ." +
"}";
Query q = QueryFactory.create(sparql);
ResultSet rs = QueryExecutionFactory.create(q, m).execSelect();
while (rs.hasNext()) {
QuerySolution row = rs.nextSolution();
System.out.println("Title: " + row.getLiteral("paperTitle").getString());
System.out.println("Author: " + row.getLiteral("authorName").getString());
}
m.close();
}
示例6: loadAllQueries
import com.hp.hpl.jena.query.Query; //导入依赖的package包/类
private List<Query> loadAllQueries() throws IOException
{
File queryDir;
File[] files;
List<Query> queries;
queries = new ArrayList<Query>();
queryDir = new File(CURR_DIR + "/" + QUERY_DIR);
files = queryDir.listFiles();
Arrays.sort(files);
for(int i = 0; i < files.length; i++)
{
readRecursiveAndCreateQuery(files[i], queries);
}
return queries;
}
示例7: getTypesFromSPARQL
import com.hp.hpl.jena.query.Query; //导入依赖的package包/类
private Set<String> getTypesFromSPARQL(String sparqlQueryString) {
Query query = QueryFactory.create(sparqlQueryString);
QueryExecution qexec = QueryExecutionFactory.sparqlService(this.endpoint, query);
Set<String> types = new HashSet<>();
ResultSet results = qexec.execSelect();
while(results.hasNext()) {
QuerySolution qs = results.next();
Resource type = qs.getResource("?type");
types.add(type.getURI());
}
qexec.close();
return types;
}
示例8: runQueryButtonActionPerformed
import com.hp.hpl.jena.query.Query; //导入依赖的package包/类
private void runQueryButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_runQueryButtonActionPerformed
List<String> lines = null;
try {
lines = Files.readAllLines(queryPath);
} catch (IOException ex) {
Logger.getLogger(Ontogui.class.getName()).log(Level.SEVERE, null,
ex);
}
String queryString = "";
for (String line : lines) {
queryString += line + System.lineSeparator();
}
Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
queryResultArea.setText("Starting query: "
+ queryPath.toFile().getName() + "\n");
Thread t = new Thread(new QueryProcessor(query, new QueryAreaStream(
queryResultArea), dataset, checkbox1.getState()));
t.start();
}
示例9: runSmellAnalysisButtonActionPerformed
import com.hp.hpl.jena.query.Query; //导入依赖的package包/类
private void runSmellAnalysisButtonActionPerformed(
java.awt.event.ActionEvent evt) {// GEN-FIRST:event_runSmellAnalysisButtonActionPerformed
String filename = smellName;
File smellFile = new File(System.getProperty("user.dir")
+ "/sparql/smells/" + filename.replaceAll(" ", "") + ".sparql");
List<String> lines = null;
try {
lines = Files.readAllLines(smellFile.toPath());
} catch (IOException ex) {
Logger.getLogger(Ontogui.class.getName()).log(Level.SEVERE, null,
ex);
}
String queryString = "";
for (String line : lines) {
queryString += line + System.lineSeparator();
}
Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
queryResultArea.setText("Starting analysis: " + smellName + "\n");
Thread t = new Thread(new QueryProcessor(query, new QueryAreaStream(
queryResultArea), dataset, checkbox1.getState()));
t.start();
}
示例10: runMetricsButtonActionPerformed
import com.hp.hpl.jena.query.Query; //导入依赖的package包/类
private void runMetricsButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_runMetricsButtonActionPerformed
String folder = metricName.split(":")[0].toLowerCase();
String filename = metricName.split(":")[1];
File metricFile = new File(System.getProperty("user.dir")
+ "/sparql/metrics/" + folder + "/" + filename + ".sparql");
List<String> lines = null;
try {
lines = Files.readAllLines(metricFile.toPath());
} catch (IOException ex) {
Logger.getLogger(Ontogui.class.getName()).log(Level.SEVERE, null,
ex);
}
String queryString = "";
for (String line : lines) {
queryString += line + System.lineSeparator();
}
Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
queryResultArea.setText("Starting analysis:" + metricName + "\n");
System.err.println(checkbox1.isEnabled());
Thread t = new Thread(new QueryProcessor(query, new QueryAreaStream(
queryResultArea), dataset, checkbox1.getState()));
t.start();
}
示例11: testMetric_TotalBuilds
import com.hp.hpl.jena.query.Query; //导入依赖的package包/类
@Test
public void testMetric_TotalBuilds() {
Query query =
QueryFactory.
create(
loadResource("/metrics/total_builds.sparql"));
QueryExecution queryExecution = null;
try {
queryExecution = QueryExecutionFactory.create(query, buildsDataSet());
ResultSet results = queryExecution.execSelect();
for(; results.hasNext();) {
QuerySolution solution = results.nextSolution();
long buildId = solution.getLiteral("total_builds").getLong();
System.out.printf("Total builds: %d%n",buildId);
}
} finally {
if (queryExecution != null) {
queryExecution.close();
}
}
}
示例12: testMetric_TotalExecutions_Global
import com.hp.hpl.jena.query.Query; //导入依赖的package包/类
@Test
public void testMetric_TotalExecutions_Global() {
Query query =
QueryFactory.
create(
loadResource("/metrics/total_executions_global.sparql"));
QueryExecution queryExecution = null;
try {
queryExecution = QueryExecutionFactory.create(query, executionsDataSet());
ResultSet results = queryExecution.execSelect();
for(; results.hasNext();) {
QuerySolution solution = results.nextSolution();
long total_executions = solution.getLiteral("total_executions").getLong();
System.out.printf("Total executions: %d%n",total_executions);
}
} finally {
if (queryExecution != null) {
queryExecution.close();
}
}
}
示例13: testMetric_TotalExecutions_PerBuild
import com.hp.hpl.jena.query.Query; //导入依赖的package包/类
@Test
public void testMetric_TotalExecutions_PerBuild() {
Query query =
QueryFactory.
create(
loadResource("/metrics/total_executions_per_build.sparql"));
QueryExecution queryExecution = null;
try {
queryExecution = QueryExecutionFactory.create(query, executionsDataSet());
ResultSet results = queryExecution.execSelect();
for(; results.hasNext();) {
QuerySolution solution = results.nextSolution();
long total_executions = solution.getLiteral("total_executions").getLong();
String buildId = shorten(solution.getResource("build").getURI());
System.out.printf("Total executions of build %s: %d%n",buildId,total_executions);
}
} finally {
if (queryExecution != null) {
queryExecution.close();
}
}
}
示例14: testMetric_TotalSuccesfulExecutions_Global
import com.hp.hpl.jena.query.Query; //导入依赖的package包/类
@Test
public void testMetric_TotalSuccesfulExecutions_Global() {
Query query =
QueryFactory.
create(
loadResource("/metrics/total_succesful_executions_global.sparql"));
QueryExecution queryExecution = null;
try {
queryExecution = QueryExecutionFactory.create(query, executionsDataSet());
ResultSet results = queryExecution.execSelect();
for(; results.hasNext();) {
QuerySolution solution = results.nextSolution();
long total_executions = solution.getLiteral("total_executions").getLong();
System.out.printf("Total succesful executions: %d%n",total_executions);
}
} finally {
if (queryExecution != null) {
queryExecution.close();
}
}
}
示例15: testMetric_TotalSuccesfulExecutions_Global_Period
import com.hp.hpl.jena.query.Query; //导入依赖的package包/类
@Test
public void testMetric_TotalSuccesfulExecutions_Global_Period() {
Query query =
QueryFactory.
create(
loadResource("/metrics/total_succesful_executions_global_period.sparql"));
QueryExecution queryExecution = null;
try {
queryExecution = QueryExecutionFactory.create(query, executionsDataSet());
ResultSet results = queryExecution.execSelect();
for(; results.hasNext();) {
QuerySolution solution = results.nextSolution();
long total_executions = solution.getLiteral("total_executions").getLong();
String day = solution.getLiteral("day").getString();
System.out.printf("Total succesful executions [%s]: %d%n",day,total_executions);
}
} finally {
if (queryExecution != null) {
queryExecution.close();
}
}
}