Skip to content

Commit

Permalink
Merge pull request #6 from pwin/v2.26
Browse files Browse the repository at this point in the history
update fork from bitbucket repo
  • Loading branch information
pwin authored Nov 26, 2020
2 parents c460d3d + e3ed166 commit d8668b1
Show file tree
Hide file tree
Showing 105 changed files with 30,701 additions and 747 deletions.
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# These are some examples of commonly ignored file patterns.
# You should customize this list as applicable to your project.
# Learn more about .gitignore:
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore

# Compiled Python bytecode
*.py[cod]
__pycache__

# Log files
*.log

*.old
*.save
*.bug
*.egg-info
build
doc/doctrees/
doc/html/

# Generated by MacOS
.DS_Store

# Generated by Windows
Thumbs.db
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ include ./README.rst

exclude .hg
exclude .hg/*
exclude .git
exclude .git/*
exclude .gitignore

exclude doc/examples/contraindications.py

Expand Down
72 changes: 69 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ Owlready2
:alt: download stats


# The source of this fork is at https://bitbucket.org/jibalamy/owlready2/src/master/


Owlready2 is a module for ontology-oriented programming in Python 3, including an optimized RDF quadstore.

Owlready2 can:
Expand Down Expand Up @@ -431,6 +430,7 @@ version 2 - 0.20
version 2 - 0.21
****************

* Use Pellet 2.3.1 (same version as Protégé) instead of 2.4 (which has a bug in SWRL for many builtin predicates including equals and matches)
* Much faster mangement of annotations on relations
* Bugfixes:
- Fix bug on blank node in RDFlib/SPARQL support
Expand All @@ -439,11 +439,77 @@ version 2 - 0.21
- Fix 'no query solution' error in search()
- Fix literal support in RDF lists, causing "TypeError: '<' not supported between instances of 'NoneType' and 'int'" when saving ontologies
- Fix DifferentFrom SWRL builtin
- Fix string parsing in SWRL rules
- Fix string and boolean literal representation (str/repr) in SWRL rules
- Fix the inverse of subproperties having a symmetric superproperty

version 2 - 0.22
****************

* Add support for disjoint unions (Class.disjoint_unions)
* Add deepcopy support on class constructs, and automatically deep-copy constructs when needed (i.e. no more OwlReadySharedBlankNodeError)
* Support the creation of blank nodes with RDFlib

version 2 - 0.23
****************

* Add get_parents_of(), get_instances_of(), get_children_of() methods to ontology, for querying the hierarchical relations defined in a given ontology
* Use Thing as default value for restrictions with number, instead of None
* Add 'filter' parameter to save(), for filtering the entities saved (contributed by Javier de la Rosa)
* Bugfixes:
- Fix value restriction with the false value
- Fix blank node loading from different ontologies
- Fix constructs reused by several classes
- Fix 'Class.is_a = []' was not turning the list into an Owlready list
- Fix destroy_entity() - was not destroying the IRI of the entity
- Improve setup.py: ignore Cython if Cython installation fails

version 2 - 0.24
****************

* Support intersection of searches (e.g. World.search(...) & World.search(...))
* Add owlready2.reasoning.JAVA_MEMORY
* Move development repository to Git
* Bugfixes:
- Fix parsing of NTriples files that do not end with a new line
- Fix KeyError with Prop.python_name when several properties share the same name
- Fix get_ontology() calls in Python module imported by ontologies in a World that is not default_world
- Fix use of PyMedTermino2 in a World that is not default_world
- Fix World.as_rdflib_graph().get_context(onto) for ontology added after the creation of the RDFLIB graph
- Fix destroying SWRL rules
- Fix disjoint with non-atomic classes

version 2 - 0.25
****************

* Allow the declaration of custom datatypes with declare_datatype()
* Support the annotation of annotations (e.g. a comment on a comment)
* search() now support the "subproperty_of" argument
* search() now support the "bm25" argument (for full-text searches)
* Bugfixes:
- Fix Concept.descendant_concepts() in PymedTermino2
- Update already loaded properties when new ontologies are loaded
- Now accept %xx quoted characters in file:// URL
- Improve error message on punned entities
- Property.get_relations() now considers inverse properties
- Fix "AttributeError: 'mappingproxy' object has no attribute 'pop'" error
- Fix Thing.instances()

version 2 - 0.26
****************

* Module owlready2.dl_render allows rendering entities to Description Logics (contributed by Simon Bin)
* Bugfixes:
- Adjustment in the comparison of strings from SameAs and DiferrentFrom, allowing equal comparison regardless of the case-sensitive (contributed by Thiago Feijó)
- Fix transitive equivalent_to relations between classes and OWL constructs
- Fix AnnotationProperty[entity] where entity is a predefined OWL entity (e.g. comment or Thing)
- Fix entity.AnnotationProperty where entity is a predefined OWL entity (e.g. comment or Thing)


Links
-----

Owlready2 on BitBucket (development repository): https://bitbucket.org/jibalamy/owlready2
Owlready2 on BitBucket (Git development repository): https://bitbucket.org/jibalamy/owlready2

Owlready2 on PyPI (Python Package Index, stable release): https://pypi.python.org/pypi/Owlready2

Expand Down
1 change: 0 additions & 1 deletion TODO.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Owlready2 TODO list
* Add support for property chain in entity.property.indirect()
* Add functions/methods for copying entities from an ontology to another
* Obtain individual property value inferred by HermiT
* Add rule support

* Support additional file formats:
* OWL/XML write
Expand Down
15 changes: 9 additions & 6 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

VERSION = "0.20"
VERSION = "0.25"

JAVA_EXE = "java"

Expand Down Expand Up @@ -61,7 +61,7 @@
owlready2.namespace.IndividualValueList = IndividualValueList
owlready2.entity.Thing = Thing
owlready2.entity.Nothing = Nothing
owlready2.entity.ClassConstruct = ClassConstruct
owlready2.entity.Construct = Construct
owlready2.entity.And = And
owlready2.entity.Or = Or
owlready2.entity.Not = Not
Expand All @@ -82,20 +82,20 @@
owlready2.disjoint.Or = Or
owlready2.prop.Restriction = Restriction
owlready2.prop.ConstrainedDatatype = ConstrainedDatatype
owlready2.prop.ClassConstruct = ClassConstruct
owlready2.prop.Construct = Construct
owlready2.prop.AnnotationProperty = AnnotationProperty
owlready2.prop.Thing = Thing
#owlready2.prop.ValueList = ValueList
owlready2.prop.PropertyChain = PropertyChain
owlready2.prop._check_superclasses = True

owlready2.prop.ThingClass = ThingClass
owlready2.prop.And = And
owlready2.prop.Or = Or
owlready2.prop.OneOf = OneOf
owlready2.annotation.ClassConstruct = ClassConstruct
owlready2.annotation.Construct = Construct

owlready2.individual._keep_most_specific = _keep_most_specific
owlready2.individual.ClassConstruct = ClassConstruct
owlready2.individual.Construct = Construct
owlready2.individual.TransitiveProperty = TransitiveProperty
owlready2.individual.SymmetricProperty = SymmetricProperty
owlready2.individual.ReflexiveProperty = ReflexiveProperty
Expand All @@ -104,6 +104,9 @@
owlready2.class_construct.Thing = Thing
owlready2.class_construct.ThingClass = ThingClass
owlready2.class_construct.EntityClass = EntityClass

#owlready2.reasoning.Construct = Construct

del owlready2

from owlready2.rule import *
Expand Down
70 changes: 44 additions & 26 deletions annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,34 @@
# return bnode

class _AnnotList(CallbackListWithLanguage):
__slots__ = ["_property", "_target", "_target_d", "_annot"]
def __init__(self, l, source, property, target, target_d, annot):
__slots__ = ["namespace", "_property", "_target", "_target_d", "_annot", "_od_2_bnode"]
def __init__(self, l, source, property, target, target_d, annot, namespace, od_2_bnode):
list.__init__(self, l)
self._obj = source
self._property = property
self._target = target
self._target_d = target_d
self._annot = annot
self.namespace = namespace
self._obj = source
self._property = property
self._target = target
self._target_d = target_d
self._annot = annot
self._od_2_bnode = od_2_bnode

def _callback(self, obj, old):
old = set(old)
new = set(self)

if isinstance(obj, _AnnotList): # Annotate an annotation
storid = obj._od_2_bnode[self._target, self._target_d]
else:
storid = obj.storid

# Add before, in order to avoid destroying the axiom and then recreating, if all annotations are modified
for added in new - old:
x = obj.namespace.ontology._add_annotation_axiom(obj.storid, self._property, self._target, self._target_d, self._annot, *obj.namespace.ontology._to_rdf(added))
o, d = obj.namespace.ontology._to_rdf(added)
bnode = obj.namespace.ontology._add_annotation_axiom(storid, self._property, self._target, self._target_d, self._annot, o, d)
self._od_2_bnode[o, d] = bnode

for removed in old - new:
obj.namespace.ontology._del_annotation_axiom (obj.storid, self._property, self._target, self._target_d, self._annot, *obj.namespace.ontology._to_rdf(removed))
obj.namespace.ontology._del_annotation_axiom(storid, self._property, self._target, self._target_d, self._annot, *obj.namespace.ontology._to_rdf(removed))


class AnnotationPropertyClass(PropertyClass):
Expand All @@ -80,34 +89,43 @@ class AnnotationPropertyClass(PropertyClass):
def __getitem__(Annot, entity):
if isinstance(entity, tuple):
source, property, target = entity
if hasattr(source, "storid"):
world = source.namespace.world # if Annot is in owl_world (e.g. comment), use the world of the source
source_orig = source
source = source.storid

if hasattr(source, "storid"):
namespace = source.namespace # if Annot is in owl_world (e.g. comment), use the namespace of the source
elif isinstance(source, _AnnotList):
namespace = source._obj.namespace
else:
world = self.namespace.world
namespace = Annot.namespace

if hasattr(property, "storid"): property = property.storid
target, target_d = world._to_rdf(target)
target, target_d = namespace.world._to_rdf(target)

if hasattr(source, "storid"):
source_orig = source
source = source.storid
elif isinstance(source, _AnnotList):
source_orig = source
source = source._od_2_bnode[target, target_d]

l = []
for bnode in world._get_annotation_axioms(source, property, target, target_d):
for o, d in world._get_triples_sp_od(bnode, Annot.storid):
l.append(world._to_python(o, d))

od_2_bnode = {}
for bnode in namespace.world._get_annotation_axioms(source, property, target, target_d):
for o, d in namespace.world._get_triples_sp_od(bnode, Annot.storid):
l.append(namespace.world._to_python(o, d))
od_2_bnode[o, d] = bnode

return _AnnotList(l, source_orig, property, target, target_d, Annot.storid)
return _AnnotList(l, source_orig, property, target, target_d, Annot.storid, namespace, od_2_bnode)

else:
if Annot is entity.namespace.world._props.get(Annot._python_name) and not isinstance(entity, ClassConstruct): # use cached value
if Annot is entity.namespace.world._props.get(Annot._python_name) and not isinstance(entity, Construct): # use cached value
r = getattr(entity, Annot._python_name)
if isinstance(r, list): return r # May not be a list if hacked (e.g. Concept.terminology)
return Annot._get_values_for_individual(entity)

def __setitem__(Annot, index, values):
if not isinstance(values, list): values = [values]

if isinstance(index, tuple):
Annot[index].reinit(values)
else:
return setattr(index, Annot.python_name, values)
Annot[index].reinit(values)

def __call__(Prop, type, c, *args):
raise ValueError("Cannot create a property value restriction on an annotation property!")
Expand Down
24 changes: 23 additions & 1 deletion base.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _universal_abbrev(iri):
_universal_abbrev("http://www.w3.org/2002/07/owl#FunctionalProperty")
_universal_abbrev("http://www.w3.org/2002/07/owl#InverseFunctionalProperty")

SPECIAL_ATTRS = { "namespace", "name", "_name", "iri", "_iri", "storid", "is_a", "equivalent_to", "_equivalent_to", "disjoint_with", "_disjoint_with", "defined_class", "__class__", "__qualname__", "__module__", "__doc__", "__bases__" }
SPECIAL_ATTRS = { "namespace", "name", "_name", "iri", "_iri", "storid", "is_a", "equivalent_to", "_equivalent_to", "disjoint_with", "_disjoint_with", "defined_class", "_disjoint_unions", "__class__", "__qualname__", "__module__", "__doc__", "__bases__" }
SPECIAL_PROP_ATTRS = { "namespace", "name", "_name", "python_name", "_python_name", "_domain", "_property_chain", "_inverse_property", "inverse_property", "inverse", "_range", "iri", "_iri", "storid", "is_a", "equivalent_to", "_equivalent_to", "disjoint_with", "_disjoint_with", "__class__", "__qualname__", "__module__", "__doc__", "__bases__" }


Expand Down Expand Up @@ -183,6 +183,21 @@ def set_datatype_iri(datatype, iri):
_universal_datatype_2_abbrev [datatype] = _universal_iri_2_abbrev[iri]
_universal_datatype_2_abbrev_unparser[datatype] = (_universal_iri_2_abbrev[iri], unparser)


def declare_datatype(datatype, iri, parser, unparser):
storid = _universal_abbrev(iri)
from owlready2 import WORLDS
for world in WORLDS:
world.graph.execute("INSERT INTO resources VALUES (?,?)", (storid, iri))
if world.graph._abbreviate_d:
world.graph._abbreviate_d [iri] = storid
world.graph._unabbreviate_d[storid] = iri

_universal_datatype_2_abbrev [datatype] = storid
_universal_datatype_2_abbrev_unparser[datatype] = (storid, unparser)
_universal_abbrev_2_datatype [storid] = datatype
_universal_abbrev_2_datatype_parser [storid] = (datatype, parser)
return storid

owl_alldisjointproperties = _universal_abbrev("http://www.w3.org/2002/07/owl#AllDisjointProperties")
owl_equivalentproperty = _universal_abbrev("http://www.w3.org/2002/07/owl#equivalentProperty")
Expand Down Expand Up @@ -255,6 +270,13 @@ def set_datatype_iri(datatype, iri):
owl_bottomobjectproperty = _universal_abbrev("http://www.w3.org/2002/07/owl#bottomObjectProperty")
owl_bottomdataproperty = _universal_abbrev("http://www.w3.org/2002/07/owl#bottomDataProperty")

owl_disjointunion = _universal_abbrev("http://www.w3.org/2002/07/owl#disjointUnionOf")

#owlready_direct_is_a = _universal_abbrev("http://www.lesfleursdunormal.fr/static/_downloads/owlready_ontology.owl#direct_is_a")
#owlready_is_a_construct = _universal_abbrev("http://www.lesfleursdunormal.fr/static/_downloads/owlready_ontology.owl#is_a_construct")
#owlready_context_is_a = _universal_abbrev("http://www.lesfleursdunormal.fr/static/_downloads/owlready_ontology.owl#context_is_a")
owlready_concrete = _universal_abbrev("http://www.lesfleursdunormal.fr/static/_downloads/owlready_ontology.owl#concrete")

issubclass_python = issubclass


Expand Down
Loading

0 comments on commit d8668b1

Please sign in to comment.