我没有尝试过,但如果你只关心英语,我建议看一下
Lingua::EN::Readability。
Lingua::EN::Readability是一个Ruby模块,用于计算英文文本的统计信息。它可以提供单词、句子和音节的计数。它还可以计算几种可读性指标,如Fog指数和Flesch-Kincaid级别。该包括模块Lingua::EN::Sentence,将英文文本分成句子并注意缩写,以及Lingua::EN::Syllable,可以猜测书面英语单词的音节数。如果有发音字典,则可以查找字典中的音节数以提高准确性。
你需要的部分在sentence.rb文件中,如下所示:
module Lingua
module EN
module Sentence
EOS = "\001"
Titles = [ 'jr', 'mr', 'mrs', 'ms', 'dr', 'prof', 'sr', 'sen', 'rep',
'rev', 'gov', 'atty', 'supt', 'det', 'rev', 'col','gen', 'lt',
'cmdr', 'adm', 'capt', 'sgt', 'cpl', 'maj' ]
Entities = [ 'dept', 'univ', 'uni', 'assn', 'bros', 'inc', 'ltd', 'co',
'corp', 'plc' ]
Months = [ 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul',
'aug', 'sep', 'oct', 'nov', 'dec', 'sept' ]
Days = [ 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun' ]
Misc = [ 'vs', 'etc', 'no', 'esp', 'cf' ]
Streets = [ 'ave', 'bld', 'blvd', 'cl', 'ct', 'cres', 'dr', 'rd', 'st' ]
@@abbreviations = Titles + Entities + Months + Days + Streets + Misc
def Sentence.sentences(text)
text = text.dup
text.gsub!( /([\.?!](?:\"|\'|\)|\]|\})?)(\s+)/ ) { $1 << EOS << $2 }
text.gsub!( /(\.\.\.*)#{EOS}/ ) { $1 }
text.gsub!( /(#{@@abbreviations.join("|")})\.#{EOS}/i ) { $1 << '.' }
text.split(EOS).map { | sentence | sentence.strip }
end
def Sentence.abbreviation(*abbreviations)
@@abbreviations += abbreviations
@@abbreviations
end
end
end
end