Sha256: 26537aa467bd1696a3df55df012d8fa28aaebcfa949e6b4b8dfa8893906efffb
Contents?: true
Size: 1.38 KB
Versions: 2
Compression:
Stored size: 1.38 KB
Contents
# -*- coding: UTF-8 -*- # Persian Module module Persian # Persian count class # Basic counters for persian chars, texts, sentences and paragraphs class Counter # Return list a hash with list of characters in the text # Hash key is the character and Hash value is number of occurrence 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 # Return number of uniq characters used in text def self.uniq_character(text) text = text.split(//) text.uniq.size end # Return how many character text is def self.character_counter(text) text.length end # Return list a hash with list of words in the text # Hash key is the word and Hash value is number of occurrence 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 # Return number of paragraph in text def self.paragraph(text) list = Persian::Tokenizer.split_paragraphs text list.length end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
persian-0.2.2 | lib/persian/counter.rb |
persian-0.2.1 | lib/persian/counter.rb |