Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/codemeta.py
Show All 16 Lines | |||||
CODEMETA_CONTEXT_PATH = os.path.join(_DATA_DIR, 'codemeta', 'codemeta.jsonld') | CODEMETA_CONTEXT_PATH = os.path.join(_DATA_DIR, 'codemeta', 'codemeta.jsonld') | ||||
with open(CODEMETA_CONTEXT_PATH) as fd: | with open(CODEMETA_CONTEXT_PATH) as fd: | ||||
CODEMETA_CONTEXT = json.load(fd) | CODEMETA_CONTEXT = json.load(fd) | ||||
CODEMETA_CONTEXT_URL = 'https://doi.org/10.5063/schema/codemeta-2.0' | CODEMETA_CONTEXT_URL = 'https://doi.org/10.5063/schema/codemeta-2.0' | ||||
CODEMETA_ALTERNATE_CONTEXT_URLS = { | |||||
('https://raw.githubusercontent.com/codemeta/codemeta/' | |||||
'master/codemeta.jsonld') | |||||
} | |||||
CODEMETA_URI = 'https://codemeta.github.io/terms/' | CODEMETA_URI = 'https://codemeta.github.io/terms/' | ||||
SCHEMA_URI = 'http://schema.org/' | SCHEMA_URI = 'http://schema.org/' | ||||
PROPERTY_BLACKLIST = { | PROPERTY_BLACKLIST = { | ||||
# CodeMeta properties that we cannot properly represent. | # CodeMeta properties that we cannot properly represent. | ||||
SCHEMA_URI + 'softwareRequirements', | SCHEMA_URI + 'softwareRequirements', | ||||
CODEMETA_URI + 'softwareSuggestions', | CODEMETA_URI + 'softwareSuggestions', | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | with open(CROSSWALK_TABLE_PATH) as fd: | ||||
CROSSWALK_TABLE = _read_crosstable(fd) | CROSSWALK_TABLE = _read_crosstable(fd) | ||||
def _document_loader(url): | def _document_loader(url): | ||||
"""Document loader for pyld. | """Document loader for pyld. | ||||
Reads the local codemeta.jsonld file instead of fetching it | Reads the local codemeta.jsonld file instead of fetching it | ||||
from the Internet every single time.""" | from the Internet every single time.""" | ||||
if url == CODEMETA_CONTEXT_URL: | if url == CODEMETA_CONTEXT_URL or url in CODEMETA_ALTERNATE_CONTEXT_URLS: | ||||
ardumont: why not:
```
if url in CODEMETA_CONTEXT_URLS:
```
CODEMETA_CONTEXT_URLS being the list of… | |||||
Done Inline ActionsThe first one is the one recommended by CodeMeta. It's also the one we use in the indexers' output. vlorentz: The first one is the one recommended by CodeMeta. It's also the one we use in the indexers'… | |||||
return { | return { | ||||
'contextUrl': None, | 'contextUrl': None, | ||||
'documentUrl': url, | 'documentUrl': url, | ||||
'document': CODEMETA_CONTEXT, | 'document': CODEMETA_CONTEXT, | ||||
} | } | ||||
elif url == CODEMETA_URI: | elif url == CODEMETA_URI: | ||||
raise Exception('{} is CodeMeta\'s URI, use {} as context url'.format( | raise Exception('{} is CodeMeta\'s URI, use {} as context url'.format( | ||||
CODEMETA_URI, CODEMETA_CONTEXT_URL)) | CODEMETA_URI, CODEMETA_CONTEXT_URL)) | ||||
Show All 14 Lines |
why not:
CODEMETA_CONTEXT_URLS being the list of accepted context urls?
Is the first one the more frequent value?