Skip to content

Commit

Permalink
chore: add html5lib dependency for rdflib to parse RDF.HTML Literal
Browse files Browse the repository at this point in the history
  • Loading branch information
ticapix committed Jan 1, 2025
1 parent db250d4 commit 5eb1a36
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
12 changes: 11 additions & 1 deletion linkml_runtime/utils/yamlutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
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
Expand Up @@ -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"
Expand Down

0 comments on commit 5eb1a36

Please sign in to comment.