Class: RDF::BERT::Server
- Inherits:
-
Object
- Object
- RDF::BERT::Server
- Defined in:
- lib/rdf/bert/server.rb
Class Method Summary (collapse)
- + (Object) run(repository = nil, options = {})
- + (Object) start(repository = nil, options = {})
- + (Object) start_with_bertrem(repository = nil, options = {})
- + (Object) start_with_ernie(repository = nil, options = {})
Instance Method Summary (collapse)
- - (Boolean) clear(*contexts)
- - (Array) contexts
- - (Integer) count(*contexts)
- - (Boolean) delete(context, *triples)
- - (Boolean) empty?(*contexts)
- - (Boolean) exist?(context, *triples)
-
- (Server) initialize(repository = nil, options = {})
constructor
A new instance of Server.
- - (Boolean) insert(context, *triples)
- - (Array) known?(context, *triples)
- - (Array) predicates(*contexts)
- - (Array) query(context, *patterns)
- - (Array) subjects(*contexts)
Constructor Details
- (Server) initialize(repository = nil, options = {})
A new instance of Server
50 51 52 53 |
# File 'lib/rdf/bert/server.rb', line 50 def initialize(repository = nil, = {}) @repository = repository || RDF::Repository.new @options = .dup end |
Class Method Details
+ (Object) run(repository = nil, options = {})
4 5 6 7 8 9 10 |
# File 'lib/rdf/bert/server.rb', line 4 def self.run(repository = nil, = {}) require 'eventmachine' unless defined?(::EM) ::EM.run do self.start(repository, ) end end |
+ (Object) start(repository = nil, options = {})
12 13 14 |
# File 'lib/rdf/bert/server.rb', line 12 def self.start(repository = nil, = {}) self.start_with_bertrem(repository, ) end |
+ (Object) start_with_bertrem(repository = nil, options = {})
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rdf/bert/server.rb', line 18 def self.start_with_bertrem(repository = nil, = {}) require 'bertrem' unless defined?(::BERTREM) host = [:host] || '0.0.0.0' port = [:port] || DEFAULT_PORT EM.run do server = self.new(repository) BERTREM::Server.mod(:rdf, lambda do self.public_instance_methods(false).each do |method_name| BERTREM::Server.fun(method_name.to_sym, server.method(method_name.to_sym)) end end) BERTREM::Server.start(host, port) end end |
+ (Object) start_with_ernie(repository = nil, options = {})
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rdf/bert/server.rb', line 37 def self.start_with_ernie(repository = nil, = {}) require 'ernie' unless defined?(::Ernie) server = self.new(repository) Ernie.mod(:rdf, lambda do self.public_instance_methods(false).each do |method_name| Ernie.fun(method_name.to_sym, server.method(method_name.to_sym)) end end) end |
Instance Method Details
- (Boolean) clear(*contexts)
110 111 112 113 114 115 116 117 118 |
# File 'lib/rdf/bert/server.rb', line 110 def clear(*contexts) if contexts.empty? @repository.clear else contexts.map! { |context| RDF::BERT.unserialize(context) } raise NotImplementedError, 'rdf:clear' # TODO: support named graphs end return true end |
- (Array) contexts
64 65 66 |
# File 'lib/rdf/bert/server.rb', line 64 def contexts @repository.contexts.map { |value| RDF::BERT.serialize(value) } end |
- (Integer) count(*contexts)
100 101 102 103 104 105 106 |
# File 'lib/rdf/bert/server.rb', line 100 def count(*contexts) if contexts.empty? return @repository.count else raise NotImplementedError, 'rdf:count' # TODO: support named graphs end end |
- (Boolean) delete(context, *triples)
185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/rdf/bert/server.rb', line 185 def delete(context, *triples) context = RDF::BERT.unserialize(context) triples.each do |triple| case triple when Array statement = RDF::BERT.unserialize(triple) statement.context = context if context @repository.delete(statement) else # TODO: support triple identifiers end end return true end |
- (Boolean) empty?(*contexts)
90 91 92 93 94 95 96 |
# File 'lib/rdf/bert/server.rb', line 90 def empty?(*contexts) if contexts.empty? return @repository.empty? else raise NotImplementedError, 'rdf:empty?' # TODO: support named graphs end end |
- (Boolean) exist?(context, *triples)
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/rdf/bert/server.rb', line 123 def exist?(context, *triples) context = RDF::BERT.unserialize(context) triples.each do |triple| case triple when Array statement = RDF::BERT.unserialize(triple) statement.context = context if context return false unless @repository.has_statement?(statement) else return false # TODO: support triple identifiers end end return true end |
- (Boolean) insert(context, *triples)
169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/rdf/bert/server.rb', line 169 def insert(context, *triples) context = RDF::BERT.unserialize(context) triples.each do |triple| case triple when Array statement = RDF::BERT.unserialize(triple) statement.context = context if context @repository.insert(statement) end end return true end |
- (Array) known?(context, *triples)
141 142 143 144 145 146 147 148 |
# File 'lib/rdf/bert/server.rb', line 141 def known?(context, *triples) return triples.map do |triple| case triple when Array then exist?(context, triple) else false # TODO: support triple identifiers end end end |
- (Array) predicates(*contexts)
80 81 82 83 84 85 86 |
# File 'lib/rdf/bert/server.rb', line 80 def predicates(*contexts) if contexts.empty? @repository.predicates.map { |value| RDF::BERT.serialize(value) } else raise NotImplementedError, 'rdf:predicates' # TODO: support named graphs end end |
- (Array) query(context, *patterns)
153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/rdf/bert/server.rb', line 153 def query(context, *patterns) result = [] context = RDF::BERT.unserialize(context) patterns.each do |pattern| pattern = RDF::BERT.unserialize(pattern) pattern.context = context if context @repository.query(pattern) do |statement| result << statement # FIXME end end return result end |
- (Array) subjects(*contexts)
70 71 72 73 74 75 76 |
# File 'lib/rdf/bert/server.rb', line 70 def subjects(*contexts) if contexts.empty? @repository.subjects.map { |value| RDF::BERT.serialize(value) } else raise NotImplementedError, 'rdf:subjects' # TODO: support named graphs end end |