select: [ "s" ], where: [ { pattern: [ "?s", "?p", "?o" ] } ] var elPanel = document.getElementById("panel"); var elTree = document.getElementById("tree"); var elTable = document.getElementById("table"); var tree, table, ds; var rootNode; var tmpNode; var mode = "tree"; var subject = ${s}, predicate, object; if (!elPanel) { elPanel = document.createElement("div"); elPanel.setAttribute("id", "panel"); elPanel.setAttribute("style", "padding:0; margin:0; background-color: #30353C; opacity: 0.9; position: fixed; left: 0; bottom: 0; width: 100%;"); document.body.appendChild(elPanel); } if (!elTable) { elTable = document.createElement("div"); elTable.setAttribute("id", "table"); elPanel.appendChild(elTable); } if (!elTree) { elTree = document.createElement("div"); elTree.setAttribute("id", "tree"); elPanel.appendChild(elTree); } if (mode === "table") { if (elTable["table"]) { table = elTable.table; } else { YAHOO.util.Dom.addClass(document.body, "yui-skin-sam"); ds = new YAHOO.util.LocalDataSource([ ]); ds.responseType = YAHOO.util.XHRDataSource.TYPE_JSARRAY; ds.responseSchema = {fields:["subject", "predicate", "object"]}; table = new YAHOO.widget.DataTable( "table", [ {key:"subject", width: 300, sortable:true, resizeable:true}, {key:"predicate", width: 300, sortable:true, resizeable:true}, {key:"object", sortable:true, resizeable:true} ], ds, {scrollable:true, height:"10em"} ); elTable.table = table; } } if (mode === "tree") { if (elTree["tree"]) { tree = elTree.tree; } else { tree = new YAHOO.widget.TreeView("tree"); elTree.tree = tree; } //get a reference to the root node; all //top level nodes are children of the root node: rootNode = tree.getRoot(); //begin adding children var tmpNode = new YAHOO.widget.TextNode(subject, tree.getRoot(), false); //the tree won't show up until you draw (render) it: tree.draw(); } /* * For each subject we get all of the triples associated with it. */ var properties = document.meta.query2({ select: [ "p", "o" ], where: [ { pattern: [ subject, "?p", "?o" ] } ] }); /* * Once again we walk the results, and this time output each triple. */ document.meta.walk2( properties, { action: function(obj) { predicate = "<" + ${p} + ">"; var predAndObj = "<" + ${p} + "> "; if (${o}) { if (${o.content}) { object = "\"" + ${o.content} + "\""; if (${o.datatype}) { object += "^^" + ${o.datatype}; } } else { object = "<" + ${o} + ">"; if (${p} === "http://www.w3.org/1999/02/22-rdf-syntax-ns#type") { if (${o} === "http://xmlns.com/foaf/0.1/Person") { if (mode === "tree") { tmpNode.labelStyle = "foaf-person"; } } } } } if (mode === "tree") { new YAHOO.widget.TextNode(predicate + " " + object, tmpNode, false); } if (mode === "table") { table.addRow({ subject: subject, predicate: predicate, object: object }); } } } );