mustrd 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mustrd/namespace.py CHANGED
@@ -1,125 +1,125 @@
1
- """
2
- MIT License
3
-
4
- Copyright (c) 2023 Semantic Partners Ltd
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in all
14
- copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- SOFTWARE.
23
- """
24
-
25
- from rdflib import URIRef
26
- from rdflib.namespace import DefinedNamespace, Namespace
27
-
28
- # Namespace for the test specifications
29
- class MUST(DefinedNamespace):
30
- _NS = Namespace("https://mustrd.com/model/")
31
-
32
- # Specification classes
33
- TestSpec: URIRef
34
- SelectSparql: URIRef
35
- ConstructSparql: URIRef
36
- UpdateSparql: URIRef
37
- AnzoQueryDrivenUpdateSparql: URIRef
38
- AskSparql: URIRef
39
- DescribeSparql: URIRef
40
-
41
- # Specification properties
42
- given: URIRef
43
- when: URIRef
44
- then: URIRef
45
- dataSource: URIRef
46
- file: URIRef
47
- fileName: URIRef
48
- queryFolder: URIRef
49
- queryName: URIRef
50
- dataSourceUrl: URIRef
51
- queryText: URIRef
52
- queryType: URIRef
53
- hasStatement: URIRef
54
- hasRow: URIRef
55
- hasBinding: URIRef
56
- variable: URIRef
57
- boundValue: URIRef
58
- focus:URIRef
59
-
60
- # Specification data sources
61
- TableDataset: URIRef
62
- StatementsDataset: URIRef
63
- FileDataset: URIRef
64
- HttpDataset: URIRef
65
- TextSparqlSource: URIRef
66
- FileSparqlSource: URIRef
67
- FolderSparqlSource: URIRef
68
- FolderDataset: URIRef
69
- EmptyGraph: URIRef
70
- EmptyTable: URIRef
71
- InheritedDataset: URIRef
72
-
73
- # runner uris
74
- fileSource: URIRef
75
- loadedFromFile: URIRef
76
- specSourceFile: URIRef
77
- specFileName: URIRef
78
-
79
- # Triple store config parameters
80
- # Anzo
81
- AnzoGraphmartDataset: URIRef
82
- AnzoQueryBuilderSparqlSource: URIRef
83
- AnzoGraphmartStepSparqlSource: URIRef
84
- AnzoGraphmartLayerSparqlSource: URIRef
85
- AnzoGraphmartQueryDrivenTemplatedStepSparqlSource: URIRef
86
- anzoQueryStep: URIRef
87
- anzoGraphmartLayer: URIRef
88
-
89
- graphmart: URIRef
90
- layer: URIRef
91
-
92
-
93
- # FIXME: There is nothing to do that by default?
94
- @classmethod
95
- def get_local_name(cls, uri: URIRef):
96
- return str(uri).split(cls._NS)[1]
97
-
98
- # Namespace for triplestores
99
- class TRIPLESTORE(DefinedNamespace):
100
- _NS = Namespace("https://mustrd.com/triplestore/")
101
- RdfLib: URIRef
102
- GraphDb: URIRef
103
- Anzo: URIRef
104
- ExternalTripleStore: URIRef
105
- InternalTripleStore: URIRef
106
-
107
- gqeURI: URIRef
108
- inputGraph: URIRef
109
- outputGraph: URIRef # anzo specials? # Triple store config parameters
110
- url: URIRef
111
- port: URIRef
112
- username: URIRef
113
- password: URIRef
114
- repository: URIRef
115
-
116
- # namespace for pytest_mustrd config
117
- class MUSTRDTEST(DefinedNamespace):
118
- _NS = Namespace("https://mustrd.com/mustrdTest/")
119
- MustrdTest: URIRef
120
- hasSpecPath: URIRef
121
- hasDataPath: URIRef
122
- triplestoreSpecPath: URIRef
123
- hasPytestPath: URIRef
124
- filterOnTripleStore: URIRef
125
-
1
+ """
2
+ MIT License
3
+
4
+ Copyright (c) 2023 Semantic Partners Ltd
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ """
24
+
25
+ from rdflib import URIRef
26
+ from rdflib.namespace import DefinedNamespace, Namespace
27
+
28
+ # Namespace for the test specifications
29
+ class MUST(DefinedNamespace):
30
+ _NS = Namespace("https://mustrd.com/model/")
31
+
32
+ # Specification classes
33
+ TestSpec: URIRef
34
+ SelectSparql: URIRef
35
+ ConstructSparql: URIRef
36
+ UpdateSparql: URIRef
37
+ AnzoQueryDrivenUpdateSparql: URIRef
38
+ AskSparql: URIRef
39
+ DescribeSparql: URIRef
40
+
41
+ # Specification properties
42
+ given: URIRef
43
+ when: URIRef
44
+ then: URIRef
45
+ dataSource: URIRef
46
+ file: URIRef
47
+ fileName: URIRef
48
+ queryFolder: URIRef
49
+ queryName: URIRef
50
+ dataSourceUrl: URIRef
51
+ queryText: URIRef
52
+ queryType: URIRef
53
+ hasStatement: URIRef
54
+ hasRow: URIRef
55
+ hasBinding: URIRef
56
+ variable: URIRef
57
+ boundValue: URIRef
58
+ focus:URIRef
59
+
60
+ # Specification data sources
61
+ TableDataset: URIRef
62
+ StatementsDataset: URIRef
63
+ FileDataset: URIRef
64
+ HttpDataset: URIRef
65
+ TextSparqlSource: URIRef
66
+ FileSparqlSource: URIRef
67
+ FolderSparqlSource: URIRef
68
+ FolderDataset: URIRef
69
+ EmptyGraph: URIRef
70
+ EmptyTable: URIRef
71
+ InheritedDataset: URIRef
72
+
73
+ # runner uris
74
+ fileSource: URIRef
75
+ loadedFromFile: URIRef
76
+ specSourceFile: URIRef
77
+ specFileName: URIRef
78
+
79
+ # Triple store config parameters
80
+ # Anzo
81
+ AnzoGraphmartDataset: URIRef
82
+ AnzoQueryBuilderSparqlSource: URIRef
83
+ AnzoGraphmartStepSparqlSource: URIRef
84
+ AnzoGraphmartLayerSparqlSource: URIRef
85
+ AnzoGraphmartQueryDrivenTemplatedStepSparqlSource: URIRef
86
+ anzoQueryStep: URIRef
87
+ anzoGraphmartLayer: URIRef
88
+
89
+ graphmart: URIRef
90
+ layer: URIRef
91
+
92
+
93
+ # FIXME: There is nothing to do that by default?
94
+ @classmethod
95
+ def get_local_name(cls, uri: URIRef):
96
+ return str(uri).split(cls._NS)[1]
97
+
98
+ # Namespace for triplestores
99
+ class TRIPLESTORE(DefinedNamespace):
100
+ _NS = Namespace("https://mustrd.com/triplestore/")
101
+ RdfLib: URIRef
102
+ GraphDb: URIRef
103
+ Anzo: URIRef
104
+ ExternalTripleStore: URIRef
105
+ InternalTripleStore: URIRef
106
+
107
+ gqeURI: URIRef
108
+ inputGraph: URIRef
109
+ outputGraph: URIRef # anzo specials? # Triple store config parameters
110
+ url: URIRef
111
+ port: URIRef
112
+ username: URIRef
113
+ password: URIRef
114
+ repository: URIRef
115
+
116
+ # namespace for pytest_mustrd config
117
+ class MUSTRDTEST(DefinedNamespace):
118
+ _NS = Namespace("https://mustrd.com/mustrdTest/")
119
+ MustrdTest: URIRef
120
+ hasSpecPath: URIRef
121
+ hasDataPath: URIRef
122
+ triplestoreSpecPath: URIRef
123
+ hasPytestPath: URIRef
124
+ filterOnTripleStore: URIRef
125
+
mustrd/run.py CHANGED
@@ -1,106 +1,106 @@
1
- """
2
- MIT License
3
-
4
- Copyright (c) 2023 Semantic Partners Ltd
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in all
14
- copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- SOFTWARE.
23
- """
24
-
25
- import argparse
26
- import logger_setup
27
- import sys
28
- import os
29
- from rdflib import Graph
30
- from .mustrd import get_triple_store_graph, run_specs, get_triple_stores, review_results, validate_specs, get_specs
31
- from pathlib import Path
32
- from .namespace import TRIPLESTORE
33
- from .utils import get_project_root
34
- import logging
35
- log = logger_setup.setup_logger(__name__)
36
-
37
-
38
- def parse_args() -> argparse.Namespace:
39
- parser = argparse.ArgumentParser()
40
- parser.add_argument("-p", "--put", help="Path under test - required", required=True)
41
- parser.add_argument("-v", "--verbose", help="verbose logging", action='store_true')
42
- parser.add_argument("-c", "--config", help="Path to triple store configuration", default=None)
43
- parser.add_argument("-d", "--data", help="Path to test data", default=None)
44
- parser.add_argument("-g", "--given", help="Override path for given files", default=None)
45
- parser.add_argument("-w", "--when", help="Override path for when files", default=None)
46
- parser.add_argument("-t", "--then", help="Override path for then files", default=None)
47
-
48
- return parser.parse_args()
49
-
50
-
51
- # https://github.com/Semantic-partners/mustrd/issues/108
52
- def main(argv):
53
- #given_path = when_path = then_path = None
54
- project_root = get_project_root()
55
- run_config = {}
56
- args = parse_args()
57
- run_config["spec_path"] = Path(args.put)
58
- log.info(f"Path under test is { run_config['spec_path']}")
59
-
60
- verbose = args.verbose
61
- if verbose:
62
- log.info(f"Verbose set")
63
- run_config["verbose"] = True
64
-
65
- if args.config:
66
- triplestore_spec_path = Path(args.config)
67
- log.info(f"Path for triple store configuration is {triplestore_spec_path}")
68
- triple_stores = get_triple_stores(get_triple_store_graph(triplestore_spec_path))
69
- else:
70
- log.info(f"No triple store configuration added, running default configuration")
71
- triple_stores = [{'type': TRIPLESTORE.RdfLib}]
72
- log.info("Triple Stores: " + str(triple_stores))
73
- if args.data:
74
- run_config["data_path"] = Path(args.data)
75
- else:
76
- run_config["data_path"] = Path(args.put)
77
- log.info(f"Path for test data folder is {run_config['data_path']}")
78
-
79
- if args.given:
80
- run_config["given_path"] = Path(args.given)
81
- log.info(f"Path for given folder is {run_config['given_path']}")
82
-
83
- if args.when:
84
- run_config["when_path"] = Path(args.when)
85
- log.info(f"Path for when folder is {run_config['when_path']}")
86
-
87
- if args.then:
88
- run_config["then_path"] = Path(args.then)
89
- log.info(f"Path for then folder is {run_config['then_path']}")
90
-
91
- shacl_graph = Graph().parse(Path(os.path.join(project_root, "model/mustrdShapes.ttl")))
92
- ont_graph = Graph().parse(Path(os.path.join(project_root, "model/ontology.ttl")))
93
-
94
- valid_spec_uris, spec_graph, invalid_spec_results = \
95
- validate_specs(run_config, triple_stores, shacl_graph, ont_graph)
96
-
97
- specs, skipped_spec_results = \
98
- get_specs(valid_spec_uris, spec_graph, triple_stores, run_config)
99
-
100
- results = invalid_spec_results + skipped_spec_results + run_specs(specs)
101
-
102
- review_results(results, verbose)
103
-
104
-
105
- if __name__ == "__main__":
106
- main(sys.argv[1:])
1
+ """
2
+ MIT License
3
+
4
+ Copyright (c) 2023 Semantic Partners Ltd
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ """
24
+
25
+ import argparse
26
+ import logger_setup
27
+ import sys
28
+ import os
29
+ from rdflib import Graph
30
+ from .mustrd import get_triple_store_graph, run_specs, get_triple_stores, review_results, validate_specs, get_specs
31
+ from pathlib import Path
32
+ from .namespace import TRIPLESTORE
33
+ from .utils import get_project_root
34
+ import logging
35
+ log = logger_setup.setup_logger(__name__)
36
+
37
+
38
+ def parse_args() -> argparse.Namespace:
39
+ parser = argparse.ArgumentParser()
40
+ parser.add_argument("-p", "--put", help="Path under test - required", required=True)
41
+ parser.add_argument("-v", "--verbose", help="verbose logging", action='store_true')
42
+ parser.add_argument("-c", "--config", help="Path to triple store configuration", default=None)
43
+ parser.add_argument("-d", "--data", help="Path to test data", default=None)
44
+ parser.add_argument("-g", "--given", help="Override path for given files", default=None)
45
+ parser.add_argument("-w", "--when", help="Override path for when files", default=None)
46
+ parser.add_argument("-t", "--then", help="Override path for then files", default=None)
47
+
48
+ return parser.parse_args()
49
+
50
+
51
+ # https://github.com/Semantic-partners/mustrd/issues/108
52
+ def main(argv):
53
+ #given_path = when_path = then_path = None
54
+ project_root = get_project_root()
55
+ run_config = {}
56
+ args = parse_args()
57
+ run_config["spec_path"] = Path(args.put)
58
+ log.info(f"Path under test is { run_config['spec_path']}")
59
+
60
+ verbose = args.verbose
61
+ if verbose:
62
+ log.info(f"Verbose set")
63
+ run_config["verbose"] = True
64
+
65
+ if args.config:
66
+ triplestore_spec_path = Path(args.config)
67
+ log.info(f"Path for triple store configuration is {triplestore_spec_path}")
68
+ triple_stores = get_triple_stores(get_triple_store_graph(triplestore_spec_path))
69
+ else:
70
+ log.info(f"No triple store configuration added, running default configuration")
71
+ triple_stores = [{'type': TRIPLESTORE.RdfLib}]
72
+ log.info("Triple Stores: " + str(triple_stores))
73
+ if args.data:
74
+ run_config["data_path"] = Path(args.data)
75
+ else:
76
+ run_config["data_path"] = Path(args.put)
77
+ log.info(f"Path for test data folder is {run_config['data_path']}")
78
+
79
+ if args.given:
80
+ run_config["given_path"] = Path(args.given)
81
+ log.info(f"Path for given folder is {run_config['given_path']}")
82
+
83
+ if args.when:
84
+ run_config["when_path"] = Path(args.when)
85
+ log.info(f"Path for when folder is {run_config['when_path']}")
86
+
87
+ if args.then:
88
+ run_config["then_path"] = Path(args.then)
89
+ log.info(f"Path for then folder is {run_config['then_path']}")
90
+
91
+ shacl_graph = Graph().parse(Path(os.path.join(project_root, "model/mustrdShapes.ttl")))
92
+ ont_graph = Graph().parse(Path(os.path.join(project_root, "model/ontology.ttl")))
93
+
94
+ valid_spec_uris, spec_graph, invalid_spec_results = \
95
+ validate_specs(run_config, triple_stores, shacl_graph, ont_graph)
96
+
97
+ specs, skipped_spec_results = \
98
+ get_specs(valid_spec_uris, spec_graph, triple_stores, run_config)
99
+
100
+ results = invalid_spec_results + skipped_spec_results + run_specs(specs)
101
+
102
+ review_results(results, verbose)
103
+
104
+
105
+ if __name__ == "__main__":
106
+ main(sys.argv[1:])