Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add language and datatype support when converting rdflib.terms.… #356

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: add html5lib dependency for rdflib to parse RDF.HTML Literal
ticapix committed Jan 1, 2025
commit 5eb1a3619b18bc300342f8571aa6187cfae3068f
12 changes: 11 additions & 1 deletion linkml_runtime/utils/yamlutils.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
from deprecated.classic import deprecated
from jsonasobj2 import JsonObj, as_json, as_dict, JsonObjTypes, items
import jsonasobj2
from rdflib import Graph, URIRef
from rdflib import Graph, URIRef, Literal
from yaml.constructor import ConstructorError

from linkml_runtime.utils.context_utils import CONTEXTS_PARAM_TYPE, merge_contexts
@@ -89,6 +89,16 @@ def _default(self, obj, filtr: Callable[[dict], dict] = None):
# elif isinstance(v, EnumDefinition):
elif isinstance(v, EnumDefinitionImpl):
rval[k] = v.code
elif isinstance(v, Literal):
if v.datatype:
# checking against v.ill_typed to not serialize the python object
rval[k] = {
'@value': str(v.value) if v.ill_typed else str(v), '@type': v.datatype}
elif v.language:
rval[k] = {
'@value': v.value, '@language': v.language.lower()}
else:
rval[k] = v
else:
rval[k] = v
return rval
36 changes: 34 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@ requests = "*"
prefixmaps = ">=0.1.4"
curies = ">=0.5.4"
pydantic = ">=1.10.2, <3.0.0"
html5lib = "^1.1"

[tool.poetry.dev-dependencies]
coverage = "^6.2"