rdf_context 0.5.10 → 0.5.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. data/.yardopts +2 -1
  2. data/History.rdoc +7 -0
  3. data/README.rdoc +14 -14
  4. data/Rakefile +7 -7
  5. data/VERSION +1 -1
  6. data/lib/rdf_context/graph.rb +19 -16
  7. data/lib/rdf_context/rdfaparser.rb +1 -1
  8. data/lib/rdf_context/store/abstract_sql_store.rb +12 -4
  9. data/lib/rdf_context/store/abstract_store.rb +6 -0
  10. data/lib/rdf_context/store/active_record_store.rb +5 -11
  11. data/lib/rdf_context/store/list_store.rb +5 -0
  12. data/lib/rdf_context/store/memory_store.rb +38 -18
  13. data/lib/rdf_context/store/sqlite3_store.rb +0 -7
  14. data/rdf_context.gemspec +11 -122
  15. data/spec/active_record_store_spec.rb +4 -0
  16. data/spec/graph_spec.rb +6 -2
  17. data/spec/matchers.rb +1 -1
  18. data/spec/rdfa_helper.rb +6 -17
  19. data/spec/spec_helper.rb +4 -9
  20. data/spec/sqlite3_store_spec.rb +2 -2
  21. data/spec/store_helper.rb +69 -15
  22. metadata +35 -122
  23. data/spec/rdfa-triples/0001.nt +0 -1
  24. data/spec/rdfa-triples/0006.nt +0 -2
  25. data/spec/rdfa-triples/0007.nt +0 -3
  26. data/spec/rdfa-triples/0008.nt +0 -1
  27. data/spec/rdfa-triples/0009.nt +0 -1
  28. data/spec/rdfa-triples/0010.nt +0 -2
  29. data/spec/rdfa-triples/0011.nt +0 -3
  30. data/spec/rdfa-triples/0012.nt +0 -1
  31. data/spec/rdfa-triples/0013.nt +0 -1
  32. data/spec/rdfa-triples/0014.nt +0 -1
  33. data/spec/rdfa-triples/0015.nt +0 -2
  34. data/spec/rdfa-triples/0017.nt +0 -3
  35. data/spec/rdfa-triples/0018.nt +0 -1
  36. data/spec/rdfa-triples/0019.nt +0 -1
  37. data/spec/rdfa-triples/0020.nt +0 -1
  38. data/spec/rdfa-triples/0021.nt +0 -1
  39. data/spec/rdfa-triples/0023.nt +0 -1
  40. data/spec/rdfa-triples/0025.nt +0 -2
  41. data/spec/rdfa-triples/0026.nt +0 -1
  42. data/spec/rdfa-triples/0027.nt +0 -1
  43. data/spec/rdfa-triples/0029.nt +0 -1
  44. data/spec/rdfa-triples/0030.nt +0 -1
  45. data/spec/rdfa-triples/0031.nt +0 -1
  46. data/spec/rdfa-triples/0032.nt +0 -1
  47. data/spec/rdfa-triples/0033.nt +0 -2
  48. data/spec/rdfa-triples/0034.nt +0 -1
  49. data/spec/rdfa-triples/0035.nt +0 -1
  50. data/spec/rdfa-triples/0036.nt +0 -1
  51. data/spec/rdfa-triples/0037.nt +0 -1
  52. data/spec/rdfa-triples/0038.nt +0 -1
  53. data/spec/rdfa-triples/0039.nt +0 -1
  54. data/spec/rdfa-triples/0040.nt +0 -1
  55. data/spec/rdfa-triples/0041.nt +0 -1
  56. data/spec/rdfa-triples/0042.nt +0 -0
  57. data/spec/rdfa-triples/0046.nt +0 -3
  58. data/spec/rdfa-triples/0047.nt +0 -3
  59. data/spec/rdfa-triples/0048.nt +0 -3
  60. data/spec/rdfa-triples/0049.nt +0 -2
  61. data/spec/rdfa-triples/0050.nt +0 -2
  62. data/spec/rdfa-triples/0051.nt +0 -2
  63. data/spec/rdfa-triples/0052.nt +0 -1
  64. data/spec/rdfa-triples/0053.nt +0 -2
  65. data/spec/rdfa-triples/0054.nt +0 -2
  66. data/spec/rdfa-triples/0055.nt +0 -2
  67. data/spec/rdfa-triples/0056.nt +0 -3
  68. data/spec/rdfa-triples/0057.nt +0 -4
  69. data/spec/rdfa-triples/0058.nt +0 -6
  70. data/spec/rdfa-triples/0059.nt +0 -6
  71. data/spec/rdfa-triples/0060.nt +0 -2
  72. data/spec/rdfa-triples/0061.nt +0 -1
  73. data/spec/rdfa-triples/0062.nt +0 -1
  74. data/spec/rdfa-triples/0063.nt +0 -1
  75. data/spec/rdfa-triples/0064.nt +0 -1
  76. data/spec/rdfa-triples/0065.nt +0 -3
  77. data/spec/rdfa-triples/0066.nt +0 -1
  78. data/spec/rdfa-triples/0067.nt +0 -1
  79. data/spec/rdfa-triples/0068.nt +0 -1
  80. data/spec/rdfa-triples/0069.nt +0 -1
  81. data/spec/rdfa-triples/0070.nt +0 -1
  82. data/spec/rdfa-triples/0071.nt +0 -1
  83. data/spec/rdfa-triples/0072.nt +0 -1
  84. data/spec/rdfa-triples/0073.nt +0 -1
  85. data/spec/rdfa-triples/0074.nt +0 -1
  86. data/spec/rdfa-triples/0075.nt +0 -1
  87. data/spec/rdfa-triples/0076.nt +0 -23
  88. data/spec/rdfa-triples/0077.nt +0 -23
  89. data/spec/rdfa-triples/0078.nt +0 -6
  90. data/spec/rdfa-triples/0079.nt +0 -3
  91. data/spec/rdfa-triples/0080.nt +0 -1
  92. data/spec/rdfa-triples/0081.nt +0 -6
  93. data/spec/rdfa-triples/0082.nt +0 -8
  94. data/spec/rdfa-triples/0083.nt +0 -6
  95. data/spec/rdfa-triples/0084.nt +0 -8
  96. data/spec/rdfa-triples/0085.nt +0 -4
  97. data/spec/rdfa-triples/0086.nt +0 -0
  98. data/spec/rdfa-triples/0087.nt +0 -23
  99. data/spec/rdfa-triples/0088.nt +0 -3
  100. data/spec/rdfa-triples/0089.nt +0 -1
  101. data/spec/rdfa-triples/0090.nt +0 -1
  102. data/spec/rdfa-triples/0091.nt +0 -3
  103. data/spec/rdfa-triples/0092.nt +0 -3
  104. data/spec/rdfa-triples/0093.nt +0 -2
  105. data/spec/rdfa-triples/0094.nt +0 -3
  106. data/spec/rdfa-triples/0099.nt +0 -1
  107. data/spec/rdfa-triples/0100.nt +0 -3
  108. data/spec/rdfa-triples/0101.nt +0 -3
  109. data/spec/rdfa-triples/0102.nt +0 -1
  110. data/spec/rdfa-triples/0103.nt +0 -1
  111. data/spec/rdfa-triples/0104.nt +0 -3
  112. data/spec/rdfa-triples/0105.nt +0 -1
  113. data/spec/rdfa-triples/0106.nt +0 -1
  114. data/spec/rdfa-triples/0107.nt +0 -0
  115. data/spec/rdfa-triples/0108.nt +0 -1
  116. data/spec/rdfa-triples/0109.nt +0 -1
  117. data/spec/rdfa-triples/0110.nt +0 -1
  118. data/spec/rdfa-triples/0111.nt +0 -2
  119. data/spec/rdfa-triples/0112.nt +0 -1
  120. data/spec/rdfa-triples/0113.nt +0 -2
  121. data/spec/rdfa-triples/0114.nt +0 -3
  122. data/spec/rdfa-triples/0115.nt +0 -4
  123. data/spec/rdfa-triples/0116.nt +0 -2
  124. data/spec/rdfa-triples/0117.nt +0 -2
  125. data/spec/rdfa-triples/0118.nt +0 -1
  126. data/spec/rdfa-triples/0119.nt +0 -1
  127. data/spec/rdfa-triples/0120.nt +0 -1
  128. data/spec/rdfa-triples/0121.nt +0 -2
  129. data/spec/rdfa-triples/0122.nt +0 -1
  130. data/spec/rdfa-triples/0123.nt +0 -3
  131. data/spec/rdfa-triples/0124.nt +0 -4
  132. data/spec/rdfa-triples/0125.nt +0 -1
  133. data/spec/rdfa-triples/0126.nt +0 -3
  134. data/spec/rdfa-triples/1001.nt +0 -6
data/.yardopts CHANGED
@@ -1,4 +1,4 @@
1
- --title "RDF::RDFa - XHTML+RDFa Support for RDF.rb"
1
+ --title "RdfContext is an RDF library for Ruby"
2
2
  --output-dir doc/yard
3
3
  --protected
4
4
  --no-private
@@ -6,5 +6,6 @@
6
6
  --markup rdoc
7
7
  --readme README.rdoc
8
8
  -
9
+ README.rdoc
9
10
  History.rdoc
10
11
  VERSION
@@ -1,3 +1,10 @@
1
+ === 0.5.11
2
+ * AbstractSQLStore was incorrectly putting Literal::Language representation rather than value in database.
3
+ * Changed Graph#eql? and Graph#== to do simple equality check.
4
+ * Added Graph#isomorphic? which does more exhaustive equivalence check.
5
+ * Fixed bug in MemoryStore where a frozen resource could be returned.
6
+ * AbstractStore#destroy either removes all triples from store, or specified context. No longer removes the DB file.
7
+
1
8
  === 0.5.10
2
9
  * N3 Parser
3
10
  * Allow mixed case literal languages.
@@ -3,32 +3,32 @@
3
3
  Context-sensitive RDF Graphs, including a ConjunctiveGraph.
4
4
 
5
5
  A set of compliant RDF parsers:
6
- * N3-rdf
6
+ * Notation3
7
7
  * RDF/XML
8
8
  * RDFa
9
9
 
10
- Multiple data-stores may be attached to a Graph, including Memory, List and SQLite3
10
+ Multiple data-stores may be attached to a Graph, including Memory, List, ActiveRecord and SQLite3
11
11
 
12
- == DESCRIPTION:
12
+ == DESCRIPTION
13
13
 
14
14
  RdfContext is an RDF library for Ruby.
15
15
 
16
- == FEATURES:
16
+ == FEATURES
17
17
  RdfContext parses RDF/XML, RDFa and N3-rdf into a Graph object. It also serializes RDF/XML and N-Triples from the Graph.
18
18
 
19
19
  * Fully compliant RDF/XML parser.
20
20
  * Fully compliant XHTML/RDFa 1.0 parser.
21
- * Fully compliant N3-rdf parser (N3-rdf level)
21
+ * Fully compliant Notation3 parser (N3-rdf level)
22
22
  * Turtle, N-Triples and RDF/XML serializer
23
23
  * RDFa tests use SPARQL for most tests due to Rasqal limitations. Other tests compare directly against N-triples.
24
- * Graph serializes into RDF/XML and N-Triples.
24
+ * Graph serializes into RDF/XML, Turtle and N-Triples.
25
25
  * ConjunctiveGraph, named Graphs and contextual storage modules.
26
26
 
27
27
  RdfContext is based, in part, on Tom Morris' Reddy gem.
28
28
 
29
29
  Install with 'gem install rdf_context'
30
30
 
31
- == Usage:
31
+ == Usage
32
32
  === Graphs
33
33
  Instantiate a graph using Graph.new. A Graph may take an :identifier (defaults to a BNode) and
34
34
  a :store (defaults to :list_store)
@@ -168,7 +168,7 @@ An RDF store could provide a standard set of interfaces for the manipulation, ma
168
168
  These interfaces work on contexts and formulae (for stores that are formula-aware) interchangeably.
169
169
  *contexts*:: Closure or list over all contexts in the graph. If triple is specified, it returns all contexts the triple is in.
170
170
 
171
- == Dependencies:
171
+ == Dependencies
172
172
 
173
173
  * Addressable
174
174
  * Treetop
@@ -180,11 +180,11 @@ These interfaces work on contexts and formulae (for stores that are formula-awar
180
180
  * Redland/Rasqal
181
181
  * ActiveSupport
182
182
 
183
- == INSTALL:
183
+ == INSTALL
184
184
 
185
185
  * sudo gem install rdf_context
186
186
 
187
- == TODO:
187
+ == TODO
188
188
  * Testing
189
189
  * RDFa updates for new tests and non XHTML representations.
190
190
  * Graphs
@@ -200,7 +200,7 @@ These interfaces work on contexts and formulae (for stores that are formula-awar
200
200
  * RDoc[http://rdoc.info/projects/gkellogg/rdf_context]
201
201
  * History[http://github.com/gkellogg/rdf_context/blob/master/History.txt]
202
202
 
203
- == LICENSE:
203
+ == LICENSE
204
204
 
205
205
  (The MIT License)
206
206
 
@@ -230,7 +230,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
230
230
  == FEEDBACK
231
231
 
232
232
233
- * gemcutter.org/rdf_context
234
- * github.com/gkellogg/rdf_context
235
- * gkellogg.lighthouseapp.com for bug reports
233
+ * http://rubygems.org/rdf_context
234
+ * http://github.com/gkellogg/rdf_context
235
+ * http://rdoc.info/github/gkellogg/rdf_context
236
236
  * public-rdf-ruby mailing list on w3.org
data/Rakefile CHANGED
@@ -8,13 +8,12 @@ begin
8
8
  gemspec.name = "rdf_context"
9
9
  gemspec.summary = "RdfContext is an RDF library for Ruby supporting contextual graphs, multiple datastores and compliant RDF/XML, RDFa and N3 parsers."
10
10
  gemspec.description = <<-DESCRIPTION
11
- RdfContext parses RDF/XML, RDFa and N3-rdf into a Graph object. It also serializes RDF/XML and N-Triples from the Graph.
11
+ RdfContext parses RDF/XML, RDFa and N3 into a Graph object. It also serializes RDF/XML, Turtle and N-Triples from the Graph.
12
12
 
13
13
  * Fully compliant RDF/XML parser.
14
14
  * Fully compliant XHTML/RDFa 1.0 parser.
15
- * N3-rdf parser
16
- * N-Triples and RDF/XML serializer
17
- * Graph serializes into RDF/XML and N-Triples.
15
+ * Notation3 parser (N3-rdf level)
16
+ * N-Triples, Turtle and RDF/XML serializer
18
17
  * ConjunctiveGraph, named Graphs and contextual storage modules.
19
18
 
20
19
  Install with 'gem install rdf_context'
@@ -27,7 +26,8 @@ begin
27
26
  gemspec.add_dependency('nokogiri', '>= 1.4.3')
28
27
  gemspec.add_dependency('builder', '>= 2.1.2')
29
28
  gemspec.add_development_dependency('rspec', '>= 2.1.0')
30
- gemspec.add_development_dependency('activesupport', '>= 2.3.0')
29
+ gemspec.add_development_dependency('activesupport', '~> 2.3.8')
30
+ gemspec.add_development_dependency('activerecord', '~> 2.3.8')
31
31
  gemspec.add_development_dependency('yard')
32
32
  gemspec.extra_rdoc_files = %w(README.rdoc History.txt)
33
33
  end
@@ -55,8 +55,8 @@ RSpec::Core::RakeTask.new("spec:rcov") do |spec|
55
55
  end
56
56
 
57
57
  desc "Generate HTML report specs"
58
- RSpec::Core::RakeTask.new("spec") do |spec|
59
- spec.rspec_opts = ["--format", "html:doc/spec.html"]
58
+ RSpec::Core::RakeTask.new("doc:spec") do |spec|
59
+ spec.rspec_opts = ["--format", "html", "-o", "doc/spec.html"]
60
60
  end
61
61
 
62
62
  task :spec => :check_dependencies
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.10
1
+ 0.5.11
@@ -64,12 +64,7 @@ module RdfContext
64
64
  # If configuration is nil, remove the graph context
65
65
  # @return [void]
66
66
  def destroy(configuration = nil)
67
- if configuration
68
- @store.destroy(configuration)
69
- else
70
- @store.remove(Triple.new(nil, nil, nil), self)
71
- end
72
-
67
+ @store.destroy(configuration ? configuration : {:context => self})
73
68
  self.freeze
74
69
  end
75
70
 
@@ -488,7 +483,19 @@ module RdfContext
488
483
  end
489
484
  end
490
485
 
491
- # Two graphs are equal if each is an instance of the other, considering BNode equivalence.
486
+ # Two graphs are equal (==) if each other if they are both graphs have the same identifiers and the same size.
487
+ #
488
+ # If each graph has a BNode identifier, they are considered to be equal if the have the same size
489
+ #
490
+ # @param [Graph] graph
491
+ # @return [Boolean]
492
+ def ==(other)
493
+ #puts "== size #{self.size} vs #{other.size}" if ::RdfContext::debug?
494
+ other.is_a?(Graph) && self.size == other.size &&
495
+ ((other.identifier.is_a?(BNode) && identifier.is_a?(BNode)) || (other.identifier.to_s == identifier.to_s))
496
+ end
497
+
498
+ # Two graphs are isomorphic if each is an instance of the other, considering BNode equivalence.
492
499
  # This may be done by creating a new graph an substituting each permutation of BNode identifiers
493
500
  # from self to other until every permutation is exhausted, or a textual equivalence is found
494
501
  # after sorting each graph.
@@ -496,20 +503,18 @@ module RdfContext
496
503
  # We just follow Python RDFlib's lead and do a simple comparison
497
504
  # @param [Graph] graph
498
505
  # @return [Boolean]
499
- def eql?(other)
500
- #puts "eql? size #{self.size} vs #{other.size}" if ::RdfContext::debug?
501
- return false if !other.is_a?(Graph) || self.size != other.size
502
- return false unless other.identifier.to_s == identifier.to_s unless other.identifier.is_a?(BNode) && identifier.is_a?(BNode)
506
+ def isomorphic?(other)
507
+ return false unless self == other
503
508
 
504
509
  bn_self = bnodes.values.sort
505
510
  bn_other = other.bnodes.values.sort
506
- puts "eql? bnodes '#{bn_self.to_sentence}' vs '#{bn_other.to_sentence}'" if ::RdfContext::debug?
511
+ puts "isomorphic? bnodes '#{bn_self.to_sentence}' vs '#{bn_other.to_sentence}'" if ::RdfContext::debug?
507
512
  return false unless bn_self == bn_other
508
513
 
509
514
  # Check each triple to see if it's contained in the other graph
510
515
  triples do |t, ctx|
511
516
  next if t.subject.is_a?(BNode) || t.predicate.is_a?(BNode) || t.object.is_a?(BNode)
512
- puts "eql? contains '#{t.to_ntriples}: #{other.contains?(t)}'" if ::RdfContext::debug?
517
+ puts "isomorphic? contains '#{t.to_ntriples}: #{other.contains?(t)}'" if ::RdfContext::debug?
513
518
  return false unless other.contains?(t)
514
519
  end
515
520
 
@@ -525,7 +530,7 @@ module RdfContext
525
530
  predicate = bn_map[predicate] if bn_map.has_key?(predicate)
526
531
  object = bn_map[object] if bn_map.has_key?(object)
527
532
  tn = Triple.new(subject, predicate, object)
528
- puts " eql? contains '#{tn.inspect}': #{other.contains?(tn)}" if ::RdfContext::debug?
533
+ puts " isomorphic? contains '#{tn.inspect}': #{other.contains?(tn)}" if ::RdfContext::debug?
529
534
  next if other.contains?(tn)
530
535
 
531
536
  puts " no, next permutation" if ::RdfContext::debug?
@@ -541,8 +546,6 @@ module RdfContext
541
546
  # Exhausted all permutations, unless there were no bnodes
542
547
  bn_self.length == 0
543
548
  end
544
-
545
- alias_method :==, :eql?
546
549
 
547
550
  # Parse source into Graph.
548
551
  #
@@ -450,7 +450,7 @@ module RdfContext
450
450
  :base => xml_base,
451
451
  :property => property,
452
452
  :typeof => typeof,
453
- :daetatype => datatype,
453
+ :datatype => datatype,
454
454
  :rel => rel,
455
455
  :rev => rev,
456
456
  :profiles => (profiles.empty? ? nil : profiles),
@@ -72,6 +72,14 @@ module RdfContext
72
72
  @db.close
73
73
  end
74
74
 
75
+ # Destroy store or context
76
+ # If context is specified remove that context, otherwise, remove all triples
77
+ #
78
+ # @option configuration [Graph] :context Remove the specified context
79
+ def destroy(configuration = {})
80
+ remove(Triple.new(nil, nil, nil), configuration[:context])
81
+ end
82
+
75
83
  # Add a triple to the store
76
84
  # Add to default context, if context is nil
77
85
  #
@@ -691,8 +699,8 @@ module RdfContext
691
699
  normalizeTerm(triple.object),
692
700
  normalizeTerm(context),
693
701
  triplePattern,
694
- (triple.object.is_a?(Literal) ? triple.object.lang : NULL),
695
- (triple.object.is_a?(Literal) ? triple.object.encoding.value.to_s : NULL),
702
+ (triple.object.is_a?(Literal) && triple.object.lang ? triple.object.lang.to_s : nil),
703
+ (triple.object.is_a?(Literal) && triple.object.encoding ? triple.object.encoding.value.to_s : nil),
696
704
  ]
697
705
  end
698
706
 
@@ -709,8 +717,8 @@ module RdfContext
709
717
  normalizeTerm(triple.object),
710
718
  normalizeTerm(context),
711
719
  triplePattern,
712
- (triple.object.is_a?(Literal) ? triple.object.lang : NULL),
713
- (triple.object.is_a?(Literal) ? triple.object.encoding.value.to_s : NULL),
720
+ (triple.object.is_a?(Literal) && triple.object.lang ? triple.object.lang.to_s : nil),
721
+ (triple.object.is_a?(Literal) && triple.object.encoding ? triple.object.encoding.value.to_s : nil),
714
722
  ]
715
723
  else
716
724
  [
@@ -62,6 +62,12 @@ module RdfContext
62
62
  # @raise [StoreException] Not Implemented
63
63
  # @return [Boolean]
64
64
  def contains?(triple, context = nil); raise StoreException, "not implemented"; end
65
+
66
+ # Return contexts in the store (optionally matching triple), or empty if not context aware
67
+ # @return [Array<Graph>]
68
+ def contexts(triple = nil)
69
+ return []
70
+ end
65
71
 
66
72
  # Default (sub-optimal) implemenations of interfaces
67
73
  def inspect
@@ -1,4 +1,4 @@
1
- gem 'activerecord'
1
+ gem 'activerecord', "~> 2.3.8"
2
2
  require 'active_record'
3
3
 
4
4
  module RdfContext
@@ -38,7 +38,7 @@ module RdfContext
38
38
  executeSQL(CREATE_QUOTED_STATEMENTS_TABLE % @internedId)
39
39
  executeSQL(CREATE_NS_BINDS_TABLE % @internedId)
40
40
  executeSQL(CREATE_LITERAL_STATEMENTS_TABLE % @internedId)
41
-
41
+
42
42
  # Create indicies
43
43
  {
44
44
  asserted_table => {
@@ -76,7 +76,7 @@ module RdfContext
76
76
  end
77
77
  end
78
78
  end
79
-
79
+
80
80
  # Teardown DB files
81
81
  def teardown
82
82
  # Drop indicies
@@ -116,7 +116,7 @@ module RdfContext
116
116
  executeSQL("DROP INDEX #{index} ON #{tn}")
117
117
  end
118
118
  end
119
-
119
+
120
120
  # Drop tables
121
121
  executeSQL("DROP TABLE #{namespace_binds}")
122
122
  executeSQL("DROP TABLE #{quoted_table}")
@@ -124,12 +124,6 @@ module RdfContext
124
124
  executeSQL("DROP TABLE #{asserted_type_table}")
125
125
  executeSQL("DROP TABLE #{asserted_table}")
126
126
  end
127
-
128
- # Destroy database
129
- #
130
- # @option options[String] :path Path to database file defaults to a file in the current directory based on a hash of the store identifier
131
- def destroy(options = {})
132
- end
133
127
 
134
128
  protected
135
129
 
@@ -204,7 +198,7 @@ module RdfContext
204
198
  # Yields each row
205
199
  def executeSQL(qStr, *params, &block)
206
200
  conn = ActiveRecord::Base.connection
207
-
201
+
208
202
  puts "executeSQL: params=#{params.flatten.inspect}" if ::RdfContext::debug?
209
203
  puts "executeSQL: '#{params.dup.unshift(qStr).join("', '")}'" if ::RdfContext::debug?
210
204
  qStr = ActiveRecord::Base.send(:replace_bind_variables, qStr, params.flatten)
@@ -16,6 +16,11 @@ module RdfContext
16
16
  "ListStore[id=#{identifier}, size=#{@triples.length}]"
17
17
  end
18
18
 
19
+ # Destroy the store, as it can contain only one context
20
+ def destroy(configuration = {})
21
+ @triples = []
22
+ end
23
+
19
24
  # Add triple to store
20
25
  # @param [Triple] triple
21
26
  # @param [Graph] context (nil) ignored
@@ -36,22 +36,7 @@ module RdfContext
36
36
  # @return [MemoryStore]
37
37
  def initialize(identifier = nil, configuration = {})
38
38
  super
39
- # indexed by [context][subject][predicate][object] = 1
40
- @cspo = {}
41
- # indexed by [context][predicate][object][subject] = 1
42
- @cpos = {}
43
- # indexed by [context][object][subject][predicate] = 1
44
- @cosp = {}
45
- # indexed by [subject][predicate][object] = [context]
46
- @spo = {}
47
- # indexed by [predicate][object][subject] = [context]
48
- @pos = {}
49
- # indexed by [object][subject][predicate] = [context]
50
- @osp = {}
51
- # indexes integer keys to identifiers
52
- @forward = {}
53
- # reverse index of forward
54
- @reverse = {}
39
+ destroy({})
55
40
  end
56
41
 
57
42
  def inspect
@@ -70,6 +55,39 @@ module RdfContext
70
55
  " reverse: #{@reverse.inspect}\n"
71
56
  end
72
57
 
58
+ # Destroy store or context
59
+ # If context is specified remove that context, otherwise, re-initialize the store
60
+ #
61
+ # @option configuration [Graph] :context Remove the specified context
62
+ def destroy(configuration = {})
63
+ if ctx = configuration[:context]
64
+ remove(Triple.new(nil, nil, nil), ctx)
65
+
66
+ ci = resource_to_int(ctx)
67
+ if ci
68
+ @reverse.delete(ctx.hash)
69
+ @forward.delete(ci)
70
+ end
71
+ else
72
+ # indexed by [context][subject][predicate][object] = 1
73
+ @cspo = {}
74
+ # indexed by [context][predicate][object][subject] = 1
75
+ @cpos = {}
76
+ # indexed by [context][object][subject][predicate] = 1
77
+ @cosp = {}
78
+ # indexed by [subject][predicate][object] = [context]
79
+ @spo = {}
80
+ # indexed by [predicate][object][subject] = [context]
81
+ @pos = {}
82
+ # indexed by [object][subject][predicate] = [context]
83
+ @osp = {}
84
+ # indexes integer keys to identifiers
85
+ @forward = {}
86
+ # reverse index of forward
87
+ @reverse = {}
88
+ end
89
+ end
90
+
73
91
  # Add a triple to the store
74
92
  # Add to default context, if context is nil
75
93
  #
@@ -145,7 +163,7 @@ module RdfContext
145
163
  osp = @osp
146
164
  else
147
165
  ci = resource_to_int(context)
148
- return [] unless ci
166
+ return [] if context.frozen? || !ci
149
167
  spo = @cspo[ci]
150
168
  pos = @cpos[ci]
151
169
  osp = @cosp[ci]
@@ -354,6 +372,8 @@ module RdfContext
354
372
  def triple_to_int(triple)
355
373
  [@reverse[triple.subject.hash], @reverse[triple.predicate.hash], @reverse[triple.object.hash]]
356
374
  end
357
- def resource_to_int(resource); @reverse[resource.hash]; end
375
+ def resource_to_int(resource);
376
+ @reverse[resource.hash]
377
+ end
358
378
  end
359
379
  end
@@ -142,13 +142,6 @@ module RdfContext
142
142
  executeSQL("DROP TABLE #{asserted_table}")
143
143
  end
144
144
 
145
- # Destroy database
146
- #
147
- # @option options[String] :path Path to database file defaults to a file in the current directory based on a hash of the store identifier
148
- def destroy(options = {})
149
- File.delete(@path)
150
- end
151
-
152
145
  protected
153
146
 
154
147
  # Where clase utility functions
@@ -5,19 +5,18 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rdf_context}
8
- s.version = "0.5.10"
8
+ s.version = "0.5.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gregg Kellogg"]
12
- s.date = %q{2010-12-19}
12
+ s.date = %q{2011-01-07}
13
13
  s.default_executable = %q{rdf_context}
14
- s.description = %q{ RdfContext parses RDF/XML, RDFa and N3-rdf into a Graph object. It also serializes RDF/XML and N-Triples from the Graph.
14
+ s.description = %q{ RdfContext parses RDF/XML, RDFa and N3 into a Graph object. It also serializes RDF/XML, Turtle and N-Triples from the Graph.
15
15
 
16
16
  * Fully compliant RDF/XML parser.
17
17
  * Fully compliant XHTML/RDFa 1.0 parser.
18
- * N3-rdf parser
19
- * N-Triples and RDF/XML serializer
20
- * Graph serializes into RDF/XML and N-Triples.
18
+ * Notation3 parser (N3-rdf level)
19
+ * N-Triples, Turtle and RDF/XML serializer
21
20
  * ConjunctiveGraph, named Graphs and contextual storage modules.
22
21
 
23
22
  Install with 'gem install rdf_context'
@@ -30,7 +29,6 @@ Gem::Specification.new do |s|
30
29
  s.files = [
31
30
  ".autotest",
32
31
  ".gitignore",
33
- ".yardoc",
34
32
  ".yardopts",
35
33
  "History.rdoc",
36
34
  "README.rdoc",
@@ -91,118 +89,6 @@ Gem::Specification.new do |s|
91
89
  "spec/parser_spec.rb",
92
90
  "spec/quoted_graph_spec.rb",
93
91
  "spec/rdf_helper.rb",
94
- "spec/rdfa-triples/0001.nt",
95
- "spec/rdfa-triples/0006.nt",
96
- "spec/rdfa-triples/0007.nt",
97
- "spec/rdfa-triples/0008.nt",
98
- "spec/rdfa-triples/0009.nt",
99
- "spec/rdfa-triples/0010.nt",
100
- "spec/rdfa-triples/0011.nt",
101
- "spec/rdfa-triples/0012.nt",
102
- "spec/rdfa-triples/0013.nt",
103
- "spec/rdfa-triples/0014.nt",
104
- "spec/rdfa-triples/0015.nt",
105
- "spec/rdfa-triples/0017.nt",
106
- "spec/rdfa-triples/0018.nt",
107
- "spec/rdfa-triples/0019.nt",
108
- "spec/rdfa-triples/0020.nt",
109
- "spec/rdfa-triples/0021.nt",
110
- "spec/rdfa-triples/0023.nt",
111
- "spec/rdfa-triples/0025.nt",
112
- "spec/rdfa-triples/0026.nt",
113
- "spec/rdfa-triples/0027.nt",
114
- "spec/rdfa-triples/0029.nt",
115
- "spec/rdfa-triples/0030.nt",
116
- "spec/rdfa-triples/0031.nt",
117
- "spec/rdfa-triples/0032.nt",
118
- "spec/rdfa-triples/0033.nt",
119
- "spec/rdfa-triples/0034.nt",
120
- "spec/rdfa-triples/0035.nt",
121
- "spec/rdfa-triples/0036.nt",
122
- "spec/rdfa-triples/0037.nt",
123
- "spec/rdfa-triples/0038.nt",
124
- "spec/rdfa-triples/0039.nt",
125
- "spec/rdfa-triples/0040.nt",
126
- "spec/rdfa-triples/0041.nt",
127
- "spec/rdfa-triples/0042.nt",
128
- "spec/rdfa-triples/0046.nt",
129
- "spec/rdfa-triples/0047.nt",
130
- "spec/rdfa-triples/0048.nt",
131
- "spec/rdfa-triples/0049.nt",
132
- "spec/rdfa-triples/0050.nt",
133
- "spec/rdfa-triples/0051.nt",
134
- "spec/rdfa-triples/0052.nt",
135
- "spec/rdfa-triples/0053.nt",
136
- "spec/rdfa-triples/0054.nt",
137
- "spec/rdfa-triples/0055.nt",
138
- "spec/rdfa-triples/0056.nt",
139
- "spec/rdfa-triples/0057.nt",
140
- "spec/rdfa-triples/0058.nt",
141
- "spec/rdfa-triples/0059.nt",
142
- "spec/rdfa-triples/0060.nt",
143
- "spec/rdfa-triples/0061.nt",
144
- "spec/rdfa-triples/0062.nt",
145
- "spec/rdfa-triples/0063.nt",
146
- "spec/rdfa-triples/0064.nt",
147
- "spec/rdfa-triples/0065.nt",
148
- "spec/rdfa-triples/0066.nt",
149
- "spec/rdfa-triples/0067.nt",
150
- "spec/rdfa-triples/0068.nt",
151
- "spec/rdfa-triples/0069.nt",
152
- "spec/rdfa-triples/0070.nt",
153
- "spec/rdfa-triples/0071.nt",
154
- "spec/rdfa-triples/0072.nt",
155
- "spec/rdfa-triples/0073.nt",
156
- "spec/rdfa-triples/0074.nt",
157
- "spec/rdfa-triples/0075.nt",
158
- "spec/rdfa-triples/0076.nt",
159
- "spec/rdfa-triples/0077.nt",
160
- "spec/rdfa-triples/0078.nt",
161
- "spec/rdfa-triples/0079.nt",
162
- "spec/rdfa-triples/0080.nt",
163
- "spec/rdfa-triples/0081.nt",
164
- "spec/rdfa-triples/0082.nt",
165
- "spec/rdfa-triples/0083.nt",
166
- "spec/rdfa-triples/0084.nt",
167
- "spec/rdfa-triples/0085.nt",
168
- "spec/rdfa-triples/0086.nt",
169
- "spec/rdfa-triples/0087.nt",
170
- "spec/rdfa-triples/0088.nt",
171
- "spec/rdfa-triples/0089.nt",
172
- "spec/rdfa-triples/0090.nt",
173
- "spec/rdfa-triples/0091.nt",
174
- "spec/rdfa-triples/0092.nt",
175
- "spec/rdfa-triples/0093.nt",
176
- "spec/rdfa-triples/0094.nt",
177
- "spec/rdfa-triples/0099.nt",
178
- "spec/rdfa-triples/0100.nt",
179
- "spec/rdfa-triples/0101.nt",
180
- "spec/rdfa-triples/0102.nt",
181
- "spec/rdfa-triples/0103.nt",
182
- "spec/rdfa-triples/0104.nt",
183
- "spec/rdfa-triples/0105.nt",
184
- "spec/rdfa-triples/0106.nt",
185
- "spec/rdfa-triples/0107.nt",
186
- "spec/rdfa-triples/0108.nt",
187
- "spec/rdfa-triples/0109.nt",
188
- "spec/rdfa-triples/0110.nt",
189
- "spec/rdfa-triples/0111.nt",
190
- "spec/rdfa-triples/0112.nt",
191
- "spec/rdfa-triples/0113.nt",
192
- "spec/rdfa-triples/0114.nt",
193
- "spec/rdfa-triples/0115.nt",
194
- "spec/rdfa-triples/0116.nt",
195
- "spec/rdfa-triples/0117.nt",
196
- "spec/rdfa-triples/0118.nt",
197
- "spec/rdfa-triples/0119.nt",
198
- "spec/rdfa-triples/0120.nt",
199
- "spec/rdfa-triples/0121.nt",
200
- "spec/rdfa-triples/0122.nt",
201
- "spec/rdfa-triples/0123.nt",
202
- "spec/rdfa-triples/0124.nt",
203
- "spec/rdfa-triples/0125.nt",
204
- "spec/rdfa-triples/0126.nt",
205
- "spec/rdfa-triples/1001.nt",
206
92
  "spec/rdfa_helper.rb",
207
93
  "spec/rdfa_parser_spec.rb",
208
94
  "spec/rdfcore/.gitignore",
@@ -848,7 +734,8 @@ Gem::Specification.new do |s|
848
734
  s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.3"])
849
735
  s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
850
736
  s.add_development_dependency(%q<rspec>, [">= 2.1.0"])
851
- s.add_development_dependency(%q<activesupport>, [">= 2.3.0"])
737
+ s.add_development_dependency(%q<activesupport>, ["~> 2.3.8"])
738
+ s.add_development_dependency(%q<activerecord>, ["~> 2.3.8"])
852
739
  s.add_development_dependency(%q<yard>, [">= 0"])
853
740
  else
854
741
  s.add_dependency(%q<addressable>, [">= 2.2.0"])
@@ -856,7 +743,8 @@ Gem::Specification.new do |s|
856
743
  s.add_dependency(%q<nokogiri>, [">= 1.4.3"])
857
744
  s.add_dependency(%q<builder>, [">= 2.1.2"])
858
745
  s.add_dependency(%q<rspec>, [">= 2.1.0"])
859
- s.add_dependency(%q<activesupport>, [">= 2.3.0"])
746
+ s.add_dependency(%q<activesupport>, ["~> 2.3.8"])
747
+ s.add_dependency(%q<activerecord>, ["~> 2.3.8"])
860
748
  s.add_dependency(%q<yard>, [">= 0"])
861
749
  end
862
750
  else
@@ -865,7 +753,8 @@ Gem::Specification.new do |s|
865
753
  s.add_dependency(%q<nokogiri>, [">= 1.4.3"])
866
754
  s.add_dependency(%q<builder>, [">= 2.1.2"])
867
755
  s.add_dependency(%q<rspec>, [">= 2.1.0"])
868
- s.add_dependency(%q<activesupport>, [">= 2.3.0"])
756
+ s.add_dependency(%q<activesupport>, ["~> 2.3.8"])
757
+ s.add_dependency(%q<activerecord>, ["~> 2.3.8"])
869
758
  s.add_dependency(%q<yard>, [">= 0"])
870
759
  end
871
760
  end
OSZAR »