Last active
December 10, 2015 03:28
-
-
Save ChangJoo-Park/4374375 to your computer and use it in GitHub Desktop.
oliver.txt파일을 읽어 파일의 내용을 분석한다.
전체 길이, 글자수(공백 유무), 단어, 문장, 문단의 수를 분석
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
lines=File.readlines("oliver.txt") | |
line_count=lines.size | |
text=lines.join | |
total_character=text.length | |
total_character_no_whitespace=text.gsub(/\s+/,'').length | |
word_count=text.split.length | |
paragraph_count=text.split(/\n\n/).length | |
sentence_count=text.split(/\.|\!|\?/).length | |
puts "전체 길이 : #{line_count}" | |
puts "전체 글자 수(공백포함) : #{total_character}" | |
puts "전체 글자 수(공백없음) : #{total_character_no_whitespace}" | |
puts "전체 단어 수 : #{word_count}" | |
puts "전체 문장 수 : #{sentence_count}" | |
puts "전체 문단 수 : #{paragraph_count}" | |
puts "문단 내의 문장 수 평균 : #{sentence_count/paragraph_count} " | |
puts "문장 내의 단어 수 평균 : #{word_count/sentence_count}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment