Skip to content

Commit 42dc6f6

Browse files
Update for woql schema (#79)
* Fixes #75 * Fixes #78
1 parent d571de3 commit 42dc6f6

File tree

7 files changed

+173
-22
lines changed

7 files changed

+173
-22
lines changed

docs/_sidebar.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@
6666
- [select](api/woql.js?id=select)
6767
- [distinct](api/woql.js?id=distinct)
6868
- [and](api/woql.js?id=and)
69-
- [read_object](api/woql.js?id=read_object)
69+
- [read_document](api/woql.js?id=read_document)
70+
- [insert_document](api/woql.js?id=insert_document)
71+
- [update_document](api/woql.js?id=update_document)
72+
- [delete_document](api/woql.js?id=delete_document)
7073
- [or](api/woql.js?id=or)
7174
- [from](api/woql.js?id=from)
7275
- [into](api/woql.js?id=into)

docs/api/woql.js.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,14 @@ WOQL.and(
9393
```
9494

9595
### read_object
96-
#### WOQL.read\_object(IRI, output, formatObj) ⇒ <code>object</code>
96+
#### ~~WOQL.read\_object()~~
97+
***Deprecated***
98+
99+
Use [read_document](#read_document) instead.
100+
101+
102+
### read_document
103+
#### WOQL.read\_document(IRI, output, formatObj) ⇒ <code>object</code>
97104
Read a node identified by an IRI as a JSON-LD document
98105

99106
**Returns**: <code>object</code> - WOQLQuery
@@ -105,6 +112,41 @@ Read a node identified by an IRI as a JSON-LD document
105112
| formatObj | <code>object</code> | |
106113

107114

115+
### insert_document
116+
#### WOQL.insert\_document(docjson, [IRI]) ⇒ <code>object</code>
117+
Insert a document in the graph.
118+
119+
**Returns**: <code>object</code> - WOQLQuery
120+
121+
| Param | Type | Description |
122+
| --- | --- | --- |
123+
| docjson | <code>object</code> | The document to insert. Must either have an '@id' or have a class specified key. |
124+
| [IRI] | <code>string</code> | An optional identifier specifying the document location. |
125+
126+
127+
### update_document
128+
#### WOQL.update\_document(docjson, [IRI]) ⇒ <code>object</code>
129+
Update a document identified by an IRI
130+
131+
**Returns**: <code>object</code> - WOQLQuery
132+
133+
| Param | Type | Description |
134+
| --- | --- | --- |
135+
| docjson | <code>object</code> | The document to update. Must either have an '@id' or have a class specified key. |
136+
| [IRI] | <code>string</code> | An optional identifier specifying the document location. |
137+
138+
139+
### delete_document
140+
#### WOQL.delete\_document(IRI) ⇒ <code>object</code>
141+
Delete a document from the graph.
142+
143+
**Returns**: <code>object</code> - WOQLQuery
144+
145+
| Param | Type | Description |
146+
| --- | --- | --- |
147+
| IRI | <code>string</code> | The document id or a variable |
148+
149+
108150
### or
109151
#### WOQL.or(...subqueries) ⇒ <code>WOQLQuery</code>
110152
Creates a logical OR of the arguments

lib/query/woqlCore.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ function WOQLQuery(query) {
5555
'DeleteTriple',
5656
'AddQuad',
5757
'DeleteQuad',
58-
'DeleteObject',
59-
'UpdateObject',
58+
'DeleteDocument',
59+
'UpdateDocument',
6060
]
6161

6262
this.vocab = this.loadDefaultVocabulary()

lib/query/woqlQuery.js

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,49 @@ let WOQLQuery = require('./woqlCore')
99
}
1010
}*/
1111

12-
WOQLQuery.prototype.read_object = function(IRI, OutputVar, Format) {
13-
//if (IRI && IRI == 'args') return ['document_uri', 'document']
12+
WOQLQuery.prototype.read_document = function(IRI, OutputVar, Format) {
1413
if (this.cursor['@type']) this.wrapCursorWithAnd()
15-
this.cursor['@type'] = 'ReadObject'
16-
this.cursor['document_uri'] = this.expandValueVariable(IRI)
14+
this.cursor['@type'] = 'ReadDocument'
15+
this.cursor['identifier'] = this.cleanNodeValue(IRI)
1716
this.cursor['document'] = this.expandValueVariable(OutputVar)
1817
return this.wform(Format)
1918
}
2019

20+
WOQLQuery.prototype.insert_document = function(docjson, IRI) {
21+
if (this.cursor['@type']) this.wrapCursorWithAnd()
22+
this.cursor['@type'] = 'InsertDocument'
23+
if(typeof IRI !== 'undefined') this.cursor['identifier'] = this.cleanNodeValue(IRI)
24+
25+
if(typeof docjson === 'string') {
26+
this.cursor['document'] = this.expandValueVariable(docjson);
27+
} else {
28+
this.cursor['document'] = docjson;
29+
}
30+
31+
return this.updated()
32+
}
33+
34+
WOQLQuery.prototype.update_document = function(docjson, IRI) {
35+
if (this.cursor['@type']) this.wrapCursorWithAnd()
36+
this.cursor['@type'] = 'UpdateDocument'
37+
if(typeof IRI !== 'undefined') this.cursor['identifier'] = this.cleanNodeValue(IRI)
38+
39+
if(typeof docjson === 'string') {
40+
this.cursor['document'] = this.expandValueVariable(docjson);
41+
} else {
42+
this.cursor['document'] = docjson;
43+
}
44+
45+
return this.updated()
46+
}
47+
48+
WOQLQuery.prototype.delete_document = function(IRI) {
49+
if (this.cursor['@type']) this.wrapCursorWithAnd()
50+
this.cursor['@type'] = 'DeleteDocument'
51+
this.cursor['identifier'] = this.cleanNodeValue(IRI)
52+
return this.updated()
53+
}
54+
2155
/**
2256
* Contains definitions of the WOQL functions which map directly to JSON-LD types
2357
* All other calls and queries can be composed from these
@@ -39,14 +73,6 @@ WOQLQuery.prototype.wrapCursorWithAnd = function() {
3973
}
4074
}
4175

42-
WOQLQuery.prototype.read_object = function(IRI, OutputVar, Format) {
43-
//if (IRI && IRI == 'args') return ['document_uri', 'document']
44-
if (this.cursor['@type']) this.wrapCursorWithAnd()
45-
this.cursor['@type'] = 'ReadObject'
46-
this.cursor['document_uri'] = this.expandValueVariable(IRI)
47-
this.cursor['document'] = this.expandValueVariable(OutputVar)
48-
return this.wform(Format)
49-
}
5076

5177
WOQLQuery.prototype.using = function(Collection, Subq) {
5278
//if (Collection && Collection == 'args')

lib/woql.js

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ WOQL.and = function(...subqueries) {
9191
}
9292

9393

94+
/**
95+
* Use {@link #read_document|read_document} instead.
96+
* @deprecated
97+
*/
98+
99+
WOQL.read_object = function(IRI, output, formatObj) {
100+
return new WOQLQuery().read_document(IRI, output, formatObj)
101+
}
102+
94103
/**
95104
* Read a node identified by an IRI as a JSON-LD document
96105
* @param {string} IRI - The document id or a variable
@@ -99,8 +108,40 @@ WOQL.and = function(...subqueries) {
99108
* @return {object} WOQLQuery
100109
*/
101110

102-
WOQL.read_object = function(IRI, output, formatObj) {
103-
return new WOQLQuery().read_object(IRI, output, formatObj)
111+
WOQL.read_document = function(IRI, output, formatObj) {
112+
return new WOQLQuery().read_document(IRI, output, formatObj)
113+
}
114+
115+
/**
116+
* Insert a document in the graph.
117+
* @param {object} docjson - The document to insert. Must either have an '@id' or have a class specified key.
118+
* @param {string} [IRI] - An optional identifier specifying the document location.
119+
* @return {object} WOQLQuery
120+
*/
121+
122+
WOQL.insert_document = function(docjson, IRI) {
123+
return new WOQLQuery().insert_document(docjson, IRI)
124+
}
125+
126+
/**
127+
* Update a document identified by an IRI
128+
* @param {object} docjson - The document to update. Must either have an '@id' or have a class specified key.
129+
* @param {string} [IRI] - An optional identifier specifying the document location.
130+
* @return {object} WOQLQuery
131+
*/
132+
133+
WOQL.update_document = function(docjson, IRI) {
134+
return new WOQLQuery().update_document(docjson, IRI)
135+
}
136+
137+
/**
138+
* Delete a document from the graph.
139+
* @param {string} IRI - The document id or a variable
140+
* @return {object} WOQLQuery
141+
*/
142+
143+
WOQL.delete_document = function(IRI) {
144+
return new WOQLQuery().delete_document(IRI)
104145
}
105146

106147
/**
@@ -1115,10 +1156,6 @@ WOQL.string = function(val) {
11151156
return new WOQLQuery().string(val)
11161157
}
11171158

1118-
WOQL.read_object = function(IRI, output, formatObj) {
1119-
return new WOQLQuery().read_object(IRI, output, formatObj)
1120-
}
1121-
11221159
/**
11231160
* Generates explicitly a JSON-LD string literal from the input
11241161
* @param {string} val - any literal type

test/woql.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,4 +393,28 @@ describe('woql queries', function () {
393393
//console.log(JSON.stringify(woqlObject01.json(), null, 4));
394394
})
395395

396+
it('check the read_document method',function(){
397+
const woqlObject=WOQL.read_document("A", "B", {});
398+
399+
expect(woqlObject.json()).to.eql(woqlJson.readDocJson);
400+
})
401+
402+
it('check the insert_document method',function(){
403+
const woqlObject=WOQL.insert_document("A", "B");
404+
405+
expect(woqlObject.json()).to.eql(woqlJson.insertDocJson);
406+
})
407+
408+
it('check the update_document method',function(){
409+
const woqlObject=WOQL.update_document("A", "B");
410+
411+
expect(woqlObject.json()).to.eql(woqlJson.updateDocJson);
412+
})
413+
414+
it('check the delete_document method',function(){
415+
const woqlObject=WOQL.delete_document("A");
416+
417+
expect(woqlObject.json()).to.eql(woqlJson.deleteDocJson);
418+
})
419+
396420
})

test/woqlJson/woqlJson.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,4 +1102,23 @@ module.exports = {
11021102
},
11031103
],
11041104
},
1105+
readDocJson: {
1106+
'@type': 'ReadDocument',
1107+
identifier: { '@type': 'NodeValue', node: 'A' },
1108+
document: { '@type': 'Value', node: 'B' }
1109+
},
1110+
insertDocJson: {
1111+
'@type': 'InsertDocument',
1112+
identifier: { '@type': 'NodeValue', node: 'B' },
1113+
document: { '@type': 'Value', node: 'A' }
1114+
},
1115+
updateDocJson: {
1116+
'@type': 'UpdateDocument',
1117+
identifier: { '@type': 'NodeValue', node: 'B' },
1118+
document: { '@type': 'Value', node: 'A' }
1119+
},
1120+
deleteDocJson: {
1121+
'@type': 'DeleteDocument',
1122+
identifier: { '@type': 'NodeValue', node: 'A' },
1123+
},
11051124
}

0 commit comments

Comments
 (0)