1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
"""
Part of the bsie test suite.
A copy of the license is provided with the project.
Author: Matthias Baumgartner, 2022
"""
# imports
import unittest
# bsie imports
from bsie.utils import ns
from bsie.utils.node import Node
# objects to test
from bsie.extractor.generic.constant import Constant
## code ##
class TestConstant(unittest.TestCase):
def test_extract(self):
schema = '''
bse:author a bsfs:Predicate ;
rdfs:domain bsfs:Entity ;
rdfs:range xsd:string ;
owl:maxCardinality "1"^^xsd:number .
bse:comment a bsfs:Predicate ;
rdfs:domain bsfs:Entity ;
rdfs:range xsd:string ;
owl:maxCardinality "INF"^^xsd:number .
'''
tuples = [
(ns.bse.author, 'Me, myself, and I'),
(ns.bse.comment, 'the quick brown fox jumps over the lazy dog.'),
]
node = Node(ns.bsfs.Entity, '') # Blank node
predicates = (ns.bse.author, ns.bse.comment)
ext = Constant(schema, tuples)
# baseline
self.assertSetEqual(set(ext.extract(node, None, predicates)),
{(node, pred, value) for pred, value in tuples})
# predicates is respected
self.assertSetEqual(set(ext.extract(node, None, (ns.bse.author, ns.bse.foobar))),
{(node, ns.bse.author, 'Me, myself, and I')})
self.assertSetEqual(set(ext.extract(node, None, (ns.bse.comment, ns.bse.foobar))),
{(node, ns.bse.comment, 'the quick brown fox jumps over the lazy dog.')})
self.assertSetEqual(set(ext.extract(node, None, (ns.bse.foobar, ns.bse.barfoo))), set())
# FIXME: should change!
# for now: no schema compliance
ext = Constant('', tuples)
self.assertSetEqual(set(ext.extract(node, None, predicates)),
{(node, pred, value) for pred, value in tuples})
## main ##
if __name__ == '__main__':
unittest.main()
## EOF ##
|