Skip to content

Commit b4bec9d

Browse files
author
Camilo Lopez
committed
putting things in order
1 parent 832c3da commit b4bec9d

File tree

6 files changed

+25
-68
lines changed

6 files changed

+25
-68
lines changed

README.rdoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
= svmredlight
2+
Very partial interface to SVM-light [http://svmlight.joachims.org/] it permits loading a
3+
model (pre-created with svm_learn) from a file and using it for classification.
24

3-
Description goes here.
5+
As of now it's know to work with SVM 6.02.
46

57
== Contributing to svmredlight
68

ext/svmredlight.c

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
/* Very partial interface to SVMLIGHT it permits loading
2-
* a model (pre-created with svm_learn) from a file and using
3-
* it from classification for examples see test.rb
1+
/* Very partial interface to SVMLIGHT it permits loading a model (pre-created with
2+
* svm_learn) from a file and using it from classification for examples see test.rb
43
*/
5-
64
#include "ruby.h"
75
#include "svm_light/svm_common.h"
86

9-
/* Helper function to determine if
10-
* a model uses linear kernel, this should
11-
* be a #define macro
12-
* */
7+
/* Helper function to determine if a model uses linear kernel, this could be a #define
8+
* macro
9+
*/
1310
int
1411
is_linear(MODEL *model){
1512
return model->kernel_parm.kernel_type == 0;
@@ -33,12 +30,10 @@ doc_free(DOC *d){
3330
free_example(d, 1);
3431
}
3532

36-
/* Read a svm_light model from a file generated
37-
* by svm_learn receives the filename as argument
38-
* make sure the file exists before calling this!
39-
* otherwise exit(1) might be called
40-
*
41-
* */
33+
/* Read a svm_light model from a file generated by svm_learn receives the filename as
34+
* argument do make sure the file exists before calling this! otherwise exit(1) might be
35+
* called and the ruby interpreter will die.
36+
*/
4237
static VALUE
4338
model_read_from_file(VALUE klass, VALUE filename){
4439
Check_Type(filename, T_STRING);
@@ -52,10 +47,7 @@ model_read_from_file(VALUE klass, VALUE filename){
5247
return Data_Wrap_Struct(klass, 0, model_free, m);
5348
}
5449

55-
/*
56-
* Classify, gets a example (instance of Document)
57-
* and returns its classification
58-
*/
50+
/* Classify, gets a example (instance of Document) and returns its classification */
5951
static VALUE
6052
model_classify_example(VALUE self, VALUE example){
6153
DOC *ex;
@@ -67,7 +59,7 @@ model_classify_example(VALUE self, VALUE example){
6759

6860

6961
/* Apparently unnecessary code
70-
*
62+
7163
if(is_linear(m))
7264
result = classify_example_linear(m, ex);
7365
else
@@ -96,15 +88,10 @@ model_total_words(VALUE self){
9688
return INT2FIX(m->totwords);
9789
}
9890

99-
//TODO Change the format for words ary from [weight, weight, weight, ]
100-
//to [[wnum, weight], [wnum, weight] ... ]
10191
/*
10292
* Creates a DOC from an array of words it also takes an id
103-
* -1 is normally OK for that value when using in filtering
104-
* also takes the C parameter for the SVM. I'm not sure if
105-
* it matters in filtering, I'm passing the real vale now
106-
* just in case.
107-
*
93+
* -1 is normally OK for that value when using in filtering it also takes the C (cost)
94+
* parameter for the SVM.
10895
*/
10996
static VALUE
11097
doc_create(VALUE klass, VALUE id, VALUE cost, VALUE words_ary ){
@@ -148,4 +135,3 @@ Init_svmredlight(){
148135
rb_cDocument = rb_define_class_under(rb_mSvmLight, "Document", rb_cObject);
149136
rb_define_singleton_method(rb_cDocument, "create", doc_create, 3);
150137
}
151-

svmredlight.gemspec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
1010
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
1111
s.authors = ["Camilo Lopez"]
1212
s.date = %q{2011-06-08}
13-
s.description = %q{TODO: longer description of your gem}
13+
s.description = %q{Ruby interface to SVMLight}
1414
s.email = %q{[email protected]}
1515
s.extensions = ["ext/extconf.rb"]
1616
s.extra_rdoc_files = [
@@ -27,14 +27,15 @@ Gem::Specification.new do |s|
2727
"ext/extconf.rb",
2828
"ext/svmredlight.c",
2929
"lib/svmredlight.rb",
30+
"svmredlight.gemspec",
3031
"test/helper.rb",
3132
"test/test_svmredlight.rb"
3233
]
3334
s.homepage = %q{http://github.com/camilo/svmredlight}
3435
s.licenses = ["MIT"]
3536
s.require_paths = ["lib"]
3637
s.rubygems_version = %q{1.5.0}
37-
s.summary = %q{TODO: one-line summary of your gem}
38+
s.summary = %q{Ruby interface to SVMLight}
3839

3940
if s.respond_to? :specification_version then
4041
s.specification_version = 3

test/svm_light_test.rb

Lines changed: 0 additions & 34 deletions
This file was deleted.

test/test_document.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
include SVMLight
55

66
class TestDocument < Test::Unit::TestCase
7+
78
def test_create
8-
assert d = Document.create(0, 0.5, [1.0, 0, 0, 0, 0.5])
9+
assert Document.create(0, 0.5, [1.0, 0, 0, 0, 0.5])
910
end
1011

1112
def test_create_with_no_array

test/test_model.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ def test_read
1010

1111
def test_classify
1212
m = Model.read_from_file('test/model')
13-
assert m.classify( Document.create(-1, 0, [1.0, 0, 0, 0, 0.5 ]))
14-
assert m.classify( Document.create(-1, 0, [0, 0, 0, 0, 0.8, 0, 0 , 0 ]))
15-
assert m.classify( Document.create(-1, 0, [0, 0.5, 0, 0, 0, 0 , 0 ]))
13+
assert m.classify( Document.create(-1, 0, [1.0, 0, 0, 0, 0.5 ])).is_a?(Numeric)
14+
assert m.classify( Document.create(-1, 0, [1.0, 0, 0, 0, 0.5 ])).is_a?(Numeric)
15+
assert m.classify( Document.create(-1, 0, [0, 0, 0, 0, 0.8, 0, 0 , 0 ])).is_a?(Numeric)
16+
assert m.classify( Document.create(-1, 0, [0, 0.5, 0, 0, 0, 0 , 0 ])).is_a?(Numeric)
1617
end
1718

1819
def test_new_is_private

0 commit comments

Comments
 (0)