[Groonga-commit] ranguba/chupa-text at a146672 [master] Introduce `Decomposer#target_score`

Back to archive index
Kouhei Sutou null+****@clear*****
Mon Feb 25 12:02:55 JST 2019


Kouhei Sutou	2019-02-25 12:02:55 +0900 (Mon, 25 Feb 2019)

  Revision: a1466720a6bbad86af22795b39ef63aef694f699
  https://github.com/ranguba/chupa-text/commit/a1466720a6bbad86af22795b39ef63aef694f699

  Message:
    Introduce `Decomposer#target_score`
    
    It's for choosing fallback decomposer.

  Modified files:
    lib/chupa-text/decomposer.rb
    lib/chupa-text/extractor.rb

  Modified: lib/chupa-text/decomposer.rb (+8 -0)
===================================================================
--- lib/chupa-text/decomposer.rb    2018-07-18 09:20:13 +0900 (6bd45ab)
+++ lib/chupa-text/decomposer.rb    2019-02-25 12:02:55 +0900 (75b1a2c)
@@ -30,6 +30,14 @@ module ChupaText
       raise NotImplementedError, "must implement #{self.class}\##{__method__}"
     end
 
+    def target_score(data)
+      if target?(data)
+        0
+      else
+        nil
+      end
+    end
+
     def decompose(data)
       raise NotImplementedError, "must implement #{self.class}\##{__method__}"
     end

  Modified: lib/chupa-text/extractor.rb (+8 -2)
===================================================================
--- lib/chupa-text/extractor.rb    2018-07-18 09:20:13 +0900 (f62e07e)
+++ lib/chupa-text/extractor.rb    2019-02-25 12:02:55 +0900 (d564e16)
@@ -99,9 +99,15 @@ module ChupaText
     end
 
     def find_decomposer(data)
-      @decomposers.find do |decomposer|
-        decomposer.target?(data)
+      candidates = []
+      @decomposers.each do |decomposer|
+        score = decomposer.target_score(data)
+        next if score.nil?
+        candidates << [score, decomposer]
       end
+      return nil if candidates.empty?
+      candidate = candidates.sort_by {|score, _| score}.first
+      candidate[1]
     end
 
     def log_tag
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190225/46f31a1a/attachment.html>


More information about the Groonga-commit mailing list
Back to archive index