Skip to content

Commit 2db2181

Browse files
committed
[tutorial] Add cardinality
1 parent c9cf77d commit 2db2181

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

doc/tutorial.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,48 @@ Also note that any style that is saved with an odML document will be lost, when
941941
document is loaded again and changes to the content are added. In this case the required
942942
style needs to be specified again when saving the changed file as described above.
943943

944+
945+
Defining and working with feature cardinality
946+
---------------------------------------------
947+
948+
The odML format allows users to define a cardinality for
949+
the number of subsections and properties of Sections and
950+
the number of values a Property might have.
951+
952+
A cardinality is checked when it is set, when its target is
953+
set and when a document is saved or loaded. If a specific
954+
cardinality is violated, a corresponding warning will be printed.
955+
956+
Setting a cardinality
957+
*********************
958+
959+
A cardinality can be set for sections or properties of sections
960+
or for values of properties. By default every cardinality is None,
961+
but it can be set to a defined minimal and/or a maximal number of
962+
an element.
963+
964+
A cardinality is set via its convenience method:
965+
966+
>>> # Set the cardinality of the properties of a Section 'sec' to
967+
>>> # a maximum of 5 elements.
968+
>>> sec = odml.Section(name="cardinality", type="test")
969+
>>> sec.set_properties_cardinality(max_val=5)
970+
971+
>>> # Set the cardinality of the subsections of Section 'sec' to
972+
>>> # a minimum of one and a maximum of 2 elements.
973+
>>> sec.set_sections_cardinality(min_val=1, max_val=2)
974+
975+
>>> # Set the cardinality of the values of a Property 'prop' to
976+
>>> # a minimum of 1 element.
977+
>>> prop = odml.Property(name="cardinality")
978+
>>> prop.set_values_cardinality(min_val=1)
979+
980+
>>> # Re-set the cardinality of the values of a Property 'prop' to not set.
981+
>>> prop.set_values_cardinality()
982+
>>> # or
983+
>>> prop.val_cardinality = None
984+
985+
944986
Advanced knowledge on Values
945987
----------------------------
946988

odml/section.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,9 @@ def set_sections_cardinality(self, min_val=None, max_val=None):
403403
Sets the Sections cardinality of a Section.
404404
405405
:param min_val: Required minimal number of values elements. None denotes
406-
no restrictions on values elements minimum. Default is None.
406+
no restrictions on sections elements minimum. Default is None.
407407
:param max_val: Allowed maximal number of values elements. None denotes
408-
no restrictions on values elements maximum. Default is None.
408+
no restrictions on sections elements maximum. Default is None.
409409
"""
410410
self.sec_cardinality = (min_val, max_val)
411411

@@ -456,9 +456,9 @@ def set_properties_cardinality(self, min_val=None, max_val=None):
456456
Sets the Properties cardinality of a Section.
457457
458458
:param min_val: Required minimal number of values elements. None denotes
459-
no restrictions on values elements minimum. Default is None.
459+
no restrictions on properties elements minimum. Default is None.
460460
:param max_val: Allowed maximal number of values elements. None denotes
461-
no restrictions on values elements maximum. Default is None.
461+
no restrictions on properties elements maximum. Default is None.
462462
"""
463463
self.prop_cardinality = (min_val, max_val)
464464

0 commit comments

Comments
 (0)