jashmenn-apriori 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/History.txt +4 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +121 -0
  4. data/README.txt +139 -0
  5. data/Rakefile +4 -0
  6. data/TODO.txt +60 -0
  7. data/attic/c_ext_test1/MyTest/MyTest.c +23 -0
  8. data/attic/c_ext_test1/MyTest/extconf.rb +11 -0
  9. data/attic/c_ext_test1/mytest.rb +10 -0
  10. data/attic/test.c +12 -0
  11. data/config/hoe.rb +77 -0
  12. data/config/requirements.rb +15 -0
  13. data/examples/01_simple_example.rb +23 -0
  14. data/examples/02_small_file_example.rb +17 -0
  15. data/examples/03_large_file_example.rb +22 -0
  16. data/examples/test_data/market_basket_basic_test.dat +9 -0
  17. data/ext/Apriori.c +149 -0
  18. data/ext/Makefile +149 -0
  19. data/ext/apriori/doc/apriori.html +1301 -0
  20. data/ext/apriori/doc/arem.gp +68 -0
  21. data/ext/apriori/doc/c_rev.gp +89 -0
  22. data/ext/apriori/doc/chi2.tex +156 -0
  23. data/ext/apriori/doc/copying +504 -0
  24. data/ext/apriori/doc/line.gif +0 -0
  25. data/ext/apriori/doc/uparrow.gif +0 -0
  26. data/ext/apriori/ex/flg2set +15 -0
  27. data/ext/apriori/ex/hdr2set +13 -0
  28. data/ext/apriori/ex/readme +71 -0
  29. data/ext/apriori/ex/row2set +7 -0
  30. data/ext/apriori/ex/rulesort +24 -0
  31. data/ext/apriori/ex/tab2set +9 -0
  32. data/ext/apriori/ex/test.app +2 -0
  33. data/ext/apriori/ex/test.rul +9 -0
  34. data/ext/apriori/ex/test1.rul +43 -0
  35. data/ext/apriori/ex/test1.tab +10 -0
  36. data/ext/apriori/ex/test2.tab +10 -0
  37. data/ext/apriori/ex/test3.tab +30 -0
  38. data/ext/apriori/ex/test4.tab +11 -0
  39. data/ext/apriori/ex/test5.tab +39 -0
  40. data/ext/apriori/ex/tid2set +23 -0
  41. data/ext/apriori/ex/xhdr2set +33 -0
  42. data/ext/apriori/src/apriori.c +750 -0
  43. data/ext/apriori/src/apriori.dsp +120 -0
  44. data/ext/apriori/src/apriori.dsw +29 -0
  45. data/ext/apriori/src/apriori.mak +99 -0
  46. data/ext/apriori/src/istree.c +1411 -0
  47. data/ext/apriori/src/istree.h +160 -0
  48. data/ext/apriori/src/makefile +105 -0
  49. data/ext/apriori/src/tract.c +870 -0
  50. data/ext/apriori/src/tract.h +261 -0
  51. data/ext/apriori_wrapper.c +757 -0
  52. data/ext/apriori_wrapper.h +10 -0
  53. data/ext/extconf.rb +32 -0
  54. data/ext/math/doc/copying +504 -0
  55. data/ext/math/src/chi2.c +151 -0
  56. data/ext/math/src/chi2.h +27 -0
  57. data/ext/math/src/choose.c +71 -0
  58. data/ext/math/src/choose.h +16 -0
  59. data/ext/math/src/gamma.c +446 -0
  60. data/ext/math/src/gamma.h +39 -0
  61. data/ext/math/src/intexp.c +35 -0
  62. data/ext/math/src/intexp.h +15 -0
  63. data/ext/math/src/makefile +164 -0
  64. data/ext/math/src/math.mak +48 -0
  65. data/ext/math/src/normal.c +387 -0
  66. data/ext/math/src/normal.h +44 -0
  67. data/ext/math/src/radfn.c +113 -0
  68. data/ext/math/src/radfn.h +34 -0
  69. data/ext/math/src/zeta.c +49 -0
  70. data/ext/math/src/zeta.h +15 -0
  71. data/ext/pre-clean.rb +8 -0
  72. data/ext/pre-setup.rb +9 -0
  73. data/ext/util/doc/copying +504 -0
  74. data/ext/util/src/listops.c +76 -0
  75. data/ext/util/src/listops.h +26 -0
  76. data/ext/util/src/makefile +103 -0
  77. data/ext/util/src/memsys.c +84 -0
  78. data/ext/util/src/memsys.h +42 -0
  79. data/ext/util/src/nstats.c +288 -0
  80. data/ext/util/src/nstats.h +69 -0
  81. data/ext/util/src/params.c +86 -0
  82. data/ext/util/src/params.h +19 -0
  83. data/ext/util/src/parse.c +133 -0
  84. data/ext/util/src/parse.h +81 -0
  85. data/ext/util/src/scan.c +767 -0
  86. data/ext/util/src/scan.h +111 -0
  87. data/ext/util/src/symtab.c +443 -0
  88. data/ext/util/src/symtab.h +121 -0
  89. data/ext/util/src/tabscan.c +279 -0
  90. data/ext/util/src/tabscan.h +99 -0
  91. data/ext/util/src/util.mak +91 -0
  92. data/ext/util/src/vecops.c +317 -0
  93. data/ext/util/src/vecops.h +42 -0
  94. data/lib/apriori/adapter.rb +13 -0
  95. data/lib/apriori/association_rule.rb +85 -0
  96. data/lib/apriori/version.rb +9 -0
  97. data/lib/apriori.rb +133 -0
  98. data/script/console +10 -0
  99. data/script/destroy +14 -0
  100. data/script/generate +14 -0
  101. data/script/txt2html +82 -0
  102. data/setup.rb +1585 -0
  103. data/tasks/apriori.rake +20 -0
  104. data/tasks/attic.rake +28 -0
  105. data/tasks/deployment.rake +34 -0
  106. data/tasks/environment.rake +7 -0
  107. data/tasks/install.rake +6 -0
  108. data/tasks/website.rake +17 -0
  109. data/test/apriori_test.rb +13 -0
  110. data/test/fixtures/market_basket_results_test.txt +5 -0
  111. data/test/fixtures/market_basket_string_test.txt +7 -0
  112. data/test/fixtures/results.txt +2 -0
  113. data/test/fixtures/sample.txt +7 -0
  114. data/test/test_helper.rb +5 -0
  115. data/test/unit/test_apriori.rb +68 -0
  116. data/test/unit/test_itemsets_and_parsing.rb +82 -0
  117. data/website/index.html +233 -0
  118. data/website/index.txt +142 -0
  119. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  120. data/website/stylesheets/screen.css +142 -0
  121. data/website/template.html.erb +49 -0
  122. metadata +188 -0
data/ext/Apriori.c ADDED
@@ -0,0 +1,149 @@
1
+ // Include the Ruby headers and goodies
2
+ #include "ruby.h"
3
+ #include "intern.h"
4
+ #include "apriori_wrapper.h"
5
+
6
+ // Defining a space for information and references about the module to be stored internally
7
+ VALUE Apriori = Qnil;
8
+
9
+ // Prototype for the initialization method - Ruby calls this, not you
10
+ void Init_mytest();
11
+
12
+ // Prototype for our method 'test1' - methods are prefixed by 'method_' here
13
+ VALUE method_do_test_apriori(VALUE self);
14
+ //VALUE method_test_hash_ap(VALUE self, VALUE filein, VALUE fileout, VALUE opts);
15
+ //VALUE method_find_association_rules(VALUE self, VALUE filein, VALUE fileout, VALUE opts);
16
+
17
+ VALUE method_ap_do_apriori(VALUE self, VALUE rargv);
18
+
19
+ // The initialization method for this module
20
+ void Init_apriori_ext() {
21
+ Apriori = rb_define_module("Apriori");
22
+ rb_define_method(Apriori, "do_test_apriori", method_do_test_apriori, 0);
23
+ rb_define_method(Apriori, "do_apriori", method_ap_do_apriori, 1);
24
+ }
25
+
26
+ VALUE method_do_test_apriori(VALUE self) {
27
+ char *arg0 = "apriori";
28
+ char *arg1 = "test/sample.txt";
29
+ char *arg2 = "test/results.txt";
30
+ char *argv[3];
31
+ argv[0] = arg0;
32
+ argv[1] = arg1;
33
+ argv[2] = arg2;
34
+
35
+ do_apriori(3, argv);
36
+ int x = 10;
37
+ return INT2NUM(x);
38
+ }
39
+
40
+ // Our 'test1' method.. it simply returns a value of '10' for now.
41
+ /*
42
+ VALUE method_test_hash_ap(VALUE self, VALUE filein, VALUE fileout, VALUE opts) {
43
+ //VALUE s = rb_str_new2("hello");
44
+ VALUE s = rb_str_new2("bye");
45
+ VALUE val = rb_hash_aref(opts, rb_str_intern(s));
46
+
47
+ if(val != Qnil) {
48
+ return val;
49
+ } else {
50
+ return rb_str_new2("nope");
51
+ }
52
+ }
53
+ */
54
+
55
+ // Our 'test1' method.. it simply returns a value of '10' for now.
56
+ /*
57
+ VALUE method_find_association_rules(VALUE self, VALUE filein, VALUE fileout, VALUE opts) {
58
+ VALUE s = rb_str_new2("hello");
59
+ //VALUE s = rb_str_new2("bye");
60
+ VALUE val = rb_hash_aref(opts, rb_str_intern(s));
61
+
62
+ if(val != Qnil) {
63
+ return val;
64
+ } else {
65
+ return rb_str_new2("nope");
66
+ }
67
+ }
68
+ */
69
+
70
+ VALUE method_ap_do_apriori(VALUE self, VALUE rargv) {
71
+ char **argv; // todo, learn the best practice here
72
+ int i = 0;
73
+ VALUE ary_value;
74
+ // get the number of arguments
75
+ int ruby_argv_length = RARRAY(rargv)->len;
76
+ // allocate enough memory for a pointer to each char *
77
+ argv = malloc(ruby_argv_length * sizeof(*argv));
78
+
79
+ // copy the ruby array of strings to a c "array of strings"
80
+ // todo, turn this into a function
81
+ while((ary_value = rb_ary_shift(rargv)) != Qnil) {
82
+ argv[i] = malloc(strlen(STR2CSTR(ary_value)) + 1);
83
+ strcpy(argv[i], STR2CSTR(ary_value));
84
+ i++;
85
+ }
86
+ do_apriori(i, argv);
87
+ return Qnil;
88
+ }
89
+
90
+ /*
91
+ VALUE better_method_ap_test_ruby_array(VALUE self, VALUE rargv) {
92
+ char **argv;
93
+ int i = 3;
94
+ argv = (char **)convert_rb_ary_strings_to_c_ary_strings(rargv);
95
+ do_apriori(i, argv);
96
+ }
97
+
98
+ char **convert_rb_ary_strings_to_c_ary_strings(VALUE rary) {
99
+ char **argv; // todo, learn the best practice here
100
+ int i = 0;
101
+ VALUE ary_value;
102
+ // get the number of arguments
103
+ int ruby_argv_length = RARRAY(rary)->len;
104
+ // allocate enough memory for a pointer to each char *
105
+ argv = malloc(ruby_argv_length * sizeof(*argv));
106
+
107
+ // copy the ruby array of strings to a c "array of strings"
108
+ // todo, turn this into a function
109
+ while((ary_value = rb_ary_shift(rary)) != Qnil) {
110
+ argv[i] = malloc(strlen(STR2CSTR(ary_value)) + 1);
111
+ strcpy(argv[i], STR2CSTR(ary_value));
112
+ fprintf(stderr, "%s\n", argv[i]);
113
+ i++;
114
+ }
115
+ printf("%d\n", i);
116
+ return argv;
117
+ }
118
+ */
119
+
120
+ void asdf_junk_box() {
121
+ /* int j; */
122
+ /* for(j=0; j<i; j++) { */
123
+ /* fprintf(stderr, "%s\n", argv[j]); */
124
+ /* } */
125
+
126
+ // VALUE tmp_argv = rb_ary_new();
127
+ //do_apriori(i, argv);
128
+
129
+ // ok, so you need to figure out how many non-nil values you have,
130
+ // i guess you could just track it above.
131
+ // then we're good! we can feed these to the main
132
+
133
+ // for(i=0; i < NUM2INT(rb_ary_length(rargv)); i++) {
134
+ // VALUE argv = rb_ary_new();
135
+ //fprintf(stderr, STR2CSTR(rb_ary_fetch(1, 1, rargv)));
136
+ // }
137
+ // get an array of ruby strings
138
+ // convert it to a c array of char *'s
139
+ //
140
+ //VALUE s = rb_str_new2("bye");
141
+ //VALUE val = rb_hash_aref(opts, rb_str_intern(s));
142
+
143
+ /* if(val != Qnil) { */
144
+ /* return val; */
145
+ /* } else { */
146
+ /* return rb_str_new2("nope"); */
147
+ /* } */
148
+ return;
149
+ }
data/ext/Makefile ADDED
@@ -0,0 +1,149 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ #### Start of system configuration section. ####
5
+
6
+ srcdir = /Users/nathan/Programming/datamining/apriori/ext
7
+ topdir = /usr/local/lib/ruby/1.8/i686-darwin8.10.1
8
+ hdrdir = $(topdir)
9
+ VPATH = $(srcdir):$(topdir):$(hdrdir)
10
+ prefix = $(DESTDIR)/usr/local
11
+ exec_prefix = $(prefix)
12
+ sitedir = $(prefix)/lib/ruby/site_ruby
13
+ rubylibdir = $(libdir)/ruby/$(ruby_version)
14
+ docdir = $(datarootdir)/doc/$(PACKAGE)
15
+ dvidir = $(docdir)
16
+ datarootdir = $(prefix)/share
17
+ archdir = $(rubylibdir)/$(arch)
18
+ sbindir = $(exec_prefix)/sbin
19
+ psdir = $(docdir)
20
+ localedir = $(datarootdir)/locale
21
+ htmldir = $(docdir)
22
+ datadir = $(datarootdir)
23
+ includedir = $(prefix)/include
24
+ infodir = $(datarootdir)/info
25
+ sysconfdir = $(prefix)/etc
26
+ mandir = $(datarootdir)/man
27
+ libdir = $(exec_prefix)/lib
28
+ sharedstatedir = $(prefix)/com
29
+ oldincludedir = $(DESTDIR)/usr/include
30
+ pdfdir = $(docdir)
31
+ sitearchdir = $(sitelibdir)/$(sitearch)
32
+ bindir = $(exec_prefix)/bin
33
+ localstatedir = $(prefix)/var
34
+ sitelibdir = $(sitedir)/$(ruby_version)
35
+ libexecdir = $(exec_prefix)/libexec
36
+
37
+ CC = gcc
38
+ LIBRUBY = $(LIBRUBY_A)
39
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
40
+ LIBRUBYARG_SHARED =
41
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
42
+
43
+ RUBY_EXTCONF_H =
44
+ CFLAGS = -fno-common -g -O2 -pipe -fno-common
45
+ INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
46
+ CPPFLAGS = -I/Users/nathan/Programming/datamining/apriori/ext/util/src -I/Users/nathan/Programming/datamining/apriori/ext/math/src -I/Users/nathan/Programming/datamining/apriori/ext/apriori/src
47
+ CXXFLAGS = $(CFLAGS)
48
+ DLDFLAGS =
49
+ LDSHARED = cc -dynamic -bundle -undefined suppress -flat_namespace
50
+ AR = ar
51
+ EXEEXT =
52
+
53
+ RUBY_INSTALL_NAME = ruby
54
+ RUBY_SO_NAME = ruby
55
+ arch = i686-darwin8.10.1
56
+ sitearch = i686-darwin8.10.1
57
+ ruby_version = 1.8
58
+ ruby = /usr/local/bin/ruby
59
+ RUBY = $(ruby)
60
+ RM = rm -f
61
+ MAKEDIRS = mkdir -p
62
+ INSTALL = /usr/bin/install -c
63
+ INSTALL_PROG = $(INSTALL) -m 0755
64
+ INSTALL_DATA = $(INSTALL) -m 644
65
+ COPY = cp
66
+
67
+ #### End of system configuration section. ####
68
+
69
+ preload =
70
+
71
+ libpath = $(libdir)
72
+ LIBPATH = -L"$(libdir)"
73
+ DEFFILE =
74
+
75
+ CLEANFILES =
76
+ DISTCLEANFILES =
77
+
78
+ extout =
79
+ extout_prefix =
80
+ target_prefix =
81
+ LOCAL_LIBS =
82
+ LIBS = -ldl -lobjc
83
+ SRCS = vecops.c nimap.c tabscan.c scform.c gamma.c chi2.c tract.c istree.c apriori_wrapper.c Apriori.c
84
+ OBJS = /Users/nathan/Programming/datamining/apriori/ext/util/src/vecops.o /Users/nathan/Programming/datamining/apriori/ext/util/src/nimap.o /Users/nathan/Programming/datamining/apriori/ext/util/src/tabscan.o /Users/nathan/Programming/datamining/apriori/ext/util/src/scform.o /Users/nathan/Programming/datamining/apriori/ext/math/src/gamma.o /Users/nathan/Programming/datamining/apriori/ext/math/src/chi2.o /Users/nathan/Programming/datamining/apriori/ext/apriori/src/tract.o /Users/nathan/Programming/datamining/apriori/ext/apriori/src/istree.o apriori_wrapper.o Apriori.o
85
+ TARGET = apriori_ext
86
+ DLLIB = $(TARGET).bundle
87
+ EXTSTATIC =
88
+ STATIC_LIB =
89
+
90
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
91
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
92
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
93
+
94
+ TARGET_SO = $(DLLIB)
95
+ CLEANLIBS = $(TARGET).bundle $(TARGET).il? $(TARGET).tds $(TARGET).map
96
+ CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
97
+
98
+ all: $(DLLIB)
99
+ static: $(STATIC_LIB)
100
+
101
+ clean:
102
+ @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
103
+
104
+ distclean: clean
105
+ @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
106
+ @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
107
+
108
+ realclean: distclean
109
+ install: install-so install-rb
110
+
111
+ install-so: $(RUBYARCHDIR)
112
+ install-so: $(RUBYARCHDIR)/$(DLLIB)
113
+ $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
114
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
115
+ install-rb: pre-install-rb install-rb-default
116
+ install-rb-default: pre-install-rb-default
117
+ pre-install-rb: Makefile
118
+ pre-install-rb-default: Makefile
119
+ $(RUBYARCHDIR):
120
+ $(MAKEDIRS) $@
121
+
122
+ site-install: site-install-so site-install-rb
123
+ site-install-so: install-so
124
+ site-install-rb: install-rb
125
+
126
+ .SUFFIXES: .c .m .cc .cxx .cpp .C .o
127
+
128
+ .cc.o:
129
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
130
+
131
+ .cxx.o:
132
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
133
+
134
+ .cpp.o:
135
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
136
+
137
+ .C.o:
138
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
139
+
140
+ .c.o:
141
+ $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
142
+
143
+ $(DLLIB): $(OBJS)
144
+ @-$(RM) $@
145
+ $(LDSHARED) $(DLDFLAGS) $(LIBPATH) -o $@ $(OBJS) $(LOCAL_LIBS) $(LIBS)
146
+
147
+
148
+
149
+ $(OBJS): ruby.h defines.h