-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
104 changed files
with
1,556 additions
and
28 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,27 @@ | ||
name: Run Unit Test via Pytest | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.10"] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
if [ -f requirements_dev.txt ]; then pip install -r requirements_dev.txt; fi | ||
- name: Test with pytest | ||
run: | | ||
coverage run -m pytest -v -s | ||
- name: Generate Coverage Report | ||
run: | | ||
coverage report -m |
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 @@ | ||
import argparse | ||
import os | ||
from src.file_parser import parse_json_schema | ||
from src.json_schema_to_shacl import JsonSchemaToShacl | ||
|
||
|
||
def main(): | ||
"""Main function to execute""" | ||
parser = argparse.ArgumentParser( | ||
description="Translate JSON Schema to SHACL") | ||
parser.add_argument("json_file", type=str, | ||
help="Path to JSON Schema file") | ||
args = parser.parse_args() | ||
|
||
file_path = args.json_file | ||
schema = parse_json_schema(file_path) | ||
|
||
json_converter = JsonSchemaToShacl() | ||
|
||
if schema is not None: | ||
json_converter.translate(schema) | ||
# Remove the last component of the path | ||
base_path = os.path.dirname(file_path) | ||
base_name = os.path.splitext(os.path.basename(file_path))[ | ||
0] # Remove the .json extension | ||
# Construct the new file name with .shape.ttl extension | ||
file_name = os.path.join(base_path, base_name + "_shape.ttl") | ||
json_converter.shacl.serialize(format="turtle", destination=file_name) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,2 @@ | ||
[pytest] | ||
pythonpath = . |
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,4 @@ | ||
jsonpath-ng==1.6.1 | ||
owlrl==6.0.2 | ||
pyshacl==0.26.0 | ||
rdflib==7.0.0 |
Empty file.
Empty file.
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,4 @@ | ||
{ | ||
"type": "number", | ||
"name": "credit_card" | ||
} |
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,18 @@ | ||
import os | ||
from rdflib import compare, Graph | ||
from src.file_parser import parse_json_schema | ||
from src.json_schema_to_shacl import JsonSchemaToShacl | ||
|
||
|
||
def test_1simpletype(): | ||
expected_graph = Graph() | ||
expected_graph.parse(os.path.join(os.path.dirname( | ||
os.path.realpath(__file__)), 'test_shape.ttl'), format="turtle") | ||
|
||
result_graph = Graph() | ||
json_schema = parse_json_schema( | ||
os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.json')) | ||
result_graph = JsonSchemaToShacl().translate( | ||
json_schema) | ||
|
||
assert compare.isomorphic(expected_graph, result_graph) |
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,8 @@ | ||
@prefix sh: <http://www.w3.org/ns/shacl#> . | ||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | ||
|
||
<http://example.com/PropertyShape/credit_card> a sh:PropertyShape ; | ||
sh:datatype xsd:decimal ; | ||
sh:name "credit_card" ; | ||
sh:path <http://example.com/credit_card> . | ||
|
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,8 @@ | ||
{ | ||
"type": "array", | ||
"name" :"test", | ||
"items": { | ||
"type": "number" | ||
} | ||
} | ||
|
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,18 @@ | ||
import os | ||
from rdflib import compare, Graph | ||
from src.file_parser import parse_json_schema | ||
from src.json_schema_to_shacl import JsonSchemaToShacl | ||
|
||
|
||
def test_10item(): | ||
expected_graph = Graph() | ||
expected_graph.parse(os.path.join(os.path.dirname( | ||
os.path.realpath(__file__)), 'test_shape.ttl'), format="turtle") | ||
|
||
result_graph = Graph() | ||
json_schema = parse_json_schema( | ||
os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.json')) | ||
result_graph = JsonSchemaToShacl().translate( | ||
json_schema) | ||
|
||
assert compare.isomorphic(expected_graph, result_graph) |
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,10 @@ | ||
@prefix sh: <http://www.w3.org/ns/shacl#> . | ||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | ||
|
||
<http://example.com/NodeShape/test> sh:property <http://example.com/PropertyShape/test> . | ||
|
||
<http://example.com/PropertyShape/test> a sh:PropertyShape ; | ||
sh:datatype xsd:decimal ; | ||
sh:name "test" ; | ||
sh:path <http://example.com/test> . | ||
|
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,11 @@ | ||
{ | ||
"type": "array", | ||
"name" :"test", | ||
"prefixItems": [ | ||
{ "type": "number" }, | ||
{ "type": "string" }, | ||
{ "enum": ["Street", "Avenue", "Boulevard"] }, | ||
{ "enum": ["NW", "NE", "SW", "SE"] } | ||
] | ||
} | ||
|
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,18 @@ | ||
import os | ||
from rdflib import compare, Graph | ||
from src.file_parser import parse_json_schema | ||
from src.json_schema_to_shacl import JsonSchemaToShacl | ||
|
||
|
||
def test_11prefixitems(): | ||
expected_graph = Graph() | ||
expected_graph.parse(os.path.join(os.path.dirname( | ||
os.path.realpath(__file__)), 'test_shape.ttl'), format="turtle") | ||
|
||
result_graph = Graph() | ||
json_schema = parse_json_schema( | ||
os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.json')) | ||
result_graph = JsonSchemaToShacl().translate( | ||
json_schema) | ||
|
||
assert compare.isomorphic(expected_graph, result_graph) |
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,35 @@ | ||
@prefix sh: <http://www.w3.org/ns/shacl#> . | ||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | ||
|
||
<http://example.com/NodeShape/test> a sh:NodeShape ; | ||
sh:name "test" ; | ||
sh:property <http://example.com/PropertyShape/testP0>, | ||
<http://example.com/PropertyShape/testP1>, | ||
<http://example.com/PropertyShape/testP2>, | ||
<http://example.com/PropertyShape/testP3> . | ||
|
||
<http://example.com/PropertyShape/testP0> a sh:PropertyShape ; | ||
sh:datatype xsd:decimal ; | ||
sh:name "testP0" ; | ||
sh:path <http://example.com/testP0> . | ||
|
||
<http://example.com/PropertyShape/testP1> a sh:PropertyShape ; | ||
sh:datatype xsd:string ; | ||
sh:name "testP1" ; | ||
sh:path <http://example.com/testP1> . | ||
|
||
<http://example.com/PropertyShape/testP2> a sh:PropertyShape ; | ||
sh:in_ "Avenue", | ||
"Boulevard", | ||
"Street" ; | ||
sh:name "testP2" ; | ||
sh:path <http://example.com/testP2> . | ||
|
||
<http://example.com/PropertyShape/testP3> a sh:PropertyShape ; | ||
sh:in_ "NE", | ||
"NW", | ||
"SE", | ||
"SW" ; | ||
sh:name "testP3" ; | ||
sh:path <http://example.com/testP3> . | ||
|
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,13 @@ | ||
{ | ||
"type": "array", | ||
"name": "test", | ||
"prefixItems": [ | ||
{ | ||
"type": "string" | ||
}, | ||
{ | ||
"type": "number" | ||
} | ||
], | ||
"unevaluatedItems": false | ||
} |
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,18 @@ | ||
import os | ||
from rdflib import compare, Graph | ||
from src.file_parser import parse_json_schema | ||
from src.json_schema_to_shacl import JsonSchemaToShacl | ||
|
||
|
||
def test_12unevaluateditems(): | ||
expected_graph = Graph() | ||
expected_graph.parse(os.path.join(os.path.dirname( | ||
os.path.realpath(__file__)), 'test_shape.ttl'), format="turtle") | ||
|
||
result_graph = Graph() | ||
json_schema = parse_json_schema( | ||
os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.json')) | ||
result_graph = JsonSchemaToShacl().translate( | ||
json_schema) | ||
|
||
assert compare.isomorphic(expected_graph, result_graph) |
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,18 @@ | ||
@prefix sh: <http://www.w3.org/ns/shacl#> . | ||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | ||
|
||
<http://example.com/NodeShape/test> a sh:NodeShape ; | ||
sh:name "test" ; | ||
sh:property <http://example.com/PropertyShape/testP0>, | ||
<http://example.com/PropertyShape/testP1> . | ||
|
||
<http://example.com/PropertyShape/testP0> a sh:PropertyShape ; | ||
sh:datatype xsd:string ; | ||
sh:name "testP0" ; | ||
sh:path <http://example.com/testP0> . | ||
|
||
<http://example.com/PropertyShape/testP1> a sh:PropertyShape ; | ||
sh:datatype xsd:decimal ; | ||
sh:name "testP1" ; | ||
sh:path <http://example.com/testP1> . | ||
|
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,11 @@ | ||
{ | ||
"type": "array", | ||
"name": "test", | ||
"items": { | ||
"type": "number" | ||
}, | ||
"contains": { | ||
"type": "number" | ||
} | ||
} | ||
|
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,18 @@ | ||
import os | ||
from rdflib import compare, Graph | ||
from src.file_parser import parse_json_schema | ||
from src.json_schema_to_shacl import JsonSchemaToShacl | ||
|
||
|
||
def test_13contains(): | ||
expected_graph = Graph() | ||
expected_graph.parse(os.path.join(os.path.dirname( | ||
os.path.realpath(__file__)), 'test_shape.ttl'), format="turtle") | ||
|
||
result_graph = Graph() | ||
json_schema = parse_json_schema( | ||
os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.json')) | ||
result_graph = JsonSchemaToShacl().translate( | ||
json_schema) | ||
|
||
assert compare.isomorphic(expected_graph, result_graph) |
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,16 @@ | ||
@prefix sh: <http://www.w3.org/ns/shacl#> . | ||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | ||
|
||
<http://example.com/NodeShape/test> sh:property <http://example.com/PropertyShape/testP0>, | ||
<http://example.com/PropertyShape/testP1> . | ||
|
||
<http://example.com/PropertyShape/testP0> a sh:PropertyShape ; | ||
sh:datatype xsd:decimal ; | ||
sh:name "testP0" ; | ||
sh:path <http://example.com/testP0> . | ||
|
||
<http://example.com/PropertyShape/testP1> a sh:PropertyShape ; | ||
sh:datatype xsd:decimal ; | ||
sh:name "testP1" ; | ||
sh:path <http://example.com/testP1> . | ||
|
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,8 @@ | ||
{ | ||
"type": "array", | ||
"name": "test", | ||
"items": { | ||
"type": "number" | ||
}, | ||
"uniqueItems": true | ||
} |
Oops, something went wrong.