pip_services3_commons.data.TagsProcessor module

class pip_services3_commons.data.TagsProcessor.TagsProcessor

Bases: object

Helper class to extract and process search tags from objects. The search tags can be kept individually or embedded as hash tags inside text like “This text has #hash_tag that can be used for search.”

static compress_tag(tag: str)str

Compress a tag by removing special symbols like spaces, ‘_’ and ‘#’ and converting the tag to lower case. When tags are compressed they can be matched in search queries.

Parameters

tag – the tag to compress.

Returns

a compressed tag.

static compress_tag_list(tag_list: str) → List[str]

Compresses a comma-separated list of tags.

Parameters

tag_list – a comma-separated list of tags to compress.

Returns

a list with compressed tags.

static compress_tags(tags: List[str]) → List[str]

Compresses a comma-separated list of tags.

Parameters

tags – a comma-separated list of tags to compress.

Returns

a list with compressed tags.

static equal_tags(tag1: str, tag2: str)bool

Compares two tags using their compressed form.

Parameters
  • tag1 – the first tag.

  • tag2 – the second tag.

Returns

true if the tags are equal and false otherwise.

static extract_hash_tags(text: str) → List[str]

Extracts hash tags from a text.

Parameters

text – a text that contains hash tags

Returns

a list with extracted and compressed tags.

static extract_hash_tags_from_value(obj: Any, *search_fields: str) → List[str]

Extracts hash tags from selected fields in an object.

Parameters
  • obj – an object which contains hash tags.

  • search_fields – a list of fields in the objects where to extract tags

Returns

a list of extracted and compressed tags.

static normalize_tag(tag: str) → Optional[str, None]

Normalizes a tag by replacing special symbols like ‘_’ and ‘#’ with spaces. When tags are normalized then can be presented to user in similar shape and form.

Parameters

tag – the tag to normalize.

Returns

a normalized tag.

static normalize_tag_list(tag_list: str) → List[str]

Normalizes a comma-separated list of tags.

Parameters

tag_list – a comma-separated list of tags to normalize.

Returns

a list with normalized tags.

static normalize_tags(tags: List[str]) → List[str]

Normalizes a list of tags.

Parameters

tags – the tags to normalize.

Returns

a list with normalized tags.