pydialogue.environments package#

Submodules#

pydialogue.environments.builders module#

This module offers functions that create instances of the class Entity based on their attributes and properties.

pydialogue.environments.builders.build_bed(world, var_name, size=None, color=None, material=None, location=None)[source]#

Builds an Entity that has type bed. The beds built here are static and hollow.

pydialogue.environments.builders.build_book(world, var_name, size=None, color=None, material=None, location=None)[source]#

Builds an Entity with type book that can be opened.

pydialogue.environments.builders.build_door(world, var_name, size=None, color=None, material=None, location=None, door_to=None)[source]#

Builds an entity with an attribute door. Additionally, the door_to property can be added to indicate where the door leads (usually, the door connects two places).

For now, the location of the door is [‘in’, <place>] instead of [‘between’, place1, place2]. This can be modified in the future.

pydialogue.environments.builders.build_entity(world, var_name=None, size=None, _type=None, color=None, material=None, location=None, name=None, surname=None, nickname=None)[source]#

Creates an Entity instance and initializes it with the properties given above. If the location is provided, the entity is added to the location.objects field.

pydialogue.environments.builders.build_place(world, var_name, size=None, _type=None, color=None, material=None, location=None)[source]#

Builds an Entity that refers to an open or enclosed space that can hold objects. There are a few differences between a container and a place:

  • the container might be part of a place or a different container.

  • the place is always static, and the container can be moved.

  • the place might require a door to be opened first, and the present containers are simplified and can be opened directly. In the future, this simplification can be changed, and containers might have a lid or/and latch.

pydialogue.environments.builders.build_player(world, var_name, size=None, _type=None, color=None, material=None, location=None, name=None, surname=None, nickname=None)[source]#

Builds an Entity and adds the attribute player. The player can perform actions in the environment.

pydialogue.environments.builders.build_table(world, var_name, size=None, color=None, material=None, location=None)[source]#

The tables created in this function are assumed too heavy to be carried by a single person and are made static. Not all tables have to be static.

pydialogue.environments.builders.build_window(world, var_name, size=None, color=None, material=None, location=None)[source]#

Builds an Entity that has a type window.

pydialogue.environments.builders.remove_none_values(dict_)[source]#

Removes the dictionary values that are None.

pydialogue.environments.easy module#

This module provides the function for creating the simulated training environment.

pydialogue.environments.easy.build_world(random_seed=None)[source]#

Build the entities of the easy world. In the easy world, only <x> rooms are used, and <y> directions for the rooms. There are a total of <z> objects.

pydialogue.environments.path_helpers module#

This module lists all the functions needed for finding the shortest path between two entities in the world.

pydialogue.environments.path_helpers.cost_function(ent1, ent2, edge, prev_edge)[source]#

Returns the edge cost. When finding the path between two locations, the edge is a tuple of two values. The first value is the cost of movement, and the second value is the direction that leads from the source location to the target location.

pydialogue.environments.path_helpers.find_shortest_path(source, target, graph)[source]#

Finds the shortest path between the source and the target using the graph.

Parameters:
  • source (Entity) – The starting location.

  • target (Entity) – The end location.

  • graph (dijkstar.Graph) – The edges of the graph connect two vertices (the source and target location)

Returns:

path – Returns the path, which is a list of directions.

Return type:

list

pydialogue.environments.world module#

This module contains the class World which represents the simulated world.

class pydialogue.environments.world.World(obj_list=None, undo_changes=None, change_action_properties=None, all_description_objects=None, location_positions=None, random_seed=None, init=True)[source]#

Bases: object

The simulated world.

obj_list#

A list of Entity-s that belong to the world.

Type:

list

undo_changes#

A list of all changes done to the entities. This list is passed to the constructor of each Entity. Whenever an action changes an entity property/attribute, an undo() function is saved in the undo_changes that will reverse the change. The changes are saved in chronological order.

Type:

list

<var_name>

For easier fetching of the entities (instead of looking for them in the list), self.<entity_var_name> can be used to get an entity. For example, self.rug or self.main_door.

Type:

Entity

directions#

A list of strings representing all directions used in the world. For example: north, northeast, south, …

Type:

list

all_properties#

A list of all property keys that the entities in the world have.

Type:

list

all_attributes#

A list of all attributes that the entities in the world have.

Type:

list

<property_key>s

To fetch all the possible values of a specific property key, the plural version of the property key is used. For example, to fetch all colors self.colors can be used. In case the property key is a tuple of strings, the strings are merged with an underscore, and the letter “s” is added at the end.

The following properties are not added because their values do not represent all possible values: the obstacles (key: (north, obstacle), … ), the directions (key: north, east, …), the locations (key: location) and the doors leading to a location (key: door_to). For example, the big apple might have location [‘on’, table], but in the future [‘in’, player] and self.locations should therefore contain all these possible variations which we found is unnecessary to compute. Please check the function self.check_val_is_key in case you want to check if a specific value can be a location.

Type:

list

<attribute>s

A list of all objects that have a specific attribute. For example, to fetch all players, you can use self.players.

Type:

list

graph#

The graph contains edges that represent connections between two neighboring places. The doors are not represented in the graph since the doors can be opened. We currently haven’t implemented any static obstacles that can be present in front of the doors. Based on the graph, the shortest path between two places can be computed.

Type:

dijkstar.Graph

all_paths#

A dictionary mapping (location A, location B) => list of directions that lead the play from location A to location B.

Type:

dict

change_action_properties#

The list of properties that can be changed. This member is used by the actions.change() function.

Type:

list

all_description_objects#

The Description objects are used for describing the entities.

Type:

list

location_positions#

A list of prepositions used in the <entity>.properties[‘location’]. The prepositions can be ‘on’, ‘under’, ‘in’… For example, carrot.properties[‘location’]=[‘on’, kitchen_table]

Type:

list

basic_init(obj_list=None)[source]#

Initializes the world’s class members that are affected by the new objects list.

check_val_is_key(key, val)[source]#

Check if a specific value belongs to a key. For example, check if ‘red’ is a color.

For most of the values, this can be done by using self.<property_key>s (self.colors in the example above). But for some properties like the object’s location, self.<property_key>s does not exist because all the location values have to be manually computed: [‘on’, obj1], [‘in’, obj1], … and so on. Instead, they are pattern-matched here in this function.

compute_directions()[source]#

Finds all directions present in the world. For example, the bathroom can have a direction north which leads to the kitchen. The directions can be “north”, “east”, “northeast”, … and so on.

expand_world(new_world)[source]#

Expands the current world with the objects of a new world. All the members of self are added without losing the current references.

find_all_objs(attr)[source]#

Finds all objects that have a specific attribute.

find_all_vals(prop_key)[source]#

Finds all the property values in the world for a given property key.

flush_undo_changes()[source]#

Removes the saved changes in order to save memory.

get_attributes()[source]#

Gets all attributes that the objects in the world have.

get_properties()[source]#

Gets all properties that the objects in the world have.

get_property_values(prop_keys)[source]#

Get all the property values for the given property keys and merge them in a list. This is done only if <property_key>s exists in the class.

query_entity_from_db(entity)[source]#

Returns all entities that are similar to the given entity. The similarity is done by comparing all properties and attributes between the given entity and the entities in self.obj_list.

recover_state(state)[source]#

Recovers the world state to a specific point in the past. That point is <state> which is a positive integer and all changes past that point are undone.

save_state()[source]#

Saves the world state by remembering the last point a world change was done.

update_all_attributes()[source]#

Updates all self.<attribute>s. This function is useful after adding new objects, or when merging worlds.

update_all_property_vals(new_world=None)[source]#

Updates all self.<property_key>s. This function is useful after adding new objects, or when merging worlds. If new_world is not None, it additionally updates all self.<property_key>s with the unassigned property values of the new_world. By unassigned, we mean the property values are not assigned to any of the objects of the new world. For example, some colors might be added, like new_world.colors.append(“blue”), but blue might not appear anywhere in the objects.

update_graph()[source]#

Update the graph after the places and/or directions are modified.

update_paths()[source]#

Update all the paths. This function is useful when the list of places is modified.

pydialogue.environments.world.compute_unique_list(_list)[source]#

Computes a list with elements that do not repeat. This function is useful when the built-in function set is not applicable due to the non-hashable elements present in the list.

pydialogue.environments.world.filter_items(all_objects, filter_conditions=None)[source]#

Returns the objects from the list all_objects that satisfy the given conditions.

Parameters:
  • all_objects (list) – A list of Entity-s.

  • filter_conditions (list) – A list of functions that accept as the first parameter an Entity. The functions should return True or False. The functions act as a set of conditions that the objects should satisfy.

pydialogue.environments.world.list_diff(list1, list2)[source]#

Returns the elements that are present in list1 but not in list2.

Module contents#