mustrd 0.2.0__py3-none-any.whl → 0.2.2__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,126 @@
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
+
29
+ # Namespace for the test specifications
30
+ class MUST(DefinedNamespace):
31
+ _NS = Namespace("https://mustrd.com/model/")
32
+
33
+ # Specification classes
34
+ TestSpec: URIRef
35
+ SelectSparql: URIRef
36
+ ConstructSparql: URIRef
37
+ UpdateSparql: URIRef
38
+ AnzoQueryDrivenUpdateSparql: URIRef
39
+ AskSparql: URIRef
40
+ DescribeSparql: URIRef
41
+
42
+ # Specification properties
43
+ given: URIRef
44
+ when: URIRef
45
+ then: URIRef
46
+ dataSource: URIRef
47
+ file: URIRef
48
+ fileName: URIRef
49
+ queryFolder: URIRef
50
+ queryName: URIRef
51
+ dataSourceUrl: URIRef
52
+ queryText: URIRef
53
+ queryType: URIRef
54
+ hasStatement: URIRef
55
+ hasRow: URIRef
56
+ hasBinding: URIRef
57
+ variable: URIRef
58
+ boundValue: URIRef
59
+ focus: URIRef
60
+
61
+ # Specification data sources
62
+ TableDataset: URIRef
63
+ StatementsDataset: URIRef
64
+ FileDataset: URIRef
65
+ HttpDataset: URIRef
66
+ TextSparqlSource: URIRef
67
+ FileSparqlSource: URIRef
68
+ FolderSparqlSource: URIRef
69
+ FolderDataset: URIRef
70
+ EmptyGraph: URIRef
71
+ EmptyTable: URIRef
72
+ InheritedDataset: URIRef
73
+
74
+ # runner uris
75
+ fileSource: URIRef
76
+ loadedFromFile: URIRef
77
+ specSourceFile: URIRef
78
+ specFileName: URIRef
79
+
80
+ # Triple store config parameters
81
+ # Anzo
82
+ AnzoGraphmartDataset: URIRef
83
+ AnzoQueryBuilderSparqlSource: URIRef
84
+ AnzoGraphmartStepSparqlSource: URIRef
85
+ AnzoGraphmartLayerSparqlSource: URIRef
86
+ AnzoGraphmartQueryDrivenTemplatedStepSparqlSource: URIRef
87
+ anzoQueryStep: URIRef
88
+ anzoGraphmartLayer: URIRef
89
+
90
+ graphmart: URIRef
91
+ layer: URIRef
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
+
99
+ # Namespace for triplestores
100
+ class TRIPLESTORE(DefinedNamespace):
101
+ _NS = Namespace("https://mustrd.com/triplestore/")
102
+ RdfLib: URIRef
103
+ GraphDb: URIRef
104
+ Anzo: URIRef
105
+ ExternalTripleStore: URIRef
106
+ InternalTripleStore: URIRef
107
+
108
+ gqeURI: URIRef
109
+ inputGraph: URIRef
110
+ outputGraph: URIRef # anzo specials? # Triple store config parameters
111
+ url: URIRef
112
+ port: URIRef
113
+ username: URIRef
114
+ password: URIRef
115
+ repository: URIRef
116
+
117
+
118
+ # namespace for pytest_mustrd config
119
+ class MUSTRDTEST(DefinedNamespace):
120
+ _NS = Namespace("https://mustrd.com/mustrdTest/")
121
+ MustrdTest: URIRef
122
+ hasSpecPath: URIRef
123
+ hasDataPath: URIRef
124
+ triplestoreSpecPath: URIRef
125
+ hasPytestPath: URIRef
126
+ filterOnTripleStore: URIRef
mustrd/run.py CHANGED
@@ -1,106 +1,105 @@
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
+ log = logger_setup.setup_logger(__name__)
35
+
36
+
37
+ def parse_args() -> argparse.Namespace:
38
+ parser = argparse.ArgumentParser()
39
+ parser.add_argument("-p", "--put", help="Path under test - required", required=True)
40
+ parser.add_argument("-v", "--verbose", help="verbose logging", action='store_true')
41
+ parser.add_argument("-c", "--config", help="Path to triple store configuration", default=None)
42
+ parser.add_argument("-d", "--data", help="Path to test data", default=None)
43
+ parser.add_argument("-g", "--given", help="Override path for given files", default=None)
44
+ parser.add_argument("-w", "--when", help="Override path for when files", default=None)
45
+ parser.add_argument("-t", "--then", help="Override path for then files", default=None)
46
+
47
+ return parser.parse_args()
48
+
49
+
50
+ # https://github.com/Semantic-partners/mustrd/issues/108
51
+ def main(argv):
52
+ # Given_path = when_path = then_path = None
53
+ project_root = get_project_root()
54
+ run_config = {}
55
+ args = parse_args()
56
+ run_config["spec_path"] = Path(args.put)
57
+ log.info(f"Path under test is { run_config['spec_path']}")
58
+
59
+ verbose = args.verbose
60
+ if verbose:
61
+ log.info("Verbose set")
62
+ run_config["verbose"] = True
63
+
64
+ if args.config:
65
+ triplestore_spec_path = Path(args.config)
66
+ log.info(f"Path for triple store configuration is {triplestore_spec_path}")
67
+ triple_stores = get_triple_stores(get_triple_store_graph(triplestore_spec_path))
68
+ else:
69
+ log.info("No triple store configuration added, running default configuration")
70
+ triple_stores = [{'type': TRIPLESTORE.RdfLib}]
71
+ log.info("Triple Stores: " + str(triple_stores))
72
+ if args.data:
73
+ run_config["data_path"] = Path(args.data)
74
+ else:
75
+ run_config["data_path"] = Path(args.put)
76
+ log.info(f"Path for test data folder is {run_config['data_path']}")
77
+
78
+ if args.given:
79
+ run_config["given_path"] = Path(args.given)
80
+ log.info(f"Path for given folder is {run_config['given_path']}")
81
+
82
+ if args.when:
83
+ run_config["when_path"] = Path(args.when)
84
+ log.info(f"Path for when folder is {run_config['when_path']}")
85
+
86
+ if args.then:
87
+ run_config["then_path"] = Path(args.then)
88
+ log.info(f"Path for then folder is {run_config['then_path']}")
89
+
90
+ shacl_graph = Graph().parse(Path(os.path.join(project_root, "model/mustrdShapes.ttl")))
91
+ ont_graph = Graph().parse(Path(os.path.join(project_root, "model/ontology.ttl")))
92
+
93
+ valid_spec_uris, spec_graph, invalid_spec_results = \
94
+ validate_specs(run_config, triple_stores, shacl_graph, ont_graph)
95
+
96
+ specs, skipped_spec_results = \
97
+ get_specs(valid_spec_uris, spec_graph, triple_stores, run_config)
98
+
99
+ results = invalid_spec_results + skipped_spec_results + run_specs(specs)
100
+
101
+ review_results(results, verbose)
102
+
103
+
104
+ if __name__ == "__main__":
105
+ main(sys.argv[1:])