Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
ontologies
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Estelle Ancelet
ontologies
Commits
999265a8
Commit
999265a8
authored
3 years ago
by
Cyril Pommier
Browse files
Options
Downloads
Patches
Plain Diff
Handle trait class generation
parent
aa151487
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Tools/td2owl/td2owl.py
+29
-1
29 additions, 1 deletion
Tools/td2owl/td2owl.py
with
29 additions
and
1 deletion
Tools/td2owl/td2owl.py
+
29
−
1
View file @
999265a8
...
...
@@ -15,6 +15,30 @@ from pathlib import Path, PurePosixPath
co
=
Namespace
(
"
http://www.cropontology.org/rdf/
"
)
trait_classes
=
{}
def
get_trait_class
(
output_graph
,
a_row
):
co_prefix
=
a_row
.
get
(
'
Trait ID
'
).
split
(
"
:
"
)[
0
]
if
a_row
.
get
(
'
Trait class
'
)
not
in
trait_classes
:
trait_class_id
=
co_prefix
+
"
:900000
"
+
str
(
len
(
trait_classes
))
trait_class_URI
=
"
http://www.cropontology.org/rdf/
"
+
trait_class_id
trait_classes
[
a_row
.
get
(
'
Trait class
'
)]
=
trait_class_URI
add_triple
(
output_graph
,
URIRef
(
trait_class_URI
),
RDF
.
type
,
co
.
TraitClass
)
add_triple
(
output_graph
,
URIRef
(
trait_class_URI
),
co
.
hasId
,
Literal
(
trait_class_id
)
)
add_triple
(
output_graph
,
URIRef
(
trait_class_URI
),
co
.
hasName
,
Literal
(
a_row
.
get
(
'
Trait class
'
))
)
return
trait_classes
[
a_row
.
get
(
'
Trait class
'
)]
# dict is of the form: label:id
#def add_trait_class_triples(output_graph, a_dict):
# for a_key in a_dict:
# trait_class_URI="http://www.cropontology.org/rdf/" + a_dict[a_key]
# add_triple(output_graph, trait_class_URI, RDF.type, co.TraitClass )
# add_triple(output_graph, trait_class_URI, co.hasId, Literal(a_dict[a_key]) )
# add_triple(output_graph, trait_class_URI, co.hasName, Literal(a_key) )
def
add_triple
(
output_graph
,
s
,
p
,
o
):
if
o
:
output_graph
.
add
((
s
,
p
,
o
))
...
...
@@ -75,7 +99,8 @@ def load_csv2graph(csv_file) -> Graph():
add_triple
(
output_graph
,
URIRef
(
traitURI
),
co
.
hasTraitId
,
to_literal
(
row
,
'
Trait ID
'
))
add_triple
(
output_graph
,
URIRef
(
traitURI
),
RDF
.
type
,
co
.
Trait
)
add_triple
(
output_graph
,
URIRef
(
traitURI
),
co
.
hasName
,
to_literal_lang
(
row
,
'
Trait name
'
))
add_triple
(
output_graph
,
URIRef
(
traitURI
),
co
.
hasTraitClass
,
to_literal
(
row
,
'
Trait class
'
))
#add_triple(output_graph,URIRef(traitURI), co.hasTraitClass, to_literal(row, 'Trait class'))
add_triple
(
output_graph
,
URIRef
(
get_trait_class
(
output_graph
,
row
))
,
co
.
hasTrait
,
URIRef
(
traitURI
))
add_triple
(
output_graph
,
URIRef
(
traitURI
),
co
.
hasDescription
,
to_literal_lang
(
row
,
'
Trait description
'
))
for
tsyn
in
row
[
'
Trait synonyms
'
].
split
(
'
,
'
):
add_triple
(
output_graph
,
URIRef
(
traitURI
),
co
.
hasSynonym
,
Literal
(
tsyn
))
...
...
@@ -115,6 +140,9 @@ def load_csv2graph(csv_file) -> Graph():
add_triple
(
output_graph
,
URIRef
(
scaleURI
),
co
.
hasCategory9
,
Literal
(
row
[
'
Category 9
'
]))
add_triple
(
output_graph
,
URIRef
(
scaleURI
),
co
.
hasCategory10
,
Literal
(
row
[
'
Category 10
'
]))
# add trait classes to the graph
#add_trait_class_triples(output_graph, trait_classes)
return
output_graph
def
read_graph_and_write_to_file
(
file_name
):
...
...
This diff is collapsed.
Click to expand it.
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