Skip to content

Commit

Permalink
Support for data, object and annotation properties
Browse files Browse the repository at this point in the history
Moved adding of concepts to help_function _add_entities, which can be used to add entities fo type owlread2.Thing/ObjectProperty/AnnotationProperty/DataProperty. _add_entities adds annotation properties, but not relations for classes or ranges and domains for properties

Data properties, object properties and annotation properties should be provided in separate sheets called AnnotationProperties, DataProperties, ObjectProperties
If these sheets do not exist in the excel workbook they will not be considered. The same if the sheets exist, but do not have prefLabels.

An extra column for OtherAnnotations has been added and it is now read correctly.

The dictionary with errors is now returned with separate keys for the different properties and classes.
  • Loading branch information
francescalb authored Jun 8, 2023
1 parent 4c018e0 commit ffb4919
Show file tree
Hide file tree
Showing 10 changed files with 825 additions and 225 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cd_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
python_version_docs: "3.7"
doc_extras: "[docs]"
changelog_exclude_labels: dependencies
warnings_as_errors: false

secrets:
PyPI_token: ${{ secrets.PYPI_TOKEN }}
Expand Down
701 changes: 514 additions & 187 deletions ontopy/excelparser.py

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions ontopy/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ def get_unabbreviated_triples(
self, subject=subject, predicate=predicate, obj=obj, blank=blank
)

def _set_label_annotations(self):
if self._label_annotations is None:
for iri in DEFAULT_LABEL_ANNOTATIONS:
try:
self.add_label_annotation(iri)
except ValueError:
pass

def get_by_label(
self,
label: str,
Expand Down Expand Up @@ -307,12 +315,7 @@ def get_by_label(
f"Invalid label definition, must be a string: {label!r}"
)

if self._label_annotations is None:
for iri in DEFAULT_LABEL_ANNOTATIONS:
try:
self.add_label_annotation(iri)
except ValueError:
pass
self._set_label_annotations()

if colon_in_label is None:
colon_in_label = self._colon_in_label
Expand Down Expand Up @@ -395,6 +398,8 @@ def get_by_label_all(self, label, label_annotations=None, prefix=None):
The current implementation also supports "*" as a wildcard
matching any number of characters. This may change in the future.
"""
self._set_label_annotations()

if not isinstance(label, str):
raise TypeError(
f"Invalid label definition, " f"must be a string: {label!r}"
Expand Down Expand Up @@ -1703,7 +1708,6 @@ def new_entity(
f"Error in entity type definition: "
f"'{entitytype}' is not a valid entity type."
)

for thing in parents:
if not isinstance(thing, parenttype):
raise EntityClassDefinitionError(
Expand Down
Binary file modified tests/test_excelparser/onto.xlsx
Binary file not shown.
Binary file added tests/test_excelparser/onto_only_classes.xlsx
Binary file not shown.
Binary file modified tests/test_excelparser/onto_update.xlsx
100755 → 100644
Binary file not shown.
Binary file not shown.
100 changes: 72 additions & 28 deletions tests/test_excelparser/result_ontology/fromexcelonto.ttl
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
@prefix : <http://emmo.info/emmo/domain/onto#> .
@prefix core: <http://www.w3.org/2004/02/skos/core#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix emmo: <http://emmo.info/emmo#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix term: <http://purl.org/dc/terms/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .

<http://emmo.info/emmo/domain/onto> a owl:Ontology ;
term:contributor "SINTEF"@en,
dcterms:contributor "SINTEF"@en,
"SINTEF Industry"@en ;
term:creator "Francesca L. Bleken"@en,
dcterms:creator "Francesca L. Bleken"@en,
"Jesper Friis"@en,
"Sylvain Gouttebroze"@en ;
term:title "A test domain ontology"@en ;
dcterms:title "A test domain ontology"@en ;
owl:imports <http://ontology.info/ontology>,
<https://raw.githubusercontent.com/emmo-repo/emmo-repo.github.io/master/versions/1.0.0-beta/emmo-inferred-chemistry> ;
owl:versionInfo "0.01"@en .
Expand All @@ -24,21 +24,38 @@
owl:someValuesFrom emmo:EMMO_d4f7d378_5e3b_468a_baa1_a7e98358cda7 ],
:EMMO_138590b8-3333-515d-87ab-717aac8434e6,
:EMMO_4b32833e-0833-56a7-903c-28a6a8191fe8 ;
core:prefLabel "FiniteTemporalPattern"@en .
skos:prefLabel "FiniteTemporalPattern"@en .

:EMMO_080262b7-4f7e-582b-916e-8274c73dd629 a owl:Class ;
rdfs:subClassOf <http://ontology.info/ontology#testclass> ;
core:prefLabel "ANewTestClass"@en .
skos:prefLabel "ANewTestClass"@en .

:EMMO_0ec801a2-7da4-55ff-906b-c5ccc905bb8d a owl:AnnotationProperty ;
rdfs:subPropertyOf :EMMO_98871837-aa90-5eef-9a56-926ae8beebbb ;
skos:prefLabel "subAnnotation"@en .

:EMMO_1c81f1eb-8b94-5e74-96de-1aeacbdb5b93 a owl:Class ;
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 "The boundary of a grain"@en ;
rdfs:subClassOf :EMMO_472ed27e-ce08-53cb-8453-56ab363275c4 ;
core:prefLabel "GrainBoundary"@en .
skos:prefLabel "GrainBoundary"@en .

:EMMO_41808a43-529f-5798-b0ed-71ddcb2c5456 a owl:Class ;
emmo:EMMO_c84c6752_6d64_48cc_9500_e54a3c34898d "\"A very secure source\""@en ;
:EMMO_0ec801a2-7da4-55ff-906b-c5ccc905bb8d "\"Another thing\""@en ;
:EMMO_98871837-aa90-5eef-9a56-926ae8beebbb "\"A text about this type of boundary\""@en ;
rdfs:subClassOf :EMMO_1b2bfe71-5da9-5c46-b137-be45c3e3f9c3 ;
skos:prefLabel "SuperSpecialBoundary"@en .

:EMMO_58de9bf1-4c92-57f0-af37-9ec8129c5db7 a owl:ObjectProperty ;
rdfs:domain :EMMO_1b2bfe71-5da9-5c46-b137-be45c3e3f9c3 ;
rdfs:range :EMMO_1b2bfe71-5da9-5c46-b137-be45c3e3f9c3 ;
rdfs:subPropertyOf :EMMO_a14817a8-a449-5115-8924-b90833317d02 ;
skos:prefLabel "hasSubBoundaryPart"@en .

:EMMO_6920d08f-b1e4-5789-9778-f75f4514ef46 a owl:Class ;
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 "NEED elucidation"@en ;
rdfs:subClassOf owl:Thing ;
core:prefLabel "SpatioTemporalBoundary"@en .
skos:prefLabel "SpatioTemporalBoundary"@en .

:EMMO_76b2eb15-3ab7-52b3-ade2-755aa390d63e a owl:Class ;
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 "Spatial pattern localized in a volume of space"@en ;
Expand All @@ -51,26 +68,37 @@
owl:someValuesFrom emmo:EMMO_f1a51559_aa3d_43a0_9327_918039f0dfed ],
:EMMO_4b32833e-0833-56a7-903c-28a6a8191fe8,
:EMMO_5f50f77e-f321-53e3-af76-fe5b0a347479 ;
core:prefLabel "FiniteSpatialPattern"@en .
skos:prefLabel "FiniteSpatialPattern"@en .

:EMMO_7c8ba943-15cf-5621-98a3-ed1e7e68fee8 a owl:Class ;
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 "A special boundary."@en ;
:EMMO_98871837-aa90-5eef-9a56-926ae8beebbb "\"A text about this type of boundary\""@en ;
rdfs:subClassOf :EMMO_1b2bfe71-5da9-5c46-b137-be45c3e3f9c3 ;
skos:prefLabel "SpecialBoundary"@en .

:EMMO_a198aa47-2eca-5738-a69e-91679676ed2b a owl:DatatypeProperty ;
rdfs:domain emmo:EMMO_4ce76d7f_03f8_45b6_9003_90052a79bfaa ;
rdfs:subPropertyOf :EMMO_4f3d7c7b-1f77-5a91-8151-ddea40d9b4a2 ;
skos:prefLabel "hasPrimeNumberData"@en .

:EMMO_b04965e6-a9bb-591f-8f8a-1adcb2c8dc39 a owl:Class ;
rdfs:subClassOf emmo:EMMO_21f56795_ee72_4858_b571_11cfaa59c1a8 ;
core:prefLabel "1"@en .
skos:prefLabel "1"@en .

:EMMO_e0b20a22-7e6f-5c81-beca-35bc5358e11b a owl:Class ;
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 "NEED elucidation"@en ;
rdfs:subClassOf :EMMO_4b32833e-0833-56a7-903c-28a6a8191fe8,
:EMMO_9fa9ca88-2891-538a-a8dd-ccb8a08b9890 ;
core:prefLabel "FiniteSpatioTemporalPattern"@en .
skos:prefLabel "FiniteSpatioTemporalPattern"@en .

:EMMO_e4e653eb-72cd-5dd6-a428-f506d9679774 a owl:Class ;
rdfs:subClassOf <http://ontology.info/subontology#testclass2> ;
core:prefLabel "AnotherNewTestClass"@en .
skos:prefLabel "AnotherNewTestClass"@en .

:EMMO_e633d033-2af6-5f04-a706-dab826854fb1 a owl:Class ;
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 "The boundary of a subgrain"@en ;
rdfs:subClassOf owl:Thing ;
core:prefLabel "SubgrainBoundary"@en .
skos:prefLabel "SubgrainBoundary"@en .

:EMMO_e919bd0f-97fb-5d47-92fa-f5756640b6fc a owl:Class ;
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 "Our own special molecules"@en ;
Expand All @@ -79,59 +107,70 @@
owl:onProperty emmo:EMMO_17e27c22_37e1_468c_9dd7_95e137f73e7f ;
owl:someValuesFrom :EMMO_8b758694-7dd3-547a-8589-a835c15a0fb2 ],
emmo:EMMO_3397f270_dfc1_4500_8f6f_4d0d85ac5f71 ;
core:prefLabel "SpecialMolecule"@en .
skos:prefLabel "SpecialMolecule"@en .

:EMMO_f8ad57d3-6cb5-5628-99e6-eb5915bece3a a owl:Class ;
rdfs:subClassOf owl:Thing ;
core:prefLabel "SubSubgrainBoundary"@en .
skos:prefLabel "SubSubgrainBoundary"@en .

:EMMO_fb1218a4-b462-5e51-9bed-5b8d394551aa a owl:Class ;
rdfs:subClassOf [ a owl:Restriction ;
owl:onProperty emmo:EMMO_17e27c22_37e1_468c_9dd7_95e137f73e7f ;
owl:someValuesFrom emmo:EMMO_eb77076b_a104_42ac_a065_798b2d2809ad ],
emmo:EMMO_3397f270_dfc1_4500_8f6f_4d0d85ac5f71 ;
core:prefLabel "AnotherSpecialMolecule"@en .
skos:prefLabel "AnotherSpecialMolecule"@en .

:EMMO_138590b8-3333-515d-87ab-717aac8434e6 a owl:Class ;
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 "Pattern with only temporal aspect"@en ;
emmo:EMMO_b432d2d5_25f4_4165_99c5_5935a7763c1a "Voltage in AC plug"@en ;
rdfs:subClassOf owl:Thing ;
core:prefLabel "TemporalPattern"@en .
skos:prefLabel "TemporalPattern"@en .

:EMMO_4f3d7c7b-1f77-5a91-8151-ddea40d9b4a2 a owl:DatatypeProperty ;
rdfs:domain emmo:EMMO_4ce76d7f_03f8_45b6_9003_90052a79bfaa ;
rdfs:subPropertyOf emmo:EMMO_faf79f53_749d_40b2_807c_d34244c192f4 ;
skos:prefLabel "hasIntegerData"@en .

:EMMO_5f50f77e-f321-53e3-af76-fe5b0a347479 a owl:Class ;
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 "Spatial pattern without regular temporal variations"@en ;
emmo:EMMO_b432d2d5_25f4_4165_99c5_5935a7763c1a "Infinite grid"@en ;
rdfs:subClassOf :EMMO_9fa9ca88-2891-538a-a8dd-ccb8a08b9890 ;
core:prefLabel "SpatialPattern"@en .
skos:prefLabel "SpatialPattern"@en .

:EMMO_8b758694-7dd3-547a-8589-a835c15a0fb2 a owl:Class ;
rdfs:subClassOf emmo:EMMO_eb77076b_a104_42ac_a065_798b2d2809ad ;
core:prefLabel "Atom"@en .
skos:prefLabel "Atom"@en .

:EMMO_1b2bfe71-5da9-5c46-b137-be45c3e3f9c3 a owl:Class ;
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 "NEED elucidation"@en ;
rdfs:subClassOf emmo:EMMO_649bf97b_4397_4005_90d9_219755d92e34 ;
core:prefLabel "Boundary"@en .
:EMMO_98871837-aa90-5eef-9a56-926ae8beebbb a owl:AnnotationProperty ;
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 "Where to find the entry in the \"book of boundaries\""@en ;
skos:prefLabel "bookOfBoundariesEntry"@en .

:EMMO_a14817a8-a449-5115-8924-b90833317d02 a owl:ObjectProperty ;
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 "has a part that is a boundary"@en ;
rdfs:comment "This definition is humbug"@en ;
rdfs:domain :EMMO_1b2bfe71-5da9-5c46-b137-be45c3e3f9c3 ;
rdfs:subPropertyOf emmo:EMMO_17e27c22_37e1_468c_9dd7_95e137f73e7f ;
skos:prefLabel "hasBoundaryPart"@en .

:EMMO_472ed27e-ce08-53cb-8453-56ab363275c4 a owl:Class ;
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 " "@en ;
rdfs:subClassOf :EMMO_1b2bfe71-5da9-5c46-b137-be45c3e3f9c3 ;
core:prefLabel "SpatialBoundary"@en .
skos:prefLabel "SpatialBoundary"@en .

:EMMO_9fa9ca88-2891-538a-a8dd-ccb8a08b9890 a owl:Class ;
emmo:EMMO_21ae69b4_235e_479d_8dd8_4f756f694c1b "A"@en,
"Just"@en,
"Test"@en ;
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 "NEED elucidation"@en ;
rdfs:subClassOf :EMMO_cd254842-c697-55f6-917d-9805c77b9187 ;
core:prefLabel "SpatioTemporalPattern"@en .
skos:prefLabel "SpatioTemporalPattern"@en .

:EMMO_cd254842-c697-55f6-917d-9805c77b9187 a owl:Class ;
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 "everything that can be perceived or measured"@en ;
rdfs:comment " this definition is much broader than definition of pattern such as \"the regular and repeated way in which something happens or is\""@en,
"a pattern is defined from a contrast"@en ;
rdfs:subClassOf emmo:EMMO_649bf97b_4397_4005_90d9_219755d92e34 ;
core:prefLabel "Pattern"@en .
skos:prefLabel "Pattern"@en .

:EMMO_4b32833e-0833-56a7-903c-28a6a8191fe8 a owl:Class ;
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 "Pattern occuring within a boundary in the 4D space"@en ;
Expand All @@ -140,4 +179,9 @@
owl:onProperty emmo:EMMO_17e27c22_37e1_468c_9dd7_95e137f73e7f ;
owl:someValuesFrom :EMMO_1b2bfe71-5da9-5c46-b137-be45c3e3f9c3 ],
:EMMO_cd254842-c697-55f6-917d-9805c77b9187 ;
core:prefLabel "FinitePattern"@en .
skos:prefLabel "FinitePattern"@en .

:EMMO_1b2bfe71-5da9-5c46-b137-be45c3e3f9c3 a owl:Class ;
emmo:EMMO_967080e5_2f42_4eb2_a3a9_c58143e835f9 "NEED elucidation"@en ;
rdfs:subClassOf emmo:EMMO_649bf97b_4397_4005_90d9_219755d92e34 ;
skos:prefLabel "Boundary"@en .
Loading

0 comments on commit ffb4919

Please sign in to comment.