""" 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 ##