swh.indexer.metadata_mapping.sword module#

class swh.indexer.metadata_mapping.sword.SwordCodemetaMapping(log_suffix='')[source]#

Bases: BaseExtrinsicMapping

dedicated class for mapping and translation from JSON-LD statements embedded in SWORD documents, optionally using Codemeta contexts, as described in the Protocol reference.

name = 'sword-codemeta'#
classmethod extrinsic_metadata_formats() Tuple[str, ...][source]#

Returns the list of extrinsic metadata formats which can be translated by this mapping

classmethod supported_terms() List[str][source]#
xml_to_jsonld(e: Element) str | Dict[str, Any][source]#
translate(content: bytes) Dict[str, Any] | None[source]#

Translates content by parsing content from a bytestring containing mapping-specific data and translating with the appropriate mapping to JSON-LD using the Codemeta and ForgeFed vocabularies.

Parameters:

raw_content – raw content to translate

Returns:

translated metadata in JSON friendly form needed for the content if parseable, None otherwise.

normalize_translation(metadata: Dict[str, Any]) Dict[str, Any][source]#
swh.indexer.metadata_mapping.sword.iter_keys(d)[source]#

Recursively iterates on dictionary keys

class swh.indexer.metadata_mapping.sword.JsonSwordCodemetaMapping(log_suffix='')[source]#

Bases: SwordCodemetaMapping

Variant of SwordCodemetaMapping that reads the legacy sword-v2-atom-codemeta-v2-in-json format and converts it back to sword-v2-atom-codemeta-v2 XML

name = 'json-sword-codemeta'#
classmethod extrinsic_metadata_formats() Tuple[str, ...][source]#

Returns the list of extrinsic metadata formats which can be translated by this mapping

translate(content: bytes) Dict[str, Any] | None[source]#

Translates content by parsing content from a bytestring containing mapping-specific data and translating with the appropriate mapping to JSON-LD using the Codemeta and ForgeFed vocabularies.

Parameters:

raw_content – raw content to translate

Returns:

translated metadata in JSON friendly form needed for the content if parseable, None otherwise.