Sha256: 6a2ae5f759d4aba51fbfcee2e096ce250e0d237829052f20c68ca97c98010651

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

# encoding: utf-8

require "harmonious_dictionary/rseg"
require "harmonious_dictionary/version"
require "harmonious_dictionary/model_additions"
require "harmonious_dictionary/railtie" if defined? Rails
   

module HarmoniousDictionary
  def self.clean?(input, model = nil)
    results = HarmoniousDictionary::Rseg.segment(input, model)
    results.size > 0 ? false : true
  end

  def self.clean_by_remote?(input)
    results = HarmoniousDictionary::Rseg.remote_segment(input)
    results.size > 0 ? false : true
  end

  def self.clean_by_remote(input)
    results = HarmoniousDictionary::Rseg.remote_segment(input)
    results.each do |result|
      encode_result = result.force_encoding('utf-8')
      input.gsub! /#{encode_result}/,self.clean_word_basic(encode_result)
    end
    input
  end

  def self.clean(input, model = nil)
    results = HarmoniousDictionary::Rseg.segment(input, model)
    results.each{|result| input.gsub! /#{result}/,self.clean_word_basic(result) }
    input
  end

  def self.harmonious_words(input, model = nil)
    return HarmoniousDictionary::Rseg.segment(input, model)
  end

  def self.clean_word_basic(word)
    clearn_words = ""
    word.size.times{  clearn_words << "*" }
    clearn_words
  end

  def self.chinese_harmonious
    Rseg.instance.send(:engines).first.dictionary
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
harmonious_check-0.0.2 lib/harmonious_dictionary.rb