如何查看SPARQL查询结果为JSON objects?
How to view SPARQL query result as JSON objects?
我想查看 SPARQL 查询结果 JSON objects。例如,我有一个 RDF 数据库,其中有 parents 图,其中包括 children、亲属及其信息。有没有办法将它们视为 JSON objects like
"Parents": {
"names": "some names"
"children":[
{"child1": {
"name": name
}}
]
.....
}
我怎样才能做到这一点?欢迎所有建议。谢谢
SPARQL 提供 "application/sparql-results+json" 作为查询解决方案的文档内容类型,供理解 JSON 的应用程序使用。
最近,我开始意识到 SPARQL 的这一方面已被普遍理解,从而为使用支持 JSON 作为默认内容类型的工具的 "Web Developers" 制造了人为的摩擦结构化数据。
无论如何,我们最近发布了一个基于 HTML5、CSS 和 Javascript 的单页应用程序,它展示了当您将其 "application/results+json" 查询解决方案放入 SPARQL 时的可能性要使用的内容类型。当然,它也提供了一个解决方案,用于理解如何处理从 SPARQL 返回的 JSON。
表单的工作原理。
关于 JSON 对象处理的代码片段
/*
Dynamic Table for processing JSON Structured Data (via "application/sparql-results+json" document content type)
that enables INSERT to be handled via a 3-tuple subject, predicate, object graph (relation) while query results
are handled via an N-Tuple structured table (relation).
*/
if (data.results.bindings.length > 0){
var table = tabCheckTable("dbmsTableID", "fsTableID") ; // creates table for header
var header = table.createTHead(); // creates empty tHead
var headRow = header.insertRow(0); // inserts row into tHead
var bindings = data.results.bindings;
for (var col = 0; col < data.head.vars.length; col++) { // for each column
// console.log("col = " + col)
var headCell = headRow.insertCell(col); // inserts new cell at position i in thead
headCell.innerHTML = "<b>" + data.head.vars[col] + "</b>"; // adds bold text to thead cell
}
for (i in bindings) {
// console.log("i = " + i)
var curr = 0 ; // curr is used to keep track of correct cell position
var binding = bindings[i];
var bodyRow = table.insertRow(-1); // create new row
for (n in binding) {
// console.log("n = " + n)
// console.log("curr = " + curr)
var bodyCell = bodyRow.insertCell(curr); // create new cell in row
bodyCell.innerHTML = tableFormat(binding[n].value); // set value of cell
curr += 1 ;
}
}
}
else{
throw new Error("No Data Returned");
console.log("No data returned by query");
}
})
} catch(e) {
console.error('Query Failed:', e) ;
}
}
链接
"Deceptively Simple" Data Entry Form -- 这也是 View-Source 友好的。驱动应用程序的所有代码
我想查看 SPARQL 查询结果 JSON objects。例如,我有一个 RDF 数据库,其中有 parents 图,其中包括 children、亲属及其信息。有没有办法将它们视为 JSON objects like
"Parents": {
"names": "some names"
"children":[
{"child1": {
"name": name
}}
]
.....
}
我怎样才能做到这一点?欢迎所有建议。谢谢
SPARQL 提供 "application/sparql-results+json" 作为查询解决方案的文档内容类型,供理解 JSON 的应用程序使用。
最近,我开始意识到 SPARQL 的这一方面已被普遍理解,从而为使用支持 JSON 作为默认内容类型的工具的 "Web Developers" 制造了人为的摩擦结构化数据。
无论如何,我们最近发布了一个基于 HTML5、CSS 和 Javascript 的单页应用程序,它展示了当您将其 "application/results+json" 查询解决方案放入 SPARQL 时的可能性要使用的内容类型。当然,它也提供了一个解决方案,用于理解如何处理从 SPARQL 返回的 JSON。
表单的工作原理。
关于 JSON 对象处理的代码片段
/*
Dynamic Table for processing JSON Structured Data (via "application/sparql-results+json" document content type)
that enables INSERT to be handled via a 3-tuple subject, predicate, object graph (relation) while query results
are handled via an N-Tuple structured table (relation).
*/
if (data.results.bindings.length > 0){
var table = tabCheckTable("dbmsTableID", "fsTableID") ; // creates table for header
var header = table.createTHead(); // creates empty tHead
var headRow = header.insertRow(0); // inserts row into tHead
var bindings = data.results.bindings;
for (var col = 0; col < data.head.vars.length; col++) { // for each column
// console.log("col = " + col)
var headCell = headRow.insertCell(col); // inserts new cell at position i in thead
headCell.innerHTML = "<b>" + data.head.vars[col] + "</b>"; // adds bold text to thead cell
}
for (i in bindings) {
// console.log("i = " + i)
var curr = 0 ; // curr is used to keep track of correct cell position
var binding = bindings[i];
var bodyRow = table.insertRow(-1); // create new row
for (n in binding) {
// console.log("n = " + n)
// console.log("curr = " + curr)
var bodyCell = bodyRow.insertCell(curr); // create new cell in row
bodyCell.innerHTML = tableFormat(binding[n].value); // set value of cell
curr += 1 ;
}
}
}
else{
throw new Error("No Data Returned");
console.log("No data returned by query");
}
})
} catch(e) {
console.error('Query Failed:', e) ;
}
}
链接
"Deceptively Simple" Data Entry Form -- 这也是 View-Source 友好的。驱动应用程序的所有代码