textworld.utils¶
-
class
textworld.utils.
RandomGenerator
(seed=None)[source]¶ Bases:
object
Random generator controlling the games generation.
-
property
seed
¶
-
property
-
class
textworld.utils.
RegexDict
[source]¶ Bases:
collections.OrderedDict
Ordered dictionary that supports querying with regex.
References
Adapted from https://stackoverflow.com/questions/21024822/python-accessing-dictionary-with-wildcards.
-
get_matching
(*regexes, exclude=[])[source]¶ Query the dictionary using one or several regular expressions.
- Parameters
*regexes – List of regular expressions determining which keys of this dictionary are relevant to this query.
exclude (
List
[str
]) – List of regular expressions determining which keys of this dictionary should be excluded from this query.
- Return type
List
[Any
]- Returns
The value associated to each relevant (and not excluded) keys.
-
-
textworld.utils.
check_modules
(required_modules, missing_modules)[source]¶ Check whether some required modules are missing.
-
textworld.utils.
make_temp_directory
(suffix='', prefix='tw_', dir=None)[source]¶ Create temporary folder to used in a with statement.
-
textworld.utils.
save_graph_to_svg
(G, labels, filename, backward=False)[source]¶ Generate a figure of a networkx’s graph object and save it.
-
textworld.utils.
take
(n, iterable)[source]¶ Return first n items of the iterable as a list.
References
https://docs.python.org/3/library/itertools.html#itertools-recipes
- Return type
Iterable
-
textworld.utils.
unique_product
(*iterables)[source]¶ Cartesian product of input iterables with pruning.
This method prunes any product tuple with duplicate elements in it.
Example
unique_product(‘ABC’, ‘Ax’, ‘xy’) –> Axy BAx BAy Bxy CAx CAy Cxy
Notes
This method is faster than the following equivalent code:
>>> for result in itertools.product(*args): >>> if len(set(result)) == len(result): >>> yield result
-
textworld.utils.
uniquify
(seq)[source]¶ Order preserving uniquify.
References
Made by Dave Kirby https://www.peterbe.com/plog/uniqifiers-benchmark
-
textworld.utils.
g_rng
= <textworld.utils.RandomGenerator object>¶ Global random generator.