Skip to content

ConstrainedDatatype causes g.parseTurtle failure #34

@weasdown

Description

@weasdown

If an ontology contains a property with a range whose value is a List rather than String, Graph._saveToGroups() fails on line 614 because the for loop casts the range item to a String. I tried changing this to cast to a var, but I'm not then sure how Graph.item() should handle it or how the resulting item should be saved to groups. Below are a sample ontology file to reproduce this (in .ttl and .xml, but both with extra .txt extensions to allow upload), and the Python file used to generate the ontology.

image

Ontology files to reproduce error (with extra .txt extension to allow upload):
Turtle: rdflib-test.ttl.txt
XML version for info: rdflib-test.xml.txt

Python used to generate ontology files:

import owlready2 as owl
import rdflib as rdf

onto_path = 'https://example.com/rdflib-test#'
onto = owl.get_ontology('https://example.com/rdflib-test')
with onto:
    class Object(owl.Thing):
        pass

    class Mass(owl.DataProperty):
        domain = [Object]
        range = [owl.ConstrainedDatatype(base_datatype=float, min_exclusive=0.0)]

    class has_mass(owl.DataProperty, owl.FunctionalProperty, Object >> Mass):
        pass

# Save the resulting ontology
file_name = 'rdflib-test'
onto.save(file=f'{file_name}.xml', format="rdfxml")  # save temporary XML that can be read by RDFlib

# Use RDFlib to parse XML ontology and save to TTL
g = rdf.Graph()  # an RDFlib graph
g.parse(f'{file_name}.xml')  # parse temporary XML into RDFlib graph

g.bind('rdflib-test', rdf.Namespace(onto_path))

g.serialize(f'{file_name}.ttl', format='turtle')  # also save TTL locally

# os.remove(f'{owl_file_name}.xml')  # delete temporary XML

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions