@@ -14,17 +14,17 @@ def to_mongo
1414 end
1515
1616 ##
17- # Create BSON for a statement representation. Note that if the statement has no context ,
17+ # Create BSON for a statement representation. Note that if the statement has no graph name ,
1818 # a value of `false` will be used to indicate the default context
1919 #
2020 # @param [RDF::Statement] statement
2121 # @return [Hash] Generated BSON representation of statement.
2222 def self . from_mongo ( statement )
2323 RDF ::Statement . new (
24- : subject => RDF ::Mongo ::Conversion . from_mongo ( statement [ 's' ] , statement [ 'st' ] , statement [ 'sl' ] ) ,
25- : predicate => RDF ::Mongo ::Conversion . from_mongo ( statement [ 'p' ] , statement [ 'pt' ] , statement [ 'pl' ] ) ,
26- : object => RDF ::Mongo ::Conversion . from_mongo ( statement [ 'o' ] , statement [ 'ot' ] , statement [ 'ol' ] ) ,
27- :context => RDF ::Mongo ::Conversion . from_mongo ( statement [ 'c' ] , statement [ 'ct' ] , statement [ 'cl' ] ) )
24+ subject : RDF ::Mongo ::Conversion . from_mongo ( statement [ 's' ] , statement [ 'st' ] , statement [ 'sl' ] ) ,
25+ predicate : RDF ::Mongo ::Conversion . from_mongo ( statement [ 'p' ] , statement [ 'pt' ] , statement [ 'pl' ] ) ,
26+ object : RDF ::Mongo ::Conversion . from_mongo ( statement [ 'o' ] , statement [ 'ot' ] , statement [ 'ol' ] ) ,
27+ graph_name : RDF ::Mongo ::Conversion . from_mongo ( statement [ 'c' ] , statement [ 'ct' ] , statement [ 'cl' ] ) )
2828 end
2929 end
3030
@@ -37,9 +37,9 @@ class Conversion
3737 #
3838 # @param [RDF::Value, Symbol, false, nil] value
3939 # URI, BNode or Literal. May also be a Variable or Symbol to indicate
40- # a pattern for a named context , or `false` to indicate the default context .
40+ # a pattern for a named graph , or `false` to indicate the default graph .
4141 # A value of `nil` indicates a pattern that matches any value.
42- # @param [:subject, :predicate, :object, :context ] place_in_statement
42+ # @param [:subject, :predicate, :object, :graph_name ] place_in_statement
4343 # Position within statement.
4444 # @return [Hash] BSON representation of the statement
4545 def self . to_mongo ( value , place_in_statement )
@@ -76,7 +76,7 @@ def self.to_mongo(value, place_in_statement)
7676 t , k1 , lt = :pt , :p , :pl
7777 when :object
7878 t , k1 , lt = :ot , :o , :ol
79- when :context
79+ when :graph_name
8080 t , k1 , lt = :ct , :c , :cl
8181 end
8282 h = { k1 => v , t => k , lt => ll }
@@ -92,9 +92,9 @@ def self.from_mongo(value, value_type = :u, literal_extra = nil)
9292 when :u
9393 RDF ::URI . intern ( value )
9494 when :ll
95- RDF ::Literal . new ( value , : language => literal_extra . to_sym )
95+ RDF ::Literal . new ( value , language : literal_extra . to_sym )
9696 when :lt
97- RDF ::Literal . new ( value , : datatype => RDF ::URI . intern ( literal_extra ) )
97+ RDF ::Literal . new ( value , datatype : RDF ::URI . intern ( literal_extra ) )
9898 when :l
9999 RDF ::Literal . new ( value )
100100 when :n
@@ -126,12 +126,15 @@ class Repository < ::RDF::Repository
126126 # @option options [String] :host
127127 # @option options [Integer] :port
128128 # @option options [String] :db
129+ # @option options [String] :user for authentication
130+ # @option options [String] :password for authentication
129131 # @option options [String] :collection ('quads')
130132 # @yield [repository]
131133 # @yieldparam [Repository] repository
132134 def initialize ( options = { } , &block )
133- options = { : host => 'localhost' , : port => 27017 , :db => 'quadb' , : collection => 'quads' } . merge ( options )
135+ options = { host : 'localhost' , port : 27017 , db : 'quadb' , collection : 'quads' } . merge ( options )
134136 @db = ::Mongo ::Connection . new ( options [ :host ] , options [ :port ] ) . db ( options [ :db ] )
137+ @db . authenticate ( options [ :user ] , options [ :password ] ) if options [ :user ] && options [ :password ]
135138 @coll = @db [ options [ :collection ] ]
136139 @coll . create_index ( "s" )
137140 @coll . create_index ( "p" )
@@ -146,21 +149,22 @@ def initialize(options = {}, &block)
146149 # @see RDF::Mutable#insert_statement
147150 def supports? ( feature )
148151 case feature . to_sym
149- when :context then true
152+ when :graph_name then true
150153 else false
151154 end
152155 end
153156
154157 def insert_statement ( statement )
158+ raise ArgumentError , "Statement #{ statement . inspect } is incomplete" if statement . incomplete?
155159 st_mongo = statement . to_mongo
156- st_mongo [ :ct ] ||= :default # Indicate statement is in the default context
160+ st_mongo [ :ct ] ||= :default # Indicate statement is in the default graph
157161 #puts "insert statement: #{st_mongo.inspect}"
158- @coll . update ( st_mongo , st_mongo , : upsert => true )
162+ @coll . update ( st_mongo , st_mongo , upsert : true )
159163 end
160164
161165 # @see RDF::Mutable#delete_statement
162166 def delete_statement ( statement )
163- case statement . context
167+ case statement . graph_name
164168 when nil
165169 @coll . remove ( statement . to_mongo . merge ( 'ct' => :default ) )
166170 else
@@ -213,8 +217,8 @@ def each_statement(&block)
213217
214218 ##
215219 # @private
216- # @see RDF::Enumerable#has_context ?
217- def has_context ?( value )
220+ # @see RDF::Enumerable#has_graph ?
221+ def has_graph ?( value )
218222 !!@coll . find_one ( RDF ::Mongo ::Conversion . to_mongo ( value , :context ) )
219223 end
220224
@@ -227,9 +231,9 @@ def has_context?(value)
227231 def query_pattern ( pattern , &block )
228232 @nodes = { } # reset cache. FIXME this should probably be in Node.intern
229233
230- # A pattern context of `false` is used to indicate the default context
234+ # A pattern graph_name of `false` is used to indicate the default graph
231235 pm = pattern . to_mongo
232- pm . merge! ( :c => nil , :ct => :default ) if pattern . context == false
236+ pm . merge! ( c : nil , ct : :default ) if pattern . graph_name == false
233237 #puts "query using #{pm.inspect}"
234238 @coll . find ( pm ) do |cursor |
235239 cursor . each do |data |
0 commit comments