Class: Ovec::Tier
- Inherits:
-
TextManipulator
- Object
- TextManipulator
- Ovec::Tier
- Defined in:
- lib/ovec/tier.rb
Constant Summary collapse
- REGEX =
The last character this regex matches is changed to a tilde.
/( ((\p{Z}|\~|\n)[KkSsVvZzOoUu]\p{Z})| # KSVZOU jako samostatne slovo ([\.\?\!](\p{Z}|\~)+[KSVZOUAI]\p{Z})| # KSVZOUAI na zacatku vety (\A[KSVZOUAI]\p{Z})| # KSVZOUAI na zacatku textu (\p{Z}(?=--(\p{Z}|\n)))| # mezera, za kterou je pomlcka (,(\p{Z}|\~|\n)+a\p{Z}) # ... modulo 10, a~timto prvkem ...; TODO: plati tohle i pro "i"? )/x
- DATE_REGEX =
TODO: generally tie “5.~batalion”, … All changes within this regex are changed to a tilde.
/( (?<=\p{Z})\p{Nd}{1,2}\.\p{Z} (\p{Nd}{1,2}\.|leden|únor|březen|duben|květen|červen|červenec|srpen|září|říjen|listopad|prosinec| # TODO: plne sklonovani? nebo nejaky wildcard? ledna|února|března|dubna|května|června|července|srpna|září|října|listopadu|prosince)\p{Z} \p{Nd}{4}(?=\p{Z}) # Datum jako "1. 5. 2013" )/x
Instance Method Summary collapse
Methods inherited from TextManipulator
Instance Method Details
#run ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ovec/tier.rb', line 23 def run # ~ neni mezi \p{Z}. # TODO: moznosti na dvojpismenne predlozky matches = @joined.to_enum(:scan, REGEX).map { Regexp.last_match } # Matches may overlap, find all matches with more scans. # TODO: optimize until matches.empty? for i in 0...matches.length # TODO: check ze za tim neni tilda nikde (napr. na dalsim radku, par mezer pozdeji, ...) match = matches[i] change = match.end(0) - 1 chunk, offset = _find_chunk_and_offset(change) chunk[offset] = '~' end _rejoin matches = @joined.to_enum(:scan, REGEX).map { Regexp.last_match } end # Dates can't overlap. 1 scan is enough. matches = @joined.to_enum(:scan, DATE_REGEX).map { Regexp.last_match } for i in 0...matches.length match = matches[i] for j in match.begin...match.end if @joined[j] == ' ' chunk, offset = _find_chunk_and_offset(j) chunk[offset] = '~' end end end end |