aboutsummaryrefslogtreecommitdiffstats
path: root/bsfs/schema/schema.py
diff options
context:
space:
mode:
authorMatthias Baumgartner <dev@igsor.net>2022-12-18 13:45:35 +0100
committerMatthias Baumgartner <dev@igsor.net>2022-12-18 13:45:35 +0100
commit1b570e45a4e99a4e7f9ad9d01b4fa93e38fbff38 (patch)
tree02352aaa301af8a412d8e611e708d0a4dd74ebda /bsfs/schema/schema.py
parent0e52514639b043454425a9cc2317d27e628a1027 (diff)
downloadbsfs-1b570e45a4e99a4e7f9ad9d01b4fa93e38fbff38.tar.gz
bsfs-1b570e45a4e99a4e7f9ad9d01b4fa93e38fbff38.tar.bz2
bsfs-1b570e45a4e99a4e7f9ad9d01b4fa93e38fbff38.zip
schema ordering
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(