diff --git a/swh/indexer/metadata_dictionary/codemeta.py b/swh/indexer/metadata_dictionary/codemeta.py --- a/swh/indexer/metadata_dictionary/codemeta.py +++ b/swh/indexer/metadata_dictionary/codemeta.py @@ -83,7 +83,14 @@ # 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 # "@context": CODEMETA_CONTEXT_URL - doc[localname].append(self.xml_to_jsonld(child)) + jsonld_child = self.xml_to_jsonld(child) + if localname == "type" and isinstance(jsonld_child, dict): + # With a codemeta context, this is later translated to a JSON-LD + # @type, which must be either an array of strings or a string. + if set(jsonld_child) != {"@value"}: + raise ValueError(f'Unexpected value for "type": {jsonld_child}') + jsonld_child = jsonld_child["@value"] + doc[localname].append(jsonld_child) else: # Otherwise, we already know the URI doc[f"{namespace}{localname}"].append(self.xml_to_jsonld(child)) diff --git a/swh/indexer/tests/metadata_dictionary/test_codemeta.py b/swh/indexer/tests/metadata_dictionary/test_codemeta.py --- a/swh/indexer/tests/metadata_dictionary/test_codemeta.py +++ b/swh/indexer/tests/metadata_dictionary/test_codemeta.py @@ -351,6 +351,32 @@ } +def test_sword_propertyvalue(): + content = """ + + Name + + schema:PropertyValue + HAL-ID + hal-03780423 + + + """ + + result = MAPPINGS["SwordCodemetaMapping"]().translate(content) + assert result == { + "@context": "https://doi.org/10.5063/schema/codemeta-2.0", + "name": "Name", + "identifier": { + "schema:propertyID": "HAL-ID", + "schema:value": "hal-03780423", + "type": "schema:PropertyValue", + }, + } + + def test_json_sword(): content = """{"id": "hal-01243573", "@xmlns": "http://www.w3.org/2005/Atom", "author": {"name": "Author 1", "email": "foo@example.org"}, "client": "hal", "codemeta:url": "http://example.org/", "codemeta:name": "The assignment problem", "@xmlns:codemeta": "https://doi.org/10.5063/SCHEMA/CODEMETA-2.0", "codemeta:author": {"codemeta:name": "Author 2"}, "codemeta:license": {"codemeta:name": "GNU General Public License v3.0 or later"}}""" # noqa result = MAPPINGS["JsonSwordCodemetaMapping"]().translate(content)