[英]How to view SPARQL query result as JSON objects?
我想將SPARQL查詢結果作為JSON對象查看。 例如,我有一個RDF數據庫,其中有父母圖,其中包括孩子,親戚及其信息。 有沒有辦法將它們視為JSON對象,例如
"Parents": {
"names": "some names"
"children":[
{"child1": {
"name": name
}}
]
.....
}
我該如何實現? 歡迎所有建議。 謝謝
SPARQL提供“ application / sparql-results + json”作為其文檔內容類型,用於查詢解決方案,以供理解JSON的應用程序使用。
最近,我開始意識到SPARQL的這一方面已被普遍理解,從而為使用支持JSON作為結構化數據的默認內容類型的工具的“ Web開發人員”造成了人為的摩擦。
無論如何,我們最近發布了一個基於HTML5,CSS和Javascript的單頁應用程序,該示例演示了在使用SPARQL的“ application / results + json”查詢解決方案內容類型時可以實現的功能。 當然,它還提供了一種解決方案,用於了解如何處理從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) ;
}
}
鏈接
“看似簡單”的數據輸入表單 -這也是View-Source友好的形式。 驅動應用的所有代碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.