svmlightcli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 47812adeae8ac5a264485ac0c22d08925697641d
4
+ data.tar.gz: c1a90ced6c01a0516063697ecceb80a4e996f9dc
5
+ SHA512:
6
+ metadata.gz: d544caeb924c3d364a12ca86ae5f51e73dd1877014f30bc4254692ef550cdb8afee8ab17ec05cbaf24def082ed41bd252d6a9a1133e3af43481ef45b33d380b8
7
+ data.tar.gz: 559b30f61f2ab3dfd8988ed5ab7ba86b58436b4b65d6174966f516307a2e7b16a5cd4bf74ca5859b643eb65811f01b689d4360afe99783fc7f20a73abafbc979
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.bundle
10
+ *.so
11
+ *.o
12
+ *.a
13
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in svmlightcli.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ svmlightcli (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.5.0)
10
+ rake-compiler (1.0.4)
11
+ rake
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.14)
18
+ rake (~> 10.0)
19
+ rake-compiler
20
+ svmlightcli!
21
+
22
+ BUNDLED WITH
23
+ 1.14.6
data/LICENSE.txt ADDED
@@ -0,0 +1,85 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 QCRI - Hossam Hammady
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
23
+ ---
24
+
25
+ Original SVM-Light license:
26
+
27
+ SVM-Light
28
+ ---------
29
+
30
+ Available at http://svmlight.joachims.org/
31
+
32
+ Author: Thorsten Joachims
33
+ thorsten@joachims.org
34
+
35
+ Cornell University
36
+ Department of Computer Science
37
+ 4153 Upson Hall
38
+ Ithaca, NY 14853
39
+ USA
40
+
41
+ LICENSING TERMS
42
+
43
+ This program is granted free of charge for research and education
44
+ purposes. However you must obtain a license from the author to use it
45
+ for commercial purposes.
46
+
47
+ Scientific results produced using the software provided shall
48
+ acknowledge the use of SVM-Light. Please cite as
49
+
50
+ T. Joachims, Making large-Scale SVM Learning
51
+ Practical. Advances in Kernel Methods - Support Vector
52
+ Learning, B. Schölkopf and C. Burges and A. Smola (ed.),
53
+ MIT-Press, 1999.
54
+ http://www-ai.cs.uni-dortmund.de/DOKUMENTE/joachims_99a.pdf
55
+
56
+ Moreover shall the author of SVM-Light be informed about the
57
+ publication.
58
+
59
+ The software must not be modified and distributed without prior
60
+ permission of the author.
61
+
62
+ By using SVM-Light you agree to the licensing terms.
63
+
64
+
65
+ NO WARRANTY
66
+
67
+ BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
68
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT
69
+ WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER
70
+ PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND,
71
+ EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
72
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
73
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
74
+ PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME
75
+ THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
76
+
77
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
78
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
79
+ REDISTRIBUTE THE PROGRAM, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
80
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF
81
+ THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO
82
+ LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
83
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY
84
+ OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED
85
+ OF THE POSSIBILITY OF SUCH DAMAGES.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # svmlightcli
2
+
3
+ This is a convenience gem wrapper for the [svm_light](http://svmlight.joachims.org/)
4
+ command line binaries. No Ruby interfaces.
5
+ After installation, it offers 2 binaries in the path: `svm_learn` and `svm_classify`.
6
+ In other words, it is something like:
7
+ `brew install svm_light` or `apt-get install svm_light`
8
+ (which do not exist), but using the RubyGems way.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'svmlightcli'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install svmlightcli
25
+
26
+ ## Usage
27
+
28
+ Use the binaries the same exact way you use them when compiling from source:
29
+
30
+ $ svm_learn ...
31
+
32
+ $ svm_classify ...
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hammady/svmlightcli.
43
+
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
48
+ The original license of the svm_light author is also maintained in [LICENSE.txt](https://github.com/hammady/svmlightcli/blob/master/LICENSE.txt).
49
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/extensiontask"
3
+
4
+ task :build => :compile
5
+
6
+ Rake::ExtensionTask.new("svmlightcli") do |ext|
7
+ ext.lib_dir = "lib/svmlightcli"
8
+ end
9
+
10
+ task :default => [:clobber, :compile, :spec]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "svmlightcli"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/svm_classify ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This is copied from the generated RubyGems bin stub
4
+ # It basically runs a specified version of the gem if given
5
+
6
+ version = ">= 0.a"
7
+
8
+ if ARGV.first
9
+ str = ARGV.first
10
+ str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
11
+ if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
12
+ version = $1
13
+ ARGV.shift
14
+ end
15
+ end
16
+
17
+ gem 'svmlightcli', version
18
+
19
+ # Now we don't want to just load the ruby bin file, we want to execute it
20
+ # The reason is that it may not be necessarily a ruby file, could be native
21
+ system(Gem.bin_path('svmlightcli', 'svm_classify_native', version))
22
+ # Capture the exit status of the binary and exit with the same
23
+ exit($?.exitstatus)
data/bin/svm_learn ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This is copied from the generated RubyGems bin stub
4
+ # It basically runs a specified version of the gem if given
5
+
6
+ version = ">= 0.a"
7
+
8
+ if ARGV.first
9
+ str = ARGV.first
10
+ str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
11
+ if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
12
+ version = $1
13
+ ARGV.shift
14
+ end
15
+ end
16
+
17
+ gem 'svmlightcli', version
18
+
19
+ # Now we don't want to just load the ruby bin file, we want to execute it
20
+ # The reason is that it may not be necessarily a ruby file, could be native
21
+ system(Gem.bin_path('svmlightcli', 'svm_learn_native', version))
22
+ # Capture the exit status of the binary and exit with the same
23
+ exit($?.exitstatus)
@@ -0,0 +1,95 @@
1
+ #
2
+ # makefile for svm_light
3
+ #
4
+ # Thorsten Joachims, 2002
5
+ #
6
+
7
+ #Use the following to compile under unix or cygwin
8
+ CC = gcc
9
+ LD = gcc
10
+
11
+ #Uncomment the following line to make CYGWIN produce stand-alone Windows executables
12
+ #SFLAGS= -mno-cygwin
13
+
14
+ #CFLAGS= $(SFLAGS) -ggdb3 -O0 -pg -Wall -pedantic # release C-Compiler flags
15
+ CFLAGS= $(SFLAGS) -O3 # release C-Compiler flags
16
+ #LFLAGS= $(SFLAGS) -O0 -pg # release linker flags
17
+ LFLAGS= $(SFLAGS) -O3 # release linker flags
18
+ #CFLAGS= $(SFLAGS) -pg -Wall -pedantic # debugging C-Compiler flags
19
+ #LFLAGS= $(SFLAGS) -pg # debugging linker flags
20
+ LIBS=-L. -lm #-lsvmlight # used libraries
21
+ SRC_DIR=.
22
+ BIN_DIR=../../bin
23
+
24
+ all: svm_learn_hideo svm_classify
25
+
26
+ tidy:
27
+ rm -f ./*.o
28
+
29
+ clean: tidy
30
+ rm -f ./svm_learn
31
+ rm -f ./svm_classify
32
+ rm -f ./libsvmlight.so
33
+
34
+ help: info
35
+
36
+ info:
37
+ @echo
38
+ @echo "make for SVM-light Thorsten Joachims, 1998"
39
+ @echo
40
+ @echo "Thanks to Ralf Herbrich for the initial version."
41
+ @echo
42
+ @echo "USAGE: make [svm_learn | svm_learn_loqo | svm_learn_hideo | "
43
+ @echo " libsvmlight_hideo | libsvmlight_loqo | "
44
+ @echo " svm_classify | all | clean | tidy]"
45
+ @echo
46
+ @echo " svm_learn builds the learning module (prefers HIDEO)"
47
+ @echo " svm_learn_hideo builds the learning module using HIDEO optimizer"
48
+ @echo " svm_classify builds the classfication module"
49
+ @echo " libsvmlight_hideo builds shared object library that can be linked into"
50
+ @echo " other code using HIDEO"
51
+ @echo " all (default) builds svm_learn + svm_classify"
52
+ @echo " clean removes .o and target files"
53
+ @echo " tidy removes .o files"
54
+ @echo
55
+
56
+ # Create executables svm_learn and svm_classify
57
+
58
+ svm_learn_hideo: svm_learn_main.o svm_learn.o svm_common.o svm_hideo.o
59
+ $(LD) $(LFLAGS) svm_learn_main.o svm_learn.o svm_common.o svm_hideo.o -o svm_learn $(LIBS)
60
+
61
+ svm_classify: svm_classify.o svm_common.o
62
+ $(LD) $(LFLAGS) svm_classify.o svm_common.o -o svm_classify $(LIBS)
63
+
64
+
65
+ # Create library libsvmlight.so, so that external code can get access to the
66
+ # learning and classification functions of svm-light by linking this library.
67
+
68
+ svm_learn_hideo_noexe: svm_learn_main.o svm_learn.o svm_common.o svm_hideo.o
69
+
70
+ libsvmlight_hideo: svm_learn_main.o svm_learn.o svm_common.o svm_hideo.o
71
+ $(LD) -shared svm_learn.o svm_common.o svm_hideo.o -o libsvmlight.so
72
+
73
+ #svm_learn_loqo_noexe: svm_learn_main.o svm_learn.o svm_common.o svm_loqo.o loqo
74
+
75
+ # Compile components
76
+
77
+ svm_hideo.o: $(SRC_DIR)/svm_hideo.c
78
+ $(CC) -c $(CFLAGS) $(SRC_DIR)/svm_hideo.c -o svm_hideo.o
79
+
80
+ svm_common.o: $(SRC_DIR)/svm_common.c $(SRC_DIR)/svm_common.h $(SRC_DIR)/kernel.h
81
+ $(CC) -c $(CFLAGS) $(SRC_DIR)/svm_common.c -o svm_common.o
82
+
83
+ svm_learn.o: $(SRC_DIR)/svm_learn.c $(SRC_DIR)/svm_common.h
84
+ $(CC) -c $(CFLAGS) $(SRC_DIR)/svm_learn.c -o svm_learn.o
85
+
86
+ svm_learn_main.o: $(SRC_DIR)/svm_learn_main.c $(SRC_DIR)/svm_learn.h $(SRC_DIR)/svm_common.h
87
+ $(CC) -c $(CFLAGS) $(SRC_DIR)/svm_learn_main.c -o svm_learn_main.o
88
+
89
+ svm_classify.o: $(SRC_DIR)/svm_classify.c $(SRC_DIR)/svm_common.h $(SRC_DIR)/kernel.h
90
+ $(CC) -c $(CFLAGS) $(SRC_DIR)/svm_classify.c -o svm_classify.o
91
+
92
+ install: svm_learn_hideo svm_classify
93
+ cp svm_learn $(BIN_DIR)/svm_learn_native
94
+ cp svm_classify $(BIN_DIR)/svm_classify_native
95
+
@@ -0,0 +1,33 @@
1
+ require "mkmf"
2
+
3
+ # The $makefile_created and fake library are taken from:
4
+ # https://yorickpeterse.com/articles/hacking-extconf-rb/
5
+
6
+ # copy Makefile which is beside this file to current working directory
7
+ # this is only needed in the Makefile preparation phase
8
+ # later on, when installing the gem using gem or bundle
9
+ # Makefile is used from the ext/svmlightcli directory
10
+ begin
11
+ makefile = File.expand_path('../Makefile', __FILE__)
12
+ FileUtils.cp(makefile, '.')
13
+ # replace SRC_DIR in the copied Makefile with the correct path
14
+ src_dir = File.dirname __FILE__
15
+ new_contents = File.read('Makefile').sub("SRC_DIR=.", "SRC_DIR=#{src_dir}")
16
+ File.write('Makefile', new_contents)
17
+ rescue Exception => e
18
+ # in the installation phase, cp will complain from copying to same dir
19
+ end
20
+
21
+ # This is normally set by calling create_makefile() but we don't need that
22
+ # method since we'll provide a dummy Makefile. Without setting this value
23
+ # RubyGems will abort the installation.
24
+ $makefile_created = true
25
+
26
+ # Create a dummy extension file. Without this RubyGems would abort the
27
+ # installation process. On Linux this would result in the file "svmlightcli.so"
28
+ # being created in the current working directory.
29
+ #
30
+ # Normally the generated Makefile would take care of this but since we
31
+ # don't generate one we'll have to do this manually.
32
+ #
33
+ File.write("svmlightcli.#{RbConfig::CONFIG['DLEXT']}", '')
@@ -0,0 +1,40 @@
1
+ /************************************************************************/
2
+ /* */
3
+ /* kernel.h */
4
+ /* */
5
+ /* User defined kernel function. Feel free to plug in your own. */
6
+ /* */
7
+ /* Copyright: Thorsten Joachims */
8
+ /* Date: 16.12.97 */
9
+ /* */
10
+ /************************************************************************/
11
+
12
+ /* KERNEL_PARM is defined in svm_common.h The field 'custom' is reserved for */
13
+ /* parameters of the user defined kernel. You can also access and use */
14
+ /* the parameters of the other kernels. Just replace the line
15
+ return((double)(1.0));
16
+ with your own kernel. */
17
+
18
+ /* Example: The following computes the polynomial kernel. sprod_ss
19
+ computes the inner product between two sparse vectors.
20
+
21
+ return((CFLOAT)pow(kernel_parm->coef_lin*sprod_ss(a->words,b->words)
22
+ +kernel_parm->coef_const,(double)kernel_parm->poly_degree));
23
+ */
24
+
25
+ /* If you are implementing a kernel that is not based on a
26
+ feature/value representation, you might want to make use of the
27
+ field "userdefined" in SVECTOR. By default, this field will contain
28
+ whatever string you put behind a # sign in the example file. So, if
29
+ a line in your training file looks like
30
+
31
+ -1 1:3 5:6 #abcdefg
32
+
33
+ then the SVECTOR field "words" will contain the vector 1:3 5:6, and
34
+ "userdefined" will contain the string "abcdefg". */
35
+
36
+ double custom_kernel(KERNEL_PARM *kernel_parm, SVECTOR *a, SVECTOR *b)
37
+ /* plug in you favorite kernel */
38
+ {
39
+ return((double)(1.0));
40
+ }