Class: Cardreader::Manage
- Inherits:
-
Object
- Object
- Cardreader::Manage
- Defined in:
- lib/cardreader/manage.rb
Instance Method Summary collapse
- #detect(image) ⇒ Object
- #distill(keyword, reg) ⇒ Object
-
#initialize(key) ⇒ Manage
constructor
A new instance of Manage.
- #make(text) ⇒ Object
- #preprocess ⇒ Object
Constructor Details
Instance Method Details
#detect(image) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/cardreader/manage.rb', line 35 def detect(image) @detected_text = @vision.post(image) preprocess text = @lang.post(@detected_text) make(text) end |
#distill(keyword, reg) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/cardreader/manage.rb', line 11 def distill(keyword, reg) matched = @detected_text.match(reg) if matched matched = matched[0] @detected_text.gsub!(/#{matched.gsub(/\+/,'')}/, "") @results[keyword] = matched end end |
#make(text) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cardreader/manage.rb', line 42 def make(text) text.each do |t| case t["type"] when "PERSON" @results[:person] = t["name"] when "ORGANIZATION" @results[:organization] = " " + t["name"] + @results[:organization] when "LOCATION" @results[:location] = " " + t["name"] + @results[:location] else end end @results.to_json end |
#preprocess ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cardreader/manage.rb', line 21 def preprocess reg= /[^\s]+[\s]*(Corp|Ltd|Inc|Co|株式会社)/ distill(:company, reg) reg = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/ distill(:mail, reg) reg = /(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?/ distill(:url, reg) reg = /(\+[\dO]{2}[\-])?[\dO]{2,5}[\-(][\dO]{1,4}[\-)][\dO]{4}/ distill(:phone, reg) end |