小型文本编辑器
发布时间:2020-12-17 04:09:32 所属栏目:百科 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 stop_words = %w{the by on for of are with just but and to the my I has some in}lines = File.readlines(ARGV[0])line_count = lines.sizetext =
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 stop_words = %w{the by on for of are with just but and to the my I has some in} lines = File.readlines(ARGV[0]) line_count = lines.size text = lines.join total_characters = text.length total_characters_nospaces = text.gsub(/s+/,'').length word_count = text.split.length sentence_count = text.split(/.|?|!/).length paragraph_count = text.split(/nn/).length all_words = text.scan(/w/) good_words = all_words.select{|word|!stop_words.include?(word)} good_percentage = ((good_words.length.to_f / all_words.length.to_f)*100).to_i sentences = text.gsub(/s+/,'').strip.split(/.|?|!/) sentences_sorted = sentences.sort_by {|sentence| sentence.length} one_third = sentences_sorted.length / 3 ideal_sentences = sentences_sorted.slice(one_third,one_third + 1) ideal_sentences = ideal_sentences.select {|sentence|sentence =~/is/} puts "#{line_count} lines" puts "#{total_characters} characters" puts "#{total_characters_nospaces} characters excluding space" puts "#{word_count} words" puts "#{sentence_count} sentences" puts "#{paragraph_count} paragraphs" puts "#{sentence_count / paragraph_count} sentences per paragraph average" puts "#{word_count / sentence_count} words per sentence average" puts "#{good_percentage}%of words are non-fluff words" puts "Summary:n n" + ideal_sentences.join(".") puts "--End of analysis" 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |