Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/metadata_dictionary/codemeta.py
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | class SwordCodemetaMapping(BaseExtrinsicMapping): | ||||
def xml_to_jsonld(self, e: ET.Element) -> Dict[str, Any]: | def xml_to_jsonld(self, e: ET.Element) -> Dict[str, Any]: | ||||
doc: Dict[str, List[Dict[str, Any]]] = collections.defaultdict(list) | doc: Dict[str, List[Dict[str, Any]]] = collections.defaultdict(list) | ||||
for child in e: | for child in e: | ||||
m = _TAG_RE.match(child.tag) | m = _TAG_RE.match(child.tag) | ||||
assert m, f"Tag with no namespace: {child}" | assert m, f"Tag with no namespace: {child}" | ||||
namespace = m.group("namespace") | namespace = m.group("namespace") | ||||
localname = m.group("localname") | localname = m.group("localname") | ||||
if namespace == ATOM_URI and localname in ("title", "name"): | if namespace == ATOM_URI and localname in ("title", "name"): | ||||
# Convert Atom name/title to Codemeta name; in case codemeta:name | # Convert Atom to Codemeta name; in case codemeta:name | ||||
# is not provided or different | # is not provided or different | ||||
doc["name"].append(self.xml_to_jsonld(child)) | doc["name"].append(self.xml_to_jsonld(child)) | ||||
elif namespace == ATOM_URI and localname in ("author", "email"): | |||||
# ditto for these author properties (note that author email is also | |||||
# covered by the previous test) | |||||
doc[localname].append(self.xml_to_jsonld(child)) | |||||
elif namespace in _IGNORED_NAMESPACES: | elif namespace in _IGNORED_NAMESPACES: | ||||
# SWORD-specific namespace that is not interesting to translate | # SWORD-specific namespace that is not interesting to translate | ||||
pass | pass | ||||
elif namespace.lower() == CODEMETA_CONTEXT_URL: | elif namespace.lower() == CODEMETA_CONTEXT_URL: | ||||
# It is a term defined by the context; write is as-is and JSON-LD | # It is a term defined by the context; write is as-is and JSON-LD | ||||
# expansion will convert it to a full URI based on | # expansion will convert it to a full URI based on | ||||
# "@context": CODEMETA_CONTEXT_URL | # "@context": CODEMETA_CONTEXT_URL | ||||
doc[localname].append(self.xml_to_jsonld(child)) | doc[localname].append(self.xml_to_jsonld(child)) | ||||
Show All 33 Lines |