diff --git a/swh/indexer/metadata_dictionary.py b/swh/indexer/metadata_dictionary.py --- a/swh/indexer/metadata_dictionary.py +++ b/swh/indexer/metadata_dictionary.py @@ -166,24 +166,26 @@ def normalize_repository(self, d): """https://docs.npmjs.com/files/package.json#repository""" if isinstance(d, dict): - return '{type}+{url}'.format(**d) + url = '{type}+{url}'.format(**d) elif isinstance(d, str): if '://' in d: - return d + url = d elif ':' in d: (schema, rest) = d.split(':', 1) if schema in self._schema_shortcuts: - return self._schema_shortcuts[schema] + rest + url = self._schema_shortcuts[schema] + rest else: return None else: - return self._schema_shortcuts['github'] + d + url = self._schema_shortcuts['github'] + d else: return None + return {'@id': url} + def normalize_bugs(self, d): - return '{url}'.format(**d) + return {'@id': '{url}'.format(**d)} _parse_author = re.compile(r'^ *' r'(?P.*?)' @@ -211,8 +213,14 @@ if email: author[SCHEMA_URI+'email'] = email if url: - author[SCHEMA_URI+'url'] = url - return author + author[SCHEMA_URI+'url'] = {'@id': url} + return {"@list": [author]} + + def normalize_license(self, s): + return {"@id": "https://spdx.org/licenses/" + s} + + def normalize_homepage(self, s): + return {"@id": s} @register_mapping @@ -265,7 +273,10 @@ url = os.path.join(url, *d['groupId'].split('.')) if d['artifactId']: url = os.path.join(url, d['artifactId']) - return url + return {"@id": url} + + def normalize_groupId(self, id_): + return {"@id": id_} def main(): diff --git a/swh/indexer/tests/test_metadata.py b/swh/indexer/tests/test_metadata.py --- a/swh/indexer/tests/test_metadata.py +++ b/swh/indexer/tests/test_metadata.py @@ -130,13 +130,13 @@ 'name': 'test_metadata', 'version': '0.0.2', 'description': 'Simple package.json test for indexer', - 'schema:codeRepository': + 'codeRepository': 'git+https://github.com/moranegg/metadata_test', - 'schema:author': { + 'author': [{ 'type': 'Person', 'name': 'Morane G', 'email': 'moranegg@example.com', - }, + }], } # when @@ -154,20 +154,20 @@ 'name': 'test_1', 'version': '0.0.2', 'description': 'Simple package.json test for indexer', - 'schema:codeRepository': + 'codeRepository': 'git+https://github.com/moranegg/metadata_test', }, { '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', 'name': 'test_0_1', 'version': '0.0.2', 'description': 'Simple package.json test for indexer', - 'schema:codeRepository': + 'codeRepository': 'git+https://github.com/moranegg/metadata_test' }, { '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', 'name': 'test_metadata', 'version': '0.0.2', - 'schema:author': 'moranegg', + 'author': 'moranegg', }] # when @@ -179,8 +179,8 @@ "version": '0.0.2', "description": 'Simple package.json test for indexer', "name": ['test_1', 'test_0_1', 'test_metadata'], - "schema:author": 'moranegg', - "schema:codeRepository": + "author": ['moranegg'], + "codeRepository": 'git+https://github.com/moranegg/metadata_test', } self.assertEqual(expected_results, results) @@ -213,7 +213,7 @@ 'translated_metadata': { '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', 'type': 'SoftwareSourceCode', - 'schema:codeRepository': + 'codeRepository': 'git+https://github.com/moranegg/metadata_test', 'description': 'Simple package.json test for indexer', 'name': 'test_metadata', @@ -224,18 +224,18 @@ 'translated_metadata': { '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', 'type': 'SoftwareSourceCode', - 'codemeta:issueTracker': + 'issueTracker': 'https://github.com/npm/npm/issues', - 'schema:author': { + 'author': [{ 'type': 'Person', 'name': 'Isaac Z. Schlueter', 'email': 'i@izs.me', - 'schema:url': 'http://blog.izs.me', - }, - 'schema:codeRepository': + 'url': 'http://blog.izs.me', + }], + 'codeRepository': 'git+https://github.com/npm/npm', 'description': 'a package manager for JavaScript', - 'schema:license': 'Artistic-2.0', + 'license': 'https://spdx.org/licenses/Artistic-2.0', 'version': '5.0.3', 'name': 'npm', 'keywords': [ @@ -244,7 +244,7 @@ 'package manager', 'package.json' ], - 'schema:url': 'https://docs.npmjs.com/' + 'url': 'https://docs.npmjs.com/' }, 'id': hash_to_bytes('d4c647f0fc257591cc9ba1722484229780d1c607') }, { @@ -432,9 +432,9 @@ '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', 'type': 'SoftwareSourceCode', 'name': 'Maven Default Project', - 'schema:identifier': 'com.mycompany.app', + 'identifier': 'com.mycompany.app', 'version': '1.2.3', - 'schema:codeRepository': + 'codeRepository': 'http://repo1.maven.org/maven2/com/mycompany/app/my-app', }) @@ -453,17 +453,17 @@ 'translated_metadata': { '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', 'type': 'SoftwareSourceCode', - 'codemeta:issueTracker': + 'issueTracker': 'https://github.com/librariesio/yarn-parser/issues', 'version': '1.0.0', 'name': 'yarn-parser', - 'schema:author': 'Andrew Nesbitt', + 'author': ['Andrew Nesbitt'], 'url': 'https://github.com/librariesio/yarn-parser#readme', 'processorRequirements': {'node': '7.5'}, 'license': 'AGPL-3.0', 'keywords': ['yarn', 'parse', 'lock', 'dependencies'], - 'schema:codeRepository': + 'codeRepository': 'git+https://github.com/librariesio/yarn-parser.git', 'description': 'Tiny web service for parsing yarn.lock files', @@ -485,14 +485,14 @@ '@context': 'https://doi.org/10.5063/schema/codemeta-2.0', 'url': 'https://github.com/librariesio/yarn-parser#readme', - 'schema:codeRepository': + 'codeRepository': 'git+https://github.com/librariesio/yarn-parser.git', - 'schema:author': 'Andrew Nesbitt', + 'author': ['Andrew Nesbitt'], 'license': 'AGPL-3.0', 'version': '1.0.0', 'description': 'Tiny web service for parsing yarn.lock files', - 'codemeta:issueTracker': + 'issueTracker': 'https://github.com/librariesio/yarn-parser/issues', 'name': 'yarn-parser', 'keywords': ['yarn', 'parse', 'lock', 'dependencies'],