typify 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/typify.rb +63 -0
  3. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1312ba3f8a7ddce9a11b27e013a7c99ec4a11fbc
4
+ data.tar.gz: 925b1fdc9b8d548ab2f7a6075aeead574852c305
5
+ SHA512:
6
+ metadata.gz: 789be577abdc9c853c49815880a337b6e132443b0e932f473ba05a27b1c77c6c47b1239e03de07b083548540bddad58460bbc54c2de5fcb18754c499857cff41
7
+ data.tar.gz: 10d7d6da34c57f0d450b3e698d44d4fc4fdb6917fdb9321014e668c6286caff80f33e4abf0c83ded6ee891792858e0f9359f60894c0b92bf252f05a2d30251d7
@@ -0,0 +1,63 @@
1
+ class Typify
2
+
3
+ VOWELS = "aeiou"
4
+ CONSONANTS = ("a".."z").reject {|l| VOWELS.include? l }.join
5
+ SAMPLE_TEXT = <<-EOF
6
+ Randomness means lack of pattern or predictability in events.[1] Randomness suggests a non-order or non-coherence in a sequence of symbols or steps, such that there is no intelligible pattern or combination.
7
+ Random events are individually unpredictable, but the frequency of different outcomes over a large number of events (or "trials") are frequently predictable. For example, when throwing two dice and counting the total, a sum of 7 will randomly occur twice as often as 4, but the outcome of any particular roll of the dice is unpredictable. This view, where randomness simply refers to situations where the certainty of the outcome is at issue, applies to concepts of chance, probability, and information entropy. In these situations, randomness implies a measure of uncertainty, and notions of haphazardness are irrelevant.
8
+ The fields of mathematics, probability, and statistics use formal definitions of randomness. In statistics, a random variable is an assignment of a numerical value to each possible outcome of an event space. This association facilitates the identification and the calculation of probabilities of the events. A random process is a sequence of random variables describing a process whose outcomes do not follow a deterministic pattern, but follow an evolution described by probability distributions. These and other constructs are extremely useful in probability theory.
9
+ Randomness is often used in statistics to signify well-defined statistical properties. Monte Carlo methods, which rely on random input, are important techniques in science, as, for instance, in computational science.[2]
10
+ Random selection is a method of selecting items (often called units) from a population where the probability of choosing a specific item is the proportion of those items in the population. For example, if we have a bowl of 100 marbles with 10 red (and any red marble is indistinguishable from any other red marble) and 90 blue (and any blue marble is indistinguishable from any other blue marble), a random selection mechanism would choose a red marble with probability 1/10. Note that a random selection mechanism that selected 10 marbles from this bowl would not necessarily result in 1 red and 9 blue. In situations where a population consists of items that are distinguishable, a random selection mechanism requires equal probabilities for any item to be chosen. That is, if the selection process is such that each member of a population, of say research subjects, has the same probability of being chosen then we can say the selection process is random.
11
+ EOF
12
+
13
+ def initialize(words = SAMPLE_TEXT)
14
+ @mapping = sample_words words
15
+ end
16
+
17
+ attr_accessor :mapping
18
+
19
+ def sample_words(words = SAMPLE_TEXT)
20
+ @mapping ||= Hash.new
21
+ @mapping[:chars] ||= Hash.new
22
+ @mapping[:starts] ||= Hash.new
23
+ @mapping[:lengths] ||= Array.new
24
+ ("a".."z").each { |l| mapping[:chars][l] = "" }
25
+ words = words.downcase.split(/[^a-z]+/)
26
+
27
+ words.each do |w|
28
+ next if w.length == 0
29
+ @mapping[:lengths] << w.length
30
+ @mapping[:starts][w.length] ||= ""
31
+ @mapping[:starts][w.length] << w[0].to_s if w
32
+ w.length.times do |i|
33
+ @mapping[:chars][w[i]] << w[i+1] if w[i+1]
34
+ end
35
+ end
36
+
37
+ return @mapping
38
+ end
39
+
40
+ def random(length = @mapping[:lengths].sample)
41
+ word = String.new
42
+ word << @mapping[:starts][length].split('').sample
43
+ length.times do |l|
44
+ begin
45
+ word << @mapping[:chars][word[l]].split('').sample
46
+ rescue
47
+ # there was no mapping here
48
+ end
49
+ end
50
+ word
51
+ end
52
+
53
+ def make(length = rand(7..50))
54
+ words = Array.new
55
+ length.times { words << random }
56
+ words
57
+ end
58
+
59
+ end
60
+
61
+ # List of sample words is analyzed for frequency of next letter occurance..
62
+ # generates a probability for what the next letter should be.
63
+ # Pick a random letter based on that probability.
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: typify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex Clink
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Takes a sample text and generates words based on the charictarists of
14
+ that text
15
+ email: code@alexclink.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/typify.rb
21
+ homepage: https://github.com/SleepingInsomniac/typify
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.4.5
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Babble on.
45
+ test_files: []