aboutsummaryrefslogtreecommitdiffstats
path: root/test/schema
diff options
context:
space:
mode:
Diffstat (limited to 'test/schema')
-rw-r--r--test/schema/test_schema.py40
-rw-r--r--test/schema/test_serialize.py126
-rw-r--r--test/schema/test_types.py108
3 files changed, 137 insertions, 137 deletions
diff --git a/test/schema/test_schema.py b/test/schema/test_schema.py
index 1b45db0..ca21f87 100644
--- a/test/schema/test_schema.py
+++ b/test/schema/test_schema.py
@@ -73,9 +73,9 @@ class TestSchema(unittest.TestCase):
# predicates
self.p_root = types.ROOT_PREDICATE
self.f_root = types.ROOT_FEATURE
- self.p_tag = self.p_root.get_child(ns.bse.tag, self.n_ent, self.n_tag, False)
- self.p_group = self.p_tag.get_child(ns.bse.group, self.n_img, self.n_tag, False)
- self.p_comment = self.p_root.get_child(ns.bse.comment, self.n_root, self.l_string, True)
+ self.p_tag = self.p_root.child(ns.bse.tag, self.n_ent, self.n_tag, False)
+ self.p_group = self.p_tag.child(ns.bse.group, self.n_img, self.n_tag, False)
+ self.p_comment = self.p_root.child(ns.bse.comment, self.n_root, self.l_string, True)
self.predicates = [self.p_root, self.f_root, self.p_tag, self.p_group, self.p_comment]
def test_construction(self):
@@ -217,16 +217,16 @@ class TestSchema(unittest.TestCase):
self.assertNotEqual(hash(schema),
hash(Schema([self.p_group, self.p_tag, self.p_root], self.nodes, self.literals)))
self.assertNotEqual(schema,
- Schema(self.predicates + [self.p_root.get_child(ns.bse.filesize, self.n_ent, self.l_integer)], self.nodes, self.literals))
+ Schema(self.predicates + [self.p_root.child(ns.bse.filesize, self.n_ent, self.l_integer)], self.nodes, self.literals))
self.assertNotEqual(hash(schema),
- hash(Schema(self.predicates + [self.p_root.get_child(ns.bse.filesize, self.n_ent, self.l_integer)], self.nodes, self.literals)))
+ hash(Schema(self.predicates + [self.p_root.child(ns.bse.filesize, self.n_ent, self.l_integer)], self.nodes, self.literals)))
def test_order(self):
# setup
class Foo(): pass
- p_foo = self.p_root.get_child(ns.bse.foo, self.n_ent, self.l_string, True)
- p_sub = p_foo.get_child(ns.bse.sub, self.n_ent, self.l_string, True)
- p_bar = self.p_root.get_child(ns.bse.bar, self.n_ent, self.l_string, True)
+ p_foo = self.p_root.child(ns.bse.foo, self.n_ent, self.l_string, True)
+ p_sub = p_foo.child(ns.bse.sub, self.n_ent, self.l_string, True)
+ p_bar = self.p_root.child(ns.bse.bar, self.n_ent, self.l_string, True)
# can only compare schema to other schema
# <
@@ -305,44 +305,44 @@ class TestSchema(unittest.TestCase):
# inconsistent schema cannot be a subset
self.assertFalse(operator.le(Schema({p_foo}), Schema({
- self.p_root.get_child(ns.bse.foo, self.n_ent, self.l_integer, True)}))) # inconsistent w.r.t. literal
+ self.p_root.child(ns.bse.foo, self.n_ent, self.l_integer, True)}))) # inconsistent w.r.t. literal
self.assertFalse(operator.le(Schema({p_foo}), Schema({
- self.p_root.get_child(ns.bse.foo, self.n_img, self.l_string, True)}))) # inconsistent w.r.t. node
+ self.p_root.child(ns.bse.foo, self.n_img, self.l_string, True)}))) # inconsistent w.r.t. node
self.assertFalse(operator.le(Schema({p_foo}), Schema({
- self.p_root.get_child(ns.bse.foo, self.n_ent, self.l_string, False)}))) # inconsistent w.r.t. unique
+ self.p_root.child(ns.bse.foo, self.n_ent, self.l_string, False)}))) # inconsistent w.r.t. unique
self.assertFalse(operator.le(Schema({}, {self.n_img}), Schema({}, {
types.Node(ns.bsfs.Image, types.Node(ns.bsfs.Node, None))})))
self.assertFalse(operator.le(Schema({}, {}, {self.l_integer}), Schema({}, {}, {
types.Literal(ns.xsd.integer, types.Literal(ns.xsd.number, types.Literal(ns.bsfs.Literal, None)))})))
# inconsistent schema cannot be a true subset
self.assertFalse(operator.lt(Schema({p_foo}), Schema({
- self.p_root.get_child(ns.bse.foo, self.n_ent, self.l_integer, True)}))) # inconsistent w.r.t. literal
+ self.p_root.child(ns.bse.foo, self.n_ent, self.l_integer, True)}))) # inconsistent w.r.t. literal
self.assertFalse(operator.lt(Schema({p_foo}), Schema({
- self.p_root.get_child(ns.bse.foo, self.n_img, self.l_string, True)}))) # inconsistent w.r.t. node
+ self.p_root.child(ns.bse.foo, self.n_img, self.l_string, True)}))) # inconsistent w.r.t. node
self.assertFalse(operator.lt(Schema({p_foo}), Schema({
- self.p_root.get_child(ns.bse.foo, self.n_ent, self.l_string, False)}))) # inconsistent w.r.t. unique
+ self.p_root.child(ns.bse.foo, self.n_ent, self.l_string, False)}))) # inconsistent w.r.t. unique
self.assertFalse(operator.lt(Schema({}, {self.n_img}), Schema({}, {
types.Node(ns.bsfs.Image, types.Node(ns.bsfs.Node, None))})))
self.assertFalse(operator.lt(Schema({}, {}, {self.l_integer}), Schema({}, {}, {
types.Literal(ns.xsd.integer, types.Literal(ns.xsd.number, types.Literal(ns.bsfs.Literal, None)))})))
# inconsistent schema cannot be a superset
self.assertFalse(operator.ge(Schema({p_foo}), Schema({
- self.p_root.get_child(ns.bse.foo, self.n_ent, self.l_integer, True)}))) # inconsistent w.r.t. literal
+ self.p_root.child(ns.bse.foo, self.n_ent, self.l_integer, True)}))) # inconsistent w.r.t. literal
self.assertFalse(operator.ge(Schema({p_foo}), Schema({
- self.p_root.get_child(ns.bse.foo, self.n_img, self.l_string, True)}))) # inconsistent w.r.t. node
+ self.p_root.child(ns.bse.foo, self.n_img, self.l_string, True)}))) # inconsistent w.r.t. node
self.assertFalse(operator.ge(Schema({p_foo}), Schema({
- self.p_root.get_child(ns.bse.foo, self.n_ent, self.l_string, False)}))) # inconsistent w.r.t. unique
+ self.p_root.child(ns.bse.foo, self.n_ent, self.l_string, False)}))) # inconsistent w.r.t. unique
self.assertFalse(operator.ge(Schema({}, {self.n_img}), Schema({}, {
types.Node(ns.bsfs.Image, types.Node(ns.bsfs.Node, None))})))
self.assertFalse(operator.ge(Schema({}, {}, {self.l_integer}), Schema({}, {}, {
types.Literal(ns.xsd.integer, types.Literal(ns.xsd.number, types.Literal(ns.bsfs.Literal, None)))})))
# inconsistent schema cannot be a true superset
self.assertFalse(operator.gt(Schema({p_foo}), Schema({
- self.p_root.get_child(ns.bse.foo, self.n_ent, self.l_integer, True)}))) # inconsistent w.r.t. literal
+ self.p_root.child(ns.bse.foo, self.n_ent, self.l_integer, True)}))) # inconsistent w.r.t. literal
self.assertFalse(operator.gt(Schema({p_foo}), Schema({
- self.p_root.get_child(ns.bse.foo, self.n_img, self.l_string, True)}))) # inconsistent w.r.t. node
+ self.p_root.child(ns.bse.foo, self.n_img, self.l_string, True)}))) # inconsistent w.r.t. node
self.assertFalse(operator.gt(Schema({p_foo}), Schema({
- self.p_root.get_child(ns.bse.foo, self.n_ent, self.l_string, False)}))) # inconsistent w.r.t. unique
+ self.p_root.child(ns.bse.foo, self.n_ent, self.l_string, False)}))) # inconsistent w.r.t. unique
self.assertFalse(operator.gt(Schema({}, {self.n_img}), Schema({}, {
types.Node(ns.bsfs.Image, types.Node(ns.bsfs.Node, None))})))
self.assertFalse(operator.gt(Schema({}, {}, {self.l_integer}), Schema({}, {}, {
diff --git a/test/schema/test_serialize.py b/test/schema/test_serialize.py
index 7392cc0..b9d8599 100644
--- a/test/schema/test_serialize.py
+++ b/test/schema/test_serialize.py
@@ -66,7 +66,7 @@ class TestFromString(unittest.TestCase):
''')
# additional nodes can be defined
- n_unused = types.ROOT_NODE.get_child(ns.bsfs.unused)
+ n_unused = types.ROOT_NODE.child(ns.bsfs.unused)
self.assertEqual(Schema({}, {n_unused}), from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
@@ -77,10 +77,10 @@ class TestFromString(unittest.TestCase):
'''))
# a node can have multiple children
- n_ent = types.ROOT_NODE.get_child(ns.bsfs.Entity)
- n_tag = types.ROOT_NODE.get_child(ns.bsfs.Tag)
- n_doc = n_ent.get_child(ns.bsfs.Document)
- n_image = n_ent.get_child(ns.bsfs.Image)
+ n_ent = types.ROOT_NODE.child(ns.bsfs.Entity)
+ n_tag = types.ROOT_NODE.child(ns.bsfs.Tag)
+ n_doc = n_ent.child(ns.bsfs.Document)
+ n_image = n_ent.child(ns.bsfs.Image)
self.assertEqual(Schema({}, {n_ent, n_tag, n_doc, n_image}), from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
@@ -97,9 +97,9 @@ class TestFromString(unittest.TestCase):
'''))
# additional nodes can be defined and used
- n_ent = types.ROOT_NODE.get_child(ns.bsfs.Entity)
- l_string = types.ROOT_LITERAL.get_child(ns.xsd.string)
- p_filename = types.ROOT_PREDICATE.get_child(ns.bse.filename,
+ n_ent = types.ROOT_NODE.child(ns.bsfs.Entity)
+ l_string = types.ROOT_LITERAL.child(ns.xsd.string)
+ p_filename = types.ROOT_PREDICATE.child(ns.bse.filename,
n_ent, l_string, False)
self.assertEqual(Schema({p_filename}), from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
@@ -168,7 +168,7 @@ class TestFromString(unittest.TestCase):
''')
# additional literals can be defined
- l_unused = types.ROOT_LITERAL.get_child(ns.xsd.unused)
+ l_unused = types.ROOT_LITERAL.child(ns.xsd.unused)
self.assertEqual(Schema({}, {}, {l_unused}), from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
@@ -179,10 +179,10 @@ class TestFromString(unittest.TestCase):
'''))
# a literal can have multiple children
- l_string = types.ROOT_LITERAL.get_child(ns.xsd.string)
- l_integer = types.ROOT_LITERAL.get_child(ns.xsd.integer)
- l_unsigned = l_integer.get_child(ns.xsd.unsigned)
- l_signed = l_integer.get_child(ns.xsd.signed)
+ l_string = types.ROOT_LITERAL.child(ns.xsd.string)
+ l_integer = types.ROOT_LITERAL.child(ns.xsd.integer)
+ l_unsigned = l_integer.child(ns.xsd.unsigned)
+ l_signed = l_integer.child(ns.xsd.signed)
self.assertEqual(Schema({}, {}, {l_string, l_integer, l_unsigned, l_signed}), from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
@@ -199,9 +199,9 @@ class TestFromString(unittest.TestCase):
'''))
# additional literals can be defined and used
- n_ent = types.ROOT_NODE.get_child(ns.bsfs.Entity)
- l_string = types.ROOT_LITERAL.get_child(ns.xsd.string)
- p_filename = types.ROOT_PREDICATE.get_child(ns.bse.filename,
+ n_ent = types.ROOT_NODE.child(ns.bsfs.Entity)
+ l_string = types.ROOT_LITERAL.child(ns.xsd.string)
+ p_filename = types.ROOT_PREDICATE.child(ns.bse.filename,
n_ent, l_string, False)
self.assertEqual(Schema({p_filename}), from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
@@ -317,9 +317,9 @@ class TestFromString(unittest.TestCase):
''')
# additional predicates can be defined
- n_ent = types.ROOT_NODE.get_child(ns.bsfs.Entity)
- l_string = types.ROOT_LITERAL.get_child(ns.xsd.string)
- p_comment = types.ROOT_PREDICATE.get_child(ns.bse.comment, domain=n_ent, range=l_string, unique=False)
+ n_ent = types.ROOT_NODE.child(ns.bsfs.Entity)
+ l_string = types.ROOT_LITERAL.child(ns.xsd.string)
+ p_comment = types.ROOT_PREDICATE.child(ns.bse.comment, domain=n_ent, range=l_string, unique=False)
self.assertEqual(Schema({p_comment}), from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
@@ -336,10 +336,10 @@ class TestFromString(unittest.TestCase):
'''))
# predicates inherit properties from parents
- n_ent = types.ROOT_NODE.get_child(ns.bsfs.Entity)
- l_string = types.ROOT_LITERAL.get_child(ns.xsd.string)
- p_annotation = types.ROOT_PREDICATE.get_child(ns.bsfs.Annotation, domain=n_ent, range=l_string)
- p_comment = p_annotation.get_child(ns.bse.comment, unique=True)
+ n_ent = types.ROOT_NODE.child(ns.bsfs.Entity)
+ l_string = types.ROOT_LITERAL.child(ns.xsd.string)
+ p_annotation = types.ROOT_PREDICATE.child(ns.bsfs.Annotation, domain=n_ent, range=l_string)
+ p_comment = p_annotation.child(ns.bse.comment, unique=True)
self.assertEqual(Schema({p_comment}), from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
@@ -358,10 +358,10 @@ class TestFromString(unittest.TestCase):
'''))
# we can define partial predicates (w/o specifying a usable range)
- n_ent = types.ROOT_NODE.get_child(ns.bsfs.Entity)
- l_string = types.ROOT_LITERAL.get_child(ns.xsd.string)
- p_annotation = types.ROOT_PREDICATE.get_child(ns.bsfs.Annotation, domain=n_ent)
- p_comment = p_annotation.get_child(ns.bse.comment, range=l_string, unique=False)
+ n_ent = types.ROOT_NODE.child(ns.bsfs.Entity)
+ l_string = types.ROOT_LITERAL.child(ns.xsd.string)
+ p_annotation = types.ROOT_PREDICATE.child(ns.bsfs.Annotation, domain=n_ent)
+ p_comment = p_annotation.child(ns.bse.comment, range=l_string, unique=False)
self.assertEqual(Schema({p_comment}), from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
@@ -381,8 +381,8 @@ class TestFromString(unittest.TestCase):
# predicate definition can be split across multiple statements.
# statements can be repeated
- n_ent = types.ROOT_NODE.get_child(ns.bsfs.Entity)
- p_foo = types.ROOT_PREDICATE.get_child(ns.bse.foo, domain=n_ent, range=types.ROOT_NODE, unique=True)
+ n_ent = types.ROOT_NODE.child(ns.bsfs.Entity)
+ p_foo = types.ROOT_PREDICATE.child(ns.bse.foo, domain=n_ent, range=types.ROOT_NODE, unique=True)
self.assertEqual(Schema({p_foo}), from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
@@ -400,11 +400,11 @@ class TestFromString(unittest.TestCase):
'''))
# domain must be a subtype of parent's domain
- n_ent = types.ROOT_NODE.get_child(ns.bsfs.Entity)
- n_image = n_ent.get_child(ns.bsfs.Image)
- p_foo = types.ROOT_PREDICATE.get_child(ns.bse.foo, domain=types.ROOT_NODE)
- p_bar = p_foo.get_child(ns.bse.bar, domain=n_ent)
- p_foobar = p_bar.get_child(ns.bse.foobar, domain=n_image)
+ n_ent = types.ROOT_NODE.child(ns.bsfs.Entity)
+ n_image = n_ent.child(ns.bsfs.Image)
+ p_foo = types.ROOT_PREDICATE.child(ns.bse.foo, domain=types.ROOT_NODE)
+ p_bar = p_foo.child(ns.bse.bar, domain=n_ent)
+ p_foobar = p_bar.child(ns.bse.foobar, domain=n_image)
self.assertEqual(Schema({p_foobar}), from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
@@ -439,11 +439,11 @@ class TestFromString(unittest.TestCase):
''')
# range must be a subtype of parent's range
- n_ent = types.ROOT_NODE.get_child(ns.bsfs.Entity)
- n_image = n_ent.get_child(ns.bsfs.Image)
- p_foo = types.ROOT_PREDICATE.get_child(ns.bse.foo, range=types.ROOT_NODE)
- p_bar = p_foo.get_child(ns.bse.bar, range=n_ent)
- p_foobar = p_bar.get_child(ns.bse.foobar, range=n_image)
+ n_ent = types.ROOT_NODE.child(ns.bsfs.Entity)
+ n_image = n_ent.child(ns.bsfs.Image)
+ p_foo = types.ROOT_PREDICATE.child(ns.bse.foo, range=types.ROOT_NODE)
+ p_bar = p_foo.child(ns.bse.bar, range=n_ent)
+ p_foobar = p_bar.child(ns.bse.foobar, range=n_image)
self.assertEqual(Schema({p_foobar}), from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
@@ -658,9 +658,9 @@ class TestFromString(unittest.TestCase):
''')
# additional predicates can be defined
- n_ent = types.ROOT_NODE.get_child(ns.bsfs.Entity)
- l_array = types.ROOT_LITERAL.get_child(ns.bsfs.array)
- p_comment = types.ROOT_FEATURE.get_child(ns.bse.colors, domain=n_ent, range=l_array, unique=False)
+ n_ent = types.ROOT_NODE.child(ns.bsfs.Entity)
+ l_array = types.ROOT_LITERAL.child(ns.bsfs.array)
+ p_comment = types.ROOT_FEATURE.child(ns.bse.colors, domain=n_ent, range=l_array, unique=False)
self.assertEqual(Schema({p_comment}), from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
@@ -678,12 +678,12 @@ class TestFromString(unittest.TestCase):
'''))
# features inherit properties from parents
- n_ent = types.ROOT_NODE.get_child(ns.bsfs.Entity)
- l_array = types.ROOT_LITERAL.get_child(ns.bsfs.array)
- l_string = types.ROOT_LITERAL.get_child(ns.xsd.string)
- p_annotation = types.ROOT_FEATURE.get_child(ns.bsfs.Annotation, domain=n_ent, range=l_array,
+ n_ent = types.ROOT_NODE.child(ns.bsfs.Entity)
+ l_array = types.ROOT_LITERAL.child(ns.bsfs.array)
+ l_string = types.ROOT_LITERAL.child(ns.xsd.string)
+ p_annotation = types.ROOT_FEATURE.child(ns.bsfs.Annotation, domain=n_ent, range=l_array,
dimension=1234, dtype=ns.xsd.string)
- p_comment = p_annotation.get_child(ns.bse.colors, unique=True)
+ p_comment = p_annotation.child(ns.bse.colors, unique=True)
self.assertEqual(Schema({p_comment}), from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
@@ -706,8 +706,8 @@ class TestFromString(unittest.TestCase):
# feature definition can be split across multiple statements.
# statements can be repeated
- n_ent = types.ROOT_NODE.get_child(ns.bsfs.Entity)
- p_foo = types.ROOT_FEATURE.get_child(ns.bse.foo, domain=n_ent, unique=True,
+ n_ent = types.ROOT_NODE.child(ns.bsfs.Entity)
+ p_foo = types.ROOT_FEATURE.child(ns.bse.foo, domain=n_ent, unique=True,
dimension=1234, dtype=ns.bsfs.f32)
self.assertEqual(Schema({p_foo}), from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
@@ -887,24 +887,24 @@ class TestFromString(unittest.TestCase):
def test_integration(self):
# nodes
- n_ent = types.ROOT_NODE.get_child(ns.bsfs.Entity)
- n_tag = types.ROOT_NODE.get_child(ns.bsfs.Tag)
- n_image = n_ent.get_child(ns.bsfs.Image)
+ n_ent = types.ROOT_NODE.child(ns.bsfs.Entity)
+ n_tag = types.ROOT_NODE.child(ns.bsfs.Tag)
+ n_image = n_ent.child(ns.bsfs.Image)
# literals
- l_string = types.ROOT_LITERAL.get_child(ns.xsd.string)
- l_array = types.ROOT_LITERAL.get_child(ns.bsfs.array)
- l_integer = types.ROOT_LITERAL.get_child(ns.xsd.integer)
- l_boolean = types.ROOT_LITERAL.get_child(ns.xsd.boolean)
+ l_string = types.ROOT_LITERAL.child(ns.xsd.string)
+ l_array = types.ROOT_LITERAL.child(ns.bsfs.array)
+ l_integer = types.ROOT_LITERAL.child(ns.xsd.integer)
+ l_boolean = types.ROOT_LITERAL.child(ns.xsd.boolean)
# predicates
- p_annotation = types.ROOT_PREDICATE.get_child(ns.bsfs.Annotation)
- p_tag = types.ROOT_PREDICATE.get_child(ns.bse.tag, domain=n_ent, range=n_tag)
- p_group = p_tag.get_child(ns.bse.group, domain=n_image, unique=True)
- p_comment = p_annotation.get_child(ns.bse.comment, range=l_string)
+ p_annotation = types.ROOT_PREDICATE.child(ns.bsfs.Annotation)
+ p_tag = types.ROOT_PREDICATE.child(ns.bse.tag, domain=n_ent, range=n_tag)
+ p_group = p_tag.child(ns.bse.group, domain=n_image, unique=True)
+ p_comment = p_annotation.child(ns.bse.comment, range=l_string)
# features
- f_colors = types.ROOT_FEATURE.get_child(URI('http://bsfs.ai/schema/Feature/colors_spatial'),
+ f_colors = types.ROOT_FEATURE.child(URI('http://bsfs.ai/schema/Feature/colors_spatial'),
domain=n_ent, range=l_array, unique=True, dtype=ns.bsfs.f16, distance=ns.bsfs.euclidean)
- f_colors1234 = f_colors.get_child(URI('http://bsfs.ai/schema/Feature/colors_spatial#1234'), dimension=1024)
- f_colors4321 = f_colors.get_child(URI('http://bsfs.ai/schema/Feature/colors_spatial#4321'), dimension=2048)
+ f_colors1234 = f_colors.child(URI('http://bsfs.ai/schema/Feature/colors_spatial#1234'), dimension=1024)
+ f_colors4321 = f_colors.child(URI('http://bsfs.ai/schema/Feature/colors_spatial#4321'), dimension=2048)
# schema
ref = Schema(
{p_annotation, p_tag, p_group, p_comment, f_colors, f_colors1234, f_colors4321},
diff --git a/test/schema/test_types.py b/test/schema/test_types.py
index af47f0d..26da270 100644
--- a/test/schema/test_types.py
+++ b/test/schema/test_types.py
@@ -14,7 +14,7 @@ from bsfs.schema.types import ROOT_PREDICATE, ROOT_VERTEX, ROOT_FEATURE
from bsfs.utils import errors
# objects to test
-from bsfs.schema.types import _Type, _Vertex, Node, Literal, Predicate, Feature
+from bsfs.schema.types import _Type, Vertex, Node, Literal, Predicate, Feature
## code ##
@@ -47,8 +47,8 @@ class TestType(unittest.TestCase):
self.assertEqual(
hash(_Type('Foo', None, foo='bar', bar='foo')),
hash(_Type('Foo', None, hello='world', foobar=1234)))
- # annotations can be passed to get_child
- self.assertDictEqual(_Type('First', foo='bar').get_child('Second', bar='foo').annotations, {
+ # annotations can be passed to child
+ self.assertDictEqual(_Type('First', foo='bar').child('Second', bar='foo').annotations, {
'bar': 'foo'})
def test_string_conversion(self):
@@ -71,16 +71,16 @@ class TestType(unittest.TestCase):
self.assertEqual(str(_Type('Foo', SubType('Bar'))), '_Type(Foo)')
self.assertEqual(repr(_Type('Foo', SubType('Bar'))), '_Type(Foo, SubType(Bar, None))')
- def test_get_child(self):
+ def test_child(self):
# callee is used as parent
- self.assertEqual(_Type('First').get_child('Second'), _Type('Second', _Type('First')))
+ self.assertEqual(_Type('First').child('Second'), _Type('Second', _Type('First')))
# works with multiple parents
- self.assertEqual(_Type('First').get_child('Second').get_child('Third'), _Type('Third', _Type('Second', _Type('First'))))
+ self.assertEqual(_Type('First').child('Second').child('Third'), _Type('Third', _Type('Second', _Type('First'))))
# type persists
class Foo(_Type): pass
- self.assertEqual(Foo('First').get_child('Second'), Foo('Second', Foo('First')))
+ self.assertEqual(Foo('First').child('Second'), Foo('Second', Foo('First')))
# annotations are respected
- self.assertDictEqual(_Type('First', foo='bar').get_child('Second', bar='foo').annotations, {
+ self.assertDictEqual(_Type('First', foo='bar').child('Second', bar='foo').annotations, {
'bar': 'foo'})
def test_equality(self):
@@ -174,7 +174,7 @@ class TestPredicate(unittest.TestCase):
# range must be a Literal, a Node, or the root Vertex
self.assertRaises(TypeError, Predicate, ns.bse.foo, None, Node(ns.bsfs.Node, None), None, True)
self.assertRaises(TypeError, Predicate, ns.bse.foo, None, Node(ns.bsfs.Node, None), 1234, True)
- self.assertRaises(TypeError, Predicate, ns.bse.foo, None, Node(ns.bsfs.Node, None), _Vertex(ns.bsfs.Foo, None), True)
+ self.assertRaises(TypeError, Predicate, ns.bse.foo, None, Node(ns.bsfs.Node, None), Vertex(ns.bsfs.Foo, None), True)
self.assertRaises(TypeError, Predicate, ns.bse.foo, None, Node(ns.bsfs.Node, None), _Type(ns.bsfs.Foo, None), True)
class Foo(): pass
self.assertRaises(TypeError, Predicate, ns.bse.foo, None, Node(ns.bsfs.Node, None), Foo(), True)
@@ -213,7 +213,7 @@ class TestPredicate(unittest.TestCase):
self.assertNotEqual(tag, Predicate(ns.bse.tag, root, n_root, n_tag, True))
self.assertNotEqual(hash(tag), hash(Predicate(ns.bse.tag, root, n_root, n_tag, True)))
- def test_get_child(self):
+ def test_child(self):
n_root = Node(ns.bsfs.Node, None)
l_root = Literal(ns.bsfs.Literal, None)
n_ent = Node(ns.bsfs.Entity, Node(ns.bsfs.Node, None))
@@ -227,45 +227,45 @@ class TestPredicate(unittest.TestCase):
unique=False,
)
- # get_child returns Predicate
- self.assertIsInstance(tag.get_child(ns.bse.foo), Predicate)
+ # child returns Predicate
+ self.assertIsInstance(tag.child(ns.bse.foo), Predicate)
# uri is respected
- self.assertEqual(ns.bse.foo, tag.get_child(ns.bse.foo).uri)
+ self.assertEqual(ns.bse.foo, tag.child(ns.bse.foo).uri)
# domain is respected
dom = Node(ns.bsfs.Image, n_ent)
- self.assertEqual(dom, tag.get_child(ns.bse.foo, domain=dom).domain)
+ self.assertEqual(dom, tag.child(ns.bse.foo, domain=dom).domain)
# range is respected
rng = Node(ns.bsfs.Group, n_tag)
- self.assertEqual(rng, tag.get_child(ns.bse.foo, range=rng).range)
+ self.assertEqual(rng, tag.child(ns.bse.foo, range=rng).range)
# cannot set range to None
- self.assertEqual(n_tag, tag.get_child(ns.bse.foo, range=None).range)
+ self.assertEqual(n_tag, tag.child(ns.bse.foo, range=None).range)
# unique is respected
- self.assertTrue(tag.get_child(ns.bse.foo, unique=True).unique)
+ self.assertTrue(tag.child(ns.bse.foo, unique=True).unique)
# annotations are respected
- self.assertDictEqual(tag.get_child(ns.bse.foo, foo='bar', bar=123).annotations, {
+ self.assertDictEqual(tag.child(ns.bse.foo, foo='bar', bar=123).annotations, {
'foo': 'bar',
'bar': 123,
})
# domain is inherited from parent
- self.assertEqual(n_root, root.get_child(ns.bse.foo).domain)
- self.assertEqual(n_ent, tag.get_child(ns.bse.foo).domain)
+ self.assertEqual(n_root, root.child(ns.bse.foo).domain)
+ self.assertEqual(n_ent, tag.child(ns.bse.foo).domain)
# range is inherited from parent
- self.assertEqual(ROOT_VERTEX, root.get_child(ns.bse.foo).range)
- self.assertEqual(n_tag, tag.get_child(ns.bse.foo).range)
+ self.assertEqual(ROOT_VERTEX, root.child(ns.bse.foo).range)
+ self.assertEqual(n_tag, tag.child(ns.bse.foo).range)
# uniqueness is inherited from parent
- self.assertFalse(tag.get_child(ns.bse.foo).unique)
+ self.assertFalse(tag.child(ns.bse.foo).unique)
# domain must be subtype of parent's domain
- self.assertRaises(errors.ConsistencyError, tag.get_child, ns.bse.foo, domain=n_root)
- self.assertRaises(errors.ConsistencyError, tag.get_child, ns.bse.foo, domain=Node(ns.bsfs.Image, n_root))
+ self.assertRaises(errors.ConsistencyError, tag.child, ns.bse.foo, domain=n_root)
+ self.assertRaises(errors.ConsistencyError, tag.child, ns.bse.foo, domain=Node(ns.bsfs.Image, n_root))
# range must be subtype of parent's range
- self.assertRaises(errors.ConsistencyError, tag.get_child, ns.bse.foo, range=n_root)
- self.assertRaises(errors.ConsistencyError, tag.get_child, ns.bse.foo, range=Node(ns.bsfs.Image, n_root))
- self.assertRaises(TypeError, tag.get_child, ns.bse.foo, range=Literal(ns.bsfs.Tag, l_root))
+ self.assertRaises(errors.ConsistencyError, tag.child, ns.bse.foo, range=n_root)
+ self.assertRaises(errors.ConsistencyError, tag.child, ns.bse.foo, range=Node(ns.bsfs.Image, n_root))
+ self.assertRaises(TypeError, tag.child, ns.bse.foo, range=Literal(ns.bsfs.Tag, l_root))
# range can be subtyped from ROOT_VERTEX to Node or Literal
- self.assertEqual(n_root, root.get_child(ns.bse.foo, range=n_root).range)
- self.assertEqual(l_root, root.get_child(ns.bse.foo, range=l_root).range)
+ self.assertEqual(n_root, root.child(ns.bse.foo, range=n_root).range)
+ self.assertEqual(l_root, root.child(ns.bse.foo, range=l_root).range)
class TestFeature(unittest.TestCase):
@@ -308,7 +308,7 @@ class TestFeature(unittest.TestCase):
self.assertNotEqual(colors, Feature(ns.bse.colors, ROOT_FEATURE, n_ent, l_array, False, 1234, ns.bsfs.float, ns.bsfs.cosine))
self.assertNotEqual(hash(colors), hash(Feature(ns.bse.colors, ROOT_FEATURE, n_ent, l_array, False, 1234, ns.bsfs.float, ns.bsfs.cosine)))
- def test_get_child(self):
+ def test_child(self):
n_root = Node(ns.bsfs.Node, None)
n_ent = Node(ns.bsfs.Entity, n_root)
l_root = Literal(ns.bsfs.Literal, None)
@@ -324,53 +324,53 @@ class TestFeature(unittest.TestCase):
distance=ns.bsfs.euclidean,
)
- # get_child returns Feature
- self.assertIsInstance(colors.get_child(ns.bse.foo), Feature)
+ # child returns Feature
+ self.assertIsInstance(colors.child(ns.bse.foo), Feature)
# uri is respected
- self.assertEqual(ns.bse.foo, colors.get_child(ns.bse.foo).uri)
+ self.assertEqual(ns.bse.foo, colors.child(ns.bse.foo).uri)
# domain is respected
dom = Node(ns.bsfs.Image, n_ent)
- self.assertEqual(dom, colors.get_child(ns.bse.foo, domain=dom).domain)
+ self.assertEqual(dom, colors.child(ns.bse.foo, domain=dom).domain)
# range is respected
rng = Literal(ns.bse.foo, l_array)
- self.assertEqual(rng, colors.get_child(ns.bse.foo, range=rng).range)
+ self.assertEqual(rng, colors.child(ns.bse.foo, range=rng).range)
# cannot set range to None
- self.assertEqual(l_array, colors.get_child(ns.bse.foo, range=None).range)
+ self.assertEqual(l_array, colors.child(ns.bse.foo, range=None).range)
# unique is respected
- self.assertTrue(colors.get_child(ns.bse.foo, unique=True).unique)
+ self.assertTrue(colors.child(ns.bse.foo, unique=True).unique)
# dimension is respected
- self.assertEqual(4321, colors.get_child(ns.bse.foo, dimension=4321).dimension)
+ self.assertEqual(4321, colors.child(ns.bse.foo, dimension=4321).dimension)
# dtype is respected
- self.assertEqual(ns.bsfs.integer, colors.get_child(ns.bse.foo, dtype=ns.bsfs.integer).dtype)
+ self.assertEqual(ns.bsfs.integer, colors.child(ns.bse.foo, dtype=ns.bsfs.integer).dtype)
# distance is respected
- self.assertEqual(ns.bsfs.cosine, colors.get_child(ns.bse.foo, distance=ns.bsfs.cosine).distance)
+ self.assertEqual(ns.bsfs.cosine, colors.child(ns.bse.foo, distance=ns.bsfs.cosine).distance)
# annotations are respected
- self.assertDictEqual(colors.get_child(ns.bse.foo, foo='bar', bar=123).annotations, {
+ self.assertDictEqual(colors.child(ns.bse.foo, foo='bar', bar=123).annotations, {
'foo': 'bar',
'bar': 123,
})
# domain is inherited from parent
- self.assertEqual(n_root, ROOT_FEATURE.get_child(ns.bse.foo).domain)
- self.assertEqual(n_ent, colors.get_child(ns.bse.foo).domain)
+ self.assertEqual(n_root, ROOT_FEATURE.child(ns.bse.foo).domain)
+ self.assertEqual(n_ent, colors.child(ns.bse.foo).domain)
# range is inherited from parent
- self.assertEqual(l_array, colors.get_child(ns.bse.foo).range)
+ self.assertEqual(l_array, colors.child(ns.bse.foo).range)
# uniqueness is inherited from parent
- self.assertFalse(colors.get_child(ns.bse.foo).unique)
+ self.assertFalse(colors.child(ns.bse.foo).unique)
# dimension is inherited from parent
- self.assertEqual(1234, colors.get_child(ns.bse.foo).dimension)
+ self.assertEqual(1234, colors.child(ns.bse.foo).dimension)
# dtype is inherited from parent
- self.assertEqual(ns.bsfs.float, colors.get_child(ns.bse.foo).dtype)
+ self.assertEqual(ns.bsfs.float, colors.child(ns.bse.foo).dtype)
# distance is inherited from parent
- self.assertEqual(ns.bsfs.euclidean, colors.get_child(ns.bse.foo).distance)
+ self.assertEqual(ns.bsfs.euclidean, colors.child(ns.bse.foo).distance)
# domain must be subtype of parent's domain
- self.assertRaises(errors.ConsistencyError, colors.get_child, ns.bse.foo, domain=n_root)
- self.assertRaises(errors.ConsistencyError, colors.get_child, ns.bse.foo, domain=Node(ns.bsfs.Image, n_root))
+ self.assertRaises(errors.ConsistencyError, colors.child, ns.bse.foo, domain=n_root)
+ self.assertRaises(errors.ConsistencyError, colors.child, ns.bse.foo, domain=Node(ns.bsfs.Image, n_root))
# range must be subtype of parent's range
- self.assertRaises(errors.ConsistencyError, colors.get_child, ns.bse.foo, range=Literal(ns.bsfs.Literal, None))
- self.assertRaises(errors.ConsistencyError, colors.get_child, ns.bse.foo, range=Literal(ns.bsfs.foo, Literal(ns.bsfs.Literal, None)))
- self.assertRaises(TypeError, colors.get_child, ns.bse.foo, range=Node(ns.bsfs.Tag, n_root))
+ self.assertRaises(errors.ConsistencyError, colors.child, ns.bse.foo, range=Literal(ns.bsfs.Literal, None))
+ self.assertRaises(errors.ConsistencyError, colors.child, ns.bse.foo, range=Literal(ns.bsfs.foo, Literal(ns.bsfs.Literal, None)))
+ self.assertRaises(TypeError, colors.child, ns.bse.foo, range=Node(ns.bsfs.Tag, n_root))
## main ##