swh.indexer.metadata_dictionary.codemeta module#

class swh.indexer.metadata_dictionary.codemeta.CodemetaMapping(log_suffix='')[source]#

Bases: SingleFileIntrinsicMapping

dedicated class for CodeMeta (codemeta.json) mapping and translation

name = 'codemeta'#
filename: bytes | Pattern[bytes] = b'codemeta.json'#
string_fields = None#
classmethod supported_terms() List[str][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.

class swh.indexer.metadata_dictionary.codemeta.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]#
class swh.indexer.metadata_dictionary.codemeta.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.