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
4
3
*/
5
-
6
4
#include "ruby.h"
7
5
#include "svm_light/svm_common.h"
8
6
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
+ */
13
10
int
14
11
is_linear (MODEL * model ){
15
12
return model -> kernel_parm .kernel_type == 0 ;
@@ -33,12 +30,10 @@ doc_free(DOC *d){
33
30
free_example (d , 1 );
34
31
}
35
32
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
+ */
42
37
static VALUE
43
38
model_read_from_file (VALUE klass , VALUE filename ){
44
39
Check_Type (filename , T_STRING );
@@ -52,10 +47,7 @@ model_read_from_file(VALUE klass, VALUE filename){
52
47
return Data_Wrap_Struct (klass , 0 , model_free , m );
53
48
}
54
49
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 */
59
51
static VALUE
60
52
model_classify_example (VALUE self , VALUE example ){
61
53
DOC * ex ;
@@ -67,7 +59,7 @@ model_classify_example(VALUE self, VALUE example){
67
59
68
60
69
61
/* Apparently unnecessary code
70
- *
62
+
71
63
if(is_linear(m))
72
64
result = classify_example_linear(m, ex);
73
65
else
@@ -96,15 +88,10 @@ model_total_words(VALUE self){
96
88
return INT2FIX (m -> totwords );
97
89
}
98
90
99
- //TODO Change the format for words ary from [weight, weight, weight, ]
100
- //to [[wnum, weight], [wnum, weight] ... ]
101
91
/*
102
92
* 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.
108
95
*/
109
96
static VALUE
110
97
doc_create (VALUE klass , VALUE id , VALUE cost , VALUE words_ary ){
@@ -148,4 +135,3 @@ Init_svmredlight(){
148
135
rb_cDocument = rb_define_class_under (rb_mSvmLight , "Document" , rb_cObject );
149
136
rb_define_singleton_method (rb_cDocument , "create" , doc_create , 3 );
150
137
}
151
-
0 commit comments