Skip to content

Commit

Permalink
Add graph column
Browse files Browse the repository at this point in the history
Also pins `levelgraph-jsonld` to the `feature/named-graphs` branch (for
now).
  • Loading branch information
BigBlueHat committed Apr 3, 2017
1 parent c04e5f3 commit cd69b86
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 35 deletions.
76 changes: 46 additions & 30 deletions dist/index.js
Expand Up @@ -40378,6 +40378,7 @@ function levelgraphJSONLD(db, jsonldOpts) {
}

jsonld.toRDF(expanded, options, function(err, triples) {

if (err || triples.length === 0) {
return callback(err, null);
}
Expand Down Expand Up @@ -40432,42 +40433,57 @@ function levelgraphJSONLD(db, jsonldOpts) {
}
});

triples['@default'].map(function(triple) {
Object.keys(triples).forEach(function(graph_key) {
var graph_name;

return ['subject', 'predicate', 'object'].reduce(function(acc, key) {
var node = triple[key];
// generate UUID to identify blank nodes
// uses type field set to 'blank node' by jsonld.js toRDF()
if (node.type === 'blank node') {
if (!blanks[node.value]) {
blanks[node.value] = '_:' + uuid.v1();
}
node.value = blanks[node.value];
}
// preserve object data types using double quotation for literals
// and don't keep data type for strings without defined language
if(key === 'object' && triple.object.datatype){
if(triple.object.datatype.match(XSDTYPE)){
if(triple.object.datatype === 'http://www.w3.org/2001/XMLSchema#string'){
node.value = '"' + triple.object.value + '"';
} else {
node.value = '"' + triple.object.value + '"^^' + triple.object.datatype;
}
} else if(triple.object.datatype.match(RDFLANGSTRING)){
node.value = '"' + triple.object.value + '"@' + triple.object.language;
var store_keys;
if (graph_key === '@default') {
// Do empty graph is @default for now.
store_keys = ['subject', 'predicate', 'object'];
} else {
store_keys = ['subject', 'predicate', 'object', 'graph'];
}

triples[graph_key].map(function(triple) {

return store_keys.reduce(function(acc, key) {
if(key === 'graph') {
acc[key] = graph_key;
} else {
node.value = '"' + triple.object.value + '"^^' + triple.object.datatype;
var node = triple[key];
// generate UUID to identify blank nodes
// uses type field set to 'blank node' by jsonld.js toRDF()
if (node.type === 'blank node') {
if (!blanks[node.value]) {
blanks[node.value] = '_:' + uuid.v1();
}
node.value = blanks[node.value];
}
// preserve object data types using double quotation for literals
// and don't keep data type for strings without defined language
if(key === 'object' && triple.object.datatype){
if(triple.object.datatype.match(XSDTYPE)){
if(triple.object.datatype === 'http://www.w3.org/2001/XMLSchema#string'){
node.value = '"' + triple.object.value + '"';
} else {
node.value = '"' + triple.object.value + '"^^' + triple.object.datatype;
}
} else if(triple.object.datatype.match(RDFLANGSTRING)){
node.value = '"' + triple.object.value + '"@' + triple.object.language;
} else {
node.value = '"' + triple.object.value + '"^^' + triple.object.datatype;
}
}
acc[key] = node.value;
}
}
acc[key] = node.value;
return acc;
}, {});
}).forEach(function(triple) {
stream.write(triple);
return acc;
}, {});
}).forEach(function(triple) {
stream.write(triple);
});
});
stream.end();
});

});
}

Expand Down
11 changes: 7 additions & 4 deletions index.html
Expand Up @@ -90,7 +90,9 @@ <h1 class="ui dividing page header">
<tr>
<th>subject</th>
<th>predicate</th>
<th colspan="2">object
<th>object</th>
<th colspan="2">
graph
<button @click="empty()" class="ui right floated negative button">empty</button>
</th>
</tr>
Expand All @@ -100,17 +102,17 @@ <h1 class="ui dividing page header">
<input v-model="filter.subject" @keyup.enter="applyFilter()">
</div>
</th>
<th class="five wide">
<th class="four wide">
<div class="ui fluid input">
<input v-model="filter.predicate" @keyup.enter="applyFilter()">
</div>
</th>
<th class="five wide">
<th class="four wide">
<div class="ui fluid input">
<input v-model="filter.object" @keyup.enter="applyFilter()">
</div>
</th>
<th class="two wide">
<th class="four wide" colspan="2">
<div class="ui tiny buttons">
<button @click="applyFilter()" class="ui button">Filter</button>
<div class="or">
Expand All @@ -124,6 +126,7 @@ <h1 class="ui dividing page header">
<td>{{spo.subject}}</td>
<td>{{spo.predicate}}</td>
<td>{{spo.object}}</td>
<td>{{spo.graph}}</td>
<td class="tight">
<div class="ui mini hover-hidden right floated buttons">
<div class="ui icon button" @click="setFilter(spo)">
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -11,7 +11,7 @@
"isomorphic-fetch": "^2.2.1",
"level-js": "^2.2.4",
"levelgraph": "^2.0.0",
"levelgraph-jsonld": "^1.0.3",
"levelgraph-jsonld": "git+ssh://git@github.com:mcollina/levelgraph-jsonld.git#feature/named-graphs",
"levelgraph-n3": "^2.0.0",
"levelup": "^1.3.3",
"vue": "^2.1.8"
Expand Down

0 comments on commit cd69b86

Please sign in to comment.