SmartfiltersMixin#

class SmartfiltersMixin#

Bases: object

Methods Summary

copy_fingerprint(type, type_id, name)

Copies the smartfilter for the provided parameters.

copy_smartfilter(type, type_id, name)

Copies the smartfilter for the provided parameters.

delete_fingerprint(type, type_id, name)

Deletes the smartfilter for the provided parameters.

delete_smartfilter(type, type_id, name)

Deletes the smartfilter for the provided parameters.

get_fingerprint(type, type_id, name)

Get a single smartfilter for the provided parameters.

get_fingerprint_matches_for_query(type, ...)

Returns the match counts for each feature of smartfilter with type, type_id and name and the query provide in kwargs.

get_project_fingerprint_scores(project_id, tags)

Get the smartfilter scores for all items contained in the specified project.

get_project_fingerprints(project_id[, tags, ...])

Get all smartfilters which are applicable on a project.

get_project_smartfilter_scores(project_id, tags)

Get the smartfilter scores for all items contained in the specified project.

get_project_smartfilters(project_id[, tags, ...])

Get all smartfilters which are applicable on a project.

get_smartfilter(type, type_id, name)

Get a single smartfilter for the provided parameters.

get_smartfilter_matches_for_query(type, ...)

Returns the match counts for each feature of smartfilter with type, type_id and name and the query provide in kwargs.

move_fingerprint(type, type_id, name, ...)

Moves the smartfilter for the provided parameters.

move_smartfilter(type, type_id, name, ...)

Moves the smartfilter for the provided parameters.

new_fingerprint(type, type_id[, name, data])

Create a new smartfilter for the provided parameters.

new_smartfilter(type, type_id[, name, data])

Create a new smartfilter for the provided parameters.

protect_fingerprint(type, type_id, name, locked)

Sets the locked state of a smartfilter.

protect_smartfilter(type, type_id, name, locked)

Sets the locked state of a smartfilter.

update_fingerprint_attributes(type, type_id, ...)

Updates the smartfilter key-value attributes for the provided parameters.

update_fingerprint_from_content(type, ...)

Updates the smartfilter for the provided parameters from content data.

update_fingerprint_from_items(type, type_id, ...)

Updates the smartfilter for the provided parameters from items data.

update_smartfilter_attributes(type, type_id, ...)

Updates the smartfilter key-value attributes for the provided parameters.

update_smartfilter_from_content(type, ...)

Updates the smartfilter for the provided parameters from content data.

update_smartfilter_from_items(type, type_id, ...)

Updates the smartfilter for the provided parameters from items data.

validate_fingerprint_attributes(data)

Validates the attributes syntax of a smartfilter.

validate_smartfilter_attributes(data)

Validates the attributes syntax of a smartfilter.

Methods Documentation

copy_fingerprint(type, type_id, name)#

Copies the smartfilter for the provided parameters.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type identifier.

  • name – Fingerprint name.

Example:

>>> client.copy_smartfilter('tenant', 'squirro', 'ma')
{}
copy_smartfilter(type, type_id, name)#

Copies the smartfilter for the provided parameters.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type identifier.

  • name – Fingerprint name.

Example:

>>> client.copy_smartfilter('tenant', 'squirro', 'ma')
{}
delete_fingerprint(type, type_id, name)#

Deletes the smartfilter for the provided parameters.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type identifier.

  • name – Fingerprint name.

Example:

>>> client.delete_smartfilter('user', 'bgFtu5rkR1STpx1xR2u1UQ',
...                           'default')
delete_smartfilter(type, type_id, name)#

Deletes the smartfilter for the provided parameters.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type identifier.

  • name – Fingerprint name.

Example:

>>> client.delete_smartfilter('user', 'bgFtu5rkR1STpx1xR2u1UQ',
...                           'default')
get_fingerprint(type, type_id, name)#

Get a single smartfilter for the provided parameters.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type identifier.

  • name – Fingerprint name.

Returns:

Fingerprint information in a dictionary.

Example:

>>> client.get_smartfilter('project', 'zgxIdCxSRWSwJzL1fwNX1Q',
...                        'default')
{}
get_fingerprint_matches_for_query(type, type_id, name, language, noise_level=0.1, **kwargs)#

Returns the match counts for each feature of smartfilter with type, type_id and name and the query provide in kwargs.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type id.

  • name – Fingerprint name.

  • language – Language for which the matches are being returned.

  • noise_level – Fingerprint noise_level.

  • kwargs – Query parameters. All keyword arguments are passed on verbatim to the API. See the [[Items#List Items|List Items]] resource for all possible parameters.

Returns:

A dictionary which contains the matching feature and counts for the query.

get_project_fingerprint_scores(project_id, tags, fields=None)#

Get the smartfilter scores for all items contained in the specified project. One ore more smartfilters are selected by specifying tags.

Parameters:
  • project_id – Project identifier.

  • tags – List of tags.

  • fields – String of comma-separated item fields to include in the result.

Returns:

A list of smartfilter score entries.

Example:

>>> client.get_project_smartfilter_scores(
...     'Sz7LLLbyTzy_SddblwIxaA', ['poc', 'testing'])
[{u'fingerprint': {u'filter_min_score': None,
                   u'name': u'ma',
                   u'title': u'',
                   u'type': u'tenant',
                   u'type_id': u'squirro'},
  u'scores': [{u'fields': {u'external_id': u'a38515'},
               u'noise_level': 0.0},
              {u'fields': {u'external_id': u'a37402'},
               u'noise_level': 0.0},
              {u'fields': {u'external_id': u'a38116'},
               u'noise_level': 0.1}]},
 {u'fingerprint': {u'filter_min_score': 1.2950184,
                   u'name': u'something',
                   u'title': u'Something',
                   u'type': u'tenant',
                   u'type_id': u'squirro'},
  u'scores': [{u'fields': {u'external_id': u'a38515'},
               u'noise_level': 0.0},
              {u'fields': {u'external_id': u'a37402'},
               u'noise_level': 0.1},
              {u'fields': {u'external_id': u'a38116'},
               u'noise_level': 0.1}]}]
get_project_fingerprints(project_id, tags=None, include_config=False)#

Get all smartfilters which are applicable on a project.

Parameters:
  • project_id – Project identifier.

  • tags – List of tags which can be used to filtering the returned smartfilters.

  • include_config – Boolean flag whether to include each Smart Filter config.

Returns:

A list of smartfilters.

Example:

>>> client.get_project_smartfilters('zgxIdCxSRWSwJzL1fwNX1Q')
[]
get_project_smartfilter_scores(project_id, tags, fields=None)#

Get the smartfilter scores for all items contained in the specified project. One ore more smartfilters are selected by specifying tags.

Parameters:
  • project_id – Project identifier.

  • tags – List of tags.

  • fields – String of comma-separated item fields to include in the result.

Returns:

A list of smartfilter score entries.

Example:

>>> client.get_project_smartfilter_scores(
...     'Sz7LLLbyTzy_SddblwIxaA', ['poc', 'testing'])
[{u'fingerprint': {u'filter_min_score': None,
                   u'name': u'ma',
                   u'title': u'',
                   u'type': u'tenant',
                   u'type_id': u'squirro'},
  u'scores': [{u'fields': {u'external_id': u'a38515'},
               u'noise_level': 0.0},
              {u'fields': {u'external_id': u'a37402'},
               u'noise_level': 0.0},
              {u'fields': {u'external_id': u'a38116'},
               u'noise_level': 0.1}]},
 {u'fingerprint': {u'filter_min_score': 1.2950184,
                   u'name': u'something',
                   u'title': u'Something',
                   u'type': u'tenant',
                   u'type_id': u'squirro'},
  u'scores': [{u'fields': {u'external_id': u'a38515'},
               u'noise_level': 0.0},
              {u'fields': {u'external_id': u'a37402'},
               u'noise_level': 0.1},
              {u'fields': {u'external_id': u'a38116'},
               u'noise_level': 0.1}]}]
get_project_smartfilters(project_id, tags=None, include_config=False)#

Get all smartfilters which are applicable on a project.

Parameters:
  • project_id – Project identifier.

  • tags – List of tags which can be used to filtering the returned smartfilters.

  • include_config – Boolean flag whether to include each Smart Filter config.

Returns:

A list of smartfilters.

Example:

>>> client.get_project_smartfilters('zgxIdCxSRWSwJzL1fwNX1Q')
[]
get_smartfilter(type, type_id, name)#

Get a single smartfilter for the provided parameters.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type identifier.

  • name – Fingerprint name.

Returns:

Fingerprint information in a dictionary.

Example:

>>> client.get_smartfilter('project', 'zgxIdCxSRWSwJzL1fwNX1Q',
...                        'default')
{}
get_smartfilter_matches_for_query(type, type_id, name, language, noise_level=0.1, **kwargs)#

Returns the match counts for each feature of smartfilter with type, type_id and name and the query provide in kwargs.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type id.

  • name – Fingerprint name.

  • language – Language for which the matches are being returned.

  • noise_level – Fingerprint noise_level.

  • kwargs – Query parameters. All keyword arguments are passed on verbatim to the API. See the [[Items#List Items|List Items]] resource for all possible parameters.

Returns:

A dictionary which contains the matching feature and counts for the query.

move_fingerprint(type, type_id, name, target_name)#

Moves the smartfilter for the provided parameters.

This saves the smartfilter and removes the temporary flag. The old smartfilter is not removed.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type identifier.

  • name – Fingerprint name.

  • target_name – Name of move target smartfilter.

Example:

>>> client.move_smartfilter('user', 'bgFtu5rkR1STpx1xR2u1UQ',
...                         'default')
move_smartfilter(type, type_id, name, target_name)#

Moves the smartfilter for the provided parameters.

This saves the smartfilter and removes the temporary flag. The old smartfilter is not removed.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type identifier.

  • name – Fingerprint name.

  • target_name – Name of move target smartfilter.

Example:

>>> client.move_smartfilter('user', 'bgFtu5rkR1STpx1xR2u1UQ',
...                         'default')
new_fingerprint(type, type_id, name=None, data=None)#

Create a new smartfilter for the provided parameters.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type identifier.

  • name – Fingerprint name.

  • data – Fingerprint attributes.

Example:

>>> data = {'title': 'Earnings Call'}
>>> client.new_smartfilter(
...     'user', 'bgFtu5rkR1STpx1xR2u1UQ', 'default', data)
{}
new_smartfilter(type, type_id, name=None, data=None)#

Create a new smartfilter for the provided parameters.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type identifier.

  • name – Fingerprint name.

  • data – Fingerprint attributes.

Example:

>>> data = {'title': 'Earnings Call'}
>>> client.new_smartfilter(
...     'user', 'bgFtu5rkR1STpx1xR2u1UQ', 'default', data)
{}
protect_fingerprint(type, type_id, name, locked)#

Sets the locked state of a smartfilter.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type identifier.

  • name – Fingerprint name.

  • locked – Boolean flag to either lock or unlock the smartfilter.

Example:

>>> client.protect_smartfilter(
...     'user', 'bgFtu5rkR1STpx1xR2u1UQ', 'default', True)
protect_smartfilter(type, type_id, name, locked)#

Sets the locked state of a smartfilter.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type identifier.

  • name – Fingerprint name.

  • locked – Boolean flag to either lock or unlock the smartfilter.

Example:

>>> client.protect_smartfilter(
...     'user', 'bgFtu5rkR1STpx1xR2u1UQ', 'default', True)
update_fingerprint_attributes(type, type_id, name, data)#

Updates the smartfilter key-value attributes for the provided parameters.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type identifier.

  • name – Fingerprint name.

  • data – Fingerprint attributes.

Example:

>>> data = {'title': 'Earnings Call'}
>>> client.update_smartfilter_attributes(
...     'user', 'bgFtu5rkR1STpx1xR2u1UQ', 'default', data)
update_fingerprint_from_content(type, type_id, name, content)#

Updates the smartfilter for the provided parameters from content data.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type identifier.

  • name – Fingerprint name.

  • content – Content data which is a list of dictionaries which contain the lang and text keys.

Example:

>>> data = [{'lang': 'en', 'text': 'english content'}]
>>> client.update_smartfilter_from_content(
...     'user', 'bgFtu5rkR1STpx1xR2u1UQ', 'default', data)
{}
update_fingerprint_from_items(type, type_id, name, items, negative=False)#

Updates the smartfilter for the provided parameters from items data.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type identifier.

  • name – Fingerprint name.

  • items – List of item identifiers

  • negative – Boolean, whether to add the items as ‘negative’ or ‘positive’ training definitions. Defaults to False

Example:

>>> data = ['tfoOHGEZRAqFURaEE2cPWA']
>>> client.update_smartfilter_from_items(
...     'user', 'bgFtu5rkR1STpx1xR2u1UQ', 'default', data)
{}
update_smartfilter_attributes(type, type_id, name, data)#

Updates the smartfilter key-value attributes for the provided parameters.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type identifier.

  • name – Fingerprint name.

  • data – Fingerprint attributes.

Example:

>>> data = {'title': 'Earnings Call'}
>>> client.update_smartfilter_attributes(
...     'user', 'bgFtu5rkR1STpx1xR2u1UQ', 'default', data)
update_smartfilter_from_content(type, type_id, name, content)#

Updates the smartfilter for the provided parameters from content data.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type identifier.

  • name – Fingerprint name.

  • content – Content data which is a list of dictionaries which contain the lang and text keys.

Example:

>>> data = [{'lang': 'en', 'text': 'english content'}]
>>> client.update_smartfilter_from_content(
...     'user', 'bgFtu5rkR1STpx1xR2u1UQ', 'default', data)
{}
update_smartfilter_from_items(type, type_id, name, items, negative=False)#

Updates the smartfilter for the provided parameters from items data.

Parameters:
  • type – Fingerprint type.

  • type_id – Fingerprint type identifier.

  • name – Fingerprint name.

  • items – List of item identifiers

  • negative – Boolean, whether to add the items as ‘negative’ or ‘positive’ training definitions. Defaults to False

Example:

>>> data = ['tfoOHGEZRAqFURaEE2cPWA']
>>> client.update_smartfilter_from_items(
...     'user', 'bgFtu5rkR1STpx1xR2u1UQ', 'default', data)
{}
validate_fingerprint_attributes(data)#

Validates the attributes syntax of a smartfilter.

Parameters:

data – Fingerprint attributes.

Valid example:

>>> data = {'config': {
    'manual_features': 'term1, 1.5, de, Term1\nterm2, 2.4',
    'default_manual_features_lang': 'de'}}
>>> client.validate_smartfilter_attributes(data)
{}

Invalid example:

>>> data = {'config': {
    'manual_features': 'invalid, 1.5, de, Term1'}}
>>> try:
>>>     client.validate_smartfilter_attributes(data)
>>> except squirro_client.exceptions.ClientError as e:
>>>     print e.error
u'[{"line": 0, "error": "required default language is missing"}]'
validate_smartfilter_attributes(data)#

Validates the attributes syntax of a smartfilter.

Parameters:

data – Fingerprint attributes.

Valid example:

>>> data = {'config': {
    'manual_features': 'term1, 1.5, de, Term1\nterm2, 2.4',
    'default_manual_features_lang': 'de'}}
>>> client.validate_smartfilter_attributes(data)
{}

Invalid example:

>>> data = {'config': {
    'manual_features': 'invalid, 1.5, de, Term1'}}
>>> try:
>>>     client.validate_smartfilter_attributes(data)
>>> except squirro_client.exceptions.ClientError as e:
>>>     print e.error
u'[{"line": 0, "error": "required default language is missing"}]'