Changeset 34106
- Timestamp:
- 06/24/09 01:44:46 (4 years ago)
- Location:
- lang/ruby/ruby-bayon/trunk
- Files:
-
- 7 modified
-
README (modified) (1 diff)
-
bayon-mswin32.gemspec (modified) (1 diff)
-
bayon.gemspec (modified) (1 diff)
-
bayon1.9-mswin32.gemspec (modified) (1 diff)
-
ext/bayonext.cpp (modified) (6 diffs)
-
lib/bayon.rb (modified) (4 diffs)
-
package.sh (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/ruby-bayon/trunk/README
r33951 r34106 32 32 puts labels.join(', ') 33 33 end 34 35 docs.output_similairty_point = true 36 result = docs.do_clustering 37 38 result.each do |label_points| 39 puts label_points.map {|label, point| 40 "#{label}(#{point})" 41 }.join(', ') 42 end 34 43 35 44 == Project Page -
lang/ruby/ruby-bayon/trunk/bayon-mswin32.gemspec
r33956 r34106 1 1 Gem::Specification.new do |spec| 2 2 spec.name = 'bayon' 3 spec.version = '0.1. 0'3 spec.version = '0.1.1' 4 4 spec.platform = 'mswin32' 5 5 spec.summary = 'Ruby bindings for bayon.' -
lang/ruby/ruby-bayon/trunk/bayon.gemspec
r33956 r34106 1 1 Gem::Specification.new do |spec| 2 2 spec.name = 'bayon' 3 spec.version = '0.1. 0'3 spec.version = '0.1.1' 4 4 spec.summary = 'Ruby bindings for bayon.' 5 5 spec.files = Dir.glob('lib/*.*') + Dir.glob('ext/*.*') + %w(README COPYING) -
lang/ruby/ruby-bayon/trunk/bayon1.9-mswin32.gemspec
r33956 r34106 1 1 Gem::Specification.new do |spec| 2 2 spec.name = 'bayon1.9' 3 spec.version = '0.1. 0'3 spec.version = '0.1.1' 4 4 spec.platform = 'mswin32' 5 5 spec.summary = 'Ruby bindings for bayon.' -
lang/ruby/ruby-bayon/trunk/ext/bayonext.cpp
r33945 r34106 86 86 bayon::Analyzer* analyzer_; 87 87 88 bool output_similairty_point_; 89 88 90 static void free(CBayonAnalyzer *p) { 89 91 if (p->analyzer_) { … … 108 110 Data_Get_Struct(self, CBayonAnalyzer, p); 109 111 p->analyzer_ = new bayon::Analyzer; 112 p->output_similairty_point_ = false; 110 113 111 114 return Qnil; … … 145 148 } 146 149 150 static VALUE set_output_similairty_point(VALUE self, VALUE v_output) { 151 CBayonAnalyzer *p; 152 bool output = false; 153 154 if (TYPE(v_output) == T_TRUE) { 155 output = true; 156 } else if (TYPE(v_output) == T_FALSE) { 157 output = false; 158 } else { 159 rb_raise(rb_eTypeError, "wrong argument type %s (expected boolean value)"); 160 } 161 162 Data_Get_Struct(self, CBayonAnalyzer, p); 163 p->output_similairty_point_ = output; 164 165 return Qnil; 166 } 167 147 168 static VALUE do_clustering(VALUE self, VALUE v_method) { 148 169 CBayonAnalyzer *p; … … 157 178 158 179 static VALUE get_next_result(VALUE self) { 180 typedef std::vector< std::pair<bayon::Document *, double> > documents; 159 181 CBayonAnalyzer *p; 160 182 bayon::Cluster cluster; … … 163 185 164 186 if(p->analyzer_->get_next_result(cluster)) { 165 const std::vector<bayon::Document *> documents = cluster.documents(); 166 VALUE docids = rb_ary_new2(documents.size()); 167 168 for(std::vector<bayon::Document *>::const_iterator i = documents.begin(); i != documents.end(); i++) { 169 bayon::Document* doc = *i; 170 rb_ary_push(docids, LONG2NUM(doc->id())); 187 std::vector< std::pair<bayon::Document *, double> > pairs; 188 cluster.sorted_documents(pairs); 189 VALUE docids = rb_ary_new2(pairs.size()); 190 191 for(documents::const_iterator i = pairs.begin(); i != pairs.end(); i++) { 192 bayon::Document* doc = i->first; 193 double point = i->second; 194 195 if (p->output_similairty_point_) { 196 VALUE docid_points = rb_ary_new3(2, LONG2NUM(doc->id()), DBL2NUM(point)); 197 rb_ary_push(docids, docid_points); 198 } else { 199 rb_ary_push(docids, LONG2NUM(doc->id())); 200 } 171 201 } 172 202 … … 186 216 rb_define_method(rb_cBayonAnalyzer, "set_cluster_size_limit", __F(&set_cluster_size_limit), 1); 187 217 rb_define_method(rb_cBayonAnalyzer, "set_eval_limit", __F(&set_eval_limit), 1); 218 rb_define_method(rb_cBayonAnalyzer, "set_output_similairty_point", __F(&set_output_similairty_point), 1); 188 219 rb_define_method(rb_cBayonAnalyzer, "do_clustering", __F(&do_clustering), 1); 189 220 rb_define_method(rb_cBayonAnalyzer, "get_next_result", __F(&get_next_result), 0); -
lang/ruby/ruby-bayon/trunk/lib/bayon.rb
r33943 r34106 7 7 @cluster_size_limit = nil 8 8 @eval_limit = nil 9 @output_similairty_point = nil 9 10 end 10 11 … … 25 26 end 26 27 28 def output_similairty_point=(output) 29 unless output.instance_of?(TrueClass) or output.instance_of?(FalseClass) 30 raise TypeError, "wrong argument type #{limit.class} (expected boolean value)" 31 end 32 33 @output_similairty_point = output 34 end 35 27 36 def add_document(label, features) 28 37 unless features.kind_of?(Hash) … … 41 50 analyzer.set_cluster_size_limit(@cluster_size_limit) if @cluster_size_limit 42 51 analyzer.set_eval_limit(@eval_limit) if @eval_limit 52 analyzer.set_output_similairty_point(@output_similairty_point) if @output_similairty_point 43 53 44 54 feature_set = [] … … 60 70 61 71 while (cluster = analyzer.get_next_result) 62 result << cluster.map {|doc_id| @documents[doc_id][0] } 72 if @output_similairty_point 73 result << cluster.map {|doc_id, point| [@documents[doc_id][0], point] } 74 else 75 result << cluster.map {|doc_id| @documents[doc_id][0] } 76 end 63 77 end 64 78 -
lang/ruby/ruby-bayon/trunk/package.sh
r33960 r34106 1 1 #!/bin/sh 2 VERSION=0.1. 02 VERSION=0.1.1 3 3 4 4 rm *.gem *.tar.bz2 2> /dev/null
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)