rdf-smart 0.0.152

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ rdf-smart
2
+ ================
3
+ Will be great.
data/ext/Makefile ADDED
@@ -0,0 +1,220 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ # V=0 quiet, V=1 verbose. other values don't work.
5
+ V = 0
6
+ Q1 = $(V:1=)
7
+ Q = $(Q1:0=@)
8
+ n=$(NULLCMD)
9
+ ECHO1 = $(V:1=@$n)
10
+ ECHO = $(ECHO1:0=@echo)
11
+
12
+ #### Start of system configuration section. ####
13
+
14
+ srcdir = .
15
+ topdir = /usr/include/ruby-1.9.1
16
+ hdrdir = /usr/include/ruby-1.9.1
17
+ arch_hdrdir = /usr/include/ruby-1.9.1/$(arch)
18
+ VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
19
+ prefix = $(DESTDIR)/usr
20
+ rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
21
+ exec_prefix = $(prefix)
22
+ vendorhdrdir = $(rubyhdrdir)/vendor_ruby
23
+ sitehdrdir = $(rubyhdrdir)/site_ruby
24
+ rubyhdrdir = $(includedir)/$(RUBY_BASE_NAME)-$(ruby_version)
25
+ vendordir = $(DESTDIR)/usr/lib/ruby/vendor_ruby
26
+ sitedir = $(DESTDIR)/usr/local/lib/site_ruby
27
+ ridir = $(datarootdir)/$(RI_BASE_NAME)
28
+ mandir = $(prefix)/share/man
29
+ localedir = $(datarootdir)/locale
30
+ libdir = $(exec_prefix)/lib
31
+ psdir = $(docdir)
32
+ pdfdir = $(docdir)
33
+ dvidir = $(docdir)
34
+ htmldir = $(docdir)
35
+ infodir = $(prefix)/share/info
36
+ docdir = $(datarootdir)/doc/$(PACKAGE)
37
+ oldincludedir = $(DESTDIR)/usr/include
38
+ includedir = $(prefix)/include
39
+ localstatedir = $(DESTDIR)/var
40
+ sharedstatedir = $(prefix)/com
41
+ sysconfdir = $(DESTDIR)/etc
42
+ datadir = $(datarootdir)
43
+ datarootdir = $(prefix)/share
44
+ libexecdir = $(prefix)/lib/ruby1.9.1
45
+ sbindir = $(exec_prefix)/sbin
46
+ bindir = $(exec_prefix)/bin
47
+ rubylibdir = $(rubylibprefix)/$(ruby_version)
48
+ archdir = $(rubylibdir)/$(arch)
49
+ sitelibdir = $(sitedir)/$(ruby_version)
50
+ sitearchdir = $(sitelibdir)/$(sitearch)
51
+ vendorlibdir = $(vendordir)/$(ruby_version)
52
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
53
+
54
+ NULLCMD = :
55
+
56
+ CC = gcc
57
+ CXX = g++
58
+ LIBRUBY = $(LIBRUBY_SO)
59
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
60
+ LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
61
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
62
+ empty =
63
+ OUTFLAG = -o $(empty)
64
+ COUTFLAG = -o $(empty)
65
+
66
+ RUBY_EXTCONF_H = extconf.h
67
+ cflags = $(optflags) $(debugflags) $(warnflags)
68
+ optflags = -O3
69
+ debugflags = -ggdb
70
+ warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration
71
+ CFLAGS = -fPIC -DRSM_VERSION=\"0.0.152\" -std=c99 -I/usr/include/rasqal -I/usr/include/raptor2 -g -Wall -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall -fno-strict-aliasing -fPIC $(ARCH_FLAG)
72
+ INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
73
+ DEFS =
74
+ CPPFLAGS = -DRUBY_EXTCONF_H=\"$(RUBY_EXTCONF_H)\" -D_FORTIFY_SOURCE=2 $(DEFS) $(cppflags)
75
+ CXXFLAGS = $(CFLAGS) -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall -fno-strict-aliasing
76
+ ldflags = -lrasqal -lraptor2 -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -L/build/buildd/ruby1.9.1-1.9.3.484/debian/lib -rdynamic -Wl,-export-dynamic
77
+ dldflags =
78
+ ARCH_FLAG =
79
+ DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
80
+ LDSHARED = $(CC) -shared
81
+ LDSHAREDXX = $(CXX) -shared
82
+ AR = ar
83
+ EXEEXT =
84
+
85
+ RUBY_BASE_NAME = ruby
86
+ RUBY_INSTALL_NAME = ruby1.9.1
87
+ RUBY_SO_NAME = ruby-1.9.1
88
+ arch = x86_64-linux
89
+ sitearch = $(arch)
90
+ ruby_version = 1.9.1
91
+ ruby = /usr/bin/ruby1.9.1
92
+ RUBY = $(ruby)
93
+ RM = rm -f
94
+ RM_RF = $(RUBY) -run -e rm -- -rf
95
+ RMDIRS = rmdir --ignore-fail-on-non-empty -p
96
+ MAKEDIRS = /bin/mkdir -p
97
+ INSTALL = /usr/bin/install -c
98
+ INSTALL_PROG = $(INSTALL) -m 0755
99
+ INSTALL_DATA = $(INSTALL) -m 644
100
+ COPY = cp
101
+ TOUCH = exit >
102
+
103
+ #### End of system configuration section. ####
104
+
105
+ preload =
106
+
107
+ libpath = . $(libdir) /usr/lib
108
+ LIBPATH = -L. -L$(libdir) -L/usr/lib
109
+ DEFFILE =
110
+
111
+ CLEANFILES = mkmf.log
112
+ DISTCLEANFILES =
113
+ DISTCLEANDIRS =
114
+
115
+ extout =
116
+ extout_prefix =
117
+ target_prefix = /rdf
118
+ LOCAL_LIBS =
119
+ LIBS = $(LIBRUBYARG_SHARED) -lrasqal -lraptor2 -lpthread -lrt -ldl -lcrypt -lm -lc
120
+ SRCS = rsm.c
121
+ OBJS = rsm.o
122
+ TARGET = smart
123
+ TARGET_NAME = smart
124
+ TARGET_ENTRY = Init_$(TARGET_NAME)
125
+ DLLIB = $(TARGET).so
126
+ EXTSTATIC =
127
+ STATIC_LIB =
128
+
129
+ BINDIR = $(bindir)
130
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
131
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
132
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
133
+ HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
134
+ ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
135
+
136
+ TARGET_SO = $(DLLIB)
137
+ CLEANLIBS = $(TARGET).so
138
+ CLEANOBJS = *.o *.bak
139
+
140
+ all: $(DLLIB)
141
+ static: $(STATIC_LIB)
142
+ .PHONY: all install static install-so install-rb
143
+ .PHONY: clean clean-so clean-rb
144
+
145
+ clean-static::
146
+ clean-rb-default::
147
+ clean-rb::
148
+ clean-so::
149
+ clean: clean-so clean-static clean-rb-default clean-rb
150
+ -$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
151
+
152
+ distclean-rb-default::
153
+ distclean-rb::
154
+ distclean-so::
155
+ distclean: clean distclean-so distclean-rb-default distclean-rb
156
+ @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
157
+ @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
158
+ @-$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
159
+
160
+ realclean: distclean
161
+ install: install-so install-rb
162
+
163
+ install-so: $(RUBYARCHDIR)/$(DLLIB)
164
+ $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
165
+ -$(Q)$(MAKEDIRS) $(@D)
166
+ $(INSTALL_PROG) $(DLLIB) $(@D)
167
+ clean-static::
168
+ -$(Q)$(RM) $(STATIC_LIB)
169
+ install-rb: pre-install-rb install-rb-default
170
+ install-rb-default: pre-install-rb-default
171
+ pre-install-rb: Makefile
172
+ pre-install-rb-default: Makefile
173
+ pre-install-rb-default:
174
+ $(ECHO) installing default smart libraries
175
+ ./.RUBYARCHDIR.time:
176
+ $(Q) $(MAKEDIRS) $(RUBYARCHDIR)
177
+ $(Q) $(TOUCH) $@
178
+
179
+ site-install: site-install-so site-install-rb
180
+ site-install-so: install-so
181
+ site-install-rb: install-rb
182
+
183
+ .SUFFIXES: .c .m .cc .mm .cxx .cpp .C .o
184
+
185
+ .cc.o:
186
+ $(ECHO) compiling $(<)
187
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
188
+
189
+ .mm.o:
190
+ $(ECHO) compiling $(<)
191
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
192
+
193
+ .cxx.o:
194
+ $(ECHO) compiling $(<)
195
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
196
+
197
+ .cpp.o:
198
+ $(ECHO) compiling $(<)
199
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
200
+
201
+ .C.o:
202
+ $(ECHO) compiling $(<)
203
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
204
+
205
+ .c.o:
206
+ $(ECHO) compiling $(<)
207
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
208
+
209
+ .m.o:
210
+ $(ECHO) compiling $(<)
211
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
212
+
213
+ $(DLLIB): $(OBJS) Makefile
214
+ $(ECHO) linking shared-object rdf/$(DLLIB)
215
+ -$(Q)$(RM) $(@)
216
+ $(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
217
+
218
+
219
+
220
+ $(OBJS): $(hdrdir)/ruby.h $(hdrdir)/ruby/defines.h $(arch_hdrdir)/ruby/config.h $(RUBY_EXTCONF_H)
data/ext/extconf.h ADDED
@@ -0,0 +1,3 @@
1
+ #ifndef EXTCONF_H
2
+ #define EXTCONF_H
3
+ #endif
data/ext/extconf.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'mkmf'
2
+
3
+ spec = eval(File.read(File.dirname(__FILE__) + '/../rdf-smart.gemspec'))
4
+ PKG_NAME="rdf/smart"
5
+
6
+ $CFLAGS = '-g -Wall ' + $CFLAGS
7
+ $LIBPATH.push(RbConfig::CONFIG['libdir'])
8
+
9
+ unless have_library("raptor2")
10
+ pp "Library raptor2 not found"
11
+ exit 1
12
+ end
13
+ unless have_library("rasqal")
14
+ pp "Library rasqal not found"
15
+ exit 1
16
+ end
17
+ $CFLAGS = ' -DRSM_VERSION=\\"' + spec.version.to_s + '\\" -std=c99 ' + `rasqal-config --cflags`.chomp + $CFLAGS
18
+ $LDFLAGS = ' ' + `rasqal-config --libs`.chomp + $LDFLAGS
19
+
20
+ create_header()
21
+ create_makefile(PKG_NAME)
data/ext/mkmf.log ADDED
@@ -0,0 +1,118 @@
1
+ have_library: checking for main() in -lraptor2... -------------------- yes
2
+
3
+ "gcc -o conftest -I/usr/include/ruby-1.9.1/x86_64-linux -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I. -D_FORTIFY_SOURCE=2 -D_FORTIFY_SOURCE=2 -g -Wall -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall -fno-strict-aliasing -fPIC conftest.c -L. -L/usr/lib -L/usr/lib -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -L/build/buildd/ruby1.9.1-1.9.3.484/debian/lib -rdynamic -Wl,-export-dynamic -lruby-1.9.1 -lpthread -lrt -ldl -lcrypt -lm -lc"
4
+ checked program was:
5
+ /* begin */
6
+ 1: #include "ruby.h"
7
+ 2:
8
+ 3: int main(int argc, char **argv)
9
+ 4: {
10
+ 5: return 0;
11
+ 6: }
12
+ /* end */
13
+
14
+ "gcc -o conftest -I/usr/include/ruby-1.9.1/x86_64-linux -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I. -D_FORTIFY_SOURCE=2 -D_FORTIFY_SOURCE=2 -g -Wall -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall -fno-strict-aliasing -fPIC conftest.c -L. -L/usr/lib -L/usr/lib -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -L/build/buildd/ruby1.9.1-1.9.3.484/debian/lib -rdynamic -Wl,-export-dynamic -lruby-1.9.1 -lraptor2 -lpthread -lrt -ldl -lcrypt -lm -lc"
15
+ conftest.c: In function ‘t’:
16
+ conftest.c:4:53: error: ‘main’ undeclared (first use in this function)
17
+ int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
18
+ ^
19
+ conftest.c:4:53: note: each undeclared identifier is reported only once for each function it appears in
20
+ conftest.c:4:28: warning: variable ‘p’ set but not used [-Wunused-but-set-variable]
21
+ int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
22
+ ^
23
+ checked program was:
24
+ /* begin */
25
+ 1: #include "ruby.h"
26
+ 2:
27
+ 3: /*top*/
28
+ 4: int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
29
+ 5: int main(int argc, char **argv)
30
+ 6: {
31
+ 7: if (argc > 1000000) {
32
+ 8: printf("%p", &t);
33
+ 9: }
34
+ 10:
35
+ 11: return 0;
36
+ 12: }
37
+ /* end */
38
+
39
+ "gcc -o conftest -I/usr/include/ruby-1.9.1/x86_64-linux -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I. -D_FORTIFY_SOURCE=2 -D_FORTIFY_SOURCE=2 -g -Wall -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall -fno-strict-aliasing -fPIC conftest.c -L. -L/usr/lib -L/usr/lib -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -L/build/buildd/ruby1.9.1-1.9.3.484/debian/lib -rdynamic -Wl,-export-dynamic -lruby-1.9.1 -lraptor2 -lpthread -lrt -ldl -lcrypt -lm -lc"
40
+ conftest.c: In function ‘t’:
41
+ conftest.c:4:1: warning: implicit declaration of function ‘main’ [-Wimplicit-function-declaration]
42
+ int t() { main(); return 0; }
43
+ ^
44
+ checked program was:
45
+ /* begin */
46
+ 1: #include "ruby.h"
47
+ 2:
48
+ 3: /*top*/
49
+ 4: int t() { main(); return 0; }
50
+ 5: int main(int argc, char **argv)
51
+ 6: {
52
+ 7: if (argc > 1000000) {
53
+ 8: printf("%p", &t);
54
+ 9: }
55
+ 10:
56
+ 11: return 0;
57
+ 12: }
58
+ /* end */
59
+
60
+ --------------------
61
+
62
+ have_library: checking for main() in -lrasqal... -------------------- yes
63
+
64
+ "gcc -o conftest -I/usr/include/ruby-1.9.1/x86_64-linux -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I. -D_FORTIFY_SOURCE=2 -D_FORTIFY_SOURCE=2 -g -Wall -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall -fno-strict-aliasing -fPIC conftest.c -L. -L/usr/lib -L/usr/lib -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -L/build/buildd/ruby1.9.1-1.9.3.484/debian/lib -rdynamic -Wl,-export-dynamic -lraptor2 -lruby-1.9.1 -lrasqal -lraptor2 -lpthread -lrt -ldl -lcrypt -lm -lc"
65
+ conftest.c: In function ‘t’:
66
+ conftest.c:4:53: error: ‘main’ undeclared (first use in this function)
67
+ int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
68
+ ^
69
+ conftest.c:4:53: note: each undeclared identifier is reported only once for each function it appears in
70
+ conftest.c:4:28: warning: variable ‘p’ set but not used [-Wunused-but-set-variable]
71
+ int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
72
+ ^
73
+ checked program was:
74
+ /* begin */
75
+ 1: #include "ruby.h"
76
+ 2:
77
+ 3: /*top*/
78
+ 4: int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
79
+ 5: int main(int argc, char **argv)
80
+ 6: {
81
+ 7: if (argc > 1000000) {
82
+ 8: printf("%p", &t);
83
+ 9: }
84
+ 10:
85
+ 11: return 0;
86
+ 12: }
87
+ /* end */
88
+
89
+ "gcc -o conftest -I/usr/include/ruby-1.9.1/x86_64-linux -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I. -D_FORTIFY_SOURCE=2 -D_FORTIFY_SOURCE=2 -g -Wall -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall -fno-strict-aliasing -fPIC conftest.c -L. -L/usr/lib -L/usr/lib -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -L/build/buildd/ruby1.9.1-1.9.3.484/debian/lib -rdynamic -Wl,-export-dynamic -lraptor2 -lruby-1.9.1 -lrasqal -lraptor2 -lpthread -lrt -ldl -lcrypt -lm -lc"
90
+ conftest.c: In function ‘t’:
91
+ conftest.c:4:1: warning: implicit declaration of function ‘main’ [-Wimplicit-function-declaration]
92
+ int t() { main(); return 0; }
93
+ ^
94
+ checked program was:
95
+ /* begin */
96
+ 1: #include "ruby.h"
97
+ 2:
98
+ 3: /*top*/
99
+ 4: int t() { main(); return 0; }
100
+ 5: int main(int argc, char **argv)
101
+ 6: {
102
+ 7: if (argc > 1000000) {
103
+ 8: printf("%p", &t);
104
+ 9: }
105
+ 10:
106
+ 11: return 0;
107
+ 12: }
108
+ /* end */
109
+
110
+ --------------------
111
+
112
+ extconf.h is:
113
+ /* begin */
114
+ 1: #ifndef EXTCONF_H
115
+ 2: #define EXTCONF_H
116
+ 3: #endif
117
+ /* end */
118
+
data/ext/rsm.c ADDED
@@ -0,0 +1,355 @@
1
+ #include "rsm.h"
2
+
3
+ /* -- */
4
+ // ***********************************************************************************
5
+ // GC
6
+ // ***********************************************************************************
7
+ void rsm_free(rsm_obj *prsm_obj) {
8
+ if (prsm_obj != NULL) {
9
+ free(prsm_obj);
10
+ }
11
+ }
12
+
13
+ void rsm_mark(rsm_obj *prsm_obj) {
14
+ if (prsm_obj == NULL) return;
15
+ if (!NIL_P(prsm_obj->data_sources)) rb_gc_mark(prsm_obj->data_sources);
16
+ }
17
+
18
+ //***********************************************************************************
19
+ // Methods
20
+ //***********************************************************************************
21
+ /* ++ */
22
+ static int rsm_print_graph_result(rasqal_query* rq,
23
+ rasqal_query_results *results,
24
+ raptor_world* raptor_world_ptr,
25
+ const char* serializer_syntax_name,
26
+ char** output,
27
+ size_t* len)
28
+ {
29
+ int triple_count = 0;
30
+ rasqal_prefix* prefix;
31
+ int i;
32
+ raptor_serializer* serializer = NULL;
33
+
34
+ serializer = raptor_new_serializer(raptor_world_ptr, serializer_syntax_name);
35
+
36
+ /* Declare any query namespaces in the output serializer */
37
+ for(i = 0; (prefix = rasqal_query_get_prefix(rq, i)); i++)
38
+ raptor_serializer_set_namespace(serializer, prefix->uri, prefix->prefix);
39
+ raptor_serializer_start_to_string(serializer, NULL, (void**)output, len);
40
+
41
+ while(1) {
42
+ raptor_statement *rs = rasqal_query_results_get_triple(results);
43
+ if(!rs)
44
+ break;
45
+
46
+ raptor_serializer_serialize_statement(serializer, rs);
47
+ triple_count++;
48
+
49
+ if(rasqal_query_results_next_triple(results))
50
+ break;
51
+ }
52
+
53
+ raptor_serializer_serialize_end(serializer);
54
+ raptor_free_serializer(serializer);
55
+
56
+ return 0;
57
+ }
58
+ static void rsm_extract_namespaces(void* user_data, raptor_namespace *nspace) {
59
+ VALUE *h = (VALUE *)user_data;
60
+ char * tmp = (char *)raptor_namespace_get_prefix(nspace);
61
+ rb_hash_aset(*h, tmp == NULL ? Qnil : rb_str_new2(tmp), rb_str_new2((char *)raptor_uri_to_string(raptor_namespace_get_uri(nspace))));
62
+ }
63
+
64
+ static void rsm_get_namespaces(VALUE namespaces, unsigned char *uri_string) {
65
+ /* input variables - parser
66
+ * 'uri_string' is set to a URI otherwise 'filename' is file name
67
+ * or if NULL, stdin. Base URI in 'base_uri_string' is required for stdin.
68
+ */
69
+ raptor_world* world = NULL;
70
+ raptor_parser* rdf_parser = NULL;
71
+ char *filename = NULL;
72
+ raptor_uri *uri;
73
+
74
+ /* other variables */
75
+ int rc;
76
+
77
+ world = raptor_new_world();
78
+ if(!world)
79
+ return;
80
+ rc = raptor_world_open(world);
81
+ if(rc)
82
+ return;
83
+
84
+ filename = (char*)uri_string;
85
+ uri_string = raptor_uri_filename_to_uri_string(filename);
86
+ if(!uri_string) {
87
+ fprintf(stderr, "Failed to create URI for file %s.\n", filename);
88
+ return;
89
+ }
90
+
91
+ uri = raptor_new_uri(world, uri_string);
92
+ if(!uri) {
93
+ fprintf(stderr, "Failed to create URI for %s\n", uri_string);
94
+ return;
95
+ }
96
+
97
+ rdf_parser = raptor_new_parser(world, "guess");
98
+ if(!rdf_parser) {
99
+ fprintf(stderr, "Failed to create raptor parser type %s\n", "guess");
100
+ return;
101
+ }
102
+
103
+ raptor_parser_set_namespace_handler(rdf_parser, (void *)&namespaces, rsm_extract_namespaces);
104
+ if(raptor_parser_parse_uri(rdf_parser, uri, NULL)) {
105
+ fprintf(stderr, "Failed to parse URI %s %s content\n", uri_string, "guess");
106
+ }
107
+
108
+ raptor_free_parser(rdf_parser);
109
+
110
+ if(uri)
111
+ raptor_free_uri(uri);
112
+ raptor_free_memory(uri_string);
113
+
114
+ raptor_free_world(world);
115
+ }
116
+
117
+
118
+ static int rsm_print_formatted_query_results(rasqal_world* world,
119
+ rasqal_query_results* results,
120
+ raptor_world* raptor_world_ptr,
121
+ const char* result_format_name,
122
+ char** output,
123
+ size_t* len)
124
+ {
125
+ raptor_iostream *iostr;
126
+ rasqal_query_results_formatter* results_formatter;
127
+ int rc = 0;
128
+
129
+ results_formatter = rasqal_new_query_results_formatter(world, result_format_name, NULL, NULL);
130
+
131
+ iostr = raptor_new_iostream_to_string(raptor_world_ptr, (void**)output, len, NULL);
132
+
133
+ rc = rasqal_query_results_formatter_write(iostr, results_formatter, results, NULL);
134
+ raptor_free_iostream(iostr);
135
+ rasqal_free_query_results_formatter(results_formatter);
136
+
137
+ if(rc)
138
+ rb_raise(rb_eRuntimeError, "Formatting query results failed");
139
+
140
+ return rc;
141
+ }
142
+
143
+
144
+ static rasqal_query* rsm_roqet_init_query(rasqal_world *world,
145
+ const char* ql_name,
146
+ const unsigned char* query_string,
147
+ raptor_sequence* data_graphs)
148
+ {
149
+ rasqal_query* rq;
150
+ rq = rasqal_new_query(world, (const char*)ql_name, NULL);
151
+ if(!rq) {
152
+ rb_raise(rb_eRuntimeError, "Failed to create query name %s\n", ql_name);
153
+ }
154
+
155
+ if(rasqal_query_prepare(rq, query_string, NULL)) {
156
+ size_t len = strlen((const char*)query_string);
157
+
158
+ if(len > MAX_QUERY_ERROR_REPORT_LEN) {
159
+ (void)fwrite(query_string,
160
+ RASQAL_GOOD_CAST(size_t, MAX_QUERY_ERROR_REPORT_LEN),
161
+ sizeof(char), stderr);
162
+ fprintf(stderr, "...' (%d bytes) failed\n", RASQAL_BAD_CAST(int, len));
163
+ } else {
164
+ (void)fwrite(query_string, len, sizeof(char), stderr);
165
+ fputs("' failed\n", stderr);
166
+ }
167
+
168
+ rasqal_free_query(rq); rq = NULL;
169
+ }
170
+
171
+ if(data_graphs) {
172
+ rasqal_data_graph* dg;
173
+
174
+ while((dg = (rasqal_data_graph*)raptor_sequence_pop(data_graphs))) {
175
+ if(rasqal_query_add_data_graph(rq, dg)) {
176
+ fprintf(stderr, "Failed to add data graph to query\n");
177
+ }
178
+ }
179
+ }
180
+ return rq;
181
+ }
182
+ /*
183
+ * This method gets all the namespaces
184
+ */
185
+ VALUE rsm_namespaces(VALUE self) {
186
+ rsm_obj *prsm_obj;
187
+ int i;
188
+ Data_Get_Struct(self, rsm_obj, prsm_obj);
189
+ VALUE namespaces = rb_hash_new();
190
+
191
+ for (i = 0; i < RARRAY_LEN(prsm_obj->data_sources); i++) {
192
+ const char* data_source = RSTRING_PTR(RARRAY_PTR(prsm_obj->data_sources)[i]);
193
+ rsm_get_namespaces(namespaces,(unsigned char *)data_source);
194
+ }
195
+
196
+ return namespaces;
197
+ }
198
+
199
+ VALUE rsm_execute(VALUE self, VALUE query) {
200
+ rsm_obj *prsm_obj;
201
+
202
+ unsigned char *query_string = (unsigned char *)RSTRING_PTR(query);
203
+ rasqal_query *rq = NULL;
204
+ rasqal_query_results *results;
205
+ rasqal_world *world;
206
+ raptor_world* raptor_world_ptr = NULL;
207
+ char* output;
208
+ size_t len = 0;
209
+ int i;
210
+ raptor_sequence* data_graphs = NULL;
211
+ char* data_graph_parser_name = NULL;
212
+
213
+ VALUE routput;
214
+ int enc;
215
+
216
+ Check_Type(query, T_STRING);
217
+ Data_Get_Struct(self, rsm_obj, prsm_obj);
218
+
219
+ world = rasqal_new_world();
220
+
221
+ // if(!world || rasqal_world_open(world)) {
222
+ // rb_raise(rb_eRuntimeError, "rasqal_world init failed");
223
+ // }
224
+ // raptor_world_ptr = rasqal_world_get_raptor(world);
225
+
226
+ // /* #{{{ Data_Graphs*/
227
+ // for (i = 0; i < RARRAY_LEN(prsm_obj->data_sources); i++) {
228
+ // const char* data_source = RSTRING_PTR(RARRAY_PTR(prsm_obj->data_sources)[i]);
229
+ // rasqal_data_graph *dg = NULL;
230
+ // unsigned int type;
231
+ //
232
+ // type = RASQAL_DATA_GRAPH_BACKGROUND;
233
+ //
234
+ // if(!access((const char*)data_source, R_OK)) {
235
+ // unsigned char* source_uri_string;
236
+ // raptor_uri* source_uri;
237
+ // raptor_uri* graph_name = NULL;
238
+ //
239
+ // source_uri_string = raptor_uri_filename_to_uri_string((const char*)data_source);
240
+ // source_uri = raptor_new_uri(raptor_world_ptr, source_uri_string);
241
+ // raptor_free_memory(source_uri_string);
242
+ //
243
+ //
244
+ // if(source_uri)
245
+ // dg = rasqal_new_data_graph_from_uri(world,
246
+ // source_uri,
247
+ // graph_name,
248
+ // type,
249
+ // NULL, data_graph_parser_name,
250
+ // NULL);
251
+ //
252
+ // if(source_uri)
253
+ // raptor_free_uri(source_uri);
254
+ // } else {
255
+ // raptor_uri* source_uri;
256
+ // raptor_uri* graph_name = NULL;
257
+ //
258
+ // source_uri = raptor_new_uri(raptor_world_ptr,
259
+ // (const unsigned char*)data_source);
260
+ //
261
+ // if(source_uri)
262
+ // dg = rasqal_new_data_graph_from_uri(world,
263
+ // source_uri,
264
+ // graph_name,
265
+ // type,
266
+ // NULL, data_graph_parser_name,
267
+ // NULL);
268
+ //
269
+ // if(source_uri)
270
+ // raptor_free_uri(source_uri);
271
+ // }
272
+ //
273
+ // if(!dg) {
274
+ // rb_raise(rb_eRuntimeError, "booboo");
275
+ // }
276
+ //
277
+ // if(!data_graphs) {
278
+ // data_graphs = raptor_new_sequence((raptor_data_free_handler)rasqal_free_data_graph,
279
+ // NULL);
280
+ //
281
+ // if(!data_graphs) {
282
+ // rb_raise(rb_eRuntimeError, "Failed to create data graphs sequence");
283
+ // }
284
+ // }
285
+ //
286
+ // raptor_sequence_push(data_graphs, dg);
287
+ // }
288
+ ///* #}}} */
289
+ //
290
+ // if (!(rq = rsm_roqet_init_query(world, "sparql", query_string,data_graphs)))
291
+ // goto tidy_query;
292
+ //
293
+ // results = rasqal_query_execute(rq);
294
+ //
295
+ // if(!results) {
296
+ // fprintf(stderr, "Query execution failed\n");
297
+ // goto tidy_query;
298
+ // }
299
+ //
300
+ // if(rasqal_query_results_is_bindings(results) || rasqal_query_results_is_boolean(results)) {
301
+ // //rsm_print_formatted_query_results(world, results, raptor_world_ptr, "json", &output, &len);
302
+ // } else if(rasqal_query_results_is_graph(results)) {
303
+ // //rsm_print_graph_result(rq, results, raptor_world_ptr, "json", &output, &len);
304
+ // } else {
305
+ // rb_raise(rb_eRuntimeError, "Query returned unknown result format");
306
+ // }
307
+ //
308
+ // rasqal_free_query_results(results);
309
+ //
310
+ // tidy_query:
311
+ // if(data_graphs) raptor_free_sequence(data_graphs);
312
+ // if(rq) rasqal_free_query(rq);
313
+ rasqal_free_world(world);
314
+ //
315
+ // //routput = rb_str_new(output,len);
316
+ // //enc = rb_enc_find_index("UTF-8");
317
+ // //rb_enc_associate_index(routput, enc);
318
+ //
319
+ // free(output);
320
+ //
321
+ // //return routput;
322
+ return Qnil;
323
+ }
324
+
325
+ VALUE rsm_data_sources(VALUE self) {
326
+ rsm_obj *prsm_obj;
327
+ Data_Get_Struct(self, rsm_obj, prsm_obj);
328
+ return(prsm_obj->data_sources);
329
+ }
330
+
331
+ VALUE rsm_new(int argc, VALUE *argv, VALUE class) {
332
+ int i;
333
+ rsm_obj *prsm_obj = (rsm_obj *)malloc(sizeof(rsm_obj));
334
+ prsm_obj->data_sources = rb_ary_new();
335
+ for (i=0; i<argc; i++) {
336
+ if (TYPE(argv[i]) == T_STRING)
337
+ rb_ary_push(prsm_obj->data_sources,argv[i]);
338
+ }
339
+ return(Data_Wrap_Struct(rsm_Smart, rsm_mark, rsm_free, prsm_obj));
340
+ }
341
+
342
+ VALUE rsm_RDF;
343
+ VALUE rsm_Smart;
344
+
345
+ void Init_smart( void ) {
346
+ rsm_RDF = rb_define_module( "RDF" );
347
+ rsm_Smart = rb_define_class_under( rsm_RDF, "Smart", rb_cObject);
348
+ rb_define_const(rsm_Smart, "VERSION", rb_str_new2(RSM_VERSION));
349
+
350
+ rb_define_singleton_method(rsm_Smart, "new", (VALUE(*)(ANYARGS))rsm_new, -1);
351
+ rb_define_method(rsm_Smart, "data_sources", (VALUE(*)(ANYARGS))rsm_data_sources, 0);
352
+ rb_define_method(rsm_Smart, "namespaces", (VALUE(*)(ANYARGS))rsm_namespaces, 0);
353
+ rb_define_private_method(rsm_Smart, "__execute", (VALUE(*)(ANYARGS))rsm_execute, 1);
354
+ }
355
+
data/ext/rsm.h ADDED
@@ -0,0 +1,45 @@
1
+ #include <stdio.h>
2
+ #include <string.h>
3
+ #include <errno.h>
4
+ #include <stdlib.h>
5
+ #include <unistd.h>
6
+
7
+ /* Rasqal includes */
8
+ #include <rasqal.h>
9
+ #define RASQAL_GOOD_CAST(t, v) (t)(v)
10
+ #define RASQAL_BAD_CAST(t, v) (t)(v)
11
+
12
+ #define MAX_QUERY_ERROR_REPORT_LEN 512
13
+
14
+ #include <ruby.h>
15
+ #ifdef RUBY_VM
16
+ #include <ruby/io.h>
17
+ #include <ruby/st.h>
18
+ #else
19
+ #include <version.h>
20
+ #include <rubyio.h>
21
+ #include <st.h>
22
+ #if (RUBY_VERSION_MAJOR == 1 && RUBY_VERSION_MINOR == 8 && RUBY_VERSION_TEENY < 7)
23
+ #define RHASH_SIZE(h) (RHASH(h)->tbl ? RHASH(h)->tbl->num_entries : 0)
24
+ #endif
25
+ #define RHASH_EMPTY_P(h) (RHASH_SIZE(h) == 0)
26
+ #endif
27
+
28
+ #ifdef HAVE_RB_IO_T
29
+ #define RB_IO_T rb_io_t
30
+ #if (RUBY_VERSION_MAJOR == 1 && RUBY_VERSION_MINOR == 8 && RUBY_VERSION_TEENY < 7)
31
+ #define RB_IO_T_FD(o) o->fd
32
+ #else
33
+ #define RB_IO_T_FD(o) fileno(o->stdio_file)
34
+ #endif
35
+ #else
36
+ #define RB_IO_T OpenFile
37
+ #define RB_IO_T_FD(o) fileno(o->f)
38
+ #endif
39
+
40
+ RUBY_EXTERN VALUE rsm_RDF;
41
+ RUBY_EXTERN VALUE rsm_Smart;
42
+
43
+ typedef struct rsm_obj {
44
+ VALUE data_sources;
45
+ } rsm_obj;
data/ext/rsm.o ADDED
Binary file
data/ext/smart.so ADDED
Binary file
data/lib/rdf/smart.rb ADDED
@@ -0,0 +1,77 @@
1
+ require File.dirname(__FILE__)+ '/../../ext/smart'
2
+ require 'json'
3
+ require 'pp'
4
+
5
+ ##
6
+ # Main Module
7
+ module RDF
8
+ ##
9
+ # Creates a RDF::Smart Object.
10
+ class Smart
11
+ ##
12
+ # Exetuces a +query+. +query+ is a string.
13
+ #
14
+ # An Error is raised if a +data_source+ does not exist
15
+ ##
16
+ # A JSON Object will be returned.
17
+ def execute(query) #{{{
18
+ data_sources.each do |s|
19
+ raise 'BlaBlaBla' unless File.exists?(s)
20
+ end
21
+ ##
22
+ # +res+ is the returned value.
23
+ (res = JSON::parse(__execute(query)))['results']['bindings'].each do |solution|
24
+ solution.each do |k,v|
25
+ catch :done do
26
+ ##
27
+ # Convert Strings into the right datatype.
28
+ ##
29
+ # Add +pvalue+ into returned Value. +pvalue+ contains the real value without namespaces.
30
+ case v['datatype']
31
+ when 'http://www.w3.org/2001/XMLSchema#integer', 'http://www.w3.org/2001/XMLSchema#long', 'http://www.w3.org/2001/XMLSchema#int', 'http://www.w3.org/2001/XMLSchema#short', 'http://www.w3.org/2001/XMLSchema#long', 'http://www.w3.org/2001/XMLSchema#nonPositiveInteger', 'http://www.w3.org/2001/XMLSchema#negativeInteger', 'http://www.w3.org/2001/XMLSchema#nonNegativeInteger', 'http://www.w3.org/2001/XMLSchema#positiveInteger', 'http://www.w3.org/2001/XMLSchema#unsignedLong', 'http://www.w3.org/2001/XMLSchema#unsignedInt', 'http://www.w3.org/2001/XMLSchema#unsignedShort'
32
+ v['ns'] = v['datatype']
33
+ v['pvalue'] = v['value'].to_i
34
+ throw :done
35
+ when 'http://www.w3.org/2001/XMLSchema#float', 'http://www.w3.org/2001/XMLSchema#decimal', 'http://www.w3.org/2001/XMLSchema#double'
36
+ v['ns'] = v['datatype']
37
+ v['pvalue'] = v['value'].to_f
38
+ throw :done
39
+ when 'http://www.w3.org/2001/XMLSchema#boolean'
40
+ v['ns'] = v['datatype']
41
+ v['pvalue'] = v['value'] == 'true' ? true : false
42
+ throw :done
43
+ when 'http://www.w3.org/2001/XMLSchema#notation', 'http://www.w3.org/2001/XMLSchema#qname'
44
+ v['ns'] = v['datatype']
45
+ v['pvalue'] = v['value']
46
+ throw :done
47
+ when nil
48
+ else
49
+ v['ns'] = v['datatype']
50
+ v['pvalue'] = v['value']
51
+ throw :done
52
+ end
53
+ if v.length == 2 && v['value'] && v['type'] == 'literal'
54
+ v['datatype'] = 'http://www.w3.org/2001/XMLSchema#string'
55
+ v['ns'] = v['datatype']
56
+ v['pvalue'] = v['value']
57
+ throw :done
58
+ end
59
+ if v['value'] == 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'
60
+ v['ns'] = v['value']
61
+ v['pvalue'] = 'a'
62
+ throw :done
63
+ end
64
+ namespaces.each do |kk, vv|
65
+ if v['value'].start_with?(vv)
66
+ v['ns'] = vv
67
+ v['pvalue'] = v['value'].sub(vv,'')
68
+ throw :done
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ res #}}}
75
+ end
76
+ end
77
+ end
data/rdf-smart.gemspec ADDED
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'rdf-smart'
3
+ s.version = '0.0.152'
4
+ s.date = '2014-06-17'
5
+ s.summary ="RDF.rb segfaults. A lot. We don't. RDF.rb has lots of features. We don't."
6
+ s.description ="Minimal sparql support for ruby. Basically the roqet tool from http://librdf.org, with always guessing input type, and always json output."
7
+ s.authors = ["Florian Stertz", "Juergen 'eTM' Mangler"]
8
+ s.email = ['florian.stertz@gmail.com', 'juergen.mangler@gmail.com']
9
+ s.files = Dir['ext/**/*'] + Dir['lib/**/*'] + ['rdf-smart.gemspec','README.md']
10
+ s.platform = Gem::Platform::RUBY
11
+ s.require_paths = ['lib']
12
+ s.extensions = Dir['ext/extconf.rb']
13
+ s.homepage = 'https://github.com/Triarier/rdf-smart'
14
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdf-smart
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.152
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Florian Stertz
9
+ - Juergen 'eTM' Mangler
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-06-17 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: Minimal sparql support for ruby. Basically the roqet tool from http://librdf.org,
16
+ with always guessing input type, and always json output.
17
+ email:
18
+ - florian.stertz@gmail.com
19
+ - juergen.mangler@gmail.com
20
+ executables: []
21
+ extensions:
22
+ - ext/extconf.rb
23
+ extra_rdoc_files: []
24
+ files:
25
+ - ext/extconf.h
26
+ - ext/rsm.o
27
+ - ext/smart.so
28
+ - ext/rsm.h
29
+ - ext/rsm.c
30
+ - ext/Makefile
31
+ - ext/extconf.rb
32
+ - ext/mkmf.log
33
+ - lib/rdf/smart.rb
34
+ - rdf-smart.gemspec
35
+ - README.md
36
+ homepage: https://github.com/Triarier/rdf-smart
37
+ licenses: []
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 1.8.23
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: RDF.rb segfaults. A lot. We don't. RDF.rb has lots of features. We don't.
60
+ test_files: []