示例#1
0
    def test_subclass(self):
        # Operators are also available. For instance we can add ex:Opera to the
        # extension of the ex:CreativeWork class via the '+=' operator

        a = Class(exNs.Opera, graph=self.graph)
        a.subClassOf = [exNs.MusicalWork]
        # assert str(a) == 'Class: ex:Opera SubClassOf: ex:MusicalWork'
        assert str(a) == "Class: ex:Opera SubClassOf: b'ex:MusicalWork'", str(
            a)

        b = Class(exNs.CreativeWork, graph=self.graph)
        b += a

        assert pformat(list(a.subClassOf)) == \
            '[Class: ex:CreativeWork , Class: ex:MusicalWork ]' or \
            '[Class: ex:MusicalWork , Class: ex:CreativeWork ]'

        # And we can then remove it from the extension as well

        b -= a
        a

        # assert pformat(a) == 'Class: ex:Opera SubClassOf: ex:MusicalWork'
        assert pformat(
            a) == "Class: ex:Opera SubClassOf: b'ex:MusicalWork'", pformat(a)
示例#2
0
    def test_owlpyclasses(self):
        # Now we have an empty Graph, we can construct OWL classes in it using the
        # Python classes defined in this module

        a = Class(exNs.Opera, graph=self.graph)

        # Now we can assert rdfs:subClassOf and owl:equivalentClass relationships
        # (in the underlying graph) with other classes using the subClassOf and
        # equivalentClass descriptors which can be set to a list of objects for
        # the corresponding predicates.

        a.subClassOf = [exNs.MusicalWork]

        # We can then access the rdfs:subClassOf relationships

        assert pformat(list(
            a.subClassOf)) == '[Class: ex:MusicalWork ]', pformat(
                list(a.subClassOf))

        # This can also be used against already populated graphs:

        owlGraph = Graph().parse(str(OWL_NS))
        nsm = self.graph.namespace_manager
        nsm.bind('owl', OWL_NS, override=False)
        owlGraph.namespace_manager = nsm

        assert pformat(
            list(Class(OWL_NS.Class, graph=owlGraph).subClassOf)) == \
            '[Class: rdfs:Class ]'
示例#3
0
    def test_owlpyclasses(self):
        # Now we have an empty Graph, we can construct OWL classes in it using the
        # Python classes defined in this module

        a = Class(exNs.Opera, graph=self.graph)

        # Now we can assert rdfs:subClassOf and owl:equivalentClass relationships
        # (in the underlying graph) with other classes using the subClassOf and
        # equivalentClass descriptors which can be set to a list of objects for
        # the corresponding predicates.

        a.subClassOf = [exNs.MusicalWork]

        # We can then access the rdfs:subClassOf relationships

        assert pformat(list(a.subClassOf)) == '[Class: ex:MusicalWork ]', pformat(list(a.subClassOf))

        # This can also be used against already populated graphs:

        owlGraph = Graph().parse(str(OWL_NS))
        nsm = self.graph.namespace_manager
        nsm.bind('owl', OWL_NS, override=False)
        owlGraph.namespace_manager = nsm

        assert pformat(
            list(Class(OWL_NS.Class, graph=owlGraph).subClassOf)) == \
            '[Class: rdfs:Class ]'
示例#4
0
    def test_booleans(self):
        # Boolean class constructions can also be created with Python operators
        # For example, The | operator can be used to construct a class consisting
        # of a owl:unionOf the operands:

        a = Class(exNs.Opera, graph=self.graph)
        a.subClassOf = [exNs.MusicalWork]
        b = Class(exNs.CreativeWork, graph=self.graph)
        c = a | b | Class(exNs.Work, graph=self.graph)

        # assert(pformat(c)) == '( ex:Opera OR ex:CreativeWork OR ex:Work )'
        assert(pformat(c)) == "( b'ex:Opera' OR b'ex:CreativeWork' OR b'ex:Work' )", pformat(c)

        # Boolean class expressions can also be operated as lists (natively in python)

        del c[c.index(Class(exNs.Work, graph=self.graph))]

        # assert pformat(c) == '( ex:Opera OR ex:CreativeWork )'
        assert pformat(c) == "( b'ex:Opera' OR b'ex:CreativeWork' )", pformat(c)
示例#5
0
    def test_booleans(self):
        # Boolean class constructions can also be created with Python operators
        # For example, The | operator can be used to construct a class consisting
        # of a owl:unionOf the operands:

        a = Class(exNs.Opera, graph=self.graph)
        a.subClassOf = [exNs.MusicalWork]
        b = Class(exNs.CreativeWork, graph=self.graph)
        c = a | b | Class(exNs.Work, graph=self.graph)

        # assert(pformat(c)) == '( ex:Opera OR ex:CreativeWork OR ex:Work )'
        assert (
            pformat(c)
        ) == "( b'ex:Opera' OR b'ex:CreativeWork' OR b'ex:Work' )", pformat(c)

        # Boolean class expressions can also be operated as lists (natively in python)

        del c[c.index(Class(exNs.Work, graph=self.graph))]

        # assert pformat(c) == '( ex:Opera OR ex:CreativeWork )'
        assert pformat(c) == "( b'ex:Opera' OR b'ex:CreativeWork' )", pformat(
            c)
示例#6
0
    def test_subclass(self):
        # Operators are also available. For instance we can add ex:Opera to the
        # extension of the ex:CreativeWork class via the '+=' operator

        a = Class(exNs.Opera, graph=self.graph)
        a.subClassOf = [exNs.MusicalWork]
        # assert str(a) == 'Class: ex:Opera SubClassOf: ex:MusicalWork'
        assert str(a) == "Class: ex:Opera SubClassOf: b'ex:MusicalWork'", str(a)

        b = Class(exNs.CreativeWork, graph=self.graph)
        b += a

        assert pformat(list(a.subClassOf)) == \
            '[Class: ex:CreativeWork , Class: ex:MusicalWork ]' or \
            '[Class: ex:MusicalWork , Class: ex:CreativeWork ]'

        # And we can then remove it from the extension as well

        b -= a
        a

        # assert pformat(a) == 'Class: ex:Opera SubClassOf: ex:MusicalWork'
        assert pformat(a) == "Class: ex:Opera SubClassOf: b'ex:MusicalWork'", pformat(a)
示例#7
0
文件: example5.py 项目: RDFLib/FuXi
namespace_manager.bind('ex', exNs, override=False)
namespace_manager.bind('owl', OWL_NS, override=False)
g = Graph()
g.namespace_manager = namespace_manager

# Now we have an empty Graph, we can construct OWL classes in it using the
# Python classes defined in this module

a = Class(exNs.Opera, graph=g)

# Now we can assert rdfs:subClassOf and owl:equivalentClass relationships
# (in the underlying graph) with other classes using the subClassOf and
# equivalentClass descriptors which can be set to a list of objects for
# the corresponding predicates.

a.subClassOf = [exNs.MusicalWork]

# We can then access the rdfs:subClassOf relationships

assert pformat(list(a.subClassOf)) == '[Class: ex:MusicalWork ]'

# This can also be used against already populated graphs:

owlGraph = Graph().parse(OWL_NS)
namespace_manager.bind('owl', OWL_NS, override=False)
owlGraph.namespace_manager = namespace_manager

assert pformat(
    list(Class(OWL_NS.Class, graph=owlGraph).subClassOf)) == \
    '[Class: rdfs:Class ]'
示例#8
0
namespace_manager.bind('ex', exNs, override=False)
namespace_manager.bind('owl', OWL_NS, override=False)
g = Graph()
g.namespace_manager = namespace_manager

# Now we have an empty Graph, we can construct OWL classes in it using the
# Python classes defined in this module

a = Class(exNs.Opera, graph=g)

# Now we can assert rdfs:subClassOf and owl:equivalentClass relationships
# (in the underlying graph) with other classes using the subClassOf and
# equivalentClass descriptors which can be set to a list of objects for
# the corresponding predicates.

a.subClassOf = [exNs.MusicalWork]

# We can then access the rdfs:subClassOf relationships

assert pformat(list(a.subClassOf)) == '[Class: ex:MusicalWork ]'

# This can also be used against already populated graphs:

owlGraph = Graph().parse(OWL_NS)
namespace_manager.bind('owl', OWL_NS, override=False)
owlGraph.namespace_manager = namespace_manager

assert pformat(
    list(Class(OWL_NS.Class, graph=owlGraph).subClassOf)) == \
    '[Class: rdfs:Class ]'