Skip to content

Commit

Permalink
feat: added support for namespace aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrkarr committed Mar 1, 2022
1 parent 0dca966 commit 6a6874e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions biosimulators_utils/omex_meta/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'BIOSIMULATIONS_PREDICATE_TYPES',
'BIOSIMULATIONS_THUMBNAIL_FORMATS',
'BIOSIMULATIONS_NAMESPACE_PREFIX_MAP',
'BIOSIMULATIONS_NAMESPACE_ALIASES',
'BIOSIMULATIONS_THUMBNAIL_FORMATS',
]

Expand Down Expand Up @@ -352,6 +353,11 @@ class OmexMetadataSchema(str, enum.Enum):
'http://xmlns.com/foaf/0.1/': 'foaf',
}

BIOSIMULATIONS_NAMESPACE_ALIASES = {
'http://purl.org/dc/elements/1.1/': 'http://dublincore.org/specifications/dublin-core/dcmi-terms/',
'http://sempublishing.sourceforge.net/scoro/': 'http://purl.org/spar/scoro/',
}

BIOSIMULATIONS_THUMBNAIL_FORMATS = [
'GIF',
'JPEG',
Expand Down
21 changes: 20 additions & 1 deletion biosimulators_utils/omex_meta/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from .data_model import (Triple, OmexMetadataOutputFormat, OmexMetadataSchema,
BIOSIMULATIONS_ROOT_URI_PATTERN,
BIOSIMULATIONS_PREDICATE_TYPES,
BIOSIMULATIONS_NAMESPACE_PREFIX_MAP)
BIOSIMULATIONS_NAMESPACE_PREFIX_MAP,
BIOSIMULATIONS_NAMESPACE_ALIASES)
from .utils import get_local_combine_archive_content_uri, get_global_combine_archive_content_uri
from .validation import validate_biosimulations_metadata
from lxml import etree
Expand Down Expand Up @@ -570,6 +571,24 @@ def parse_triples_to_schema(cls, triples, combine_archive_uri):
errors = []
warnings = []

for triple in triples:
subject = str(triple.subject)
predicate = str(triple.predicate)
object = str(triple.object)

for ns, alias in BIOSIMULATIONS_NAMESPACE_ALIASES.items():
if isinstance(triple.subject, rdflib.term.URIRef) and subject.startswith(ns):
subject = alias + subject[len(ns):]
triple.subject = rdflib.term.URIRef(subject)

if isinstance(triple.predicate, rdflib.term.URIRef) and predicate.startswith(ns):
predicate = alias + predicate[len(ns):]
triple.predicate = rdflib.term.URIRef(predicate)

if isinstance(triple.object, rdflib.term.URIRef) and object.startswith(ns):
object = alias + object[len(ns):]
triple.object = rdflib.term.URIRef(object)

objects = {}
for triple in triples:
for node, is_subject in [(triple.subject, True), (triple.object, False)]:
Expand Down

0 comments on commit 6a6874e

Please sign in to comment.