@@ -23,16 +23,20 @@ const WOQLQueryExt = require('./woqlQuery');
2323// const WOQLLibrary = require('./woqlLibrary');
2424
2525class WOQLQuery extends WOQLQueryExt {
26- counter = 1 ;
27-
2826 // eslint-disable-next-line no-useless-constructor
2927 constructor ( query ) {
3028 super ( query ) ;
3129 }
3230}
3331
3432// WOQLQuery.prototype.counter = 1;
35-
33+ /**
34+ * @param {typedef.GraphRef } [Graph] - the resource identifier of a graph possible
35+ * @param {string|Var } [Subj] - The IRI of a triple’s subject or a variable
36+ * @param {string|Var } [Pred] - The IRI of a property or a variable
37+ * @param {string|Var } [Obj] - The IRI of a node or a variable, or a literal
38+ * @returns {WOQLQuery } - A WOQLQuery which contains the pattern matching expression
39+ */
3640/**
3741 * Simple composite functions which produce WOQL queries
3842 */
@@ -47,6 +51,14 @@ WOQLQuery.prototype.star = function (Graph, Subj, Pred, Obj) {
4751 return this . triple ( Subj , Pred , Obj ) ;
4852} ;
4953
54+ /**
55+ * @param {string|Var } [Subj] - The IRI of a triple’s subject or a variable
56+ * @param {string|Var } [Pred] - The IRI of a property or a variable
57+ * @param {string|Var } [Obj] - The IRI of a node or a variable, or a literal
58+ * @param {typedef.GraphRef } [Graph] - the resource identifier of a graph possible
59+ * @returns {WOQLQuery } - A WOQLQuery which contains the pattern matching expression
60+ */
61+
5062WOQLQuery . prototype . all = function ( Subj , Pred , Obj , Graph ) {
5163 return this . star ( Graph , Subj , Pred , Obj ) ;
5264} ;
@@ -55,27 +67,61 @@ WOQLQuery.prototype.all = function (Subj, Pred, Obj, Graph) {
5567 return new WOQLLibrary();
5668}; */
5769
70+ /**
71+ * @param {string } s
72+ * @returns {object }
73+ * @example
74+ */
75+
5876WOQLQuery . prototype . string = function ( s ) {
5977 return { '@type' : 'xsd:string' , '@value' : String ( s ) } ;
6078} ;
6179
80+ /**
81+ * @param {boolean } tf
82+ * @returns {object }
83+ * @example
84+ */
85+
6286WOQLQuery . prototype . boolean = function ( tf ) {
6387 tf = tf || false ;
6488 return this . literal ( tf , 'boolean' ) ;
6589} ;
6690
91+ /**
92+ * @param {any } s
93+ * @param {string } t
94+ * @returns {object }
95+ * @example
96+ */
6797WOQLQuery . prototype . literal = function ( s , t ) {
6898 t = t . indexOf ( ':' ) === - 1 ? `xsd:${ t } ` : t ;
6999 return { '@type' : t , '@value' : s } ;
70100} ;
71101
102+ /**
103+ * @param {string } s
104+ * @returns {object }
105+ * @example
106+ */
107+
72108WOQLQuery . prototype . iri = function ( s ) {
73109 return {
74110 '@type' : 'NodeValue' ,
75111 node : s ,
76112 } ;
77113} ;
78114
115+ /**
116+ * Update a pattern matching rule for the triple (Subject, Predicate, oldObjValue) with the
117+ * new one (Subject, Predicate, newObjValue)
118+ * @param {string|Var } subject - The IRI of a triple’s subject or a variable
119+ * @param {string|Var } predicate - The IRI of a property or a variable
120+ * @param {string|Var } newObjValue - The value to update or a literal
121+ * @param {string|Var } oldObjValue - The old value of the object
122+ * @returns {WOQLQuery } A WOQLQuery which contains the a Update Triple Statement
123+ */
124+
79125WOQLQuery . prototype . update_triple = function ( subject , predicate , new_object , old_object ) {
80126 const tmp_name = old_object || `v:AnyObject__${ this . counter += 1 } ` ;
81127 return this . and (
@@ -117,7 +163,7 @@ WOQLQuery.prototype.update_quad = function (subject, predicate, new_object, grap
117163
118164/**
119165 * Removes all triples from a graph
120- * @param {string } g - optional graph resource identifier
166+ * @param {string } [g] - optional graph resource identifier
121167 */
122168
123169WOQLQuery . prototype . nuke = function ( g ) {
@@ -127,6 +173,16 @@ WOQLQuery.prototype.nuke = function (g) {
127173 return this . triple ( 'v:A' , 'v:B' , 'v:C' ) . delete_triple ( 'v:A' , 'v:B' , 'v:C' ) ;
128174} ;
129175
176+ /**
177+ *
178+ * @param {string|Var } node - The IRI of a node or a variable containing an IRI which will
179+ * be the subject of the builder functions
180+ * @param {typedef.FuntionType } [type] - Optional type of builder function to build
181+ * (default is triple)
182+ * @returns {WOQLQuery } - A WOQLQuery which contains the partial Node pattern matching expression
183+ * @example
184+ */
185+
130186WOQLQuery . prototype . node = function ( node , type ) {
131187 type = type || false ;
132188 if ( type === 'add_quad' ) type = 'AddTriple' ;
@@ -164,6 +220,13 @@ WOQLQuery.prototype._set_context = function (ctxt) {
164220 return this ;
165221} ;
166222
223+ /**
224+ * @param {string|Var } id - IRI string or variable containing
225+ * @param {string|Var } type - IRI string or variable containing the IRI of the
226+ * @param {typedef.GraphRef } [refGraph] - Optional Graph resource identifier
227+ * @returns {WOQLQuery } A WOQLQuery which contains the insert expression
228+ */
229+
167230WOQLQuery . prototype . insert = function ( id , type , refGraph ) {
168231 refGraph = refGraph || ( this . triple_builder_context ? this . triple_builder_context . graph : false ) ;
169232 if ( refGraph ) {
0 commit comments