Class LOLspeak::Tranzlator
In: lib/lolspeak.rb
Parent: Object

A class to perform English to LOLspeak translation based on a dictionary of words.

Methods

Attributes

heuristics_exclude  [RW]  (Set) Words to exclude if heuristics are on.
trace  [RW]  (bool -> false) Wether or not to record translations
traced_words  [R]  (Hash) Stores all translations, if trace is true.
translated_heuristics  [R]  (Hash) Stores all words translated via heuristics, if try_heuristics is true.
try_heuristics  [RW]  (bool -> false) If true, try heurstics when translating words. If false, only use the dictionary for translation.

Public Class methods

Creates a Tranzlator using a dictionary from a YAML file

Creates a Tranzlator from the given dictionary

Public Instance methods

Clears the trace word hash

Clears the hash storing words translated by heuristics

Translates a single word into LOLspeak. By default, the result is in all lower case:

  translator.translate_word("Hi") -> "oh hai"

If a block is given the word may be transformed. You could use this to upper case or XML encode the result. This example upper cases the result:

  translator.translate_word("hi") { |w| w.upcase } -> "OH HAI"

If heuristics are off, then only words in the dictionary are translated. If heuristics are on, then words not in the dictionary may be translated using standard LOLspeak heuristics, such as "*tion" -> "*shun".

Translates all the words in a string. If a block is given, it is called to transform each individual word.

Translates the REXML::Text parts of a single REXML::Element. The element is modified in place.

If a block is given, it is called to transform each individual word. By default, each word is XML escaped, so this transform applies on top of that.

Translates the REXML::Text parts of an REXML::Element and all child elements. The elements are modified in place.

If a block is given, it iscalled to transform each individual word. By default, each word is XML escaped, so this transform applies on top of that.

Translates the text parts of a well-formed XML string. It parses the string using REXML and then translates the root element using translate_xml_element_recursive!.

If a block is given, it is called to transform each individual word.

[Validate]