WOQLQuery
class WOQLQuery()
__init__
def __init__(query=None, graph="schema")
defines the internal functions of the woql query object - the language API is defined in WOQLQuery
Arguments:
query
(dict
): json-ld query for initialisationgraph
(str
): graph that this query is appled to, default to be schema/main
__add__
def __add__(other)
Creates a logical AND with the argument passed, for WOQLQueries.
Arguments:
other
(WOQLQuery object
): None
Returns:
WOQLQuery object
: query object that can be chained and/or execute__and__
def __and__(other)
Creates a logical AND with the argument passed, for WOQLQueries.
Arguments:
other
(WOQLQuery object
): None
Returns:
WOQLQuery object
: query object that can be chained and/or execute__or__
def __or__(other)
Creates a logical OR with the argument passed, for WOQLQueries.
Arguments:
other
(WOQLQuery object
): None
Returns:
WOQLQuery object
: query object that can be chained and/or execute__invert__
def __invert__()
Creates a logical Not with the argument passed, for WOQLQueries.
Arguments:
other
(WOQLQuery object
): None
Returns:
WOQLQuery object
: query object that can be chained and/or executeexecute
def execute(client, commit_msg=None, file_dict=None)
Executes the query using the passed client to connect to a server
Arguments:
client
(Client object
): client that provide connection to the database for the query to execute.commit_msg
(str
): optional, commit message for this query. Recommended for query that carrries an update.file_dict
(``): File dictionary to be associated with post name => filename, for multipart POST
to_json
def to_json()
Dumps the JSON-LD format of the query in a json string
from_json
def from_json(input_json)
Set a query from a JSON-LD json string
to_dict
def to_dict()
Give the dictionary that represents the query in JSON-LD format.
from_dict
def from_dict(dictdata)
Set a query from a dictionary that represents the query in JSON-LD format.
load_vocabulary
def load_vocabulary(client)
Queries the schema graph and loads all the ids found there as vocabulary that can be used without prefixes ignoring blank node ids
using
def using(collection, subq=None)
Use a specific data product for the enclosed query
Arguments:
collection
(str
): the name of the data product
Returns:
WOQLQuery object
: query object that can be chained and/or executecomment
def comment(comment, subq=None)
Adds a text comment to a query - can also be used to wrap any part of a query to turn it off
Arguments:
comment
(str
): text comment
Returns:
WOQLQuery object
: query object that can be chained and/or executeselect
def select(*args)
Filters the query so that only the variables included in [V1...Vn] are returned in the bindings
Arguments:
args
: only these variables are returned
Returns:
WOQLQuery object
: query object that can be chained and/or executedistinct
def distinct(*args)
Ensures that the solutions for the variables [V1...Vn] are distinct
Arguments:
args
: The variables to make distinct with the final argument being a query.
Returns:
WOQLQuery object
: query object that can be chained and/or executewoql_and
def woql_and(*args)
Creates a logical AND of the arguments
Commonly used to combine WOQLQueries.
Arguments:
args
(WOQLQuery objects
): None
Returns:
WOQLQuery object
: query object that can be chained and/or executewoql_or
def woql_or(*args)
Creates a logical OR of the arguments
Arguments:
args
(WOQLQuery objects
): None
Returns:
WOQLQuery object
: query object that can be chained and/or executewoql_from
def woql_from(graph, query=None)
Specifies the database URL that will be the default database for the enclosed query
Arguments:
graph
(str
): url of the databasequery
(WOQLQuery object
): None
Returns:
WOQLQuery object
: query object that can be chained and/or executeinto
def into(graph_descriptor, query)
Sets the current output graph for writing output to.
Arguments:
graph_descriptor
(str
): output graphquery
(WOQLQuery object
): None
Returns:
WOQLQuery object
: query object that can be chained and/or executetriple
def triple(sub, pred, obj, opt=False)
Creates a triple pattern matching rule for the triple [S, P, O] (Subject, Predicate, Object)
Arguments:
sub
(str
): Subject, has to be a node (URI)pred
(str
): Predicate, can be variable (prefix with "v:") or nodeobj
(str
): Object, can be variable or node or valueopt
(bool
): weather or not this triple is optional, default to be False
Returns:
WOQLQuery object
: query object that can be chained and/or executeadded_triple
def added_triple(sub, pred, obj, opt=False)
Creates a triple pattern matching rule for the triple [S, P, O] (Subject, Predicate, Object) added to the current commit.
Arguments:
sub
(str
): Subjectpred
(str
): Predicateobj
(str
): Objectopt
(bool
): weather or not this triple is optional, default to be False
Returns:
WOQLQuery object
: query object that can be chained and/or executeremoved_triple
def removed_triple(sub, pred, obj, opt=False)
Creates a triple pattern matching rule for the triple [S, P, O] (Subject, Predicate, Object) added to the current commit.
Arguments:
sub
(str
): Subjectpred
(str
): Predicateobj
(str
): Objectopt
(bool
): weather or not this triple is optional, default to be False
Returns:
WOQLQuery object
: query object that can be chained and/or executequad
def quad(sub, pred, obj, graph, opt=False)
Creates a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate, Object, Graph)
Arguments:
sub
(str
): Subjectpre
(str
): Predicateobj
(str
): Objectgra
(str
): Graphopt
(bool
): weather or not this quad is optional, default to be False
Returns:
WOQLQuery object
: query object that can be chained and/or executeadded_quad
def added_quad(sub, pred, obj, graph, opt=False)
Creates a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate, Object, Graph) added to the current commit.
Arguments:
sub
(str
): Subjectpre
(str
): Predicateobj
(str
): Objectgra
(str
): Graphopt
(bool
): weather or not this quad is optional, default to be False
Returns:
WOQLQuery object
: query object that can be chained and/or executeremoved_quad
def removed_quad(sub, pred, obj, graph, opt=False)
Creates a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate, Object, Graph) added to the current commit.
Arguments:
sub
(str
): Subjectpre
(str
): Predicateobj
(str
): Objectgra
(str
): Graphopt
(bool
): weather or not this quad is optional, default to be False
Returns:
WOQLQuery object
: query object that can be chained and/or executestring
def string(input_str)
Transforms the given string into the proper json-ld form
Arguments:
input_str
(str
): the given input string
Returns:
dict
:boolean
def boolean(input_bool)
Transforms the given bool object into the proper json-ld form
Arguments:
input_bool
(bool
): the given input string
Returns:
dict
:datetime
def datetime(input_obj)
Transforms the given datetime object into the proper json-ld form
Arguments:
input_obj
(str
): the given input dateTime object
Returns:
dict
:sub
def sub(parent, child)
Returns true if child is a sub-class of parent, according to the current DB schema
Arguments:
parent
(str
): the parent class to be checkedchild
(str
): the child class to be checked
Returns:
bool
:eq
def eq(left, right)
Matches if a is equal to b
Arguments:
left
(str
): object in the graphright
(str
): object in the graph
Returns:
WOQLQuery object
: query object that can be chained and/or executeupdate_document
def update_document(docjson, json_or_iri=None)
Update a document in the database
Arguments:
docjson
(JSON
): object to be updatedjson_or_iri
(str
): the output ID, or a JSON to compare the ID against
Returns:
WOQLQuery object
: query object that can be chained and/or executeinsert_document
def insert_document(docjson, json_or_iri=None)
Insert a document into the database
Arguments:
docjson
(JSON
): object to be insertedjson_or_iri
(str
): the output ID, or a JSON to compare the ID against
Returns:
WOQLQuery object
: query object that can be chained and/or executedelete_document
def delete_document(json_or_iri)
Delete a document into the database
Arguments:
docjson
(JSON
): object to be deletedjson_or_iri
(str
): the output ID, or a JSON to compare the ID against
Returns:
WOQLQuery object
: query object that can be chained and/or executeread_document
def read_document(iri, output_var)
Read a document from the database
query = (WOQLQuery().triple('v:TermId', 'rdf:type', '@schema:Term') & WOQLQuery().triple('v:TermCountId','term','v:TermId') & WOQLQuery().triple('v:DocumentId', 'terms', 'v:TermCountId') & WOQLQuery().read_document('v:TermId','v:TermDoc'))
get
def get(as_vars, query_resource=None)
Takes an as structure
put
def put(as_vars, query, query_resource=None)
Takes an array of variables, an optional array of column names
file
def file(fpath, opts=None)
Provides details of a file source in a JSON format that includes a URL property
Arguments:
fpath
(dict
): file data source in a JSON formatopts
(input options
): optional
Returns:
WOQLQuery object
: query object that can be chained and/or executeonce
def once(query=None)
Obtains only one result from subquery
Arguments:
query
(WOQLQuery object
): NoneReturns
: None----------
: NoneWOQLQuery object
: query object that can be chained and/or executed
remote
def remote(uri, opts=None)
Provides details of a remote data source in a JSON format that includes a URL property
Arguments:
uri
(str
): remote data sourceopts
(input options
): optional
Returns:
WOQLQuery object
: query object that can be chained and/or executedelete_triple
def delete_triple(subject, predicate, object_or_literal)
Deletes any triples that match the rule [subject, predicate, object]
Arguments:
subject
(str
): Subjectpredicate
(str
): Predicateobject_or_literal
(str
): Object or Literal
Returns:
WOQLQuery object
: query object that can be chained and/or executeadd_triple
def add_triple(subject, predicate, object_or_literal)
Adds triples according to the the pattern [subject, predicate, object]
Arguments:
subject
(str
): Subjectpredicate
(str
): Predicateobject_or_literal
(str
): Object or Literal
Returns:
WOQLQuery object
: query object that can be chained and/or executedelete_quad
def delete_quad(subject, predicate, object_or_literal, graph=None)
Deletes any quads that match the rule [subject, predicate, object, graph]
Arguments:
subject
(str
): Subjectpredicate
(str
): Predicateobject_or_literal
(str
): Object or Literalgraph
(str
): Graph
Returns:
WOQLQuery object
: query object that can be chained and/or executeadd_quad
def add_quad(subject, predicate, object_or_literal, graph)
Adds quads according to the pattern [subject, predicate, object, graph]
Arguments:
subject
(str
): Subjectpredicate
(str
): Predicateobject_or_literal
(str
): Object or Literalgraph
(str
): Graph
Returns:
WOQLQuery object
: query object that can be chained and/or executetrim
def trim(untrimmed, trimmed)
A trimmed version of untrimmed (with leading and trailing whitespace removed) is copied into trimmed
Arguments:
untrimmed
(str
): original stringtrimmed
(str
): WOQL varible storing the result string
Returns:
WOQLQuery object
: query object that can be chained and/or executeeval
def eval(arith, res)
Evaluates the Arithmetic Expression Arith and copies the output to variable V
Arguments:
arith
(WOQLQuery or dict
): query or JSON-LD representing the queryres
(str
): output variable
Returns:
WOQLQuery object
: query object that can be chained and/or executeplus
def plus(*args)
Adds numbers N1...Nn together
Arguments:
args
(int or float
): numbers to add together
Returns:
WOQLQuery object
: query object that can be chained and/or executeminus
def minus(*args)
Adds numbers N1...Nn together
Arguments:
args
(int or float
): numbers to add together
Returns:
WOQLQuery object
: query object that can be chained and/or executetimes
def times(*args)
Multiplies numbers N1...Nn together
Arguments:
args
(int or float
): numbers to be multiplied
Returns:
WOQLQuery object
: query object that can be chained and/or executedivide
def divide(*args)
Divides numbers N1...Nn by each other left, to right precedence
Arguments:
args
(int or float
): numbers to be divided
Returns:
WOQLQuery object
: query object that can be chained and/or executediv
def div(*args)
Division - integer division - args are divided left to right
Arguments:
args
(int or float
): numbers for division
Returns:
WOQLQuery
: query object that can be chained and/or executeexp
def exp(first, second)
Raises A to the power of B
Arguments:
first
(int or float
): base numbersecond
(int or float
): power of
Returns:
WOQLQuery object
: query object that can be chained and/or executefloor
def floor(user_input)
The floor function of a real number x denotes the greatest integer less than or equal to x.
Arguments:
user_input
(int or float
): number whose floor needs to be calculated
Returns:
WOQLQuery object
: query object that can be chained and/or executeisa
def isa(element, of_type)
Matches if element is a member of a certain type, according to the current state of the DB
Arguments:
element
(str
): element to be checkedof_type
(str
): type to be checked
Returns:
bool
:like
def like(left, right, dist)
Matches left string to right string with a distance
Arguments:
left
(str
): first string to compareright
(str
): second string to comparedist
(str
): Hamming distance between left and right
Returns:
WOQLQuery object
: query object that can be chained and/or executeless
def less(left, right)
Compares the value of v1 against v2 and returns true if v1 is less than v2
Arguments:
left
(str
): first variable to compareright
(str
): second variable to compare
Returns:
WOQLQuery object
: query object that can be chained and/or executegreater
def greater(left, right)
Compares the value of v1 against v2 and returns true if v1 is greater than v2
Arguments:
left
(str
): first variable to compareright
(str
): second variable to compare
Returns:
WOQLQuery object
: query object that can be chained and/or executeopt
def opt(query=None)
The Query in the Optional argument is specified as optional
Arguments:
query
(WOQLQuery object
): None
Returns:
WOQLQuery object
: query object that can be chained and/or executeunique
def unique(prefix, key_list, uri)
Generates an ID for a node as a function of the passed VariableList with a specific prefix (URL base)(A.K.A Hashing) If the values of the passed variables are the same, the output will be the same
Arguments:
prefix
(str
): prefix for the idkey_list
(str
): variable to generate id foruri
(str
): the variable to hold the id
Returns:
WOQLQuery object
: query object that can be chained and/or executeidgen
def idgen(prefix, input_var_list, output_var)
Generates an ID for a node as a function of the passed VariableList with a specific prefix (URL base). If the values of the passed variables are the same, the output will be the same
Arguments:
prefix
(str
): prefix for the idinput_var_list
(str or list
): variable to generate id foroutput_var
(str
): the variable to hold the id
Returns:
WOQLQuery object
: query object that can be chained and/or executerandom_idgen
def random_idgen(prefix, key_list, uri)
Randomly generates an ID and appends to the end of the key_list.
Arguments:
prefix
(str
): prefix for the idkey_list
(str
): variable to generate id foruri
(str
): the variable to hold the id
Returns:
WOQLQuery object
: query object that can be chained and/or executeupper
def upper(left, right)
Changes a string to upper-case - input is in left, output in right
Arguments:
left
(str
): input stringright
(str
): stores output
Returns:
WOQLQuery object
: query object that can be chained and/or executelower
def lower(left, right)
Changes a string to lower-case - input is in u, output in l
Arguments:
left
(str
): input stringright
(str
): stores output
Returns:
WOQLQuery object
: query object that can be chained and/or executepad
def pad(user_input, pad, length, output)
Pads out the string input to be exactly len long by appending the pad character pad to form output
Arguments:
user_input
(str
): input stringpad
(str
): padding character(s)length
(int
): length to padoutput
(str
): stores output
Returns:
WOQLQuery object
: query object that can be chained and/or executesplit
def split(user_input, glue, output)
Splits a variable apart (input) into a list of variables (output) by separating the strings together with separator
Arguments:
user_input
(str
): input string or WOQL variable "v:"glue
(str
): character string to separate string into listoutput
(str
): WOQL variable that stores output list
Returns:
WOQLQuery object
: query object that can be chained and/or executedot
def dot(document, field, value)
Iterates through a list and returns a value for each member
Arguments:
dictionary
: a WOQL dictionary or variable representing a dictionaryfield
(str
): a string representing the field or key to access the dictionaryvalue
: a WOQL value representing the result
Returns:
WOQLQuery object
: query object that can be chained and/or executemember
def member(member, mem_list)
Iterates through a list and returns a value for each member
Arguments:
member
(str
): a WOQL variable representing an element of the listmem_list
(str
): a WOQL list variable
Returns:
WOQLQuery object
: query object that can be chained and/or executeconcat
def concat(concat_list, result)