Skip to content

Commit 35a1f2f

Browse files
prohdeavellino-7
andcommitted
add documentation
Documentation built with Sphinx and hosted at github.io. --------- Co-authored-by: avellino <[email protected]>
1 parent b6b6203 commit 35a1f2f

36 files changed

+126359
-363
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ venv/
1414

1515
DeTrusty/Sparql/Parser/parsetab.py
1616

17-
.decompositions.log
17+
.decompositions.log
18+
.rdfmts.log

DeTrusty/Molecule/MTCreation.py

+22
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@ def get_params(self):
5858
def create_rdfmts(endpoints: list | dict,
5959
output: Optional[str] = DEFAULT_OUTPUT_PATH,
6060
interlinking: bool = False) -> Optional[JSONConfig]:
61+
62+
"""Generating rdfmts.json, which need to be supplied during query execution using run_query
63+
64+
Parameters
65+
----------
66+
endpoints : list or dict
67+
The endpoints, from which informations will be collected.
68+
output : str, optional
69+
Path location in which the generated configuration will be saved.
70+
71+
* In case of not supplied: default path will be used, i.e. path/to/DeTrusty-installation/Config/rdfmts.json'
72+
* In case of None is supplied: the config won't be saved, instead JSONConfig files will be returned.
73+
74+
interlinking : bool, optional
75+
When supplied with True, the module will assume that there's an interlinks between endpoints, and thus generating configuration that suits this purpose. Default value is False.
76+
77+
Return
78+
------
79+
JSONConfig, optional
80+
only generating return value when output=None.
81+
82+
"""
6183
logger_wrapper = get_logger('DeTrusty.Wrapper.RDFWrapper')
6284
logger_wrapper.setLevel(logging.WARNING) # temporarily disable logging of contacting the source
6385

DeTrusty/Molecule/MTManager.py

+37
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,39 @@
1313

1414

1515
def get_config(config_input: str | list[dict]):
16+
"""Creates an object with the internal representation of the source descriptions.
17+
18+
Based on the type of input, this function will create a ``Config`` object either
19+
from a local file, remote file, or a list of dictionaries. The source descriptions
20+
are later used by DeTrusty for the source selection and decomposition. The main
21+
usage of this function is to read stored source descriptions from a file (local or remote)
22+
in order to reuse them for query execution over the same federation.
23+
24+
Parameters
25+
----------
26+
config_input: str | list[dict]
27+
The source description to transform into the internal representation. Might be a string holding the path
28+
to a configuration file. The configuration file can be local or remote (accessible via GET request).
29+
The source description can also be a parsed JSON, i.e., a list of Python dictionaries. Each dictionary
30+
represents a so-called *RDF Molecule Template*.
31+
32+
Returns
33+
-------
34+
Config
35+
The object holding the internal representation of the source descriptions. The result might be ``None``
36+
if there was an issue while reading the source descriptions that did not lead to an exception.
37+
38+
Examples
39+
--------
40+
The example calls assume that the file ``rdftms.json`` is a valid source description file created by DeTrusty.
41+
See `Creating Source Descriptions <https://sdm-tib.github.io/DeTrusty/library.html#creating-source-descriptions>`_
42+
for more information.
43+
44+
>>> get_config('./rdfmts.json')
45+
46+
>>> get_config('http://example.com/rdfmts.json')
47+
48+
"""
1649
if isinstance(config_input, list):
1750
return JSONConfig(config_input)
1851
else:
@@ -167,11 +200,15 @@ def saveToFile(self, path):
167200

168201
class ConfigFile(Config):
169202
def __init__(self, configfile):
203+
self.orig_file = configfile
170204
if os.path.isfile(configfile):
171205
super().__init__(configfile=configfile)
172206
else:
173207
super().__init__()
174208

209+
def __repr__(self):
210+
return 'ConfigFile(' + str(self.orig_file) + ')'
211+
175212
def getAll(self):
176213
return self.read_json_file(self.configfile)
177214

DeTrusty/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ def run_query(query: str,
6464
It returns an error message in the 'error' field if something went wrong. Other metadata might
6565
be omitted in that case.
6666
67+
Examples
68+
--------
69+
The example calls assume that an object ``config`` with the source descriptions exists.
70+
71+
>>> run_query('SELECT ?s WHERE { ?s a <http://example.com/Person> }', config=config)
72+
73+
>>> run_query('./query.rq', config=config)
74+
75+
>>> run_query('http://example.com/queries/query.rq', config=config)
76+
6777
"""
6878
start_time = time.time()
6979
decomposer = Decomposer(get_query_string(query), config,

0 commit comments

Comments
 (0)