@@ -178,6 +178,20 @@ def __or__(self, other):
178
178
"""
179
179
return WOQLQuery ().woql_or (self , other )
180
180
181
+ def __invert__ (self ):
182
+ """Creates a logical Not with the argument passed, for WOQLQueries.
183
+
184
+ Parameters
185
+ ----------
186
+ other : WOQLQuery object
187
+
188
+ Returns
189
+ -------
190
+ WOQLQuery object
191
+ query object that can be chained and/or execute
192
+ """
193
+ return WOQLQuery ().woql_not (self )
194
+
181
195
def _add_sub_query (self , sub_query = None ):
182
196
"""Internal library function which adds a subquery and sets the cursor"""
183
197
if sub_query :
@@ -695,6 +709,18 @@ def _wrap_cursor_with_and(self):
695
709
self ._cursor = self ._cursor ["and" ][1 ]
696
710
697
711
def using (self , collection , subq = None ):
712
+ """Use a specific data product for the enclosed query
713
+
714
+ Parameters
715
+ ----------
716
+ collection : str
717
+ the name of the data product
718
+ Returns
719
+ -------
720
+ WOQLQuery object
721
+ query object that can be chained and/or execute
722
+ """
723
+
698
724
if collection and collection == "args" :
699
725
return ["collection" , "query" ]
700
726
if self ._cursor .get ("@type" ):
@@ -1242,8 +1268,7 @@ def substr(self, string, length, substring, before=0, after=0):
1242
1268
1243
1269
def update_object (self , docjson ):
1244
1270
warnings .warn (
1245
- "update_object() is deprecated; use update_document()" ,
1246
- warnings .DeprecationWarning ,
1271
+ DeprecationWarning ("update_object() is deprecated; use update_document()" )
1247
1272
)
1248
1273
return self .update_document (docjson )
1249
1274
# if docjson and docjson == "args":
@@ -1259,6 +1284,19 @@ def update_object(self, docjson):
1259
1284
# return self._updated()
1260
1285
1261
1286
def update_document (self , docjson , json_or_iri = None ):
1287
+ """Update a document in the database
1288
+
1289
+ Parameters
1290
+ ----------
1291
+ docjson : JSON
1292
+ object to be updated
1293
+ json_or_iri : str
1294
+ the output ID, or a JSON to compare the ID against
1295
+ Returns
1296
+ -------
1297
+ WOQLQuery object
1298
+ query object that can be chained and/or execute
1299
+ """
1262
1300
if docjson and docjson == "args" :
1263
1301
return ["document" ]
1264
1302
if self ._cursor .get ("@type" ):
@@ -1274,6 +1312,19 @@ def update_document(self, docjson, json_or_iri=None):
1274
1312
return self ._updated ()
1275
1313
1276
1314
def insert_document (self , docjson , json_or_iri = None ):
1315
+ """Insert a document into the database
1316
+
1317
+ Parameters
1318
+ ----------
1319
+ docjson : JSON
1320
+ object to be inserted
1321
+ json_or_iri : str
1322
+ the output ID, or a JSON to compare the ID against
1323
+ Returns
1324
+ -------
1325
+ WOQLQuery object
1326
+ query object that can be chained and/or execute
1327
+ """
1277
1328
if docjson and docjson == "args" :
1278
1329
return ["document" ]
1279
1330
if self ._cursor .get ("@type" ):
@@ -1290,19 +1341,24 @@ def insert_document(self, docjson, json_or_iri=None):
1290
1341
1291
1342
def delete_object (self , json_or_iri ):
1292
1343
warnings .warn (
1293
- "delete_object() is deprecated; use delete_document()" ,
1294
- warnings .DeprecationWarning ,
1344
+ DeprecationWarning ("delete_object() is deprecated; use delete_document()" )
1295
1345
)
1296
1346
return self .delete_document (json_or_iri )
1297
- # if json_or_iri and json_or_iri == "args":
1298
- # return ["document"]
1299
- # if self._cursor.get("@type"):
1300
- # self._wrap_cursor_with_and()
1301
- # self._cursor["@type"] = "DeleteObject"
1302
- # self._cursor["document_uri"] = self._clean_node_value(json_or_iri)
1303
- # return self._updated()
1304
1347
1305
1348
def delete_document (self , json_or_iri ):
1349
+ """Delete a document into the database
1350
+
1351
+ Parameters
1352
+ ----------
1353
+ docjson : JSON
1354
+ object to be deleted
1355
+ json_or_iri : str
1356
+ the output ID, or a JSON to compare the ID against
1357
+ Returns
1358
+ -------
1359
+ WOQLQuery object
1360
+ query object that can be chained and/or execute
1361
+ """
1306
1362
if json_or_iri and json_or_iri == "args" :
1307
1363
return ["document" ]
1308
1364
if self ._cursor .get ("@type" ):
@@ -1313,8 +1369,7 @@ def delete_document(self, json_or_iri):
1313
1369
1314
1370
def read_object (self , iri , output_var ):
1315
1371
warnings .warn (
1316
- "read_object() is deprecated; use read_document()" ,
1317
- warnings .DeprecationWarning ,
1372
+ DeprecationWarning ("read_object() is deprecated; use read_document()" )
1318
1373
)
1319
1374
return self .read_document (iri , output_var )
1320
1375
# if iri and iri == "args":
@@ -1327,6 +1382,25 @@ def read_object(self, iri, output_var):
1327
1382
# return self
1328
1383
1329
1384
def read_document (self , iri , output_var ):
1385
+ """Read a document from the database
1386
+
1387
+ Parameters
1388
+ ----------
1389
+ iri : str
1390
+ object to be deleted
1391
+ output_var : str
1392
+ the document as JSON
1393
+ Returns
1394
+ -------
1395
+ WOQLQuery object
1396
+ query object that can be chained and/or execute
1397
+ Example
1398
+ -------
1399
+ >>> query = (WOQLQuery().triple('v:TermId', 'rdf:type', '@schema:Term') &
1400
+ WOQLQuery().triple('v:TermCountId','term','v:TermId') &
1401
+ WOQLQuery().triple('v:DocumentId', 'terms', 'v:TermCountId') &
1402
+ WOQLQuery().read_document('v:TermId','v:TermDoc'))
1403
+ """
1330
1404
if iri and iri == "args" :
1331
1405
return ["document" ]
1332
1406
if self ._cursor .get ("@type" ):
@@ -1941,6 +2015,21 @@ def isa(self, element, of_type):
1941
2015
return self
1942
2016
1943
2017
def like (self , left , right , dist ):
2018
+ """Matches left string to right string with a distance
2019
+
2020
+ Parameters
2021
+ ----------
2022
+ left : str
2023
+ first string to compare
2024
+ right : str
2025
+ second string to compare
2026
+ dist : str
2027
+ Hamming distance between left and right
2028
+ Returns
2029
+ -------
2030
+ WOQLQuery object
2031
+ query object that can be chained and/or execute
2032
+ """
1944
2033
if left and left == "args" :
1945
2034
return ["left" , "right" , "similarity" ]
1946
2035
if self ._cursor .get ("@type" ):
@@ -2125,6 +2214,20 @@ def random_idgen(self, prefix, key_list, uri):
2125
2214
return self
2126
2215
2127
2216
def upper (self , left , right ):
2217
+ """Changes a string to upper-case - input is in left, output in right
2218
+
2219
+ Parameters
2220
+ ----------
2221
+ left : str
2222
+ input string
2223
+ right : str
2224
+ stores output
2225
+
2226
+ Returns
2227
+ -------
2228
+ WOQLQuery object
2229
+ query object that can be chained and/or execute
2230
+ """
2128
2231
if left and left == "args" :
2129
2232
return ["left" , "right" ]
2130
2233
if self ._cursor .get ("@type" ):
@@ -2408,9 +2511,15 @@ def limit(self, limit, query=None):
2408
2511
return self ._add_sub_query (query )
2409
2512
2410
2513
def re (self , pattern , reg_str , reg_list ):
2514
+ warnings .warn (
2515
+ DeprecationWarning ("re() is deprecated; use regexp()" )
2516
+ )
2517
+ return self .regexp (pattern , reg_str , reg_list )
2518
+
2519
+ def regexp (self , pattern , reg_str , reg_list ):
2411
2520
"""Regular Expression Call
2412
- p is a regex pattern (.*) using normal regular expression syntax, the only unusual thing is that special characters have to be escaped twice, s is the string to be matched and m is a list of matches:
2413
- e.g. WOQL.re ("(.).*", "hello", ["v:All", "v:Sub"])
2521
+ pattern is a regex pattern (.*) using normal regular expression syntax, the only unusual thing is that special characters have to be escaped twice, s is the string to be matched and m is a list of matches:
2522
+ e.g. WOQLQuery().regexp ("(.).*", "hello", ["v:All", "v:Sub"])
2414
2523
2415
2524
Parameters
2416
2525
----------
@@ -2437,6 +2546,21 @@ def re(self, pattern, reg_str, reg_list):
2437
2546
return self
2438
2547
2439
2548
def length (self , var_list , var_len ):
2549
+ """Length
2550
+ Calculates the length of a list
2551
+
2552
+ Parameters
2553
+ ----------
2554
+ var_list : list
2555
+ list of elements
2556
+ var_len : num
2557
+ number of eleemnts
2558
+
2559
+ Returns
2560
+ -------
2561
+ WOQLQuery object
2562
+ query object that can be chained and/or execute
2563
+ """
2440
2564
if var_list and var_list == "args" :
2441
2565
return ["list" , "length" ]
2442
2566
if self ._cursor .get ("@type" ):
@@ -2983,3 +3107,19 @@ def vars(self, *args):
2983
3107
if len (vars_tuple ) == 1 :
2984
3108
vars_tuple = vars_tuple [0 ]
2985
3109
return vars_tuple
3110
+
3111
+ def variables (self , * args ):
3112
+ """Generate variables to be used in WOQLQueries
3113
+ Parameters
3114
+ ----------
3115
+ args
3116
+ string arguments
3117
+ Returns
3118
+ -------
3119
+ tuple/string
3120
+ args prefixed with "v:"
3121
+ """
3122
+ vars_tuple = tuple (Var (arg ) for arg in args )
3123
+ if len (vars_tuple ) == 1 :
3124
+ vars_tuple = vars_tuple [0 ]
3125
+ return vars_tuple
0 commit comments