I've created a repo with the functions I've been using in different projects to edit an rdf/owl graph, which I am sharing here as it might be useful to others.
The code contains the following functions:
- Create a class given a name
- Get all classes
- Check if instance has object properties
- Returns true if item is domain or range individual.
- Get all the object properties of the ontology
- Get all the data properties of the ontology
- Find an instance by string name
- Get classes of an instance
- Get a class by its string name
- Attach an instance to a class
- Get all the individuals in the ontology
- Add one or more values as data properties of a specific type to an instance
- Create a uri given the base name and class name
- Create an instance of a class
- Remove the superclasses of a given class if they are superclasses of a given super class (if we'd want to attach the given class to the given superclass)
- Given a class name and that class super class name, and a sub class, assign the super class of that subclass, creating it if necessary. There can be more than one super class to assign (csv string).
- Same as last point above but for subclasses
- Given a class name and its super class name, we create that new class if it does not exist or we return the existing one
- Given an instance (domain) and an object property, assign another instance by name as range of the domain instance object property. There can be more than one (comma separated).
- Returns True if the instance is of the class name. If descendants input argument is set to True then it looks for the subclasses too.