|
13 | 13 |
|
14 | 14 |
|
15 | 15 | 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 | + """ |
16 | 49 | if isinstance(config_input, list):
|
17 | 50 | return JSONConfig(config_input)
|
18 | 51 | else:
|
@@ -167,11 +200,15 @@ def saveToFile(self, path):
|
167 | 200 |
|
168 | 201 | class ConfigFile(Config):
|
169 | 202 | def __init__(self, configfile):
|
| 203 | + self.orig_file = configfile |
170 | 204 | if os.path.isfile(configfile):
|
171 | 205 | super().__init__(configfile=configfile)
|
172 | 206 | else:
|
173 | 207 | super().__init__()
|
174 | 208 |
|
| 209 | + def __repr__(self): |
| 210 | + return 'ConfigFile(' + str(self.orig_file) + ')' |
| 211 | + |
175 | 212 | def getAll(self):
|
176 | 213 | return self.read_json_file(self.configfile)
|
177 | 214 |
|
|
0 commit comments