Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare adding shacl import #148

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ Importing from alternative modeling frameworks
See :ref:`importers`

* OWL (but this only works for schema-style OWL)
* SHACL (in progress)
* JSON-Schema
* SQL DDL

In future other frameworks will be supported
In future other frameworks will be supported.

Annotating schemas
------------------
Expand Down
10 changes: 10 additions & 0 deletions docs/packages/importers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ Use robot to convert ahead of time:
robot convert -i schemaorg.ttl -o schemaorg.ofn
schemauto import-owl schemaorg.ofn

Importing from SHACL
--------------------

You can import from a SHACL shapes file.

.. code-block::

schemauto import-shacl tests/resources/test_shacl_simple.ttl


Importing from SQL
------------------

Expand Down
16 changes: 7 additions & 9 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,19 @@ linkml-runtime = "^1.7.2"
duckdb = "^0.10.1"
numpy = "<2.0"

Sphinx = { version = ">=4.4.0", optional = true }
sphinx-pdj-theme = { version = ">=0.2.1", optional = true }
sphinx-click = ">=3.1.0"
sphinxcontrib-mermaid = { version = ">=0.9.2", optional = true }

[tool.poetry.dev-dependencies]
pytest = ">=7.1.1"
Sphinx = ">=4.4.0"
sphinx-pdj-theme = ">=0.2.1"
sphinx-click = ">=3.1.0"
sphinxcontrib-mermaid = ">=0.9.2"
myst-parser = "*"
jupyter = ">=1.0.0"
lxml = ">=4.9.1"

#mariadb = { version = "^1.3", optional = true }

[tool.poetry.group.llm.dependencies]
llm = ">=0.12"

Expand All @@ -82,7 +85,7 @@ extract-schema = "schema_automator.utils.schema_extractor:cli"

[tool.poetry.extras]
docs = ["Sphinx", "sphinx-pdj-theme", "sphinxcontrib-mermaid"]
mariadb = ["mariadb"]
#mariadb = ["mariadb"]

[tool.codespell]
# Ref: https://github.com/codespell-project/codespell#using-a-config-file
Expand Down
28 changes: 28 additions & 0 deletions schema_automator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,34 @@ def import_rdfs(rdfsfile, output, metamodel_mappings, **args):
schema = sie.convert(rdfsfile, **args)
write_schema(schema, output)

@main.command()
@click.argument('shaclfile')
@output_option
@schema_name_option
@click.option('--input-type', '-I',
default='turtle',
help="Input format, eg. turtle")
@click.option('--identifier', '-I', help="Slot to use as identifier")
@click.option('--model-uri', help="Model URI prefix")
@click.option('--metamodel-mappings',
help="Path to metamodel mappings YAML dictionary")
@click.option('--output', '-o', help="Path to saved yaml schema")
def import_shacl(shaclfile, output, metamodel_mappings, **args):
"""
Import an SHACL profile to LinkML

Example:

schemauto import-shacl mymodel.shacl.ttl -o mymodel.yaml
"""
mappings_obj = None
if metamodel_mappings:
with open(metamodel_mappings) as f:
mappings_obj = yaml.safe_load(f)
sie = ShaclImportEngine(initial_metamodel_mappings=mappings_obj)
schema = sie.convert(shaclfile, **args)
write_schema(schema, output)

@main.command()
@click.argument('rdffile')
@output_option
Expand Down
1 change: 1 addition & 0 deletions schema_automator/importers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from schema_automator.importers.dosdp_import_engine import DOSDPImportEngine
from schema_automator.importers.frictionless_import_engine import FrictionlessImportEngine
from schema_automator.importers.cadsr_import_engine import CADSRImportEngine
from schema_automator.importers.shacl_import_engine import ShaclImportEngine
Loading
Loading