mindmeld.query_cache module

This module contains the query cache implementation.

class mindmeld.query_cache.QueryCache(app_path, schema_version_hash)[source]

Bases: object

QueryCache stores ProcessedQuerys and associated metadata in a sqlite3 backed cache to save processing time on reloading the examples later.

compatible_version()[source]

Checks to see if the cache db file exists and that the data version matches the current data version.

static copy_db(source, dest)[source]
flush_to_disk()[source]

Flushes data from the in-memory cache into the disk-backed cache

get_domain(row_id)[source]

Get the domain only from a cached example. See notes on get().

get_entities(row_id)[source]

Get entities from a cached example. See notes on get().

get_intent(row_id)[source]

Get the intent only from a cached example. See notes on get().

static get_key(domain, intent, query_text)[source]

Calculates a hash key for the domain, intent and text of an example. This key is required for further interactions with the query cache.

Parameters:
  • domain (str) -- The domain of the example
  • intent (str) -- The intent of the example
  • query_text (str) -- The raw text of the example
Returns:

Hash id representing this query

Return type:

str

get_query(row_id)[source]

Get the Query from a cached example. See notes on get().

get_raw_query(row_id)[source]

Get the raw text only from a cached example. See notes on get().

get_value(domain, intent, query_text)[source]
key_to_row_id(key)[source]
Parameters:key (str) -- A key generated by the QueryCache.get_key() function
Returns:Unique id of the query in the cache if it exists
Return type:Optional(Integer)
put(key, processed_query)[source]

Adds a ProcessedQuery to the cache

Parameters:
  • key (str) -- A key generated by QueryCache.get_key() for this example
  • processed_query (ProcessedQuery) -- The ProcessedQuery generated for this example
Returns:

The unique id of the query in the cache.

Return type:

integer

connection
get[source]

Get a cached ProcessedQuery by id. Note -- this call should never fail as it is required that the row_id exist in the database before this method is called. Exceptions may be thrown in the case of database corruption.

The method caches the previously retrieved element because it is common for a set of iterators (examples and labels) to retrieve the same row_id in sequence. The cache prevents extra db lookups in this case.

Parameters:row_id (integer) -- The unique id returned by QueryCache.key_to_row_id() or QueryCache.put().
Returns:The ProcessedQuery associated with the identifier.
Return type:ProcessedQuery