aboutsummaryrefslogtreecommitdiffstats
path: root/bsfs/schema/schema.py
diff options
context:
space:
mode:
Diffstat (limited to 'bsfs/schema/schema.py')
-rw-r--r--bsfs/schema/schema.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/bsfs/schema/schema.py b/bsfs/schema/schema.py
index 0e053c0..b6f37a7 100644
--- a/bsfs/schema/schema.py
+++ b/bsfs/schema/schema.py
@@ -103,6 +103,41 @@ class Schema():
SchemaDiff = namedtuple('SchemaDiff', ['nodes', 'literals', 'predicates'])
+ def _issubset(self, other: 'Schema') -> bool:
+ # inconsistent schema can't be ordered.
+ if not self.consistent_with(other):
+ return False
+ # since schemas are consistent, it's sufficient to compare their URIs.
+ # self's sets are fully contained in other's sets
+ # pylint: disable=protected-access
+ return set(self._predicates) <= set(other._predicates) \
+ and set(self._nodes) <= set(other._nodes) \
+ and set(self._literals) <= set(other._literals)
+
+ def __lt__(self, other: typing.Any) -> bool:
+ """Return True if *other* is a true subset of *self*."""
+ if not isinstance(other, Schema): # other is not a Schema
+ return NotImplemented
+ return self != other and self._issubset(other)
+
+ def __le__(self, other: typing.Any) -> bool:
+ """Return True if *other* is a subset of *self*."""
+ if not isinstance(other, Schema): # other is not a Schema
+ return NotImplemented
+ return self == other or self._issubset(other)
+
+ def __gt__(self, other: typing.Any) -> bool:
+ """Return True if *other* is a true superset of *self*."""
+ if not isinstance(other, Schema): # other is not a Schema
+ return NotImplemented
+ return self != other and other._issubset(self)
+
+ def __ge__(self, other: typing.Any) -> bool:
+ """Return True if *other* is a superset of *self*."""
+ if not isinstance(other, Schema): # other is not a Schema
+ return NotImplemented
+ return self == other or other._issubset(self)
+
def diff(self, other: 'Schema') -> SchemaDiff:
"""Return node, literals, and predicates that are in *self* but not in *other*."""
return self.SchemaDiff(