rubyrdf 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/History.txt +4 -0
  2. data/License.txt +24 -0
  3. data/Manifest.txt +52 -0
  4. data/README.txt +79 -0
  5. data/Rakefile +4 -0
  6. data/config/hoe.rb +70 -0
  7. data/config/requirements.rb +15 -0
  8. data/lib/rdf/blank_node.rb +41 -0
  9. data/lib/rdf/exceptions.rb +26 -0
  10. data/lib/rdf/format/ntriples.rb +493 -0
  11. data/lib/rdf/graph/base.rb +118 -0
  12. data/lib/rdf/graph/memory.rb +146 -0
  13. data/lib/rdf/graph/tests.rb +137 -0
  14. data/lib/rdf/namespace.rb +90 -0
  15. data/lib/rdf/plain_literal_node.rb +36 -0
  16. data/lib/rdf/query/binding.rb +68 -0
  17. data/lib/rdf/query/executer.rb +42 -0
  18. data/lib/rdf/query/result.rb +54 -0
  19. data/lib/rdf/query.rb +54 -0
  20. data/lib/rdf/triple.rb +61 -0
  21. data/lib/rdf/typed_literal_node.rb +39 -0
  22. data/lib/rdf/uri_node.rb +35 -0
  23. data/lib/rdf/version.rb +9 -0
  24. data/lib/rubyrdf.rb +59 -0
  25. data/log/debug.log +0 -0
  26. data/script/console +11 -0
  27. data/script/destroy +14 -0
  28. data/script/generate +14 -0
  29. data/script/txt2html +74 -0
  30. data/setup.rb +1585 -0
  31. data/tasks/deployment.rake +34 -0
  32. data/tasks/environment.rake +7 -0
  33. data/tasks/website.rake +17 -0
  34. data/test/helper.rb +14 -0
  35. data/test/test_blank_node.rb +67 -0
  36. data/test/test_format_ntriples.rb +247 -0
  37. data/test/test_graph_base.rb +71 -0
  38. data/test/test_graph_memory.rb +146 -0
  39. data/test/test_namespace.rb +130 -0
  40. data/test/test_plain_literal_node.rb +83 -0
  41. data/test/test_query.rb +49 -0
  42. data/test/test_query_binding.rb +84 -0
  43. data/test/test_query_result.rb +111 -0
  44. data/test/test_rdf.rb +56 -0
  45. data/test/test_triple.rb +147 -0
  46. data/test/test_typed_literal_node.rb +61 -0
  47. data/test/test_uri_node.rb +45 -0
  48. data/website/index.html +169 -0
  49. data/website/index.txt +92 -0
  50. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  51. data/website/stylesheets/screen.css +138 -0
  52. data/website/template.html.erb +48 -0
  53. metadata +139 -0
@@ -0,0 +1,61 @@
1
+ require File.dirname(__FILE__) + '/helper.rb'
2
+
3
+ class TestTypedLiteralNode < Test::Unit::TestCase
4
+ def test_new_should_initialize_lexical_form
5
+ assert_equal 'test', RDF::TypedLiteralNode.new('test', EX::a.uri).lexical_form
6
+ end
7
+
8
+ def test_new_should_initialize_datatype_uri
9
+ assert_equal EX::a.uri, RDF::TypedLiteralNode.new('test', EX::a.uri).datatype_uri
10
+ end
11
+
12
+ def test_new_should_raise_error_for_empty_datatype_uri
13
+ assert_raise(ArgumentError) {
14
+ RDF::TypedLiteralNode.new('test', nil)
15
+ }
16
+ end
17
+
18
+ def test_new_should_initialize_datatype_uri_from_uri_node
19
+ assert_equal EX::a.uri, RDF::TypedLiteralNode.new('test', EX::a).datatype_uri
20
+ end
21
+
22
+ def test_equal_should_be_true_for_same_lexical_form_and_datatype_uri
23
+ assert_equal RDF::TypedLiteralNode.new('test', EX::a), RDF::TypedLiteralNode.new('test', EX::a)
24
+ end
25
+
26
+ def test_equal_should_be_false_for_same_lexical_form_and_different_datatype_uri
27
+ assert_not_equal RDF::TypedLiteralNode.new('test', EX::a), RDF::TypedLiteralNode.new('test', EX::b)
28
+ end
29
+
30
+ def test_equal_should_be_false_for_different_lexical_form_and_same_datatype_uri
31
+ assert_not_equal RDF::TypedLiteralNode.new('test2', EX::a), RDF::TypedLiteralNode.new('test', EX::a)
32
+ end
33
+
34
+ def test_hash_should_be_equal_for_same_lexical_form_and_datatype_uri
35
+ assert_equal RDF::TypedLiteralNode.new('test', EX::a).hash, RDF::TypedLiteralNode.new('test', EX::a).hash
36
+ end
37
+
38
+ def test_hash_should_not_be_equal_for_same_lexical_form_and_different_datatype_uri
39
+ assert_not_equal RDF::TypedLiteralNode.new('test', EX::a).hash, RDF::TypedLiteralNode.new('test', EX::b).hash
40
+ end
41
+
42
+ def test_hash_should_not_be_equal_for_different_lexical_form_and_same_datatype_uri
43
+ assert_not_equal RDF::TypedLiteralNode.new('test2', EX::a).hash, RDF::TypedLiteralNode.new('test', EX::a).hash
44
+ end
45
+
46
+ def test_eql_should_be_true_for_same_lexical_form_and_datatype_uri
47
+ assert RDF::TypedLiteralNode.new('test', EX::a).eql?(RDF::TypedLiteralNode.new('test', EX::a))
48
+ end
49
+
50
+ def test_eql_should_be_false_for_same_lexical_form_and_different_datatype_uri
51
+ assert !RDF::TypedLiteralNode.new('test', EX::a).eql?(RDF::TypedLiteralNode.new('test', EX::b))
52
+ end
53
+
54
+ def test_eql_should_be_false_for_different_lexical_form_and_same_datatype_uri
55
+ assert !RDF::TypedLiteralNode.new('test2', EX::a).eql?(RDF::TypedLiteralNode.new('test', EX::a))
56
+ end
57
+
58
+ def test_to_s_should_be_ntriples_format
59
+ assert_equal "\"test\"^^<#{EX::a.uri}>", RDF::TypedLiteralNode.new('test', EX::a).to_s
60
+ end
61
+ end
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/helper.rb'
2
+
3
+ class TestUriNode < Test::Unit::TestCase
4
+ def test_new_should_initialize_uri
5
+ assert_equal EX::a.uri, RDF::UriNode.new(EX::a).uri
6
+ end
7
+
8
+ def test_new_should_initialize_uri_from_uri_node
9
+ assert_equal EX::a.uri, RDF::UriNode.new(RDF::UriNode.new(EX::a)).uri
10
+ end
11
+
12
+ def test_new_should_raise_error_for_blank_uri
13
+ assert_raise(ArgumentError) {
14
+ RDF::UriNode.new(nil)
15
+ }
16
+ end
17
+
18
+ def test_equal_should_be_true_for_same_uri
19
+ assert_equal RDF::UriNode.new(EX::a), RDF::UriNode.new(EX::a)
20
+ end
21
+
22
+ def test_equal_should_be_false_for_different_uri
23
+ assert_not_equal RDF::UriNode.new(EX::a), RDF::UriNode.new(EX::b)
24
+ end
25
+
26
+ def test_hash_should_be_equal_for_same_uri
27
+ assert_equal RDF::UriNode.new(EX::a).hash, RDF::UriNode.new(EX::a).hash
28
+ end
29
+
30
+ def test_hash_should_not_be_equal_for_different_uri
31
+ assert_not_equal RDF::UriNode.new(EX::a).hash, RDF::UriNode.new(EX::b).hash
32
+ end
33
+
34
+ def test_eql_should_be_true_for_same_uri
35
+ assert RDF::UriNode.new(EX::a).eql?(RDF::UriNode.new(EX::a))
36
+ end
37
+
38
+ def test_eql_should_be_false_for_different_uri
39
+ assert !RDF::UriNode.new(EX::a).eql?(RDF::UriNode.new(EX::b))
40
+ end
41
+
42
+ def test_to_s_should_be_ntriples_format
43
+ assert_equal "<#{EX::a.uri}>", EX::a.to_s
44
+ end
45
+ end
@@ -0,0 +1,169 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
+ <title>
8
+ RubyRDF
9
+ </title>
10
+ <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
+ <style>
12
+
13
+ </style>
14
+ <script type="text/javascript">
15
+ window.onload = function() {
16
+ settings = {
17
+ tl: { radius: 10 },
18
+ tr: { radius: 10 },
19
+ bl: { radius: 10 },
20
+ br: { radius: 10 },
21
+ antiAlias: true,
22
+ autoPad: true,
23
+ validTags: ["div"]
24
+ }
25
+ var versionBox = new curvyCorners(settings, document.getElementById("version"));
26
+ versionBox.applyCornersToAll();
27
+ }
28
+ </script>
29
+ </head>
30
+ <body>
31
+ <div id="main">
32
+
33
+ <h1>RubyRDF</h1>
34
+ <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/rubyrdf"; return false'>
35
+ <p>Get Version</p>
36
+ <a href="http://rubyforge.org/projects/rubyrdf" class="numbers">0.0.1</a>
37
+ </div>
38
+ <h1>&#x2192; &#8216;rubyrdf&#8217;</h1>
39
+
40
+
41
+ <h2>What</h2>
42
+
43
+
44
+ <p>An <span class="caps">RDF</span> (Resource Description Framework) data access layer for the Ruby programming language with a pluggable graph implementation. I have three goals:</p>
45
+
46
+
47
+ <ol>
48
+ <li>Provide an in-memory, pure Ruby implementation of the <span class="caps">RDF</span> graph model for situations where a high performance triple store is not needed.</li>
49
+ <li>Provide plug-in graph implementations that delegate to high performance triple stores for situations where high performance is needed.</li>
50
+ <li>Smooth out differences between triple stores to provide a consistent interface to <span class="caps">RDF</span> data. An example of this would be to deletgate reasoning to a triple store when available, but to provide a pure Ruby <span class="caps">RDF</span> reasoning engine that can be used with the in-memory model, or with triple stores that do not support reasoning. Same goes for <span class="caps">SPARQL</span> queries, import/export formats, etc.</li>
51
+ </ol>
52
+
53
+
54
+ <h2>Installing</h2>
55
+
56
+
57
+ <p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">rubyrdf</span></pre></p>
58
+
59
+
60
+ <h2>The basics</h2>
61
+
62
+
63
+ <p>RubyRDF implements the basic <span class="caps">RDF</span> data model (UriNode, TypedLiteralNode, PlainLiteralNode, BlankNode, Graph, etc.). There is also a very, <em>very</em> simple querying mechanism that would hopefully be replaced by <span class="caps">SPARQL</span> or a <span class="caps">SPARQL</span>-based <span class="caps">DSL</span>. There is also a fully compliant NTriples import/export function.</p>
64
+
65
+
66
+ <p>There is a in-memory graph implementation, and a Sesame 1.x graph implementation that uses Sesame&#8217;s <span class="caps">HTTP</span> protocol.</p>
67
+
68
+
69
+ <p>There is a class (Namespace) that is used to generate new UriNodes easily.</p>
70
+
71
+
72
+ <p>For more details about the <span class="caps">API</span> see the <a href="http://rubyrdf.rubyforge.org/rdoc/">rdocs</a>.</p>
73
+
74
+
75
+ <p>There are also some subprojects (at this point just one) that provide graph implementations for specific triple stores:</p>
76
+
77
+
78
+ <ul>
79
+ <li><a href="http://rubyrdf.rubyforge.org/rubyrdf-sesame/">RubyRDF Sesame</a></li>
80
+ </ul>
81
+
82
+
83
+ <h2>Demonstration of usage</h2>
84
+
85
+
86
+ <h3>Adding data to a graph</h3>
87
+
88
+
89
+ <p><pre class='syntax'>
90
+ <span class="ident">g</span> <span class="punct">=</span> <span class="constant">RDF</span><span class="punct">::</span><span class="constant">Graph</span><span class="punct">::</span><span class="constant">Memory</span><span class="punct">.</span><span class="ident">new</span>
91
+ <span class="ident">g</span><span class="punct">.</span><span class="ident">add</span><span class="punct">(</span><span class="constant">UriNode</span><span class="punct">.</span><span class="ident">new</span><span class="punct">('</span><span class="string">http://paul.stadig.name/</span><span class="punct">'),</span> <span class="constant">RDF</span><span class="punct">::</span><span class="ident">type</span><span class="punct">,</span> <span class="constant">RDF</span><span class="punct">::</span><span class="constant">Resource</span><span class="punct">)</span>
92
+ </pre></p>
93
+
94
+
95
+ <h3>Registering a new namespace</h3>
96
+
97
+
98
+ <p><pre class='syntax'>
99
+ <span class="constant">RDF</span><span class="punct">::</span><span class="constant">Namespace</span><span class="punct">.</span><span class="ident">register</span><span class="punct">(</span><span class="symbol">:dc</span><span class="punct">,</span> <span class="punct">'</span><span class="string">http://purl.org/dc/elements/1.1/</span><span class="punct">')</span>
100
+
101
+ <span class="comment"># you can also create instances of Triple and add them to the graph</span>
102
+ <span class="ident">t</span> <span class="punct">=</span> <span class="constant">RDF</span><span class="punct">::</span><span class="constant">Triple</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="constant">UriNode</span><span class="punct">.</span><span class="ident">new</span><span class="punct">('</span><span class="string">http://paul.stadig.name/</span><span class="punct">'),</span>
103
+ <span class="constant">DC</span><span class="punct">::</span><span class="ident">author</span><span class="punct">,</span>
104
+ <span class="ident">g</span><span class="punct">.</span><span class="ident">new_blank_node</span><span class="punct">('</span><span class="string">paul</span><span class="punct">'))</span>
105
+ <span class="ident">g</span><span class="punct">.</span><span class="ident">add</span><span class="punct">(</span><span class="ident">t</span><span class="punct">)</span>
106
+ </pre></p>
107
+
108
+
109
+ <h3>Querying a graph</h3>
110
+
111
+
112
+ <p><pre class='syntax'>
113
+ <span class="ident">q</span> <span class="punct">=</span> <span class="constant">Query</span><span class="punct">.</span><span class="ident">new</span>
114
+ <span class="ident">q</span><span class="punct">.</span><span class="ident">select</span><span class="punct">(</span><span class="symbol">:x</span><span class="punct">,</span> <span class="symbol">:y</span><span class="punct">).</span><span class="ident">where</span><span class="punct">(</span><span class="symbol">:x</span><span class="punct">,</span> <span class="constant">DC</span><span class="punct">::</span><span class="ident">author</span><span class="punct">,</span> <span class="symbol">:y</span><span class="punct">)</span>
115
+ <span class="ident">result</span> <span class="punct">=</span> <span class="ident">g</span><span class="punct">.</span><span class="ident">execute</span><span class="punct">(</span><span class="ident">q</span><span class="punct">)</span>
116
+ <span class="ident">result</span><span class="punct">.</span><span class="ident">bindings</span><span class="punct">.</span><span class="ident">each</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">b</span><span class="punct">|</span>
117
+ <span class="ident">puts</span> <span class="punct">&quot;</span><span class="string">x = <span class="expr">#{b[:x]}</span></span><span class="punct">&quot;</span>
118
+ <span class="ident">puts</span> <span class="punct">&quot;</span><span class="string">y = <span class="expr">#{b[:y]}</span></span><span class="punct">&quot;</span>
119
+ <span class="keyword">end</span>
120
+ </pre></p>
121
+
122
+
123
+ <h2>Forum</h2>
124
+
125
+
126
+ <p><a href="http://groups.google.com/group/rubyrdf">http://groups.google.com/group/rubyrdf</a></p>
127
+
128
+
129
+ <h2>How to get involved</h2>
130
+
131
+
132
+ <p>I am using Bazaar for source control, and Launchpad for development management. This provides (in my opinion) a superior development process. Since bazaar is a distributed version control system, you do not need my permission to start hacking on the code, you only need to branch it</p>
133
+
134
+
135
+ <pre>bzr branch http://bazaar.launchpad.net/~pjstadig/rubyrdf/trunk rubyrdf</pre>
136
+
137
+ <p>Write your tests. Write your code. Test. Then commit</p>
138
+
139
+
140
+ <pre>bzr commit -m"Some useful message about what you have done"</pre>
141
+
142
+ <p>If you want to let me know about your changes to have them included in the main development branch, then you&#8217;ll need to publish your branch somewhere. Launchpad provides bazaar hosting. To host your code there you&#8217;ll need a Launchpad account.</p>
143
+
144
+
145
+ <pre>bzr push sftp://bazaar.launchpad.net/~[your launchpad login]/rubyrdf/[your branch name]</pre>
146
+
147
+ <p>Let me know what you have done, and if your changes work, then I&#8217;ll pull them into the main branch, or I&#8217;ll provide feedback. You can also do stuff like associate a commit with a bug report, and Launchpad will automagically notice. For a more detailed tutorial see <a href="http://doc.bazaar-vcs.org/latest/en/mini-tutorial/index.html">Bazaar in five minutes</a> and <a href="http://doc.bazaar-vcs.org/latest/en/tutorials/using_bazaar_with_launchpad.html">Using Bazaar with Launchpad</a>.</p>
148
+
149
+
150
+ <h2>License</h2>
151
+
152
+
153
+ <p>This code is free to use under the terms of the <span class="caps">BSD</span> license (revised).</p>
154
+
155
+
156
+ <h2>Contact</h2>
157
+
158
+
159
+ <p>Comments are welcome. Send an email to <a href="mailto:paul@stadig.name">Paul Stadig</a> via the <a href="http://groups.google.com/group/rubyrdf">forum</a></p>
160
+ <p class="coda">
161
+ <a href="FIXME email">FIXME full name</a>, 9th April 2008<br>
162
+ Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
163
+ </p>
164
+ </div>
165
+
166
+ <!-- insert site tracking codes here, like Google Urchin -->
167
+
168
+ </body>
169
+ </html>
data/website/index.txt ADDED
@@ -0,0 +1,92 @@
1
+ h1. RubyRDF
2
+
3
+ h1. &#x2192; 'rubyrdf'
4
+
5
+
6
+ h2. What
7
+
8
+ An RDF (Resource Description Framework) data access layer for the Ruby programming language with a pluggable graph implementation. I have three goals:
9
+
10
+ # Provide an in-memory, pure Ruby implementation of the RDF graph model for situations where a high performance triple store is not needed.
11
+ # Provide plug-in graph implementations that delegate to high performance triple stores for situations where high performance is needed.
12
+ # Smooth out differences between triple stores to provide a consistent interface to RDF data. An example of this would be to deletgate reasoning to a triple store when available, but to provide a pure Ruby RDF reasoning engine that can be used with the in-memory model, or with triple stores that do not support reasoning. Same goes for SPARQL queries, import/export formats, etc.
13
+
14
+ h2. Installing
15
+
16
+ <pre syntax="ruby">sudo gem install rubyrdf</pre>
17
+
18
+ h2. The basics
19
+
20
+ RubyRDF implements the basic RDF data model (UriNode, TypedLiteralNode, PlainLiteralNode, BlankNode, Graph, etc.). There is also a very, _very_ simple querying mechanism that would hopefully be replaced by SPARQL or a SPARQL-based DSL. There is also a fully compliant NTriples import/export function.
21
+
22
+ There is a in-memory graph implementation, and a Sesame 1.x graph implementation that uses Sesame's HTTP protocol.
23
+
24
+ There is a class (Namespace) that is used to generate new UriNodes easily.
25
+
26
+ For more details about the API see the "rdocs":http://rubyrdf.rubyforge.org/rdoc/.
27
+
28
+ There are also some subprojects (at this point just one) that provide graph implementations for specific triple stores:
29
+
30
+ * "RubyRDF Sesame":http://rubyrdf.rubyforge.org/rubyrdf-sesame/
31
+
32
+ h2. Demonstration of usage
33
+
34
+ h3. Adding data to a graph
35
+
36
+ <pre syntax="ruby">
37
+ g = RDF::Graph::Memory.new
38
+ g.add(UriNode.new('http://paul.stadig.name/'), RDF::type, RDF::Resource)
39
+ </pre>
40
+
41
+ h3. Registering a new namespace
42
+
43
+ <pre syntax="ruby">
44
+ RDF::Namespace.register(:dc, 'http://purl.org/dc/elements/1.1/')
45
+
46
+ # you can also create instances of Triple and add them to the graph
47
+ t = RDF::Triple.new(UriNode.new('http://paul.stadig.name/'),
48
+ DC::author,
49
+ g.new_blank_node('paul'))
50
+ g.add(t)
51
+ </pre>
52
+
53
+ h3. Querying a graph
54
+
55
+ <pre syntax="ruby">
56
+ q = Query.new
57
+ q.select(:x, :y).where(:x, DC::author, :y)
58
+ result = g.execute(q)
59
+ result.bindings.each do |b|
60
+ puts "x = #{b[:x]}"
61
+ puts "y = #{b[:y]}"
62
+ end
63
+ </pre>
64
+
65
+ h2. Forum
66
+
67
+ "http://groups.google.com/group/rubyrdf":http://groups.google.com/group/rubyrdf
68
+
69
+ h2. How to get involved
70
+
71
+ I am using Bazaar for source control, and Launchpad for development management. This provides (in my opinion) a superior development process. Since bazaar is a distributed version control system, you do not need my permission to start hacking on the code, you only need to branch it
72
+
73
+ <pre>bzr branch http://bazaar.launchpad.net/~pjstadig/rubyrdf/trunk rubyrdf</pre>
74
+
75
+ Write your tests. Write your code. Test. Then commit
76
+
77
+ <pre>bzr commit -m"Some useful message about what you have done"</pre>
78
+
79
+ If you want to let me know about your changes to have them included in the main development branch, then you'll need to publish your branch somewhere. Launchpad provides bazaar hosting. To host your code there you'll need a Launchpad account.
80
+
81
+ <pre>bzr push sftp://bazaar.launchpad.net/~[your launchpad login]/rubyrdf/[your branch name]</pre>
82
+
83
+ Let me know what you have done, and if your changes work, then I'll pull them into the main branch, or I'll provide feedback. You can also do stuff like associate a commit with a bug report, and Launchpad will automagically notice. For a more detailed tutorial see "Bazaar in five minutes":http://doc.bazaar-vcs.org/latest/en/mini-tutorial/index.html and "Using Bazaar with Launchpad":http://doc.bazaar-vcs.org/latest/en/tutorials/using_bazaar_with_launchpad.html.
84
+
85
+ h2. License
86
+
87
+ This code is free to use under the terms of the BSD license (revised).
88
+
89
+ h2. Contact
90
+
91
+ Comments are welcome. Send an email to "Paul Stadig":mailto:paul@stadig.name via the "forum":http://groups.google.com/group/rubyrdf
92
+