usersimcrs.items.item_collection

Represents a collection of items.

Items are characterized by a set of properties, which correspond to slots in a domain. Items are stored in a SQLite database and can be populated from a CSV file.

Attributes

MappingConfig

SQL_DELIMITER

Classes

ItemCollection

Initializes an item collection.

Module Contents

usersimcrs.items.item_collection.MappingConfig
usersimcrs.items.item_collection.SQL_DELIMITER = '|'
class usersimcrs.items.item_collection.ItemCollection(db_path: str, table_name: str)

Initializes an item collection.

Parameters:
  • db_path – Path to the SQLite database.

  • table_name – Name of the table containing the items.

connect() None

Connects to the SQLite database.

close() None

Closes the connection to the SQLite database.

Connection and cursor are set to None to allow pickling.

get_item(item_id: str) usersimcrs.items.item.Item

Returns an item from the collection based on its ID.

Parameters:

item_id – Item ID.

Returns:

Item or None, if not found.

get_random_item() usersimcrs.items.item.Item

Returns a random item from the collection.

Returns:

Random item.

exists(item_id: str) bool

Checks if a given item exists in the item collection.

Parameters:

item_id – Item ID.

Returns:

True if the item exists in the collection.

num_items() int

Returns the number of items in the collection.

Returns:

Number of items.

add_item(item: usersimcrs.items.item.Item) None

Adds an item to the collection.

Parameters:

item – Item.

load_items_csv(file_path: str, domain: usersimcrs.core.simulation_domain.SimulationDomain, domain_mapping: MappingConfig, id_col: str = 'ID', delimiter: str = ',') None

Loads an item collection from a CSV file.

If items are connected to a Domain, only domain properties will be kept.

Parameters:
  • file_path – Path to CSV file.

  • domain – Domain of the items.

  • domain_mapping – Mapping configuration.

  • id_col – Name of the column containing the item ID.

  • delimiter – CSV delimiter.

get_possible_property_values(property: str) Set[str]

Returns the possible values for a given property.

Parameters:

property – Property name.

Returns:

Set of possible values.

get_items_by_properties(annotations: List[dialoguekit.core.slot_value_annotation.SlotValueAnnotation]) List[usersimcrs.items.item.Item]

Returns items that match the given slot-value annotations.

Parameters:

annotations – List of slot-value pair annotations.

Returns:

List of matching items.