Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/rbbt/bow/bow.rb,
lib/rbbt/util/misc.rb
Constant Summary collapse
- CONSONANTS =
[]
Instance Method Summary collapse
-
#arabic ⇒ Object
Turns a roman number into arabic form is possible.
-
#bigrams ⇒ Object
Shortcut for BagOfWords.bigrams(self).
-
#downcase_first ⇒ Object
Turns the first letter to lowercase.
-
#is_special? ⇒ Boolean
Uses heuristics to checks if a string seems like a special word, like a gene name.
-
#words ⇒ Object
Shortcut for BagOfWords.words(self).
Instance Method Details
#arabic ⇒ Object
Turns a roman number into arabic form is possible. Just simple romans only…
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rbbt/util/misc.rb', line 46 def arabic return 1 if self =~ /^I$/; return 2 if self =~ /^II$/; return 3 if self =~ /^III$/; return 4 if self =~ /^IV$/; return 5 if self =~ /^V$/; return 10 if self =~ /^X$/; return nil end |
#bigrams ⇒ Object
Shortcut for BagOfWords.bigrams(self)
83 84 85 |
# File 'lib/rbbt/bow/bow.rb', line 83 def bigrams BagOfWords.bigrams(self) end |
#downcase_first ⇒ Object
Turns the first letter to lowercase
37 38 39 40 41 42 |
# File 'lib/rbbt/util/misc.rb', line 37 def downcase_first return "" if self == "" letters = self.scan(/./) letters[0].downcase! letters.join("") end |
#is_special? ⇒ Boolean
Uses heuristics to checks if a string seems like a special word, like a gene name.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rbbt/util/misc.rb', line 11 def is_special? # Only consonants return true if self =~ /^[bcdfghjklmnpqrstvwxz]+$/i # Not a word return false if self =~ /[^\s]\s[^\s]/; return false if self.length < 3; # Alphanumeric return true if self =~ /[0-9]/ && self =~ /[a-z]/i # All Caps return true if self =~ /[A-Z]{2,}/; # Caps Mix return true if self =~ /[a-z][A-Z]/; # All consonants return true if self =~ /^[a-z]$/i && self !~ /[aeiou]/i # Dashed word return true if self =~ /(^\w-|-\w$)/ # To many consonants (very heuristic) if self =~ /([^aeiouy]{3,})/i && !CONSONANTS.include?($1.downcase) return true end return false end |
#words ⇒ Object
Shortcut for BagOfWords.words(self)
78 79 80 |
# File 'lib/rbbt/bow/bow.rb', line 78 def words BagOfWords.words(self) end |