class Persian::Counter
Persian
count class Basic counters for persian chars, texts, sentences and paragraphs
Public Class Methods
character(text, char = nil)
click to toggle source
Return list a hash with list of characters in the text Hash key is the character and Hash value is number of occurrence
# File lib/persian/counter.rb, line 9 def self.character(text, char = nil) list = text.split(//) occurrence = {} occurrence.default = 0 list.each do |item| occurrence[item] += 1 end if char.nil? occurrence else occurrence[char] end end
character_counter(text)
click to toggle source
Return how many character text is
# File lib/persian/counter.rb, line 32 def self.character_counter(text) text.length end
paragraph(text)
click to toggle source
Return number of paragraph in text
# File lib/persian/counter.rb, line 55 def self.paragraph(text) list = Persian::Tokenizer.split_paragraphs text list.length end
uniq_character(text)
click to toggle source
Return number of uniq characters used in text
# File lib/persian/counter.rb, line 26 def self.uniq_character(text) text = text.split(//) text.uniq.size end
word(text, keyword = nil)
click to toggle source
Return list a hash with list of words in the text Hash key is the word and Hash value is number of occurrence
# File lib/persian/counter.rb, line 38 def self.word(text, keyword = nil) list = Persian::Tokenizer.tokenize(text) occurrence = {} occurrence.default = 0 list.each do |item| occurrence[item] += 1 end if keyword.nil? occurrence else occurrence[keyword] end end