403Webshell
Server IP : 192.158.238.246  /  Your IP : 18.116.82.202
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/cpanel/ea-ruby24/root/usr/share/gems/gems/did_you_mean-1.1.0/evaluation/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/cpanel/ea-ruby24/root/usr/share/gems/gems/did_you_mean-1.1.0/evaluation/calculator.rb
# frozen-string-literal: true

require 'benchmark'
require 'did_you_mean'

def report(message, &block)
  time = 1000 * Benchmark.realtime(&block)

  if (time / 1000 / 60) >= 1
    minutes = (time / 1000 / 60).floor
    seconds = (time % (60 * 1000)) / 1000

    puts " \e[36m%2dm%.3fs:\e[0m %s" % [minutes, seconds, message]
  elsif (time / 1000) >= 1
    seconds = (time % (60 * 1000)) / 1000

    puts " \e[36m%9.3fs:\e[0m %s" % [seconds, message]
  else
    puts " \e[36m%8.1fms:\e[0m %s" % [time, message]
  end

  time
end

puts "did_you_mean version: #{DidYouMean::VERSION}\n\n"

report "loading program" do
  require 'yaml'
  require 'set'

  begin
    require 'jaro_winkler'
    DidYouMean::JaroWinkler.module_eval do
      module_function
      def distance(str1, str2)
        ::JaroWinkler.distance(str1, str2)
      end if RUBY_ENGINE != 'jruby'
    end
  rescue LoadError, NameError => e
    puts "couldn't load the jaro_winkler gem: #{e.message}\n\n"
  end
end

report "loading dictionary" do
  yaml = open("evaluation/dictionary.yml").read
  yaml = YAML.load(yaml).map{|word| word.downcase.tr(" ", "_") }

  DICTIONARY = Set.new(yaml)
end

report "loading correct/incorrect words" do
  SPELL_CHECKER   = DidYouMean::SpellChecker.new(dictionary: DICTIONARY)
  INCORRECT_WORDS = YAML.load(open("evaluation/incorrect_words.yaml").read)
end

total_count         = 0
correct_count       = 0
words_not_corrected = []
filename            = "log/words_not_corrected_#{Time.now.to_i}.yml"

puts <<-MSG

 Total number of test data: #{INCORRECT_WORDS.size}

MSG

report "calculating accuracy" do
  INCORRECT_WORDS.each_with_index do |(expected, user_input), index|
    if DICTIONARY.include?(expected)
      total_count += 1

      corrections = SPELL_CHECKER.correct(user_input)
      if corrections.first == expected
        correct_count += 1
      else
        words_not_corrected << {
          'input'    => user_input,
          'expected' => expected,
          'actual'   => corrections
        }
      end
    end

    puts "processed #{index} items" if index % 100 == 0
  end

  puts "\n"
end

puts <<-MSG

Evaulation result

  Total count  : #{total_count}
  Correct count: #{correct_count}
  Accuracy     : #{correct_count.to_f / total_count}

MSG

Dir.mkdir('log') unless File.exist?('log')
File.open(filename, 'w') do |file|
  file.write(words_not_corrected.to_yaml)
end

puts "Incorrect corrections were logged to #{filename}."

Youez - 2016 - github.com/yon3zu
LinuXploit