Skip to content

Commit cb6e783

Browse files
authored
Merge branch 'develop' into 48-implement-workflow-retrieval-phase-ruleset
2 parents b836a4b + a7c7165 commit cb6e783

File tree

122 files changed

+7524
-1151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+7524
-1151
lines changed

docs/0_toc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
:maxdepth: 5
2727
:caption: Resources
2828

29+
12_validation_profiles
2930
11_writing_a_profile
3031
10_api
3132
genindex

docs/11_writing_a_profile.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,25 @@ These instructions assume you are familiar with code development using Python an
6363
checks to write, you can create multiple files - the validator will
6464
collect them all automatically at runtime.
6565

66-
* Note: some profiles split the checks into folders called ``must/``,
66+
.. note::
67+
68+
Some profiles split the checks into folders called ``must/``,
6769
``should/`` and ``may/`` according to the requirement severity. This
6870
is not mandatory - you can also label individual checks/shapes with
6971
``sh:severity`` in the SHACL code instead.
7072

73+
#. Optionally, associate an ontology graph with the profile by providing
74+
an ``ontology.ttl`` file alongside the SHACL files.
75+
This graph is merged into the crate's data graph at validation time,
76+
allowing you to define formal relationships and additional definitions
77+
between profile entities (e.g., using ``rdfs:subClassOf``,
78+
``owl:equivalentClass``, etc.).
79+
80+
.. warning::
81+
82+
Including an ontology can significantly impact validation times and
83+
overall performance, especially for large graphs. Use with caution.
84+
7185
#. From the root folder of the repo, create a test folder for the profile
7286
under
7387
`tests/integration/profiles <https://github.com/crs4/rocrate-validator/tree/develop/tests/integration/profiles>`_. The name should match the folder you made earlier.
@@ -90,4 +104,6 @@ When running the validator manually, use ``--profile-identifier`` to select the
90104

91105
The crates in ``tests/data/crates``` can be used as examples for running the validator. For example: ::
92106

93-
rocrate-validator validate --profile-identifier your-profile-name tests/data/crates/invalid/1_wroc_crate/no_mainentity/
107+
rocrate-validator validate \
108+
--profile-identifier your-profile-name \
109+
tests/data/crates/invalid/1_wroc_crate/no_mainentity/

docs/12_validation_profiles.rst

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Validation Profiles
2+
===================
3+
4+
The system comes with a set of **predefined validation profiles** that are loaded
5+
automatically when the application starts (see `supported profiles <../#features>`_).
6+
These profiles define the standard rules and checks that are applied during RO-Crate validation.
7+
8+
Additional Profiles
9+
-------------------
10+
11+
You can **extend or override** the predefined validation profiles by specifying
12+
the path to additional profiles using the ``--extra-profiles-path`` option on the command line.
13+
14+
CLI Usage
15+
^^^^^^^^^
16+
17+
.. code-block:: bash
18+
19+
rocrate-validator validate --extra-profiles-path /path/to/additional/profiles <other_options> <path_to_rocrate>
20+
21+
API Usage
22+
^^^^^^^^^^^^^
23+
24+
.. code-block:: python
25+
26+
# Import the `services` and `models` module from the rocrate_validator package
27+
from rocrate_validator import services, models
28+
29+
# Create an instance of `ValidationSettings` class to configure the validation
30+
settings = services.ValidationSettings(
31+
# ... value for other settings ...
32+
33+
# Define the path to additional validation profiles
34+
extra_profiles_path="/path/to/additional/profiles" # Path to additional validation profiles
35+
)
36+
37+
# Call the validation service with the settings
38+
result = services.validate(settings)
39+
40+
# process the validation result
41+
...
42+
43+
44+
Behavior
45+
^^^^^^^^
46+
47+
* Profiles provided via ``--extra-profiles-path`` are **loaded in addition to** the system’s predefined profiles.
48+
* If an additional profile has the **same name** as a predefined profile, the additional profile **overrides** the predefined one.
49+
50+
This mechanism allows you to:
51+
52+
* **Add new custom validation profiles** to implement project-specific checks.
53+
* **Modify existing profiles** without altering the system’s predefined configuration files.
54+
* **Maintain a clear separation** between standard validation logic and project-specific customizations.

docs/3_usage_api.rst

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,105 @@ Programmatic Validation
2929
:parser: myst_parser.sphinx_
3030
:start-line: 121
3131
:end-line: 162
32+
33+
34+
Metadata-only Validation
35+
------------------------
36+
37+
In addition to full validation, which checks both metadata and data files,
38+
the library also supports metadata-only validation. This is useful when you
39+
want to ensure that the metadata conforms to the expected schema without
40+
checking the actual data files.
41+
42+
To perform metadata-only validation, you can use the `validate_metadata_as_dict`
43+
from the `rocrate_validator.services` module. This function takes a dictionary
44+
representing the metadata and validates it against a given validation profile.
45+
46+
.. code-block:: python
47+
48+
import json
49+
from rocrate_validator.services import validate_metadata_as_dict
50+
51+
settings = {
52+
"profile_identifier": "workflow-ro-crate-1.0"
53+
}
54+
55+
with open('tests/data/crates/invalid/0_main_workflow/main_workflow_bad_type/ro-crate-metadata.json', 'r') as f:
56+
# load the metadata from the JSON file
57+
rocrate_metadata = json.load(f)
58+
59+
# validate the metadata dictionary
60+
result = validate_metadata_as_dict(rocrate_metadata, settings=settings)
61+
62+
# process the validation result as needed
63+
...
64+
65+
66+
Formatting Validation Results
67+
-----------------------------
68+
69+
Validation results can be rendered using different output formatters provided by
70+
the library. Two formatter types are available: *text* and *JSON*.
71+
Both rely on the ``rich`` Python library and integrate with the
72+
``rocrate_validator.io.output.console.Console`` class, which extends
73+
``rich.console.Console`` to support custom formatter registration.
74+
75+
To format results, create a ``Console`` instance, register one formatter,
76+
and then print any validation output object (e.g., the full report or the
77+
aggregated statistics).
78+
79+
80+
TextOutputFormatter
81+
~~~~~~~~~~~~~~~~~~~
82+
83+
``TextOutputFormatter`` renders validation reports as human-readable, styled text.
84+
It is typically used for console output, report generation, or writing results
85+
to a file.
86+
87+
.. code-block:: python
88+
89+
from rocrate_validator.io.output.console import Console
90+
from rocrate_validator.io.output.text import TextOutputFormatter
91+
92+
console = Console()
93+
console.register_formatter(TextOutputFormatter())
94+
95+
# Print the main validation result
96+
console.print(result)
97+
98+
# Print aggregated statistics (violations by severity, executed checks, etc.)
99+
console.print(result.statistics)
100+
101+
# Write the output to a file
102+
with open("validation_report.txt", "w") as f:
103+
file_console = Console(file=f)
104+
file_console.register_formatter(TextOutputFormatter())
105+
file_console.print(result.statistics)
106+
file_console.print(result)
107+
108+
109+
JSONOutputFormatter
110+
~~~~~~~~~~~~~~~~~~~
111+
112+
``JSONOutputFormatter`` produces JSON-structured output, suitable for logging,
113+
programmatic processing, or integration with external tools.
114+
115+
.. code-block:: python
116+
117+
from rocrate_validator.io.output.console import Console
118+
from rocrate_validator.io.output.json import JSONOutputFormatter
119+
120+
console = Console()
121+
console.register_formatter(JSONOutputFormatter())
122+
123+
# Print the main validation result as JSON
124+
console.print(result)
125+
126+
# Print the aggregated statistics
127+
console.print(result.statistics)
128+
129+
# Write the output to a file
130+
with open("validation_report.json", "w") as f:
131+
file_console = Console(file=f)
132+
file_console.register_formatter(JSONOutputFormatter())
133+
file_console.print(result)

docs/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
'myst_parser',
6464
'sphinx.ext.mathjax',
6565
'enum_tools.autoenum',
66+
'sphinx.ext.intersphinx',
67+
'sphinx.ext.autosectionlabel',
68+
'sphinx_copybutton',
6669
]
6770

6871
templates_path = ['_templates']

docs/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
Welcome to rocrate-validator's documentation!
1818
=============================================
1919

20+
.. _index:
21+
2022
.. include:: ../README.md
2123
:parser: myst_parser.sphinx_
2224
:start-line: 2
2325
:end-line: 32
2426

27+
2528
.. include:: 0_toc.rst

0 commit comments

Comments
 (0)