Coverage for lode / models / datatypeRestriction.py: 100%
22 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-11-22 15:54 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-11-22 15:54 +0000
1"""DatatypeRestriction: an owl:DatatypeRestriction (a datatype narrowed by facets)."""
2from .restriction import Restriction
4class DatatypeRestriction(Restriction):
5 """A datatype narrowed by XSD facet/value pairs, such as numeric bounds."""
7 def __init__(self, **kwargs):
8 """Create a datatype restriction with no base datatype or facets."""
9 super().__init__(**kwargs)
10 self.applies_on_concept = None # Datatype from owl:onDatatype
11 self.has_facets = [] # Ordered (facet operator, Literal) pairs
12 self.has_restriction_value = None # Last value, for single-facet callers
15 def get_applies_on_concept(self):
16 """Return the base datatype."""
17 return self.applies_on_concept
19 def set_applies_on_concept(self, datatype):
20 """Set the base datatype without changing its facets."""
21 self.applies_on_concept = datatype
23 def set_has_facet(self, constraint, value):
24 """Add a facet/value pair, preserving its association and list order."""
25 pair = (constraint, value)
26 if pair not in self.has_facets:
27 self.has_facets.append(pair)
28 self.set_has_restriction_value(value)
30 def get_has_facets(self):
31 """Return a copy of all facet/value pairs."""
32 return list(self.has_facets)
34 def set_has_restriction_value(self, string):
35 """Set has_restriction_value (the literal value of the facet)."""
36 self.has_restriction_value = string
38 def get_has_restriction_value(self):
39 """Return the last facet value; use get_has_facets() for all constraints."""
40 return self.has_restriction_value