iq_rdf 0.0.15 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +92 -0
- data/iq_rdf.gemspec +2 -2
- data/lib/iq_rdf/rails/iq_rdf.rb +22 -21
- data/lib/iq_rdf/version.rb +1 -1
- metadata +44 -63
- data/README.rdoc +0 -77
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# IqRdf - RDF Renderering for Ruby and Rails
|
2
|
+
IqRdf is a RDF renderer for Ruby and Rails. You can use it in any Ruby
|
3
|
+
environment to render Trurtle-, N-Triple- (not implemented jet) or XML-RDF.
|
4
|
+
|
5
|
+
IqRdf underlays a [Builder](http://builder.rubyforge.org/)-like approach to specify
|
6
|
+
the RDF-Data by using a internal Ruby DSL. The basic Idea for specifing a triple
|
7
|
+
(subject, predicate, object) is that the predicate is a method call on the
|
8
|
+
subject with the object as parameters:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
IqRdf::some_subject.some_predicate(IqRdf::some_object)
|
12
|
+
```
|
13
|
+
|
14
|
+
The IqRdf namespaces are needed not to mess up the rest of your project due to
|
15
|
+
the heavy use of method_missing in the IqRdf-Library. See the IqRdf::use method
|
16
|
+
for Ruby 1.9 to omit the `IqRdf::` prefix.
|
17
|
+
|
18
|
+
## Ruby example
|
19
|
+
You can use IqRdf in pure Ruby to produce Strings in a certain RDF Syntax like
|
20
|
+
Turtle or XML:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
require 'IqRdf'
|
24
|
+
document = IqRdf::Document.new('http://www.test.de/')
|
25
|
+
|
26
|
+
document.namespaces :skos => 'http://www.w3.org/2008/05/skos#',
|
27
|
+
:foaf => 'http://xmlns.com/foaf/0.1/' # A :rdf namespace is added automatically
|
28
|
+
|
29
|
+
document << IqRdf::john_doe.myCustomNote("This is an example", :lang => :en)
|
30
|
+
# Turtle: :john_doe :myCustomNote "This is an example"@en.
|
31
|
+
|
32
|
+
document << IqRdf::john_doe(IqRdf::Foaf::build_uri("Person")).Foaf::name("John Doe")
|
33
|
+
# Turtle: :john_doe a foaf:Person; foaf:name "John Doe".
|
34
|
+
|
35
|
+
document << IqRdf::john_doe.Foaf::knows(IqRdf::jane_doe)
|
36
|
+
# Turtle: :john_doe foaf:knows :jane_doe.
|
37
|
+
|
38
|
+
document.to_turtle
|
39
|
+
# => "@prefix : <http://www.test.de/>. ..."
|
40
|
+
```
|
41
|
+
|
42
|
+
## Rails example
|
43
|
+
Include IqRdf to your Ruby on Rails project by adding the following line to your
|
44
|
+
Gemfile (or with Rails 2.x in your config/environment.rb):
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
gem "iq_rdf"
|
48
|
+
```
|
49
|
+
|
50
|
+
Add the mime types you want to support to your config/initializers/mime_types.rb
|
51
|
+
file:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
Mime::Type.register "application/rdf+xml", :rdf
|
55
|
+
Mime::Type.register "text/turtle", :ttl
|
56
|
+
Mime::Type.register "application/n-triples", :nt
|
57
|
+
```
|
58
|
+
|
59
|
+
Now you can define views in you application. Use the extension *.iqrdf*
|
60
|
+
for the view files. You can use the extensions *.ttl* or
|
61
|
+
*.rdf* in the URL of your request, to force the output to be
|
62
|
+
in Turtle or XML/RDF.
|
63
|
+
|
64
|
+
### Views
|
65
|
+
In your views IqRdf gives you a *document* object you can add your triples
|
66
|
+
to. But first you will have to define your namespaces and the global language if
|
67
|
+
you want to label all String literals in a certain language (as long as there is
|
68
|
+
no other language or `:none` given).
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
document.namespaces :default => 'http://data.example.com/', :foaf => 'http://xmlns.com/foaf/0.1/'
|
72
|
+
document.lang = :en
|
73
|
+
|
74
|
+
document << IqRdf::test_subject.test_predicate("test")
|
75
|
+
# Turtle: :test_subject :test_predicate "test"@en.
|
76
|
+
|
77
|
+
document << IqRdf::test_subject.test_predicate("test", :lang => :de)
|
78
|
+
# Turtle: :test_subject :test_predicate "test"@de.
|
79
|
+
|
80
|
+
document << IqRdf::test_subject.test_predicate("test", :lang => :none)
|
81
|
+
# Turtle: :test_subject :test_predicate "test".
|
82
|
+
|
83
|
+
# ...
|
84
|
+
```
|
85
|
+
|
86
|
+
Use the namespace token `:default` to mark the default namespace. This has the
|
87
|
+
same effect as specifing the default namespace in `IqRdf::Document.new`.
|
88
|
+
|
89
|
+
## Complex RDF definitions
|
90
|
+
TODO
|
91
|
+
|
92
|
+
Copyright (c) 2011 innoQ Deutschland GmbH, released under the Apache License 2.0
|
data/iq_rdf.gemspec
CHANGED
@@ -25,12 +25,12 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.homepage = "http://github.com/innoq/iq_rdf"
|
26
26
|
s.summary = "IqRdf - A builder like rdf library for ruby and rails"
|
27
27
|
s.description = s.summary
|
28
|
-
s.extra_rdoc_files = ['README.
|
28
|
+
s.extra_rdoc_files = ['README.md', 'LICENSE']
|
29
29
|
|
30
30
|
s.add_dependency "bundler"
|
31
31
|
s.add_dependency "builder"
|
32
32
|
|
33
|
-
s.files = %w(LICENSE README.
|
33
|
+
s.files = %w(LICENSE README.md Rakefile iq_rdf.gemspec) + Dir.glob("{lib,rails,test}/**/*")
|
34
34
|
s.test_files = Dir.glob("{test}/**/*")
|
35
35
|
s.executables = Dir.glob("{bin}/**/*")
|
36
36
|
s.require_paths = ["lib"]
|
data/lib/iq_rdf/rails/iq_rdf.rb
CHANGED
@@ -12,31 +12,32 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
module ActionView
|
15
|
+
module ActionView
|
16
|
+
module Template::Handlers
|
16
17
|
|
17
|
-
|
18
|
-
include ActionView::TemplateHandlers::Compilable
|
18
|
+
class IqRdf
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
def self.call(template)
|
21
|
+
<<-EOV
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
23
|
+
document = IqRdf::Document.new()
|
24
|
+
#{template.source}
|
25
|
+
if params[:format].to_s == "ttl"
|
26
|
+
controller.response.headers["Content-Type"] ||= 'text/turtle'
|
27
|
+
document.to_turtle
|
28
|
+
elsif params[:format].to_s == "nt"
|
29
|
+
controller.response.headers["Content-Type"] ||= 'text/plain'
|
30
|
+
document.to_ntriples
|
31
|
+
elsif params[:format].to_s == "rdf"
|
32
|
+
controller.response.headers["Content-Type"] ||= 'application/xml+rdf'
|
33
|
+
document.to_xml
|
34
|
+
else # Default => turtle
|
35
|
+
controller.response.headers["Content-Type"] ||= 'text/turtle'
|
36
|
+
document.to_turtle
|
37
|
+
end
|
38
|
+
EOV
|
37
39
|
end
|
38
|
-
EOV
|
39
40
|
end
|
41
|
+
|
40
42
|
end
|
41
|
-
|
42
43
|
end
|
data/lib/iq_rdf/version.rb
CHANGED
metadata
CHANGED
@@ -1,64 +1,49 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: iq_rdf
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 15
|
10
|
-
version: 0.0.15
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Till Schulte-Coerne
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-01-10 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: bundler
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2154052080 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: builder
|
37
23
|
prerelease: false
|
38
|
-
|
24
|
+
version_requirements: *2154052080
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: builder
|
27
|
+
requirement: &2154050800 !ruby/object:Gem::Requirement
|
39
28
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
version: "0"
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
47
33
|
type: :runtime
|
48
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2154050800
|
49
36
|
description: IqRdf - A builder like rdf library for ruby and rails
|
50
|
-
email:
|
37
|
+
email:
|
51
38
|
- till.schulte-coerne@innoq.com
|
52
39
|
executables: []
|
53
|
-
|
54
40
|
extensions: []
|
55
|
-
|
56
|
-
|
57
|
-
- README.rdoc
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.md
|
58
43
|
- LICENSE
|
59
|
-
files:
|
44
|
+
files:
|
60
45
|
- LICENSE
|
61
|
-
- README.
|
46
|
+
- README.md
|
62
47
|
- Rakefile
|
63
48
|
- iq_rdf.gemspec
|
64
49
|
- lib/iq_rdf/blank_node.rb
|
@@ -79,41 +64,37 @@ files:
|
|
79
64
|
- test/test_helper.rb
|
80
65
|
- test/turtle_test.rb
|
81
66
|
- test/xml_test.rb
|
82
|
-
has_rdoc: true
|
83
67
|
homepage: http://github.com/innoq/iq_rdf
|
84
68
|
licenses: []
|
85
|
-
|
86
69
|
post_install_message:
|
87
70
|
rdoc_options: []
|
88
|
-
|
89
|
-
require_paths:
|
71
|
+
require_paths:
|
90
72
|
- lib
|
91
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
74
|
none: false
|
93
|
-
requirements:
|
94
|
-
- -
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
|
97
|
-
segments:
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
segments:
|
98
80
|
- 0
|
99
|
-
|
100
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
hash: -3269158319309008120
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
83
|
none: false
|
102
|
-
requirements:
|
103
|
-
- -
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
|
106
|
-
segments:
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
segments:
|
107
89
|
- 0
|
108
|
-
|
90
|
+
hash: -3269158319309008120
|
109
91
|
requirements: []
|
110
|
-
|
111
92
|
rubyforge_project:
|
112
|
-
rubygems_version: 1.
|
93
|
+
rubygems_version: 1.8.10
|
113
94
|
signing_key:
|
114
95
|
specification_version: 3
|
115
96
|
summary: IqRdf - A builder like rdf library for ruby and rails
|
116
|
-
test_files:
|
97
|
+
test_files:
|
117
98
|
- test/iq_rdf_test.rb
|
118
99
|
- test/test_helper.rb
|
119
100
|
- test/turtle_test.rb
|
data/README.rdoc
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
== IqRdf
|
2
|
-
IqRdf is a RDF renderer for Ruby and Rails. You can use it in any Ruby
|
3
|
-
environment to render Trurtle-, N-Triple- (not implemented jet) or XML-RDF.
|
4
|
-
|
5
|
-
IqRdf underlays a Builder-like (http://builder.rubyforge.org/) approach to specify
|
6
|
-
the RDF-Data by using a internal Ruby DSL. The basic Idea for specifing a triple
|
7
|
-
(subject, predicate, object) is that the predicate is a method call on the
|
8
|
-
subject with the object as parameters:
|
9
|
-
|
10
|
-
IqRdf::some_subject.some_predicate(IqRdf::some_object)
|
11
|
-
|
12
|
-
The IqRdf namespaces are needed not to mess up the rest of your project due to
|
13
|
-
the heavy use of method_missing in the IqRdf-Library. See the IqRdf::use method
|
14
|
-
for Ruby 1.9 to omit the "IqRdf::" prefix.
|
15
|
-
|
16
|
-
=== Ruby example
|
17
|
-
You can use IqRdf in pure Ruby to produce Strings in a certain RDF Syntax like
|
18
|
-
Turtle or XML:
|
19
|
-
require 'IqRdf'
|
20
|
-
document = IqRdf::Document.new('http://www.test.de/')
|
21
|
-
|
22
|
-
document.namespaces :skos => 'http://www.w3.org/2008/05/skos#',
|
23
|
-
:foaf => 'http://xmlns.com/foaf/0.1/' # A :rdf namespace is added automatically
|
24
|
-
|
25
|
-
document << IqRdf::john_doe.myCustomNote("This is an example", :lang => :en)
|
26
|
-
# Turtle: :john_doe :myCustomNote "This is an example"@en.
|
27
|
-
|
28
|
-
document << IqRdf::john_doe(IqRdf::Foaf::build_uri("Person")).Foaf::name("John Doe")
|
29
|
-
# Turtle: :john_doe a foaf:Person; foaf:name "John Doe".
|
30
|
-
|
31
|
-
document << IqRdf::john_doe.Foaf::knows(IqRdf::jane_doe)
|
32
|
-
# Turtle: :john_doe foaf:knows :jane_doe.
|
33
|
-
|
34
|
-
document.to_turtle
|
35
|
-
# => "@prefix : <http://www.test.de/>. ..."
|
36
|
-
|
37
|
-
=== Rails example
|
38
|
-
Include IqRdf to your Ruby on Rails project by adding the following line to your
|
39
|
-
Gemfile (or with Rails 2.x in your config/environment.rb):
|
40
|
-
gem "iq_rdf"
|
41
|
-
Add the mime types you want to support to your config/initializers/mime_types.rb
|
42
|
-
file:
|
43
|
-
Mime::Type.register "application/rdf+xml", :rdf
|
44
|
-
Mime::Type.register "text/turtle", :ttl
|
45
|
-
Mime::Type.register "application/n-triples", :nt
|
46
|
-
Now you can define views in you application. Use the extension <em>.iqrdf</em>
|
47
|
-
for the view files. You can use the extensions <em>.ttl</em> or
|
48
|
-
<em>.rdf</em> in the URL of your request, to force the output to be
|
49
|
-
in Turtle or XML/RDF.
|
50
|
-
|
51
|
-
==== The views
|
52
|
-
In your views IqRdf gives you a <em>document</em> object you can add your triples
|
53
|
-
to. But first you will have to define your namespaces and the global language if
|
54
|
-
you want to label all String literals in a certain language (as long as there is
|
55
|
-
no other language or <em>:none</em> given).
|
56
|
-
document.namespaces :default => 'http://data.example.com/', :foaf => 'http://xmlns.com/foaf/0.1/'
|
57
|
-
document.lang = :en
|
58
|
-
|
59
|
-
document << IqRdf::test_subject.test_predicate("test")
|
60
|
-
# Turtle: :test_subject :test_predicate "test"@en.
|
61
|
-
|
62
|
-
document << IqRdf::test_subject.test_predicate("test", :lang => :de)
|
63
|
-
# Turtle: :test_subject :test_predicate "test"@de.
|
64
|
-
|
65
|
-
|
66
|
-
document << IqRdf::test_subject.test_predicate("test", :lang => :none)
|
67
|
-
# Turtle: :test_subject :test_predicate "test".
|
68
|
-
|
69
|
-
...
|
70
|
-
|
71
|
-
Use the namespace token <em>:default</em> to mark the default namespace. This has the
|
72
|
-
same effect as specifing the default namespace in IqRdf::Document.new.
|
73
|
-
|
74
|
-
=== Complex RDF definitions
|
75
|
-
...
|
76
|
-
|
77
|
-
Copyright (c) 2011 innoQ Deutschland GmbH, released under the Apache License 2.0
|