Skip to content

hdx.data.vocabulary

Vocabulary class containing all logic for creating, checking, and updating vocabularies.

Vocabulary Objects

class Vocabulary(HDXObject)

[view_source]

Vocabulary class containing all logic for creating, checking, and updating vocabularies.

Arguments:

  • initial_data Optional[Dict] - Initial dataset metadata dictionary. Defaults to None.
  • name str - Name of vocabulary
  • tags Optional[List] - Initial list of tags. Defaults to None.
  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.

actions

@staticmethod
def actions() -> Dict[str, str]

[view_source]

Dictionary of actions that can be performed on object

Returns:

Dict[str, str]: Dictionary of actions that can be performed on object

update_from_yaml

def update_from_yaml(path: str = join("config",
                                      "hdx_vocabulary_static.yaml")) -> None

[view_source]

Update vocabulary metadata with static metadata from YAML file

Arguments:

  • path Optional[str] - Path to YAML dataset metadata. Defaults to config/hdx_vocabulary_static.yaml.

Returns:

None

update_from_json

def update_from_json(path: str = join("config",
                                      "hdx_vocabulary_static.json")) -> None

[view_source]

Update vocabulary metadata with static metadata from JSON file

Arguments:

  • path Optional[str] - Path to JSON dataset metadata. Defaults to config/hdx_vocabulary_static.json.

Returns:

None

read_from_hdx

@classmethod
def read_from_hdx(cls,
                  identifier: str,
                  configuration: Optional[Configuration] = None
                  ) -> Optional["Vocabulary"]

[view_source]

Reads the vocabulary given by identifier from HDX and returns Vocabulary object

Arguments:

  • identifier str - Identifier of vocabulary
  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.

Returns:

  • Optional[Vocabulary] - Vocabulary object if successful read, None if not

get_all_vocabularies

@staticmethod
def get_all_vocabularies(
        configuration: Optional[Configuration] = None) -> List["Vocabulary"]

[view_source]

Get all vocabulary names in HDX

Arguments:

  • identifier str - Identifier of resource
  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.

Returns:

  • List[Vocabulary] - List of Vocabulary objects

check_required_fields

def check_required_fields(ignore_fields: ListTuple[str] = tuple()) -> None

[view_source]

Check that metadata for vocabulary is complete. The parameter ignore_fields should be set if required to any fields that should be ignored for the particular operation.

Arguments:

  • ignore_fields ListTuple[str] - Fields to ignore. Default is tuple().

Returns:

None

update_in_hdx

def update_in_hdx(**kwargs: Any) -> None

[view_source]

Check if vocabulary exists in HDX and if so, update vocabulary

Returns:

None

create_in_hdx

def create_in_hdx(**kwargs: Any) -> None

[view_source]

Check if vocabulary exists in HDX and if so, update it, otherwise create vocabulary

Returns:

None

delete_from_hdx

def delete_from_hdx(empty: bool = True) -> None

[view_source]

Deletes a vocabulary from HDX. First tags are removed then vocabulary is deleted.

Arguments:

  • empty bool - Remove all tags and update before deleting. Defaults to True.

Returns:

None

get_tags

def get_tags() -> List[str]

[view_source]

Lists tags in vocabulary

Returns:

  • List[str] - List of tags in vocabulary

add_tag

def add_tag(tag: str) -> bool

[view_source]

Add a tag

Arguments:

  • tag str - Tag to add

Returns:

  • bool - True if tag added or False if tag already present

add_tags

def add_tags(tags: ListTuple[str]) -> List[str]

[view_source]

Add a list of tags

Arguments:

  • tags ListTuple[str] - list of tags to add

Returns:

  • List[str] - Tags that were successfully added

remove_tag

def remove_tag(tag: str) -> bool

[view_source]

Remove a tag

Arguments:

  • tag str - Tag to remove

Returns:

  • bool - True if tag removed or False if not

get_approved_vocabulary

@classmethod
def get_approved_vocabulary(cls,
                            configuration: Optional[Configuration] = None
                            ) -> "Vocabulary"

[view_source]

Get the HDX approved vocabulary

Arguments:

  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.

Returns:

  • Vocabulary - HDX Vocabulary object

create_approved_vocabulary

@classmethod
def create_approved_vocabulary(
        cls,
        url: Optional[str] = None,
        configuration: Optional[Configuration] = None) -> "Vocabulary"

[view_source]

Create the HDX approved vocabulary

Arguments:

  • url Optional[str] - Tag to check. Defaults to None (url in internal configuration).
  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.

Returns:

  • Vocabulary - HDX Vocabulary object

update_approved_vocabulary

@classmethod
def update_approved_vocabulary(cls,
                               url: Optional[str] = None,
                               configuration: Optional[Configuration] = None,
                               replace: bool = True) -> "Vocabulary"

[view_source]

Update the HDX approved vocabulary

Arguments:

  • url Optional[str] - Tag to check. Defaults to None (url in internal configuration).
  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.
  • replace bool - True to replace existing tags, False to append. Defaults to True.

Returns:

  • Vocabulary - HDX Vocabulary object

delete_approved_vocabulary

@classmethod
def delete_approved_vocabulary(cls,
                               configuration: Optional[Configuration] = None
                               ) -> None

[view_source]

Delete the approved vocabulary

Arguments:

  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.

Returns:

None

approved_tags

@classmethod
def approved_tags(cls,
                  configuration: Optional[Configuration] = None) -> List[str]

[view_source]

Return list of approved tags

Arguments:

  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.

Returns:

  • List[str] - List of approved tags

is_approved

@classmethod
def is_approved(cls,
                tag: str,
                configuration: Optional[Configuration] = None) -> bool

[view_source]

Return if tag is an approved one or not

Arguments:

  • tag str - Tag to check
  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.

Returns:

  • bool - True if tag is approved, False if not

read_tags_mappings

@classmethod
def read_tags_mappings(cls,
                       configuration: Optional[Configuration] = None,
                       url: Optional[str] = None,
                       keycolumn: int = 1,
                       failchained: bool = True) -> Dict

[view_source]

Read tag mappings and setup tags cleanup dictionaries

Arguments:

  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.
  • url Optional[str] - Url of tags cleanup spreadsheet. Defaults to None (internal configuration parameter).
  • keycolumn int - Column number of tag column in spreadsheet. Defaults to 1.
  • failchained bool - Fail if chained rules found. Defaults to True.

Returns:

  • Dict - Returns Tags dictionary

set_tagsdict

@classmethod
def set_tagsdict(cls, tags_dict: Dict) -> None

[view_source]

Set tags dictionary

Arguments:

  • tags_dict Dict - Tags dictionary

Returns:

None

get_mapped_tag

@classmethod
def get_mapped_tag(
    cls,
    tag: str,
    log_deleted: bool = True,
    configuration: Optional[Configuration] = None
) -> Tuple[List[str], List[str]]

[view_source]

Given a tag, return a list of tag(s) to which it maps and any deleted tags

Arguments:

  • tag str - Tag to map
  • log_deleted bool - Whether to log informational messages about deleted tags. Defaults to True.
  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.

Returns:

Tuple[List[str], List[str]]: Tuple containing list of mapped tag(s) and list of deleted tags

get_mapped_tags

@classmethod
def get_mapped_tags(
    cls,
    tags: ListTuple[str],
    log_deleted: bool = True,
    configuration: Optional[Configuration] = None
) -> Tuple[List[str], List[str]]

[view_source]

Given a list of tags, return a list of tags to which they map and any deleted tags

Arguments:

  • tags ListTuple[str] - List of tags to map
  • log_deleted bool - Whether to log informational messages about deleted tags. Defaults to True.
  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.

Returns:

Tuple[List[str], List[str]]: Tuple containing list of mapped tags and list of deleted tags

add_mapped_tag

@classmethod
def add_mapped_tag(cls,
                   hdxobject: HDXObject,
                   tag: str,
                   log_deleted: bool = True) -> Tuple[List[str], List[str]]

[view_source]

Add a tag to an HDX object that has tags

Arguments:

  • hdxobject HDXObject - HDX object such as dataset
  • tag str - Tag to add
  • log_deleted bool - Whether to log informational messages about deleted tags. Defaults to True.

Returns:

Tuple[List[str], List[str]]: Tuple containing list of added tags and list of deleted tags and tags not added

add_mapped_tags

@classmethod
def add_mapped_tags(cls,
                    hdxobject: HDXObject,
                    tags: ListTuple[str],
                    log_deleted: bool = True) -> Tuple[List[str], List[str]]

[view_source]

Add a list of tag to an HDX object that has tags

Arguments:

  • hdxobject HDXObject - HDX object such as dataset
  • tags ListTuple[str] - List of tags to add
  • log_deleted bool - Whether to log informational messages about deleted tags. Defaults to True.

Returns:

Tuple[List[str], List[str]]: Tuple containing list of added tags and list of deleted tags and tags not added

clean_tags

@classmethod
def clean_tags(cls,
               hdxobject: HDXObject,
               log_deleted: bool = True) -> Tuple[List[str], List[str]]

[view_source]

Clean tags in an HDX object according to tags cleanup spreadsheet

Arguments:

  • hdxobject HDXObject - HDX object such as dataset
  • log_deleted bool - Whether to log informational messages about deleted tags. Defaults to True.

Returns:

Tuple[List[str], List[str]]: Tuple containing list of mapped tags and list of deleted tags and tags not added

autocomplete

@classmethod
def autocomplete(cls,
                 name: str,
                 limit: int = 20,
                 configuration: Optional[Configuration] = None,
                 **kwargs: Any) -> List

[view_source]

Autocomplete a tag name and return matches

Arguments:

  • name str - Name to autocomplete
  • limit int - Maximum number of matches to return
  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration. **kwargs:
  • offset int - The offset to start returning tags from.

Returns:

  • List - Autocomplete matches