Skip to content

Commit

Permalink
6 left
Browse files Browse the repository at this point in the history
  • Loading branch information
pius committed Apr 17, 2010
1 parent 5375a29 commit 4a4a8bf
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions lib/rdf/mongo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def self.to_mongo(value, place_in_statement)
v, k = value.to_s, :u
when RDF::Literal
v, k = value.value, :l
when nil
v, k = nil, nil
else
v, k = value.to_s, :u
end
Expand All @@ -53,7 +55,8 @@ def self.to_mongo(value, place_in_statement)
when :context
t, k1 = :ct, :c
end
return {k1 => v, t => k}
h = {k1 => (v == '' ? nil : v), t => (k == '' ? nil : k)}
h.delete_if {|k,v| h[k].nil?}
end

def self.from_mongo(value, value_type = :u)
Expand Down Expand Up @@ -123,28 +126,34 @@ def query(pattern, &block)
the_statements.each {|s| block.call(RDF::Statement.from_mongo(s))}
else
#e = enumerator!.new(statements.extend(RDF::Queryable),:rdf_each)
s = the_statements.extend(RDF::Enumerable, RDF::Queryable)
#s = the_statements.extend(RDF::Enumerable, RDF::Queryable)
def the_statements.each(&block)
if block_given?
super {|statement| block.call(RDF::Statement.from_mongo(statement)) }
else
enumerator!.new(the_statements,:rdf_each)
end
end
s

def the_statements.size
count
end
s = the_statements
end
else
super(pattern)
end
end

def query_hash(hash)
h = {}
(h[:s] = hash[:subject]) if hash[:subject]
(h[:p] = hash[:predicate]) if hash[:predicate]
(h[:o] = hash[:object]) if hash[:object]
(h[:c] = hash[:context]) if hash[:context]
@coll.find(h) || []
return @coll.find if hash.empty?
h = RDF::Statement.new(hash).to_mongo
# h = {}
# (h[:s] = hash[:subject]) if hash[:subject]
# (h[:p] = hash[:predicate]) if hash[:predicate]
# (h[:o] = hash[:object]) if hash[:object]
# (h[:c] = hash[:context]) if hash[:context]
@coll.find(h)
end


Expand Down

0 comments on commit 4a4a8bf

Please sign in to comment.