Sha256: 845c5b24f83fec94c134297b1d9810f78dc481842af3d6bcfb6969d404be52cb
Contents?: true
Size: 989 Bytes
Versions: 1
Compression:
Stored size: 989 Bytes
Contents
# -*- coding: utf-8 -*- require 'sqlite3' require 'open-uri' require 'natto' module Polaris module Nlp module_function @path_to_db = "#{Dir.home}/.polaris/features.sqlite3" # init method is called in first setup. def calc_polarity(sentence) if File.exists?(@path_to_db) db = SQLite3::Database.new("#{@home}/.polaris/features.sqlite3") nm = Natto::MeCab.new sum = 0 nm.parse(sentence).split(/\n/).each do |line| elem = line.split(/\t/) break if elem[0] == 'EOS' word = (elem[1].split(/\,/)[6] == '*') ? elem[0] : elem[1].split(/\,/)[6] value = db.execute("SELECT value FROM models WHERE word = ? LIMIT 1",word)[0] sum += value[0] if value end e = Math.exp(1) return (e ** sum - e** (-1 * sum)) / (e ** sum + e** (-1 * sum)) else puts ("features.sqlite3 not found.\nplease run Polaris::Nlp.init") exit end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
polaris-nlp-0.2.0 | lib/polaris/nlp/calc.rb |