Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConstrainedDatatype causes g.parseTurtle failure #34

Open
weasdown opened this issue Jun 16, 2024 · 5 comments
Open

ConstrainedDatatype causes g.parseTurtle failure #34

weasdown opened this issue Jun 16, 2024 · 5 comments
Assignees

Comments

@weasdown
Copy link

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
@weasdown
Copy link
Author

I've written a working parser for List attributes here, although I admit the code is pretty horrible so I'll definitely clean it up when I can.

@weasdown
Copy link
Author

I've found that my code linked above doesn't currently handle multiple restrictions for ConstrainedDatatypes, so I'm working on that. Generally, I need to adapt the code so it uses the list brackets (( or [) to work out whether there will be deeper lists, rather than assuming it knows the structure. Once my parser is complete and tested for a variety of ontology entries, I'll add a pull request in this repo.

@zheyxu zheyxu self-assigned this Jul 1, 2024
@zheyxu
Copy link
Collaborator

zheyxu commented Jul 2, 2024

Thanks @weasdown! I made pr weasdown#1 to your forked repository.
Update parseObjectValues to parse deeper lists.

@zheyxu
Copy link
Collaborator

zheyxu commented Jul 31, 2024

Hi @weasdown, can you make pr to the main branch? As the issue #46 is related to this one. Thanks!

@weasdown
Copy link
Author

weasdown commented Aug 1, 2024

Sure, added! My code is pretty rough but will hopefully be a good starting point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants