AI::ExpertSystem::Advanced::Dictionary - Array/hash dictionary
The dictionary offers a unified interface for:
Reading through a list of items with a minimal use of memory since it offers an iterator that works with a stack. So everytime it gets asked for the next element it drops the first or last element of the stack.
Finding an element in the stack.
Adding or deleting elements from the stack.
An array with all the keys of stack_hash. Useful for creating the iterable_array and for knowing the order of the items as they get added or removed.
stack_hash
iterable_array
The original hash, has all the elements with all their properties (eg extra keys). The disadvantage of it is that it doesn't keeps the order of the elements, hence the need of stack.
stack
Used by the iterate() and iterate_reverse() methods. It starts as a copy of stack and as the iterate methods start running this array starts getting reduced until it gets to an empty list.
iterate()
iterate_reverse()
Looks for a given value ($look_for). By default it will look for the value by reading the id of each item, however this can be changed by passing a different hash key ($find_by).
$look_for
id
$find_by
In case there's no match, undef is returned.
undef
A simple wrapper of find(). It will look for the the name of a given item in our stack_hash.
find()
The AI::ExpertSystem::Advanced::Dictionary consists of a hash of elements, each one of the elements have properties (eg, extra keys).
This method looks for the value of the given $key of a given element id.
$key
It will return the value, but if element doesn't have the given $key then undef will be returned.
Adds a new element to the stack_hash and stack. The element gets added to the end of stack.
The $id parameter specifies the id of the new element and the next parameter is a stack of extra keys.
$id
Same as append(), but the element gets added to the top of the stack.
append()
Removes the element that matches the given $id from stack_hash and stack.
Returns true if the removal is successful, otherwise false is returned.
Returns the size of stack.
Returns the first element of the iterable_array and iterable_array is reduced by one.
If no more items are found in iterable_array, undef is returned.
Same as iterate(), but instead of returning the first element, it returns the last element of iterable_array.
The iterable_array gets populated when a dictionary instance is created, however if new items are added or removed then it's extremely needed to call this method so iterable_array gets populated again.
Pablo Fischer (pablo@pablo.com.mx).
Copyright (C) 2010 by Pablo Fischer.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install AI::ExpertSystem::Advanced, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AI::ExpertSystem::Advanced
CPAN shell
perl -MCPAN -e shell install AI::ExpertSystem::Advanced
For more information on module installation, please visit the detailed CPAN module installation guide.