Module: ShEx
- Defined in:
- lib/shex.rb,
lib/shex/format.rb,
lib/shex/parser.rb,
lib/shex/algebra.rb,
lib/shex/version.rb,
lib/shex/terminals.rb,
lib/shex/extensions/test.rb
Overview
A ShEx runtime for RDF.rb.
Defined Under Namespace
Modules: Algebra, Meta, Terminals, VERSION Classes: Error, Extension, Format, NotMatched, NotSatisfied, ParseError, Parser, StructureError
Constant Summary collapse
- CONTEXT =
Location of the ShEx JSON-LD context
"http://www.w3.org/ns/shex.jsonld"
- EXTENSIONS =
Extensions defined in this gem
%w{test}
- Test =
Class.new(ShEx::Extension("http://shex.io/extensions/Test/")) do # (see ShEx::Extension#visit) def visit(code: nil, matched: nil, depth: 0, **) str = if md = /^ *(fail|print) *\( *(?:(\"(?:[^\\"]|\\")*\")|([spo])) *\) *$/.match(code.to_s) md[2] || case md[3] when 's' then matched.subject when 'p' then matched.predicate when 'o' then matched.object else matched.to_sxp end.to_s else matched ? matched.to_sxp : 'no statement' end $stdout.puts str return !md || md[1] == 'print' end end
Class Method Summary collapse
-
.execute(expression, queryable, map, format: 'shexc', **options) ⇒ Hash{RDF::Term => Array<ShapeResult>}
Parse and validate the given ShEx
expression
string againstqueriable
. -
.Extension(uri) ⇒ Class
Alias for
ShEx::Extension.create
. -
.open(filename, format: 'shexc', **options, &block) ⇒ ShEx::Algebra::Schema
Parses input from the given file name or URL.
-
.parse(expression, format: 'shexc', **options) ⇒ ShEx::Algebra::Schema
Parse the given ShEx
query
string. -
.satisfies?(expression, queryable, map, format: 'shexc', **options) ⇒ Boolean
Parse and validate the given ShEx
expression
string againstqueriable
.
Class Method Details
.execute(expression, queryable, map, format: 'shexc', **options) ⇒ Hash{RDF::Term => Array<ShapeResult>}
Parse and validate the given ShEx expression
string against queriable
.
78 79 80 81 82 83 |
# File 'lib/shex.rb', line 78 def self.execute(expression, queryable, map, format: 'shexc', **) shex = self.parse(expression, format: format, **) queryable = queryable || RDF::Graph.new shex.execute(queryable, map, **) end |
.Extension(uri) ⇒ Class
Alias for ShEx::Extension.create
.
108 109 110 |
# File 'lib/shex.rb', line 108 def self.Extension(uri) Extension.send(:create, uri) end |
.open(filename, format: 'shexc', **options, &block) ⇒ ShEx::Algebra::Schema
Parses input from the given file name or URL.
61 62 63 64 65 |
# File 'lib/shex.rb', line 61 def self.open(filename, format: 'shexc', **, &block) RDF::Util::File.open_file(filename, **) do |file| self.parse(file, format: format, **) end end |
.parse(expression, format: 'shexc', **options) ⇒ ShEx::Algebra::Schema
Parse the given ShEx query
string.
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/shex.rb', line 37 def self.parse(expression, format: 'shexc', **) case format.to_s when 'shexc' then Parser.new(expression, **).parse when 'shexj' expression = expression.read if expression.respond_to?(:read) Algebra.from_shexj(JSON.parse(expression), **) when 'sxp' expression = expression.read if expression.respond_to?(:read) Algebra.from_sxp(expression, **) else raise "Unknown expression format: #{format.inspect}" end end |
.satisfies?(expression, queryable, map, format: 'shexc', **options) ⇒ Boolean
Parse and validate the given ShEx expression
string against queriable
.
96 97 98 99 100 101 |
# File 'lib/shex.rb', line 96 def self.satisfies?(expression, queryable, map, format: 'shexc', **) shex = self.parse(expression, format: format, **) queryable = queryable || RDF::Graph.new shex.satisfies?(queryable, map, **) end |