rdf 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,13 +1,45 @@
1
1
  RDF.rb: RDF API for Ruby
2
2
  ========================
3
3
 
4
- This is an RDF API for Ruby.
4
+ This is a pure-Ruby library for working with Resource Description Framework
5
+ (RDF) data.
5
6
 
6
7
  ### About the Resource Description Framework (RDF)
7
8
 
8
9
  * <http://www.w3.org/RDF/>
9
10
  * <http://en.wikipedia.org/wiki/Resource_Description_Framework>
10
11
 
12
+ Examples
13
+ --------
14
+
15
+ require 'rdf'
16
+
17
+ ### Creating an RDF statement
18
+
19
+ s = RDF::URI.parse("http://gemcutter.org/gems/rdf")
20
+ p = RDF::DC.creator
21
+ o = RDF::URI.parse("http://ar.to/#self")
22
+
23
+ stmt = RDF::Statement.new(s, p, o)
24
+
25
+ ### Using pre-defined RDF vocabularies
26
+
27
+ include RDF
28
+
29
+ DC.title #=> RDF::URI("http://purl.org/dc/terms/title")
30
+ FOAF.knows #=> RDF::URI("http://xmlns.com/foaf/0.1/knows")
31
+ RDFS.seeAlso #=> RDF::URI("http://www.w3.org/2000/01/rdf-schema#seeAlso")
32
+ RSS.title #=> RDF::URI("http://purl.org/rss/1.0/title")
33
+ OWL.sameAs #=> RDF::URI("http://www.w3.org/2002/07/owl#sameAs")
34
+ XSD.dateTime #=> RDF::URI("http://www.w3.org/2001/XMLSchema#dateTime")
35
+
36
+ ### Using ad-hoc RDF vocabularies
37
+
38
+ foaf = RDF::Vocabulary.new("http://xmlns.com/foaf/0.1/")
39
+ foaf.knows #=> RDF::URI("http://xmlns.com/foaf/0.1/knows")
40
+ foaf[:name] #=> RDF::URI("http://xmlns.com/foaf/0.1/name")
41
+ foaf['mbox'] #=> RDF::URI("http://xmlns.com/foaf/0.1/mbox")
42
+
11
43
  Documentation
12
44
  -------------
13
45
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/lib/rdf.rb CHANGED
@@ -1,5 +1,41 @@
1
1
  require 'rdf/version'
2
2
 
3
3
  module RDF
4
- # TODO
4
+ autoload :Statement, 'rdf/statement'
5
+ autoload :URI, 'rdf/uri'
6
+ autoload :Vocabulary, 'rdf/vocabulary'
7
+
8
+ autoload :CC, 'rdf/vocabulary/cc'
9
+ autoload :DC, 'rdf/vocabulary/dc'
10
+ autoload :DOAP, 'rdf/vocabulary/doap'
11
+ autoload :EXIF, 'rdf/vocabulary/exif'
12
+ autoload :FOAF, 'rdf/vocabulary/foaf'
13
+ autoload :HTTP, 'rdf/vocabulary/http'
14
+ autoload :OWL, 'rdf/vocabulary/owl'
15
+ autoload :RDFS, 'rdf/vocabulary/rdfs'
16
+ autoload :RSS, 'rdf/vocabulary/rss'
17
+ autoload :SIOC, 'rdf/vocabulary/sioc'
18
+ autoload :SKOS, 'rdf/vocabulary/skos'
19
+ autoload :WOT, 'rdf/vocabulary/wot'
20
+ autoload :XHTML, 'rdf/vocabulary/xhtml'
21
+ autoload :XSD, 'rdf/vocabulary/xsd'
22
+
23
+ def self.Vocabulary(uri)
24
+ Vocabulary.create(uri)
25
+ end
26
+
27
+ def self.[](property)
28
+ RDF::URI.parse([to_s, property.to_s].join)
29
+ end
30
+
31
+ def self.method_missing(property, *args, &block)
32
+ if args.empty?
33
+ self[property]
34
+ else
35
+ super
36
+ end
37
+ end
38
+
39
+ def self.to_uri() RDF::URI.parse(to_s) end
40
+ def self.to_s() "http://www.w3.org/1999/02/22-rdf-syntax-ns#" end
5
41
  end
@@ -0,0 +1,52 @@
1
+ module RDF
2
+ ##
3
+ # An RDF statement.
4
+ class Statement
5
+ attr_accessor :context
6
+ attr_accessor :subject
7
+ attr_accessor :predicate
8
+ attr_accessor :object
9
+
10
+ def initialize(s, p, o, options = {})
11
+ @subject, @predicate, @object = s, p, o
12
+ @context = options[:context] if options[:context]
13
+ end
14
+
15
+ def subject?() !!subject end
16
+ def predicate?() !!predicate end
17
+ def object?() !!object end
18
+ def context?() !!context end
19
+ def asserted?() !quoted? end
20
+ def quoted?() false end
21
+
22
+ def ==(other)
23
+ to_a == other.to_a
24
+ end
25
+
26
+ def [](index)
27
+ to_a[index]
28
+ end
29
+
30
+ def to_a
31
+ [subject, predicate, object]
32
+ end
33
+
34
+ def to_hash
35
+ { subject => { predicate => object } }
36
+ end
37
+
38
+ def to_s
39
+ require 'stringio' unless defined?(StringIO)
40
+ StringIO.open do |buffer|
41
+ buffer << "<#{subject}> "
42
+ buffer << "<#{predicate}> "
43
+ buffer << "<#{object}> ."
44
+ buffer.string
45
+ end
46
+ end
47
+
48
+ def inspect
49
+ sprintf("#<%s:%#0x(%s)>", self.class.name, object_id, to_s)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ require 'addressable/uri'
2
+
3
+ module RDF
4
+ include Addressable
5
+ end
@@ -2,7 +2,7 @@ module RDF
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 1
5
+ TINY = 2
6
6
  EXTRA = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
@@ -0,0 +1,81 @@
1
+ module RDF
2
+ ##
3
+ # An RDF vocabulary.
4
+ class Vocabulary
5
+
6
+ def self.inspect
7
+ if self == Vocabulary
8
+ self.to_s
9
+ else
10
+ sprintf("%s(%s)", superclass.to_s, to_s)
11
+ end
12
+ end
13
+
14
+ def self.to_uri() RDF::URI.parse(to_s) end
15
+ def self.to_s() @@uris.has_key?(self) ? @@uris[self].to_s : super end
16
+
17
+ def self.[](property)
18
+ RDF::URI.parse([to_s, property.to_s].join(''))
19
+ end
20
+
21
+ def self.property(symbol) end # TODO
22
+
23
+ def initialize(uri)
24
+ case uri
25
+ when RDF::URI then @uri = uri.to_s
26
+ else @uri = RDF::URI.parse(uri.to_s) ? uri.to_s : nil
27
+ end
28
+ end
29
+
30
+ def inspect
31
+ sprintf("#<%s:%#0x(%s)>", self.class.name, object_id, to_s)
32
+ end
33
+
34
+ def to_uri() RDF::URI.parse(to_s) end
35
+ def to_s() @uri.to_s end
36
+
37
+ def [](property)
38
+ RDF::URI.parse([to_s, property.to_s].join(''))
39
+ end
40
+
41
+ protected
42
+ @@uris = {}
43
+ @@uri = nil
44
+
45
+ # @private
46
+ def self.create(uri)
47
+ @@uri = uri
48
+ self
49
+ end
50
+
51
+ # @private
52
+ def self.inherited(subclass)
53
+ unless @@uri.nil?
54
+ subclass.send(:private_class_method, :new)
55
+ @@uris[subclass] = @@uri
56
+ @@uri = nil
57
+ end
58
+ end
59
+
60
+ def self.method_missing(property, *args, &block)
61
+ if args.empty? && @@uris.has_key?(self)
62
+ self[property]
63
+ else
64
+ super
65
+ end
66
+ end
67
+
68
+ def method_missing(property, *args, &block)
69
+ if args.empty?
70
+ self[property]
71
+ else
72
+ raise ArgumentError.new("wrong number of arguments (#{args.size} for 0)")
73
+ end
74
+ end
75
+
76
+ end
77
+
78
+ def self.Vocabulary(uri)
79
+ Vocabulary.create(uri)
80
+ end
81
+ end
@@ -0,0 +1,7 @@
1
+ module RDF
2
+ ##
3
+ # Creative Commons (CC)
4
+ class CC < Vocabulary("http://creativecommons.org/ns#")
5
+ # TODO
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module RDF
2
+ ##
3
+ # Dublin Core (DC)
4
+ class DC < Vocabulary("http://purl.org/dc/terms/")
5
+ # TODO
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module RDF
2
+ ##
3
+ # Description of a Project (DOAP)
4
+ class DOAP < Vocabulary("http://usefulinc.com/ns/doap#")
5
+ # TODO
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module RDF
2
+ ##
3
+ # Exchangeable Image File Format (EXIF)
4
+ class EXIF < Vocabulary("http://www.w3.org/2003/12/exif/ns#")
5
+ # TODO
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module RDF
2
+ ##
3
+ # Friend of a Friend (FOAF)
4
+ class FOAF < Vocabulary("http://xmlns.com/foaf/0.1/")
5
+ # TODO
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module RDF
2
+ ##
3
+ # Hypertext Transfer Protocol (HTTP)
4
+ class HTTP < Vocabulary("http://www.w3.org/2006/http#")
5
+ # TODO
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module RDF
2
+ ##
3
+ # Web Ontology Language (OWL)
4
+ class OWL < Vocabulary("http://www.w3.org/2002/07/owl#")
5
+ # TODO
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module RDF
2
+ ##
3
+ # Resource Description Framework (RDF)
4
+ class RDF < Vocabulary("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
5
+ # TODO
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module RDF
2
+ ##
3
+ # RDF Schema (RDFS)
4
+ class RDFS < Vocabulary("http://www.w3.org/2000/01/rdf-schema#")
5
+ # TODO
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module RDF
2
+ ##
3
+ # RDF Site Summary (RSS)
4
+ class RSS < Vocabulary("http://purl.org/rss/1.0/")
5
+ # TODO
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module RDF
2
+ ##
3
+ # Semantically-Interlinked Online Communities (SIOC)
4
+ class SIOC < Vocabulary("http://rdfs.org/sioc/ns#")
5
+ # TODO
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module RDF
2
+ ##
3
+ # Simple Knowledge Organization System (SKOS)
4
+ class SKOS < Vocabulary("http://www.w3.org/2004/02/skos/core#")
5
+ # TODO
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module RDF
2
+ ##
3
+ # Web of Trust (WOT)
4
+ class WOT < Vocabulary("http://xmlns.com/wot/0.1/")
5
+ # TODO
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module RDF
2
+ ##
3
+ # Extensible HyperText Markup Language (XHTML)
4
+ class XHTML < Vocabulary("http://www.w3.org/1999/xhtml/vocab#")
5
+ # TODO
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module RDF
2
+ ##
3
+ # XML Schema (XSD)
4
+ class XSD < Vocabulary("http://www.w3.org/2001/XMLSchema#")
5
+ # TODO
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arto Bendiken
@@ -9,9 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-20 00:00:00 +01:00
12
+ date: 2009-12-21 00:00:00 +01:00
13
13
  default_executable: rdf
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
15
25
  - !ruby/object:Gem::Dependency
16
26
  name: addressable
17
27
  type: :runtime
@@ -37,8 +47,26 @@ files:
37
47
  - UNLICENSE
38
48
  - VERSION
39
49
  - bin/rdf
40
- - lib/rdf.rb
50
+ - lib/rdf/statement.rb
51
+ - lib/rdf/uri.rb
41
52
  - lib/rdf/version.rb
53
+ - lib/rdf/vocabulary/cc.rb
54
+ - lib/rdf/vocabulary/dc.rb
55
+ - lib/rdf/vocabulary/doap.rb
56
+ - lib/rdf/vocabulary/exif.rb
57
+ - lib/rdf/vocabulary/foaf.rb
58
+ - lib/rdf/vocabulary/http.rb
59
+ - lib/rdf/vocabulary/owl.rb
60
+ - lib/rdf/vocabulary/rdf.rb
61
+ - lib/rdf/vocabulary/rdfs.rb
62
+ - lib/rdf/vocabulary/rss.rb
63
+ - lib/rdf/vocabulary/sioc.rb
64
+ - lib/rdf/vocabulary/skos.rb
65
+ - lib/rdf/vocabulary/wot.rb
66
+ - lib/rdf/vocabulary/xhtml.rb
67
+ - lib/rdf/vocabulary/xsd.rb
68
+ - lib/rdf/vocabulary.rb
69
+ - lib/rdf.rb
42
70
  has_rdoc: false
43
71
  homepage: http://rdfrb.rubyforge.org/
44
72
  licenses: