aboutsummaryrefslogtreecommitdiffstats
path: root/test/schema/test_serialize.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/schema/test_serialize.py')
-rw-r--r--test/schema/test_serialize.py308
1 files changed, 80 insertions, 228 deletions
diff --git a/test/schema/test_serialize.py b/test/schema/test_serialize.py
index 205150a..fc6b20a 100644
--- a/test/schema/test_serialize.py
+++ b/test/schema/test_serialize.py
@@ -581,151 +581,60 @@ class TestFromString(unittest.TestCase):
def test_feature(self):
- # domain must be defined
- self.assertRaises(errors.ConsistencyError, from_string, '''
- prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
- prefix xsd: <http://www.w3.org/2001/XMLSchema#>
- prefix bsfs: <http://bsfs.ai/schema/>
- prefix bse: <http://bsfs.ai/schema/Entity#>
-
- bsfs:Feature rdfs:subClassOf bsfs:Predicate .
- bsfs:array rdfs:subClassOf bsfs:Literal .
-
- bse:colors rdfs:subClassOf bsfs:Feature ;
- rdfs:domain bsfs:Entity ; # undefined symbol
- rdfs:range bsfs:array ;
- bsfs:unique "false"^^xsd:boolean .
- ''')
- # domain cannot be a literal
- self.assertRaises(errors.ConsistencyError, from_string, '''
- prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
- prefix xsd: <http://www.w3.org/2001/XMLSchema#>
- prefix bsfs: <http://bsfs.ai/schema/>
- prefix bse: <http://bsfs.ai/schema/Entity#>
-
- bsfs:Feature rdfs:subClassOf bsfs:Predicate .
- bsfs:Entity rdfs:subClassOf bsfs:Literal .
- bsfs:array rdfs:subClassOf bsfs:Literal .
-
- bse:colors rdfs:subClassOf bsfs:Feature ;
- rdfs:domain bsfs:Entity ; # literal instead of node
- rdfs:range bsfs:array ;
- bsfs:unique "false"^^xsd:boolean .
- ''')
-
- # range must be defined
- self.assertRaises(errors.ConsistencyError, from_string, '''
- prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
- prefix xsd: <http://www.w3.org/2001/XMLSchema#>
- prefix bsfs: <http://bsfs.ai/schema/>
- prefix bse: <http://bsfs.ai/schema/Entity#>
-
- bsfs:Feature rdfs:subClassOf bsfs:Predicate .
- bsfs:Entity rdfs:subClassOf bsfs:Node .
-
- bse:colors rdfs:subClassOf bsfs:Feature ;
- rdfs:domain bsfs:Entity ;
- rdfs:range bsfs:array ; # undefined symbol
- bsfs:unique "false"^^xsd:boolean .
- ''')
- # range must be defined
- self.assertRaises(errors.ConsistencyError, from_string, '''
+ # additional features can be defined
+ f_colors = types.ROOT_FEATURE.child(ns.bsfs.Colors)
+ self.assertEqual(Schema(literals={f_colors}), from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix bsfs: <http://bsfs.ai/schema/>
prefix bse: <http://bsfs.ai/schema/Entity#>
- bsfs:Feature rdfs:subClassOf bsfs:Predicate .
- bsfs:Entity rdfs:subClassOf bsfs:Node .
+ bsfs:Array rdfs:subClassOf bsfs:Literal .
+ bsfs:Feature rdfs:subClassOf bsfs:Array.
- bse:colors rdfs:subClassOf bsfs:Feature ;
- rdfs:domain bsfs:Entity ;
- rdfs:range bsfs:Foo ; # undefined symbol
- bsfs:unique "false"^^xsd:boolean .
- ''')
- # range must be a node or a literal
- self.assertRaises(errors.ConsistencyError, from_string, '''
- prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
- prefix xsd: <http://www.w3.org/2001/XMLSchema#>
- prefix bsfs: <http://bsfs.ai/schema/>
- prefix bse: <http://bsfs.ai/schema/Entity#>
-
- bsfs:Feature rdfs:subClassOf bsfs:Predicate .
- bsfs:Entity rdfs:subClassOf bsfs:Node .
-
- bse:colors rdfs:subClassOf bsfs:Feature ;
- rdfs:domain bsfs:Entity ;
- rdfs:range bsfs:Predicate ; # invalid symbol
- bsfs:unique "false"^^xsd:boolean .
- ''')
+ bsfs:Colors rdfs:subClassOf bsfs:Feature .
- # additional predicates can be defined
- 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#>
- prefix bsfs: <http://bsfs.ai/schema/>
- prefix bse: <http://bsfs.ai/schema/Entity#>
-
- bsfs:Feature rdfs:subClassOf bsfs:Predicate .
- bsfs:Entity rdfs:subClassOf bsfs:Node .
- bsfs:array rdfs:subClassOf bsfs:Literal .
-
- bse:colors rdfs:subClassOf bsfs:Feature ;
- rdfs:domain bsfs:Entity ;
- rdfs:range bsfs:array ;
- bsfs:unique "false"^^xsd:boolean .
'''))
# features inherit properties from parents
- 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.child(ns.bse.colors, unique=True)
- self.assertEqual(Schema({p_comment}), from_string('''
+ f_colors = types.ROOT_FEATURE.child(ns.bsfs.Colors, dimension=1234, dtype=ns.bsfs.i32)
+ f_main_colors = f_colors.child(ns.bsfs.MainColor, distance=ns.bsfs.cosine, dtype=ns.bsfs.f16)
+ self.assertEqual(Schema(literals={f_colors, f_main_colors}), from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix bsfs: <http://bsfs.ai/schema/>
prefix bse: <http://bsfs.ai/schema/Entity#>
- bsfs:Feature rdfs:subClassOf bsfs:Predicate .
- bsfs:Entity rdfs:subClassOf bsfs:Node .
- bsfs:array rdfs:subClassOf bsfs:Literal .
+ bsfs:Array rdfs:subClassOf bsfs:Literal .
+ bsfs:Feature rdfs:subClassOf bsfs:Array.
- bsfs:Annotation rdfs:subClassOf bsfs:Feature ; # inherits defaults from bsfs:Feature
- rdfs:domain bsfs:Entity ;
- rdfs:range bsfs:array ;
- bsfs:dimension "1234"^^xsd:integer ;
- bsfs:dtype xsd:string .
+ bsfs:Colors rdfs:subClassOf bsfs:Feature ; # inherits distance from bsfs:Feature
+ bsfs:dimension "1234"^^xsd:integer ; # overwrites bsfs:Feature
+ bsfs:dtype bsfs:i32 . # overwrites bsfs:Feature
+
+ bsfs:MainColor rdfs:subClassOf bsfs:Colors ; # inherits dimension from bsfs:Colors
+ bsfs:distance bsfs:cosine ; # overwrites bsfs:Feature
+ bsfs:dtype bsfs:f16 . # overwrites bsfs:Colors
- bse:colors rdfs:subClassOf bsfs:Annotation ; # inherits domain/range/etc. from bsfs:Annotation
- bsfs:unique "true"^^xsd:boolean . # overwrites bsfs:Predicate
'''))
# feature definition can be split across multiple statements.
# statements can be repeated
- 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('''
+ f_colors = types.ROOT_FEATURE.child(ns.bsfs.Colors, dimension=1234, dtype=ns.bsfs.f32)
+ self.assertEqual(Schema(literals={f_colors}), from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix bsfs: <http://bsfs.ai/schema/>
prefix bse: <http://bsfs.ai/schema/Entity#>
- bsfs:Feature rdfs:subClassOf bsfs:Predicate .
- bsfs:Entity rdfs:subClassOf bsfs:Node .
+ bsfs:Array rdfs:subClassOf bsfs:Literal .
+ bsfs:Feature rdfs:subClassOf bsfs:Array.
- bse:foo rdfs:subClassOf bsfs:Feature ;
- bsfs:unique "true"^^xsd:boolean ;
+ bsfs:Colors rdfs:subClassOf bsfs:Feature ;
bsfs:dimension "1234"^^xsd:integer .
- bse:foo rdfs:subClassOf bsfs:Feature ;
- rdfs:domain bsfs:Entity ;
+ bsfs:Colors rdfs:subClassOf bsfs:Feature ;
+ bsfs:dimension "1234"^^xsd:integer ; # non-conflicting repetition
bsfs:dtype bsfs:f32 .
'''))
@@ -736,75 +645,14 @@ class TestFromString(unittest.TestCase):
prefix bsfs: <http://bsfs.ai/schema/>
prefix bse: <http://bsfs.ai/schema/Entity#>
- bsfs:Feature rdfs:subClassOf bsfs:Predicate .
- bsfs:Annotation rdfs:subClassOf bsfs:Feature .
- bsfs:Entity rdfs:subClassOf bsfs:Node .
+ bsfs:Array rdfs:subClassOf bsfs:Literal .
+ bsfs:Feature rdfs:subClassOf bsfs:Array.
+ bsfs:ColorSpace rdfs:subClassOf bsfs:Feature .
- bse:foo rdfs:subClassOf bsfs:Feature ;
- rdfs:domain bsfs:Node ;
- bsfs:unique "false"^^xsd:boolean .
-
- bse:foo rdfs:subClassOf bsfs:Annotation ;
- rdfs:domain bsfs:Node ;
- bsfs:unique "false"^^xsd:boolean .
+ bsfs:Colors rdfs:subClassOf bsfs:Feature .
+ bsfs:Colors rdfs:subClassOf bsfs:ColorSpace .
''')
- # cannot assign multiple conflicting domains to the same feature
- self.assertRaises(errors.ConsistencyError, from_string, '''
- prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
- prefix xsd: <http://www.w3.org/2001/XMLSchema#>
- prefix bsfs: <http://bsfs.ai/schema/>
- prefix bse: <http://bsfs.ai/schema/Entity#>
-
- bsfs:Feature rdfs:subClassOf bsfs:Predicate .
- bsfs:Entity rdfs:subClassOf bsfs:Node .
-
- bse:foo rdfs:subClassOf bsfs:Feature ;
- rdfs:domain bsfs:Node ;
- bsfs:unique "false"^^xsd:boolean .
-
- bse:foo rdfs:subClassOf bsfs:Feature ;
- rdfs:domain bsfs:Entity . # conflicting domain
- ''')
- # cannot assign multiple conflicting ranges to the same feature
- self.assertRaises(errors.ConsistencyError, from_string, '''
- prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
- prefix xsd: <http://www.w3.org/2001/XMLSchema#>
- prefix bsfs: <http://bsfs.ai/schema/>
- prefix bse: <http://bsfs.ai/schema/Entity#>
-
- bsfs:Feature rdfs:subClassOf bsfs:Predicate .
- bsfs:Entity rdfs:subClassOf bsfs:Node .
- bsfs:array rdfs:subClassOf bsfs:Literal .
- bsfs:large_array rdfs:subClassOf bsfs:array .
- bsfs:small_array rdfs:subClassOf bsfs:array .
-
- bse:foo rdfs:subClassOf bsfs:Feature ;
- rdfs:domain bsfs:Node ;
- rdfs:range bsfs:large_array ;
- bsfs:unique "false"^^xsd:boolean .
-
- bse:foo rdfs:subClassOf bsfs:Feature ;
- rdfs:range bsfs:small_array . # conflicting range
- ''')
- # cannot assign multiple conflicting uniques to the same feature
- self.assertRaises(errors.ConsistencyError, from_string, '''
- prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
- prefix xsd: <http://www.w3.org/2001/XMLSchema#>
- prefix bsfs: <http://bsfs.ai/schema/>
- prefix bse: <http://bsfs.ai/schema/Entity#>
-
- bsfs:Feature rdfs:subClassOf bsfs:Predicate .
- bsfs:Entity rdfs:subClassOf bsfs:Node .
-
- bse:foo rdfs:subClassOf bsfs:Feature ;
- rdfs:domain bsfs:Node ;
- rdfs:range bsfs:Node ;
- bsfs:unique "false"^^xsd:boolean .
-
- bse:foo rdfs:subClassOf bsfs:Feature ;
- bsfs:unique "true"^^xsd:boolean . # conflicting unique
- ''')
# cannot assign multiple conflicting dimensions to the same feature
self.assertRaises(errors.ConsistencyError, from_string, '''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
@@ -812,15 +660,15 @@ class TestFromString(unittest.TestCase):
prefix bsfs: <http://bsfs.ai/schema/>
prefix bse: <http://bsfs.ai/schema/Entity#>
- bsfs:Feature rdfs:subClassOf bsfs:Predicate .
- bsfs:Entity rdfs:subClassOf bsfs:Node .
+ bsfs:Array rdfs:subClassOf bsfs:Literal .
+ bsfs:Feature rdfs:subClassOf bsfs:Array.
- bse:foo rdfs:subClassOf bsfs:Feature ;
- rdfs:domain bsfs:Node ;
+ bsfs:Colors rdfs:subClassOf bsfs:Feature ;
bsfs:dimension "1234"^^xsd:integer .
- bse:foo rdfs:subClassOf bsfs:Feature ;
+ bsfs:Colors rdfs:subClassOf bsfs:Feature ;
bsfs:dimension "4321"^^xsd:integer . # conflicting dimension
+
''')
# cannot assign multiple conflicting dtypes to the same feature
self.assertRaises(errors.ConsistencyError, from_string, '''
@@ -829,14 +677,13 @@ class TestFromString(unittest.TestCase):
prefix bsfs: <http://bsfs.ai/schema/>
prefix bse: <http://bsfs.ai/schema/Entity#>
- bsfs:Feature rdfs:subClassOf bsfs:Predicate .
- bsfs:Entity rdfs:subClassOf bsfs:Node .
+ bsfs:Array rdfs:subClassOf bsfs:Literal .
+ bsfs:Feature rdfs:subClassOf bsfs:Array.
- bse:foo rdfs:subClassOf bsfs:Feature ;
- rdfs:domain bsfs:Node ;
+ bsfs:Colors rdfs:subClassOf bsfs:Feature ;
bsfs:dtype bsfs:f32 .
- bse:foo rdfs:subClassOf bsfs:Feature ;
+ bsfs:Colors rdfs:subClassOf bsfs:Feature ;
bsfs:dtype bsfs:f16 . # conflicting dtype
''')
# cannot assign multiple conflicting distance metrics to the same feature
@@ -846,14 +693,13 @@ class TestFromString(unittest.TestCase):
prefix bsfs: <http://bsfs.ai/schema/>
prefix bse: <http://bsfs.ai/schema/Entity#>
- bsfs:Feature rdfs:subClassOf bsfs:Predicate .
- bsfs:Entity rdfs:subClassOf bsfs:Node .
+ bsfs:Array rdfs:subClassOf bsfs:Literal .
+ bsfs:Feature rdfs:subClassOf bsfs:Array.
- bse:foo rdfs:subClassOf bsfs:Feature ;
- rdfs:domain bsfs:Node ;
+ bsfs:Colors rdfs:subClassOf bsfs:Feature ;
bsfs:distance bsfs:euclidean .
- bse:foo rdfs:subClassOf bsfs:Feature ;
+ bsfs:Colors rdfs:subClassOf bsfs:Feature ;
bsfs:distance bsfs:cosine . # conflicting distance
''')
@@ -864,24 +710,28 @@ class TestFromString(unittest.TestCase):
prefix bsfs: <http://bsfs.ai/schema/>
prefix bse: <http://bsfs.ai/schema/Entity#>
- bsfs:Feature rdfs:subClassOf bsfs:Predicate .
- bse:colors rdfs:subClassOf bsfs:Feature ;
+ bsfs:Array rdfs:subClassOf bsfs:Literal .
+ bsfs:Feature rdfs:subClassOf bsfs:Array.
+
+ bsfs:Colors rdfs:subClassOf bsfs:Feature ;
bsfs:dimension "1234"^^xsd:integer .
- ''').predicate(ns.bse.colors).annotations, {})
+ ''').literal(ns.bsfs.Colors).annotations, {})
self.assertDictEqual(from_string('''
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix bsfs: <http://bsfs.ai/schema/>
prefix bse: <http://bsfs.ai/schema/Entity#>
- bsfs:Feature rdfs:subClassOf bsfs:Predicate .
- bse:colors rdfs:subClassOf bsfs:Feature ;
+ bsfs:Array rdfs:subClassOf bsfs:Literal .
+ bsfs:Feature rdfs:subClassOf bsfs:Array.
+
+ bsfs:Colors rdfs:subClassOf bsfs:Feature ;
bsfs:dimension "1234"^^xsd:integer ;
rdfs:label "hello world"^^xsd:string ;
bsfs:foo "1234"^^xsd:integer .
- ''').predicate(ns.bse.colors).annotations, {
+ ''').literal(ns.bsfs.Colors).annotations, {
ns.rdfs.label: 'hello world',
ns.bsfs.foo: 1234,
})
@@ -904,14 +754,14 @@ class TestFromString(unittest.TestCase):
p_comment = p_annotation.child(ns.bse.comment, range=l_string)
# features
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)
+ dtype=ns.bsfs.f16, distance=ns.bsfs.euclidean)
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},
+ {p_annotation, p_tag, p_group, p_comment},
{n_ent, n_tag, n_image},
- {l_string, l_integer, l_boolean})
+ {l_string, l_integer, l_boolean, f_colors, f_colors1234, f_colors4321})
# load from string
gen = from_string('''
# generic prefixes
@@ -932,21 +782,19 @@ class TestFromString(unittest.TestCase):
# literals
xsd:string rdfs:subClassOf bsfs:Literal ;
rdfs:label "A sequence of characters"^^xsd:string .
- bsfs:array rdfs:subClassOf bsfs:Literal .
+ bsfs:Array rdfs:subClassOf bsfs:Literal .
+ bsfs:Feature rdfs:subClassOf bsfs:Array.
bsfs:Number rdfs:subClassOf bsfs:Literal .
xsd:integer rdfs:subClassOf bsfs:Number .
xsd:boolean rdfs:subClassOf bsfs:Literal .
+
# abstract predicates
bsfs:Annotation rdfs:subClassOf bsfs:Predicate ;
rdfs:label "node annotation"^^xsd:string .
- bsfs:Feature rdfs:subClassOf bsfs:Predicate .
# feature instances
<http://bsfs.ai/schema/Feature/colors_spatial> rdfs:subClassOf bsfs:Feature ;
- rdfs:domain bsfs:Entity ;
- rdfs:range bsfs:array ;
- bsfs:unique "true"^^xsd:boolean ;
bsfs:dtype bsfs:f16 ;
bsfs:distance bsfs:euclidean ;
# annotations
@@ -986,15 +834,22 @@ class TestFromString(unittest.TestCase):
self.assertDictEqual(gen.node(ns.bsfs.Tag).annotations, {ns.rdfs.label: 'Tag'})
self.assertDictEqual(gen.literal(ns.xsd.string).annotations, {ns.rdfs.label: 'A sequence of characters'})
self.assertDictEqual(gen.predicate(ns.bsfs.Annotation).annotations, {ns.rdfs.label: 'node annotation'})
- self.assertDictEqual(gen.predicate(URI('http://bsfs.ai/schema/Feature/colors_spatial')).annotations, {
+ self.assertDictEqual(gen.literal(URI('http://bsfs.ai/schema/Feature/colors_spatial')).annotations, {
ns.rdfs.label: 'ColorsSpatial instances. Dimension depends on instance.',
ns.bsfs.first_arg: 1234,
ns.bsfs.second_arg: 'hello world',
})
- self.assertDictEqual(gen.predicate(URI('http://bsfs.ai/schema/Feature/colors_spatial#1234')).annotations, {
+ self.assertDictEqual(gen.literal(URI('http://bsfs.ai/schema/Feature/colors_spatial#1234')).annotations, {
ns.rdfs.label: 'Main colors spatial instance'})
self.assertDictEqual(gen.predicate(ns.bse.tag).annotations, {ns.rdfs.label: 'connect entity to a tag'})
+ # blank nodes result in an error
+ self.assertRaises(errors.BackendError, from_string, '''
+ prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
+ prefix bsfs: <http://bsfs.ai/schema/>
+ bsfs:Entity rdfs:subClassOf bsfs:Node ;
+ bsfs:foo _:bar .
+ ''')
class TestToString(unittest.TestCase):
@@ -1002,6 +857,11 @@ class TestToString(unittest.TestCase):
def test_empty(self):
self.assertEqual(Schema(), from_string(to_string(Schema())))
+ def test_parse(self):
+ schema = Schema()
+ schema._nodes[ns.bsfs.Invalid] = 123 # NOTE: Access protected to force an invalid schema
+ self.assertRaises(TypeError, to_string, schema)
+
def test_literal(self):
# root literals
l_str = types.ROOT_LITERAL.child(ns.xsd.string)
@@ -1120,37 +980,29 @@ class TestToString(unittest.TestCase):
def test_feature(self):
- # auxiliary types
- n_ent = types.ROOT_NODE.child(ns.bsfs.Entity)
- l_array = types.ROOT_LITERAL.child(ns.bsfs.array)
# root features
f_colors = types.ROOT_FEATURE.child(URI('http://bsfs.ai/schema/Feature/colors'),
- range=l_array, unique=True, distance=ns.bsfs.cosine)
+ distance=ns.bsfs.cosine)
# derived features
f_colors1234 = f_colors.child(URI('http://bsfs.ai/schema/Feature/colors#1234'),
- dimension=1024, domain=n_ent) # inherits range/dtype/distance
+ dimension=1024) # inherits dtype, distance
f_colors4321 = f_colors.child(URI('http://bsfs.ai/schema/Feature/colors#4321'),
- dimension=2048, distance=ns.bsfs.euclidean) # inherits domain/range/dtype
+ dimension=2048, distance=ns.bsfs.euclidean) # inherits dtype
# create schema
- schema = Schema({f_colors, f_colors1234, f_colors4321})
+ schema = Schema(literals={f_colors, f_colors1234, f_colors4321})
schema_str = to_string(schema)
# all symbols are serialized
- self.assertIn('bsfs:Entity', schema_str)
- self.assertIn('bsfs:array', schema_str)
+ self.assertIn('bsfs:Array', schema_str)
self.assertIn('<http://bsfs.ai/schema/Feature/colors', schema_str)
self.assertIn('<http://bsfs.ai/schema/Feature/colors#1234', schema_str)
self.assertIn('<http://bsfs.ai/schema/Feature/colors#4321', schema_str)
# inherited properties are not serialized
- self.assertIsNotNone(re.search(r'<http://bsfs\.ai/schema/Feature/colors#1234>[^\.]*rdfs:domain[^\.]', schema_str))
self.assertIsNotNone(re.search(r'<http://bsfs\.ai/schema/Feature/colors#1234>[^\.]*bsfs:dimension[^\.]', schema_str))
- self.assertIsNone(re.search(r'<http://bsfs\.ai/schema/Feature/colors#1234>[^\.]*rdfs:range[^\.]', schema_str))
self.assertIsNone(re.search(r'<http://bsfs\.ai/schema/Feature/colors#1234>[^\.]*bsfs:dtype[^\.]', schema_str))
self.assertIsNone(re.search(r'<http://bsfs\.ai/schema/Feature/colors#1234>[^\.]*bsfs:distance[^\.]', schema_str))
self.assertIsNotNone(re.search(r'<http://bsfs\.ai/schema/Feature/colors#4321>[^\.]*bsfs:dimension[^\.]', schema_str))
self.assertIsNotNone(re.search(r'<http://bsfs\.ai/schema/Feature/colors#4321>[^\.]*bsfs:distance[^\.]', schema_str))
- self.assertIsNone(re.search(r'<http://bsfs\.ai/schema/Feature/colors#4321>[^\.]*rdfs:domain[^\.]', schema_str))
- self.assertIsNone(re.search(r'<http://bsfs\.ai/schema/Feature/colors#4321>[^\.]*rdfs:range[^\.]', schema_str))
self.assertIsNone(re.search(r'<http://bsfs\.ai/schema/Feature/colors#4321>[^\.]*bsfs:dtype[^\.]', schema_str))
# unserialize yields the original schema
self.assertEqual(schema, from_string(schema_str))
@@ -1163,11 +1015,11 @@ class TestToString(unittest.TestCase):
ns.bsfs.bar: False,
}
f_colors = types.ROOT_FEATURE.child(URI('http://bsfs.ai/schema/Feature/colors'),
- domain=n_ent, range=l_array, unique=True, dtype=ns.bsfs.f16, distance=ns.bsfs.euclidean,
+ dtype=ns.bsfs.f16, distance=ns.bsfs.euclidean,
**annotations)
self.assertDictEqual(
annotations,
- from_string(to_string(Schema({f_colors}))).predicate(URI('http://bsfs.ai/schema/Feature/colors')).annotations)
+ from_string(to_string(Schema(literals={f_colors}))).literal(URI('http://bsfs.ai/schema/Feature/colors')).annotations)
## main ##