Query Manager

Provides basic methods for user interaction through a command window.

@author: J. Cid-Sueiro

class src.query_manager.QueryManager

Bases: object

This class contains all user queries needed by the datamanager.

__init__()

Initializes the query manager object

__weakref__

list of weak references to the object (if defined)

ask_keywords(kw_library=None)

Ask the user for a list of keywords.

Parameters

kw_library (list) – A list of possible keywords

Returns

keywords – List of keywords

Return type

list of str

ask_label()

Ask the user for a single binary label

Returns

label – Binary value read from the standard input

Return type

int

ask_label_tag()

Ask the user for a tag to compose the label file name.

Returns

keywords – List of keywords

Return type

list of str

ask_labels()

Ask the user for a weighted list of labels related to some documents

Returns

labels – List of labels

Return type

list of int

ask_topics(topic_words)

Ask the user for a weighted list of topics

Parameters

topic_words (list of str) – List of the main words from each topic

Returns

tw – Dictionary of topics: weights

Return type

dict

ask_value(query='Write value: ', convert_to=<class 'str'>, default=None)

Ask user for a value

Parameters
  • query (str, optional (default value=”Write value: “)) – Text to print

  • convert_to (function, optional (default=str)) – A function to apply to the selected value. It can be used, for instance, for type conversion.

  • default (optional (default=None)) – Default value to return if an empty value is returned

Returns

The returned value is equal to conver_to(x), where x is the string introduced by the user (if any) or the default value.

Return type

value

confirm()

Ask the user for confirmation

Return type

True if the user inputs ‘y’, False otherwise

static str2dict(text)

Converts a string of comma-separated keys and values (“k1, v1, k2, v2, …!” into a dictionary {k1: v1, k2: v2, …} of integer keys and normalized weight values

Parameters

text (str) – String o comma-separated keys and values

Returns

tw – A dictionary integer keys and float values.

Return type

dict