Skip to content

Commit

Permalink
Release 2.0.0.beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Feb 22, 2016
2 parents 2b72a05 + b0cb643 commit c82e34a
Show file tree
Hide file tree
Showing 23 changed files with 252 additions and 440 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ script: "bundle exec rspec spec"
env:
- CI=true
rvm:
- 1.9.3
- 2.0
- 2.1
- 2.2
- jruby
- 2.2.4
- 2.3.0
- jruby-9.0.4.0
- rbx-2
cache: bundler
sudo: false
matrix:
allow_failures:
- rvm: 2.2
- rvm: jruby-9.0.4.0
- rvm: rbx-2
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ gem "rdf", git: "git://github.com/ruby-rdf/rdf.git", branch: "develop
group :development do
gem "rdf-spec", git: "git://github.com/ruby-rdf/rdf-spec.git", branch: "develop"
gem "rdf-isomorphic", git: "git://github.com/ruby-rdf/rdf-isomorphic.git", branch: "develop"
gem "rdf-rdfa", git: "git://github.com/ruby-rdf/rdf-rdfa.git", branch: "develop"
gem "rdf-rdfxml", git: "git://github.com/ruby-rdf/rdf-rdfxml.git", branch: "develop"
gem "rdf-xsd", git: "git://github.com/ruby-rdf/rdf-xsd.git", branch: "develop"
gem "json-ld", git: "git://github.com/ruby-rdf/json-ld.git", branch: "develop"
end

group :debug do
gem "wirble"
gem "debugger", platforms: [:mri_19, :mri_20]
gem "byebug", platform: :mri
end

platforms :rbx do
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RDF::N3 parses [Notation-3][N3], [Turtle][Turtle] and [N-Triples][N-Triples] int
Install with `gem install rdf-n3`

## Limitations
* Full support of Unicode input requires Ruby version 1.9 or greater.
* Full support of Unicode input requires Ruby version 2.0 or greater.
* Support for Variables in Formulae dependent on underlying repository. Existential variables are quantified to RDF::Node instances, Universals to RDF::Query::Variable, with the URI of the variable target used as the variable name.
* No support for N3 Reification. If there were, it would be through a :reify option to the reader.

Expand Down Expand Up @@ -64,7 +64,7 @@ results in:

h = RDF::Query::Variable.new(<#h>)
g = RDF::Node.new()
RDF::Statement.new(f, <#loves>, h)
RDF::Statement(f, <#loves>, h)

## Implementation Notes
The parser is driven through a rules table contained in lib/rdf/n3/reader/meta.rb. This includes
Expand All @@ -84,7 +84,7 @@ http://www.w3.org/2000/10/swap/grammar/n3.n3 (along with bnf-rules.n3) using cwm
* Create equivalent to `--think` to iterate on solutions.

## Dependencies
* [RDF.rb](http://rubygems.org/gems/rdf) (>= 1.1)
* [RDF.rb](http://rubygems.org/gems/rdf) (>= 2.0)

## Documentation
Full documentation available on [RubyDoc.info](http://rubydoc.info/github/ruby-rdf/rdf-n3/frames)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.99.0
2.0.0.beta1
3 changes: 0 additions & 3 deletions lib/rdf/n3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,5 @@ module N3
autoload :Reader, 'rdf/n3/reader'
autoload :VERSION, 'rdf/n3/version'
autoload :Writer, 'rdf/n3/writer'

def self.debug?; @debug; end
def self.debug=(value); @debug = value; end
end
end
19 changes: 4 additions & 15 deletions lib/rdf/n3/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,10 @@ class Format < RDF::Format

reader { RDF::N3::Reader }
writer { RDF::N3::Writer }
end

# Alias for N3 format
#
# This allows the following:
#
# @example Obtaining an Notation3 format class
# RDF::Format.for(:ttl) #=> RDF::N3::Notation3
# RDF::Format.for(:ttl).reader #=> RDF::N3::Reader
# RDF::Format.for(:ttl).writer #=> RDF::N3::Writer
class Notation3 < RDF::Format
content_type 'text/n3', extension: :n3
content_encoding 'utf-8'

reader { RDF::N3::Reader }
writer { RDF::N3::Writer }
# Symbols which may be used to lookup this format
def self.symbols
[:n3, :notation3]
end
end
end
64 changes: 28 additions & 36 deletions lib/rdf/n3/reader.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding: utf-8
module RDF::N3
##
# A Notation-3/Turtle parser in Ruby
Expand All @@ -16,6 +17,7 @@ module RDF::N3
class Reader < RDF::Reader
format Format

include RDF::Util::Logger
include Meta
include Parser

Expand All @@ -26,8 +28,6 @@ class Reader < RDF::Reader
#
# @param [IO, File, String] input
# the input stream to read
# @option options [Array] :debug
# Array to place debug messages
# @option options [#to_s] :base_uri (nil)
# the base URI to use when resolving relative URIs (not supported by
# all readers)
Expand Down Expand Up @@ -65,12 +65,12 @@ def initialize(input = $stdin, options = {}, &block)
@variables = {} # variable definitions along with defining formula

if options[:base_uri]
add_debug("@uri") { base_uri.inspect}
log_debug("@uri") { base_uri.inspect}
namespace(nil, uri("#{base_uri}#"))
end
add_debug("validate") {validate?.inspect}
add_debug("canonicalize") {canonicalize?.inspect}
add_debug("intern") {intern?.inspect}
log_debug("validate") {validate?.inspect}
log_debug("canonicalize") {canonicalize?.inspect}
log_debug("intern") {intern?.inspect}

if block_given?
case block.arity
Expand All @@ -96,6 +96,10 @@ def each_statement(&block)
@callback = block

parse(START.to_sym)

if validate? && log_statistics[:error]
raise RDF::ReaderError, "Errors found during processing"
end
end
enum_for(:each_triple)
end
Expand All @@ -121,7 +125,7 @@ def each_triple(&block)
# Start of production
def onStart(prod)
handler = "#{prod}Start".to_sym
add_debug("#{handler}(#{respond_to?(handler, true)})", prod)
log_debug("#{handler}(#{respond_to?(handler, true)})", prod)
@productions << prod
send(handler, prod) if respond_to?(handler, true)
end
Expand All @@ -130,7 +134,7 @@ def onStart(prod)
def onFinish
prod = @productions.pop()
handler = "#{prod}Finish".to_sym
add_debug("#{handler}(#{respond_to?(handler, true)})") {"#{prod}: #{@prod_data.last.inspect}"}
log_debug("#{handler}(#{respond_to?(handler, true)})") {"#{prod}: #{@prod_data.last.inspect}"}
send(handler) if respond_to?(handler, true)
end

Expand All @@ -139,7 +143,7 @@ def onToken(prod, tok)
unless @productions.empty?
parentProd = @productions.last
handler = "#{parentProd}Token".to_sym
add_debug("#{handler}(#{respond_to?(handler, true)})") {"#{prod}, #{tok}: #{@prod_data.last.inspect}"}
log_debug("#{handler}(#{respond_to?(handler, true)})") {"#{prod}, #{tok}: #{@prod_data.last.inspect}"}
send(handler, prod, tok) if respond_to?(handler, true)
else
error("Token has no parent production")
Expand Down Expand Up @@ -186,9 +190,9 @@ def declarationFinish
# This means that <#foo> can be written :foo and using @keywords one can reduce that to foo.

namespace(nil, uri.match(/[\/\#]$/) ? base_uri : process_uri("#{uri}#"))
add_debug("declarationFinish[@base]") {"@base=#{base_uri}"}
log_debug("declarationFinish[@base]") {"@base=#{base_uri}"}
when "@keywords"
add_debug("declarationFinish[@keywords]") {@keywords.inspect}
log_debug("declarationFinish[@keywords]") {@keywords.inspect}
# Keywords are handled in tokenizer and maintained in @keywords array
if (@keywords & N3_KEYWORDS) != @keywords
error("Undefined keywords used: #{(@keywords - N3_KEYWORDS).to_sentence}") if validate?
Expand Down Expand Up @@ -238,7 +242,7 @@ def expressionFinish
# If we're in teh middle of a pathtail, append
if @prod_data.last[:pathtail] && expression[:pathitem] && expression[:pathtail]
path_list = [expression[:pathitem]] + expression[:pathtail]
add_debug("expressionFinish(pathtail)") {"set pathtail to #{path_list.inspect}"}
log_debug("expressionFinish(pathtail)") {"set pathtail to #{path_list.inspect}"}
@prod_data.last[:pathtail] = path_list

dir_list = [expression[:direction]] if expression[:direction]
Expand Down Expand Up @@ -402,7 +406,7 @@ def simpleStatementFinish
properties.each do |p|
predicate = p[:verb]
next unless predicate
add_debug("simpleStatementFinish(pred)") {predicate.to_s}
log_debug("simpleStatementFinish(pred)") {predicate.to_s}
error(%(Illegal statment: "#{predicate}" missing object)) unless p.has_key?(:object)
objects = Array(p[:object])
objects.each do |object|
Expand Down Expand Up @@ -505,14 +509,14 @@ def verbFinish
###################

def process_anonnode(anonnode)
add_debug("process_anonnode") {anonnode.inspect}
log_debug("process_anonnode") {anonnode.inspect}

if anonnode[:propertylist]
properties = anonnode[:propertylist]
bnode = RDF::Node.new
properties.each do |p|
predicate = p[:verb]
add_debug("process_anonnode(verb)") {predicate.inspect}
log_debug("process_anonnode(verb)") {predicate.inspect}
objects = Array(p[:object])
objects.each { |object| add_triple("anonnode", bnode, predicate, object) }
end
Expand All @@ -535,7 +539,7 @@ def process_anonnode(anonnode)
#
# Create triple and return property used for next iteration
def process_path(expression)
add_debug("process_path") {expression.inspect}
log_debug("process_path") {expression.inspect}

pathitem = expression[:pathitem]
pathtail = expression[:pathtail]
Expand Down Expand Up @@ -579,17 +583,17 @@ def process_qname(tok)
end

uri = if prefix(prefix)
add_debug('process_qname(ns)') {"#{prefix(prefix)}, #{name}"}
log_debug('process_qname(ns)') {"#{prefix(prefix)}, #{name}"}
ns(prefix, name)
elsif prefix == '_'
add_debug('process_qname(bnode)', name)
log_debug('process_qname(bnode)', name)
bnode(name)
else
add_debug('process_qname(default_ns)', name)
log_debug('process_qname(default_ns)', name)
namespace(nil, uri("#{base_uri}#")) unless prefix(nil)
ns(nil, name)
end
add_debug('process_qname') {uri.inspect}
log_debug('process_qname') {uri.inspect}
uri
end

Expand Down Expand Up @@ -619,18 +623,6 @@ def univar(label)
RDF::Query::Variable.new(label.to_s)
end

# Add debug event to debug array, if specified
#
# @param [any] node string for showing graph_name
# @param [String] message
# @yieldreturn [String] appended to message, to allow for lazy-evaulation of message
def add_debug(node, message = "")
return unless ::RDF::N3.debug? || @options[:debug]
message = message + yield if block_given?
puts "[#{@lineno},#{@pos}]#{' ' * @productions.length}#{node}: #{message}" if ::RDF::N3::debug?
@options[:debug] << "[#{@lineno},#{@pos}]#{' ' * @productions.length}#{node}: #{message}" if @options[:debug].is_a?(Array)
end

# add a statement, object can be literal or URI or bnode
#
# @param [any] node string for showing graph_name
Expand All @@ -642,8 +634,8 @@ def add_debug(node, message = "")
def add_triple(node, subject, predicate, object)
graph_name_opts = @formulae.last ? {graph_name: @formulae.last} : {}

statement = RDF::Statement.new(subject, predicate, object, graph_name_opts)
add_debug(node) {statement.to_s}
statement = RDF::Statement(subject, predicate, object, graph_name_opts)
log_debug(node) {statement.to_s}
@callback.call(statement)
end

Expand All @@ -652,7 +644,7 @@ def namespace(prefix, uri)
if uri == '#'
uri = prefix(nil).to_s + '#'
end
add_debug("namespace") {"'#{prefix}' <#{uri}>"}
log_debug("namespace") {"'#{prefix}' <#{uri}>"}
prefix(prefix, uri(uri))
end

Expand Down Expand Up @@ -682,7 +674,7 @@ def uri(value, append = nil)
def ns(prefix, suffix)
base = prefix(prefix).to_s
suffix = suffix.to_s.sub(/^\#/, "") if base.index("#")
add_debug("ns") {"base: '#{base}', suffix: '#{suffix}'"}
log_debug("ns") {"base: '#{base}', suffix: '#{suffix}'"}
uri(base + suffix.to_s)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/rdf/n3/reader/meta.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding: utf-8
# This file is automatically generated by script/build_meta
# Branch and Regexp tables derived from http://www.w3.org/2000/10/swap/grammar/n3-selectors.n3
module RDF::N3::Meta
Expand Down
Loading

0 comments on commit c82e34a

Please sign in to comment.