Module: ShEx
- Defined in:
- lib/shex.rb,
lib/shex/parser.rb,
lib/shex/algebra.rb,
lib/shex/version.rb,
lib/shex/terminals.rb
Overview
A ShEx runtime for RDF.rb.
Defined Under Namespace
Modules: Algebra, Meta, Terminals, VERSION Classes: Error, Extension, NotMatched, NotSatisfied, ParseError, Parser, StructureError, Test
Constant Summary collapse
- CONTEXT =
Location of the ShEx JSON-LD context
"https://shexspec.github.io/context.jsonld"- EXTENSIONS =
Extensions defined in this gem
%w{test}
Class Method Summary collapse
-
.execute(expression, queryable, focus, shape, format: 'shexc', **options) ⇒ Operand
Parse and validate the given ShEx
expressionstring 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
querystring. -
.satisfies?(expression, queryable, focus, shape, format: 'shexc', **options) ⇒ Boolean
Parse and validate the given ShEx
expressionstring againstqueriable.
Class Method Details
.execute(expression, queryable, focus, shape, format: 'shexc', **options) ⇒ Operand
Parse and validate the given ShEx expression string against queriable.
74 75 76 77 78 79 |
# File 'lib/shex.rb', line 74 def self.execute(expression, queryable, focus, shape, format: 'shexc', **) shex = self.parse(expression, .merge(format: format)) queryable = queryable || RDF::Graph.new shex.execute(focus, queryable, {focus => shape}, ) end |
.Extension(uri) ⇒ Class
Alias for ShEx::Extension.create.
104 105 106 |
# File 'lib/shex.rb', line 104 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.
57 58 59 60 61 |
# File 'lib/shex.rb', line 57 def self.open(filename, format: 'shexc', **, &block) RDF::Util::File.open_file(filename, ) do |file| self.parse(file, .merge(format: format)) end end |
.parse(expression, format: 'shexc', **options) ⇒ ShEx::Algebra::Schema
Parse the given ShEx query string.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/shex.rb', line 33 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(JSON.parse expression) else raise "Unknown expression format: #{format.inspect}" end end |
.satisfies?(expression, queryable, focus, shape, format: 'shexc', **options) ⇒ Boolean
Parse and validate the given ShEx expression string against queriable.
92 93 94 95 96 97 |
# File 'lib/shex.rb', line 92 def self.satisfies?(expression, queryable, focus, shape, format: 'shexc', **) shex = self.parse(expression, .merge(format: format)) queryable = queryable || RDF::Graph.new shex.satisfies?(focus, queryable, {focus => shape}, ) end |