Module: Poefy
- Defined in:
- lib/poefy.rb,
lib/poefy/self.rb,
lib/poefy/version.rb,
lib/poefy/database.rb,
lib/poefy/generation.rb,
lib/poefy/handle_error.rb,
lib/poefy/poetic_forms.rb,
lib/poefy/poefy_gen_base.rb,
lib/poefy/string_manipulation.rb,
lib/poefy/core_extensions/array.rb,
lib/poefy/poetic_form_from_text.rb,
lib/poefy/conditional_satisfaction.rb
Overview
Two methods for assessing permutations of an input array versus an
array of conditions for each element.
Both methods return an output array consisting of samples from an
input array, for which output[0] satisfies condition[0], etc.
Both methods may take a whole lot of time, depending on how lenient the
conditions are. It is better for the stricter conditions to be at the
start of the array, due to the way the code is written.
If none of the conditions match, then it will run in factorial time,
which will get exponentially longer the more elements there are in the
input array.
I would recommend wrapping inside a Timeout block to assuage this. If it
fails to resolve in, say, two seconds, then it's probably not possible
to fit the conditions to the lines:
begin
Timeout::timeout(2) do
output = conditional_selection(lines.shuffle, conditions)
end
rescue
output = []
end
‘#conditional_permutation’ returns a complete permutation of an array. i.e. output length == array length Any elements in the array that are extra to the number of conditions will be assumed valid.
array = [1,2,3,4,5].shuffle
conditions = [
proc { |arr, elem| elem < 2},
proc { |arr, elem| elem > 2},
proc { |arr, elem| elem > 1}
]
possible output = [1,3,4,5,2]
‘#conditional_selection’ returns an array that satisfies only the conditions. i.e. output length == conditions length
array = [1,2,3,4,5].shuffle
conditions = [
proc { |arr, elem| elem < 2},
proc { |arr, elem| elem > 2},
proc { |arr, elem| elem > 1}
]
possible output = [1,5,3]
Condition array: Must contain boolean procs using args |arr, elem| ‘arr’ is a reference to the current array that has been built up
through the recursion chain.
‘elem’ is a reference to the current element.
Defined Under Namespace
Modules: ConditionalSatisfaction, CoreExtensions, Generation, HandleError, PoefyGenBase, PoeticFormFromText, PoeticForms, StringManipulation, VERSION Classes: Database, PoefyGen
Class Method Summary collapse
-
.all_databases ⇒ Object
Array of all ‘.db’ files in /data/.
- .version_date ⇒ Object
- .version_number ⇒ Object
Class Method Details
.all_databases ⇒ Object
Array of all ‘.db’ files in /data/. Do not include databases used for testing.
12 13 14 15 16 17 |
# File 'lib/poefy/self.rb', line 12 def self.all_databases path = File.('../../../data', __FILE__) Dir["#{path}/*.db"].map do |i| File.basename(i, '.db') end.reject{ |i| i.start_with?('spec_') } end |
.version_date ⇒ Object
14 15 16 |
# File 'lib/poefy/version.rb', line 14 def self.version_date '2017-06-19' end |