1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
9 _logger = logging.getLogger('arvados.vocabulary')
11 def load_vocabulary(api_client=api('v1')):
12 """Load the Arvados vocabulary from the API.
14 return Vocabulary(api_client.vocabulary())
16 class Vocabulary(object):
17 def __init__(self, voc_definition={}):
18 self._definition = voc_definition
19 self.strict_keys = self._definition.get('strict_tags', False)
22 for key_id, val in voc_definition.get('tags', {}).items():
23 strict = val.get('strict', False)
24 key_labels = [l['label'] for l in val.get('labels', [])]
26 for v_id, v_val in val.get('values', {}).items():
27 labels = [l['label'] for l in v_val.get('labels', [])]
28 values[v_id] = VocabularyValue(v_id, labels)
29 self.key_aliases[key_id] = VocabularyKey(key_id, key_labels, values, strict)
31 class VocabularyData(object):
32 def __init__(self, identifier, aliases=[]):
33 self.identifier = identifier
34 self.aliases = set([x.lower() for x in aliases])
36 class VocabularyValue(VocabularyData):
37 def __init__(self, identifier, aliases=[]):
38 super(VocabularyValue, self).__init__(identifier, aliases)
40 class VocabularyKey(VocabularyData):
41 def __init__(self, identifier, aliases=[], values={}, strict=False):
42 super(VocabularyKey, self).__init__(identifier, aliases)