Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ontoScorer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tetras MARS
ontoScorer
Commits
8e482965
Commit
8e482965
authored
1 year ago
by
Aurélien Lamercerie
Browse files
Options
Downloads
Patches
Plain Diff
Rename class (ontology) Element to Entity
parent
a582ae25
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
ontoScorer/ontology.py
+10
-19
10 additions, 19 deletions
ontoScorer/ontology.py
ontoScorer/ontology_entity.py
+8
-9
8 additions, 9 deletions
ontoScorer/ontology_entity.py
tests/context.py
+1
-1
1 addition, 1 deletion
tests/context.py
with
19 additions
and
29 deletions
ontoScorer/ontology.py
+
10
−
19
View file @
8e482965
...
...
@@ -4,7 +4,7 @@
#==============================================================================
# Ontology Analyzer
#------------------------------------------------------------------------------
# Extracts various e
lement
s (Classes, Object Properties, Data Properties,
# Extracts various e
ntitie
s (Classes, Object Properties, Data Properties,
# Individuals, Annotations) from RDF/OWL ontologies. Enables foundational
# comparisons between different ontologies.
#==============================================================================
...
...
@@ -14,7 +14,7 @@ from rdflib import URIRef, BNode
from
rdflib.namespace
import
split_uri
from
ontology_metadata
import
Metadata
from
ontology_e
lement
import
E
lement
,
NamedE
lement
,
BlankE
lement
from
ontology_e
ntity
import
E
ntity
,
NamedE
ntity
,
BlankE
ntity
#==============================================================================
# Class: Ontology
...
...
@@ -32,7 +32,6 @@ class Ontology:
self
.
graph
=
self
.
load_ontology
(
ontology_path
)
self
.
classes
=
self
.
get_classes
()
#--------------------------------------------------------------------------
# Base Method(s)
#--------------------------------------------------------------------------
...
...
@@ -44,15 +43,14 @@ class Ontology:
return
g
def
_get_elements_of_type
(
self
,
rdf_type
):
"""
Extract all e
lement
s of a specific RDF type from the ontology.
"""
e
lement
s
=
[]
"""
Extract all e
ntitie
s of a specific RDF type from the ontology.
"""
e
ntitie
s
=
[]
for
s
,
_
,
o
in
self
.
graph
.
triples
((
None
,
RDF
.
type
,
rdf_type
)):
if
isinstance
(
s
,
BNode
):
e
lement
s
.
append
(
BlankE
lement
(
s
,
self
.
graph
))
e
ntitie
s
.
append
(
BlankE
ntity
(
s
,
self
.
graph
))
elif
isinstance
(
s
,
URIRef
):
elements
.
append
(
NamedElement
(
s
,
self
.
graph
))
return
elements
entities
.
append
(
NamedEntity
(
s
,
self
.
graph
))
return
entities
#--------------------------------------------------------------------------
# Metadata and Annotation Extraction
...
...
@@ -68,7 +66,6 @@ class Ontology:
pass
# TODO
return
-
1
def
get_annotations
(
self
):
"""
Extract all annotation comments from the ontology.
"""
annotations
=
set
()
...
...
@@ -76,9 +73,8 @@ class Ontology:
annotations
.
add
(
str
(
o
))
return
annotations
#--------------------------------------------------------------------------
# E
lement
Extraction
# E
ntity
Extraction
#--------------------------------------------------------------------------
def
get_classes
(
self
):
...
...
@@ -94,22 +90,19 @@ class Ontology:
return
self
.
_get_elements_of_type
(
OWL
.
DatatypeProperty
)
def
get_individuals
(
self
)
->
list
:
"""
Extract all individuals from the ontology, including e
lement
s explicitly typed as owl:Individual,
"""
Extract all individuals from the ontology, including e
ntitie
s explicitly typed as owl:Individual,
owl:NamedIndividual or any class.
"""
# Getting elements of type owl:NamedIndividual and owl:Individual
individuals
=
self
.
_get_elements_of_type
(
OWL
.
NamedIndividual
)
individuals
+=
self
.
_get_elements_of_type
(
URIRef
(
"
http://www.w3.org/2002/07/owl#Individual
"
))
# Getting all elements typed as one of the classes
all_classes
=
{
cls
.
reference
for
cls
in
self
.
get_classes
()}
for
cls
in
all_classes
:
individuals
+=
[
NamedE
lement
(
s
,
self
.
graph
)
if
isinstance
(
s
,
URIRef
)
else
BlankE
lement
(
s
,
self
.
graph
)
individuals
+=
[
NamedE
ntity
(
s
,
self
.
graph
)
if
isinstance
(
s
,
URIRef
)
else
BlankE
ntity
(
s
,
self
.
graph
)
for
s
,
_
,
o
in
self
.
graph
.
triples
((
None
,
RDF
.
type
,
cls
))]
return
list
(
set
(
individuals
))
# Ensuring uniqueness
#--------------------------------------------------------------------------
# Taxonomic Relation Extraction (Hierarchical Structure)
#--------------------------------------------------------------------------
...
...
@@ -125,7 +118,6 @@ class Ontology:
"""
Extract all restrictons from the ontology.
"""
return
self
.
_get_elements_of_type
(
OWL
.
Restriction
)
#--------------------------------------------------------------------------
# Comparison Method(s)
#--------------------------------------------------------------------------
...
...
@@ -135,7 +127,6 @@ class Ontology:
self_classes
=
{
c
.
name
()
for
c
in
self
.
classes
}
other_classes
=
{
c
.
name
()
for
c
in
other_ontology
.
classes
}
# Pour des comparaisons plus avancées, ajustez ce code
unique_to_self
=
self_classes
-
other_classes
unique_to_other
=
other_classes
-
self_classes
...
...
This diff is collapsed.
Click to expand it.
ontoScorer/ontology_e
lement
.py
→
ontoScorer/ontology_e
ntity
.py
+
8
−
9
View file @
8e482965
...
...
@@ -2,28 +2,28 @@
# -*-coding:Utf-8 -*
#==============================================================================
# Ontology E
lement
s
# Ontology E
ntitie
s
#------------------------------------------------------------------------------
# Represents various e
lement
s (Classes, Object Properties, Data Properties,
# Represents various e
ntitie
s (Classes, Object Properties, Data Properties,
# Individuals) within an ontology.
#==============================================================================
from
rdflib
import
URIRef
,
BNode
from
rdflib.namespace
import
split_uri
class
E
lement
:
class
E
ntity
:
def
__init__
(
self
,
reference
,
graph
):
self
.
reference
=
reference
self
.
graph
=
graph
def
properties
(
self
):
"""
Retrieve properties associated with the e
lement
.
"""
"""
Retrieve properties associated with the e
ntity
.
"""
return
list
(
self
.
graph
.
predicate_objects
(
subject
=
self
.
reference
))
def
name
(
self
):
raise
NotImplementedError
(
"
The method name() must be implemented by subclasses.
"
)
class
NamedE
lement
(
Element
):
class
NamedE
ntity
(
Entity
):
def
__init__
(
self
,
uri
,
graph
):
super
().
__init__
(
uri
,
graph
)
self
.
uri
=
uri
...
...
@@ -32,10 +32,10 @@ class NamedElement(Element):
return
str
(
self
.
uri
)
def
name
(
self
):
_
,
e
lement
_name
=
split_uri
(
self
.
uri
)
return
e
lement
_name
_
,
e
ntity
_name
=
split_uri
(
self
.
uri
)
return
e
ntity
_name
class
BlankE
lement
(
Element
):
class
BlankE
ntity
(
Entity
):
def
__init__
(
self
,
bnode
,
graph
):
super
().
__init__
(
bnode
,
graph
)
self
.
id
=
str
(
bnode
)
...
...
@@ -45,4 +45,3 @@ class BlankElement(Element):
def
name
(
self
):
return
self
.
id
This diff is collapsed.
Click to expand it.
tests/context.py
+
1
−
1
View file @
8e482965
...
...
@@ -3,7 +3,7 @@ import sys
CURRENT_DIRPATH
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
LIB_PATH
=
os
.
path
.
dirname
(
f
'
{
CURRENT_DIRPATH
}
/../..
'
)
print
(
f
'
Test Context:
{
LIB_PATH
}
'
)
#
print(f'Test Context: {LIB_PATH}')
sys
.
path
.
insert
(
0
,
os
.
path
.
abspath
(
LIB_PATH
))
import
ontoScorer
...
...
This diff is collapsed.
Click to expand it.
Aurélien Lamercerie
@alam
mentioned in issue
#3 (closed)
·
1 year ago
mentioned in issue
#3 (closed)
mentioned in issue #3
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment