-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from white-gecko/feature/fixSchemaGeneration
Fix schema generation and reorganize some schema code
- Loading branch information
Showing
4 changed files
with
80 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from rdflib import Graph | ||
from urllib.parse import urlparse | ||
|
||
|
||
class Generator: | ||
def __init__(self, graph: Graph, prefixes=None): | ||
pass | ||
|
||
def sh_label_gen(self, uri): | ||
prefix, namespace, name = self.namespaces.compute_qname(uri) | ||
return prefix + "_" + name | ||
|
||
def uri_validator(self, x): | ||
try: | ||
result = urlparse(x) | ||
return all([result.scheme, result.netloc]) | ||
except Exception: | ||
return False | ||
|
||
def gen_graph(self, namespace=None, implicit_class_target=False): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from rdflib import Graph | ||
from shaclgen.schema import schema | ||
from helpers import assertAskQuery | ||
|
||
|
||
def test_namespace(): | ||
source_graph = Graph() | ||
|
||
data = """ | ||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | ||
<urn:test:Class> a rdfs:Class . | ||
""" | ||
|
||
source_graph.parse(data=data, format="turtle") | ||
|
||
extraction_graph = schema(source_graph) | ||
shacl_graph = extraction_graph.gen_graph( | ||
namespace=("http://custom.namespace.org/", "custom") | ||
) | ||
|
||
assertAskQuery( | ||
shacl_graph, | ||
""" | ||
prefix sh: <http://www.w3.org/ns/shacl#> | ||
prefix xsd: <http://www.w3.org/2001/XMLSchema#> | ||
ask { | ||
?nodeShape a sh:NodeShape . | ||
filter regex(str(?nodeShape), "^http://custom.namespace.org/") | ||
} | ||
""", | ||
) |