Class: CategorizerSr
- Inherits:
-
Object
- Object
- CategorizerSr
- Defined in:
- lib/categorizer_sr.rb
Overview
Copyright © 2016-2018, Claudio Bustos Navarrete All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
-
Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Constant Summary collapse
- STOPWORDS =
%w{the an a with we dont to in that these those from each @ i it other how is are why}
Instance Attribute Summary collapse
-
#categorias_cd_id ⇒ Object
readonly
Returns the value of attribute categorias_cd_id.
Instance Method Summary collapse
- #cd_categoria(cd_id) ⇒ Object
- #get_stemmer_text(text) ⇒ Object
-
#initialize(rs, model = nil) ⇒ CategorizerSr
constructor
A new instance of CategorizerSr.
Constructor Details
#initialize(rs, model = nil) ⇒ CategorizerSr
Returns a new instance of CategorizerSr
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/categorizer_sr.rb', line 33 def initialize(rs,model=nil) require 'categorize' require 'lingua/stemmer' @rs=rs if(model.nil?) @model = Categorize::Models::BagOfWords.new @model.max_buckets = @rs.cd_all_id.length>0 ? Math.log(@rs.cd_all_id.length).floor*2 : 1 else @model.min_support = 0.01 @model=model end categorizer_process end |
Instance Attribute Details
#categorias_cd_id ⇒ Object (readonly)
Returns the value of attribute categorias_cd_id
30 31 32 |
# File 'lib/categorizer_sr.rb', line 30 def categorias_cd_id @categorias_cd_id end |
Instance Method Details
#cd_categoria(cd_id) ⇒ Object
73 74 75 |
# File 'lib/categorizer_sr.rb', line 73 def cd_categoria(cd_id) @cd_id_categorias[cd_id] end |
#get_stemmer_text(text) ⇒ Object
49 50 51 52 |
# File 'lib/categorizer_sr.rb', line 49 def get_stemmer_text(text) res=Lingua.stemmer(text.split(/[\s-]+/).map {|vv| vv.downcase.gsub(/[[:punct:]]/, "")}.find_all {|v| !STOPWORDS.include? v}) res.is_a?(Array) ? res.join(" ") : res end |