lib/sxp/reader/sparql.rb in sxp-1.0.1 vs lib/sxp/reader/sparql.rb in sxp-1.0.2
- old
+ new
@@ -27,11 +27,15 @@
# Anonymous BNode
BNODE_NEW = /^_:$/
# Distinguished variable
VAR_ID = /^\?(.*)/
# Non-distinguished variable
- ND_VAR = /^\?(:?\?([0-9]+)?|(\.[0-9]+))/
+ ND_VAR = /^\?(?:[\?\.])(.*)/
+ # Distinguished existential variable
+ EVAR_ID = /^\$(.*)/
+ # Non-distinguished existential variable
+ ND_EVAR = /^\$(?:[\$\.])(.*)/
# A QName, subject to expansion to URIs using {PREFIX}
PNAME = /([^:]*):(.*)/
RDF_TYPE = (a = RDF.type.dup; a.lexical = 'a'; a).freeze
@@ -65,11 +69,11 @@
##
# Initializes the reader.
#
# @param [IO, StringIO, String] input
# @param [Hash{Symbol => Object}] options
- def initialize(input, options = {}, &block)
+ def initialize(input, **options, &block)
super { @prefixes = {}; @bnodes = {}; @list_depth = 0 }
if block_given?
case block.arity
when 1 then block.call(self)
@@ -221,12 +225,14 @@
when DOUBLE then RDF::Literal::Double.new(buffer)
when DECIMAL then RDF::Literal::Decimal.new(buffer)
when INTEGER then RDF::Literal::Integer.new(buffer)
when BNODE_ID then @bnodes[$1] ||= RDF::Node($1)
when BNODE_NEW then RDF::Node.new
- when ND_VAR then variable($1, false)
- when VAR_ID then variable($1, true)
+ when ND_VAR then variable($1, distinguished: false)
+ when VAR_ID then variable($1, distinguished: true)
+ when ND_EVAR then variable($1, existential: true, distinguished: false)
+ when EVAR_ID then variable($1, existential: true, distinguished: true)
else buffer.to_sym
end
end
##
@@ -249,23 +255,19 @@
#
# The variable has a #distinguished? method applied depending on if this
# is a disinguished or non-distinguished variable. Non-distinguished
# variables are effectively the same as BNodes.
# @return [RDF::Query::Variable]
- def variable(id, distinguished = true)
+ def variable(id, distinguished: true, existential: false)
id = nil if id.to_s.empty?
if id
@vars ||= {}
@vars[id] ||= begin
- v = RDF::Query::Variable.new(id)
- v.distinguished = distinguished
- v
+ RDF::Query::Variable.new(id, distinguished: distinguished, existential: existential)
end
else
- v = RDF::Query::Variable.new
- v.distinguished = distinguished
- v
+ RDF::Query::Variable.new(distinguished: distinguished, existential: existential)
end
end
end # SPARQL
end; end # SXP::Reader