summaryrefslogtreecommitdiff
path: root/test/test_extras/test_infixowl/test_property.py
blob: 8440381e977c839bc13b1914f80d9ba3511aa78a (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import pytest

from rdflib import OWL, XSD, Graph, Literal, Namespace, URIRef
from rdflib.extras.infixowl import Property

EXNS = Namespace("http://example.org/vocab/")
PZNS = Namespace(
    "http://www.co-ode.org/ontologies/pizza/2005/10/18/classified/pizza.owl#"
)


@pytest.fixture(scope="function")
def graph():
    g = Graph(identifier=EXNS.context0)
    g.bind("ex", EXNS)

    yield g

    del g


def test_property(graph):

    comment = Literal("This is a woman")
    verbannotations = ("woman", "Women", "Womens")
    nameannotation = Literal("Woman")
    iswoman = Property(
        identifier=EXNS.iswoman,
        graph=graph,
        baseType=OWL.DatatypeProperty,
        subPropertyOf=None,
        domain=None,
        range=None,
        inverseOf=None,
        otherType=None,
        equivalentProperty=None,
        comment=comment,
        verbAnnotations=verbannotations,
        nameAnnotation=nameannotation,
        nameIsLabel=True,
    )

    comment = Literal("This is a man")
    verbannotations = ("Man", "Men", "Mens")
    nameannotation = Literal("Man")

    isman = Property(
        identifier=EXNS.isman,
        graph=graph,
        subPropertyOf=[EXNS.nosuchproperty],
        domain=EXNS.Parent,
        range=XSD.integer,
        inverseOf=iswoman,
        otherType=None,
        equivalentProperty=[EXNS.nosuchequivalentproperty],
        comment=comment,
        verbAnnotations=verbannotations,
        nameAnnotation=nameannotation,
        nameIsLabel=True,
    )

    isman.setupVerbAnnotations(None)

    assert str(repr(isman)) == (
        "ObjectProperty( ex:isman annotation(This is a man)\n"
        "  inverseOf( DatatypeProperty( ex:iswoman This is a woman\n"
        ") )\n"
        "   super( ex:nosuchproperty )\n"
        "   domain( ex:Parent )\n"
        "   range( Class: xsd:integer  )\n"
        ")"
    )

    assert str(repr(iswoman)) == "DatatypeProperty( ex:iswoman This is a woman\n)"

    isman.extent = None

    isman.extent = [(EXNS.aclass, EXNS.somextent)]

    assert list(isman.extent) == [
        (
            URIRef("http://example.org/vocab/aclass"),
            URIRef("http://example.org/vocab/isman"),
            URIRef("http://example.org/vocab/somextent"),
        )
    ]

    sg = Graph()

    isman.serialize(sg)

    assert len(sg) > 0

    iswoman.domain = None

    iswoman.domain = EXNS.Parent

    iswoman.domain = [EXNS.Parent, EXNS.Mother]

    iswoman.range = None

    iswoman.range = XSD.decimal

    iswoman.range = [XSD.decimal, XSD.float]

    assert list(isman.extent) == [
        (
            URIRef("http://example.org/vocab/aclass"),
            URIRef("http://example.org/vocab/isman"),
            URIRef("http://example.org/vocab/somextent"),
        )
    ]

    # TODO, this deletes but does replace?
    isman.replace(EXNS.someotherextent)

    assert list(isman.extent) == []

    assert sg.serialize(format="ttl") == (
        "@prefix ns1: <http://attempto.ifi.uzh.ch/ace_lexicon#> .\n"
        "@prefix owl: <http://www.w3.org/2002/07/owl#> .\n"
        "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"
        "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n"
        "\n"
        "<http://example.org/vocab/isman> a owl:ObjectProperty ;\n"
        '    rdfs:label "Man" ;\n'
        '    ns1:PN_sg "Man" ;\n'
        '    ns1:TV_pl "Men" ;\n'
        '    ns1:TV_sg "Man" ;\n'
        '    ns1:TV_vbg "Mens" ;\n'
        '    rdfs:comment "This is a man" ;\n'
        "    rdfs:domain <http://example.org/vocab/Parent> ;\n"
        "    rdfs:range xsd:integer ;\n"
        "    rdfs:subPropertyOf <http://example.org/vocab/nosuchproperty> ;\n"
        "    owl:inverseOf <http://example.org/vocab/iswoman> .\n"
        "\n"
        "<http://example.org/vocab/Parent> a owl:Class .\n"
        "\n"
        "<http://example.org/vocab/iswoman> a owl:DatatypeProperty ;\n"
        '    rdfs:label "Woman" ;\n'
        '    ns1:PN_sg "Woman" ;\n'
        '    ns1:TV_pl "Women" ;\n'
        '    ns1:TV_sg "woman" ;\n'
        '    ns1:TV_vbg "Womens" ;\n'
        '    rdfs:comment "This is a woman" .\n'
        "\n"
        "xsd:integer a owl:Class .\n"
        "\n"
    )