Module: ZhongwenTools::Regex

Defined in:
lib/zhongwen_tools/regex.rb

Class Method Summary collapse

Class Method Details

.bopomofoObject

Public: A Regex for bopomofo, a.k.a. Zhuyin Fuhao 注音符号.

Examples

bopomofo #=> <Regex>

Returns a Regex.



76
77
78
# File 'lib/zhongwen_tools/regex.rb', line 76

def self.bopomofo
  /\p{Bopomofo}/
end

.capital_lettersObject



27
28
29
# File 'lib/zhongwen_tools/regex.rb', line 27

def self.capital_letters
  /(#{Regexp.union(ZhongwenTools::Caps::CAPS.keys)})/
end

.fullwidthObject



23
24
25
# File 'lib/zhongwen_tools/regex.rb', line 23

def self.fullwidth
  /[0-9A-Za-z%.:#$&+-/\=;<>]/
end

.lowercase_lettersObject



31
32
33
# File 'lib/zhongwen_tools/regex.rb', line 31

def self.lowercase_letters
  /(#{Regexp.union(ZhongwenTools::Caps::CAPS.values)})/
end

.pinyin_numObject



15
16
17
# File 'lib/zhongwen_tools/regex.rb', line 15

def self.pinyin_num
  /(([BPMFDTNLGKHZCSRJQXWYbpmfdtnlgkhzcsrjqxwy]?[h]?)(A[io]?|a[io]?|i[aeu]?o?|Ei?|ei?|Ou?|ou?|u[aoe]?i?|ve?)?(n?g?)(r?)([1-5])(\-+)?)/
end

.pinyin_tonelessObject



19
20
21
# File 'lib/zhongwen_tools/regex.rb', line 19

def self.pinyin_toneless
  @pynt ||= /(#{pyn_regexes.values.join('|')}|r)([\s\-]+)?/
end

.puncObject



39
40
41
# File 'lib/zhongwen_tools/regex.rb', line 39

def self.punc
  /\p{Punct}/
end

.pyObject



9
10
11
12
13
# File 'lib/zhongwen_tools/regex.rb', line 9

def self.py
  # FIXME: need to detect Ālābó
  # ([ĀÁǍÀA][io]?|[io]?|[][āáǎàaēéěèeūúǔùu]?o?|[ĒÉĚÈE]i?|[]i?|[ŌÓǑÒO]u?|[]u?|u[āáǎàaēoēéěèe]?i?|[]e?)(n?g?r?)){1,}
  @py ||= /(#{pyn_regexes.map{|k,v| v.to_s[7..-2].gsub(/[aeiouv]/,py_tones)}.join('|')}([\s\-])?)/
end

.pynObject



5
6
7
# File 'lib/zhongwen_tools/regex.rb', line 5

def self.pyn
  @pyn ||= /(#{pyn_regexes.values.join('|')}|r)([1-5])([\s\-]+)?/
end

.zhObject



35
36
37
# File 'lib/zhongwen_tools/regex.rb', line 35

def self.zh
  /\p{Han}/
end

.zh_number_multipleObject



64
65
66
# File 'lib/zhongwen_tools/regex.rb', line 64

def self.zh_number_multiple
  /[拾十百佰千仟万萬亿億]/
end

.zh_numbersObject



48
49
50
51
52
53
# File 'lib/zhongwen_tools/regex.rb', line 48

def self.zh_numbers
  # TODO: include numbers like yotta, etc.
  # 垓	秭	穰	溝	澗	正	載 --> beyond 100,000,000!
  # Regional: Dong Guai
  /[〇零一壹幺二贰貳两兩三弎叁參仨四肆䦉五伍六陆陸七柒八捌九玖十拾廿卅百佰千仟万萬亿億]/
end

.zh_puncObject



43
44
45
46
# File 'lib/zhongwen_tools/regex.rb', line 43

def self.zh_punc
  # TODO: includes non-zh punctuation codes. Should only include punctuation in CJK ranges.
  /[\u2E00-\u2E2E]|[\u2E30-\u2E3B]|[\u3001-\u3003]|[\u3008-\u3011]|[\u3014-\u301F]|[\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF]|[\uA60D-\uA60F]|[\uA673\uA67E]|[\uA6F2-\uA6F7]|[\uA874-\uA877]|[\uA8CE\uA8CF]|[\uA8F8-\uA8FA]|[\uA92E\uA92F\uA95F]|[\uA9C1-\uA9CD]|[\uA9DE\uA9DF]|[\uAA5C-\uAA5F]|[\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F]|[\uFE10-\uFE19]|[\uFE30-\uFE52]|[\uFE54-\uFE61]|[\uFE63\uFE68\uFE6A\uFE6B]|[\uFF01-\uFF03]|[\uFF05-\uFF0A]|[\uFF0C-\uFF0F]|[\uFF1A\uFF1B\uFF1F\uFF20]|[\uFF3B-\uFF3D]|[\uFF3F\uFF5B\uFF5D]|[\uFF5F-\uFF65]/
end

.zhs_numbersObject



55
56
57
58
# File 'lib/zhongwen_tools/regex.rb', line 55

def self.zhs_numbers
  # TODO: check if 佰,仟 are the financial numbers in zhs
  /[〇零一壹幺二贰两三弎叁仨四肆䦉五伍六陆七柒八捌九玖十拾廿卅百佰千仟万亿]/
end

.zht_numbersObject



60
61
62
# File 'lib/zhongwen_tools/regex.rb', line 60

def self.zht_numbers
  /[〇零一壹幺二貳兩三弎參仨四肆䦉五伍六陸七柒八捌九玖十拾廿卅佰千仟萬億]/
end