Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
OWL2YAMS
Commits
266ea5e621d7
Commit
266ea5e6
authored
Nov 09, 2021
by
Fabien Amarger
Browse files
fix(entities.py): Use jinja instead of f-string
By the way, add the registration_callback function
parent
90480b9feebf
Changes
1
Hide whitespace changes
Inline
Side-by-side
owl2yams/generate_entities.py
View file @
266ea5e6
from
yams.schema
import
Schema
from
typing
import
Dict
import
jinja2
entities_template
=
jinja2
.
Template
(
"""
from cubicweb.entities.adapters import EntityRDFAdapter
from rdflib import URIRef, OWL
{% for fragment, uri in entitytype_fragment_to_uri.items() %}
class {{fragment}}RDFAdapter(EntityRDFAdapter):
def triples(self):
yield from super().triples()
yield(URIRef("{{uri}}"), OWL.sameAs, URIRef(self.uri))
{% endfor %}
def registration_callback(vreg):
vreg.register_all(
globals().values(),
__name__,
({% for fragment in entitytype_fragment_to_uri %} {{fragment}}RDFAdapter, {% endfor %})
)
"""
)
def
generate_entities
(
...
...
@@ -7,18 +31,6 @@
entitytype_fragment_to_uri
:
Dict
[
str
,
str
],
relationtype_fragment_to_uri
:
Dict
[
str
,
str
],
)
->
str
:
entities_py_content
=
"""
from cubicweb.entities.adapters import EntityRDFAdapter
from rdflib import URIRef, OWL
"""
for
fragment
,
uri
in
entitytype_fragment_to_uri
.
items
():
entities_py_content
+=
f
"""
class
{
fragment
}
RDFAdapter(EntityRDFAdapter):
def triples(self):
yield from super().triples()
yield(URIRef("
{
uri
}
"), OWL.sameAs, URIRef(self.uri))
"""
return
entities_py_content
return
entities_template
.
render
(
entitytype_fragment_to_uri
=
entitytype_fragment_to_uri
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment