Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating docstrings, minor fixes #40

Merged
merged 7 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.3
current_version = 0.0.4
commit = False
tag = False

Expand All @@ -9,3 +9,4 @@ tag = False

[bumpversion:file:woqlclient/__version__.py]

[bumpversion:file:docs/source/conf.py]
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version: 2

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py
configuration: docs/source/conf.py

# Build documentation with MkDocs
#mkdocs:
Expand Down
3 changes: 2 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Terminus Client Python
==========================

[![build status](https://api.travis-ci.org/terminusdb/terminus-client-python.svg?branch=master)](https://travis-ci.org/terminusdb/terminus-client-python)
[![Documentation Status](https://readthedocs.org/projects/terminus-client-python/badge/?version=latest)](https://terminus-client-python.readthedocs.io/en/latest/?badge=latest)

Python terminus client for TerminusDB API and WOQLpy

Expand All @@ -17,7 +18,7 @@ Python terminus client for TerminusDB API and WOQLpy
`pip3 install git+https://github.com/terminusdb/terminus-client-python.git`

## Usage
For the [full Documentation](https://terminusdb.com/docs/client_api)
For the [full Documentation](https://terminus-client-python.readthedocs.io/)

## Testing
* Clone this repository
Expand Down
6 changes: 0 additions & 6 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
pip==9.0.3
certifi==2019.9.11
chardet==3.0.4
idna==2.8
requests==2.22.0
urllib3==1.25.6
sphinx
sphinx_rtd_theme
sphinxcontrib-napoleon
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

setuptools.setup(
name="terminus-client-python",
version="0.0.3",
version="0.0.4",
author="TerminusDB group",
author_email="[email protected]",
description="Python client for Terminus DB",
Expand Down
2 changes: 1 addition & 1 deletion woqlclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
__all__ = ['woqlClient', 'woql']

name = "woqlclient"
__version__ = "0.0.3"
__version__ = "0.0.4"
# cmdclass = {'test': PyTest}
2 changes: 1 addition & 1 deletion woqlclient/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__title__ = 'woqlClient'
__description__ = 'woqlClient library for accessing the Terminus DB API'
__url__ = ''
__version__ = '0.0.3'
__version__ = '0.0.4'
__build__ = 00
__author__ = 'TerminusDB group'
__author_email__ = '[email protected]'
Expand Down
82 changes: 43 additions & 39 deletions woqlclient/woql.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def get(self, arr1, arr2=None, target=None):
If WQOLQuery, arr2 will replace the target. If list, its column names of the source csv
arr2 : list or str
List, if arr1 is list and it will take the variable names for the input. Str, if arr1 is WQOLQuery, it will be the target
target : str, target of the source data, optional
Used only if arr1 and arr2 is list
target : str, optional
target of the source data, used only if arr1 and arr2 is list

Returns
-------
Expand Down Expand Up @@ -129,24 +129,24 @@ def check_vars_cols(obj):
clauses.append({'as': [v]})
return clauses

def typecast(self, va, type, vb):
def typecast(self, vara, type, varb):
"""Changes the type of va to type and saves the return in vb

Parameters
----------
va : str
vara : str
original variable
type : str
type to be changed
vb : str
varb : str
save the return variable

Returns
-------
WOQLQuery object
query object that can be chained and/or execute
"""
self.cursor['typecast'] = [va, type, vb];
self.cursor['typecast'] = [vara, type, varb];
return self

def insert(self, node, type, graph=None):
Expand Down Expand Up @@ -231,7 +231,7 @@ def file(self, json, opts=None):
Parameters
----------
json : dict
remote data source in a JSON format
file data source in a JSON format
opts : imput options, optional

Returns
Expand Down Expand Up @@ -373,10 +373,12 @@ def idgen(self, prefix, vari, type, mode=None):
----------
prefix : str
prefix for the id
vari : str
vari : str or list
variable to generate id for
type : str
the variable to hold the id
mode : str
idgen mode

Returns
-------
Expand Down Expand Up @@ -425,41 +427,41 @@ def unique(self, prefix, vari, type):
self.cursor['unique'].append(type)
return self

def re(self, p, s, m):
def re(self, pattern, test, matches):
"""Regular Expression Call

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:
e.g. WOQL.re("(.).*", "hello", ["v:All", "v:Sub"])

Parameters
----------
p : str
pattern : str
regex pattern
s : str
test : str
string to be matched
m : str or list or dict
matches : str or list or dict
store list of matches

Returns
-------
WOQLQuery object
query object that can be chained and/or execute
"""
if type(p) == str:
if p[:2] != 'v:':
p = {"@value" : p, "@type": "xsd:string"}
if type(pattern) == str:
if pattern[:2] != 'v:':
pattern = {"@value" : pattern, "@type": "xsd:string"}

if type(s) == str:
if s[:2] != 'v:':
s = {"@value" : s, "@type": "xsd:string"}
if type(test) == str:
if test[:2] != 'v:':
test = {"@value" : test, "@type": "xsd:string"}

if type(m) == str:
m = [m]
if type(matches) == str:
matches = [matches]

if (type(m) != dict) or ('list' not in m):
m = {'list': m}
if (type(matches) != dict) or ('list' not in matches):
matches = {'list': matches}

self.cursor['re'] = [p, s, m]
self.cursor['re'] = [pattern, test, matches]
return self

def concat(self, list, v):
Expand Down Expand Up @@ -1119,7 +1121,7 @@ def divide(self, *args):
Parameters
----------
args : int or float
numbers to tbe divided
numbers to be divided

Returns
-------
Expand Down Expand Up @@ -1155,7 +1157,9 @@ def exp(self, a, b):
Parameters
----------
a : int or float
base number
b : int or float
power of

Returns
-------
Expand Down Expand Up @@ -1256,7 +1260,7 @@ def delete_quad(self, subject, predicate, object_or_literal, graph):
return self._chainable_update('delete_quad', subject)

def add_quad(self, subject, predicate, object_or_literal, graph):
"""Adds quads according to the the pattern [S,P,O]
"""Adds quads according to the pattern [S,P,O,G]

Parameters
----------
Expand All @@ -1282,12 +1286,12 @@ def add_quad(self, subject, predicate, object_or_literal, graph):

# Schema manipulation shorthand

def add_class(self, c=None, graph=None):
def add_class(self, classid=None, graph=None):
"""Generates a new Class with the given ClassID and writes it to the DB schema

Parameters
----------
c : str
classid : str
class to be added
graph : str, optional
target graph
Expand All @@ -1297,19 +1301,19 @@ class to be added
WOQLQuery object
query object that can be chained and/or execute
"""
if c:
if classid:
graph = self.clean_graph(graph) if graph else "db:schema"
self.adding_class = c
c = "scm:" + c if c.find(":") == -1 else c
self.add_quad(c, "rdf:type", "owl:Class", graph)
self.adding_class = classid
classid = "scm:" + classid if classid.find(":") == -1 else classid
self.add_quad(classid, "rdf:type", "owl:Class", graph)
return self

def delete_class(self, c=None, graph=None):
def delete_class(self, classid=None, graph=None):
"""Deletes the Class with the passed ID form the schema (and all references to it)

Parameters
----------
c : str
classid : str
class to be deleted
graph : str, optional
target graph
Expand All @@ -1319,12 +1323,12 @@ class to be deleted
WOQLQuery object
query object that can be chained and/or execute
"""
if c:
if classid:
graph = self._clean_graph(graph) if graph else "db:schema"
c = "scm:" + c if c.find(":") == -1 else c
classid = "scm:" + classid if classid.find(":") == -1 else classid

return self.woql_and(WOQLQuery().delete_quad(c, "v:All", "v:Al2", graph),
WOQLQuery().opt().delete_quad("v:Al3", "v:Al4", c, graph))
return self.woql_and(WOQLQuery().delete_quad(classid, "v:All", "v:Al2", graph),
WOQLQuery().opt().delete_quad("v:Al3", "v:Al4", classid, graph))
return self

def add_property(self, p=None, t=None, g=None):
Expand All @@ -1336,8 +1340,8 @@ def add_property(self, p=None, t=None, g=None):
property id to be added
t : str
type of the proerty
g : str
target graph ,optional
g : str, optional
target graph

Returns
-------
Expand Down