You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/tutorial.rst
+43Lines changed: 43 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -983,6 +983,49 @@ A cardinality is set via its convenience method:
983
983
>>> # or
984
984
>>> prop.val_cardinality =None
985
985
986
+
Working with Validations
987
+
------------------------
988
+
989
+
odML Validations are a set of pre-defined checks that are run against an odML document automatically when it is saved or loaded. A document cannot be saved, if a Validation fails a check that is classified as an Error. Most validation checks are Warnings that are supposed to raise the overall data quality of the odml Document.
990
+
991
+
When an odML document is saved or loaded, tha automatic validation will print a short report of encountered Validation Warnings and it is up to the user whether they want to resolve the Warnings. The odML document provides the ``validate`` method to gain easy access to the default validations. A Validation in turn provides not only a specific description of all encountered warnings or errors within an odML document, but it also provides direct access to each and every odML entity i.e. an odml.Section or an odml.Property where am issue has been found. This enables the user to quickly access and fix an encountered issue.
992
+
993
+
A minimal example shows how a workflow using default validations might look like:
994
+
995
+
>>> # Create a minimal document with Section issues: name and type are not assigned
996
+
>>> doc = odml.Document()
997
+
>>> sec = odml.Section(parent=doc)
998
+
>>> odml.save(doc, "validation_example.odml.xml")
999
+
1000
+
This minimal example document will be saved, but will also print the following Validation report:
1001
+
1002
+
>>> UserWarning: The saved Document contains unresolved issues. Run the Documents 'validate' method to access them.
To fix the encountered warnings, users can access the validation via the documents' ``validate`` method:
1006
+
1007
+
>>> validation = doc.validate()
1008
+
>>> for issue in validation.errors:
1009
+
>>> print(issue)
1010
+
1011
+
This will show that the validation has encountered two Warnings and also displays the offending odml entity.
1012
+
1013
+
>>> ValidationWarning: Section[73f29acd-16ae-47af-afc7-371d57898e28] 'Section type not specified'
1014
+
>>> ValidationWarning: Section[73f29acd-16ae-47af-afc7-371d57898e28] 'Name not assigned'
1015
+
1016
+
To fix the "Name not assigned" warning the Section can be accessed via the validation entry and used to directly assign a human readable name to Section in the original document. Re-running the validation will show, that the warning has been removed.
>>> # Check that the section name has been changed in the document
1020
+
>>> print(doc.sections)
1021
+
>>> # Re-running validation
1022
+
>>> validation = doc.validate()
1023
+
>>> for issue in validation.errors:
1024
+
>>> print(issue)
1025
+
1026
+
Similarly the second validation warning can be resolved before saving the document again.
1027
+
1028
+
Please note that the automatic validation is run whenever a document is saved or loaded using the ``odml.save`` and ``odml.load`` functions as well as the ``ODMLWriter`` or the ``ODMLReader``. The validation is not run when using any of the lower level ``xmlparser``, ``dict_parser`` or ``rdf_converter`` classes.
0 commit comments