Skip to content

Commit

Permalink
Finish 3.1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Dec 25, 2020
2 parents 53f46cc + d04a222 commit e6800d0
Show file tree
Hide file tree
Showing 27 changed files with 326 additions and 161 deletions.
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repo_token: n1Ae6aLVyChERzltBHnuNg7YREyRseSlp
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This workflow runs continuous CI across different versions of ruby on all branches and pull requests to develop.

name: CI

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the develop branch
push:
branches: [ '**' ]
pull_request:
branches: [ develop ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
tests:
name: Ruby ${{ matrix.ruby }}
if: "contains(github.event.commits[0].message, '[ci skip]') == false"
runs-on: ubuntu-latest
env:
CI: true
ALLOW_FAILURES: false # ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'jruby' }}
strategy:
fail-fast: false
matrix:
ruby:
- 2.4
- 2.5
- 2.6
- 2.7
- 3.0
- ruby-head
- jruby
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Install dependencies
run: bundle install --jobs 4 --retry 3
- name: Run tests
run: bundle exec rspec spec || $ALLOW_FAILURES

2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ rvm:
- 2.5
- 2.6
- 2.7
- ruby-head
- jruby
cache: bundler
sudo: false
matrix:
allow_failures:
- rvm: jruby
- rvm: ruby-head
dist: trusty
5 changes: 2 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ group :develop do
end

group :debug do
gem 'psych', platforms: [:mri, :rbx]
gem "redcarpet", platforms: :ruby
gem "byebug", platforms: :mri
gem 'guard-rspec'
Expand All @@ -33,6 +32,6 @@ group :test do
gem "rake"
gem "equivalent-xml"
gem 'fasterer'
gem 'simplecov', platforms: :mri
gem 'coveralls', '~> 0.8', platforms: :mri
gem 'simplecov', require: false, platforms: :mri
gem 'coveralls', require: false, platforms: :mri
end
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ This is a pure-Ruby library for working with [Resource Description Framework
* <https://ruby-rdf.github.com/rdf>

[![Gem Version](https://badge.fury.io/rb/rdf.png)](https://badge.fury.io/rb/rdf)
[![Build Status](https://travis-ci.org/ruby-rdf/rdf.png?branch=master)](https://travis-ci.org/ruby-rdf/rdf)
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf/badge.svg)](https://coveralls.io/r/ruby-rdf/rdf)
[![Join the chat at https://gitter.im/ruby-rdf/rdf](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ruby-rdf/rdf?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://github.com/ruby-rdf/rdf/workflows/CI/badge.svg?branch=develop)](https://github.com/ruby-rdf/rdf/actions?query=workflow%3ACI)
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf/badge.svg)](https://coveralls.io/github/ruby-rdf/rdf)
[![Gitter chat](https://badges.gitter.im/ruby-rdf/rdf.png)](https://gitter.im/ruby-rdf/rdf)

## Features

Expand Down Expand Up @@ -39,6 +39,22 @@ resources. Clients may also consider using [RestClient Components][] to enable
client-side caching of HTTP results using [Rack::Cache][] or other Rack
middleware.

See {RDF::Util::File} for configuring other mechanisms for retrieving resources.

### Term caching and configuration.

RDF.rb uses a weak-reference cache for storing internalized versions of URIs and Nodes. This is particularly useful for Nodes as two nodes are equivalent only if they're the same node.

By default, each cache can grow to an unlimited size, but this can be configured using {RDF.config}, for general limits, along with URI- or Node-specific limits.

For example, to limit the size of the URI intern cache only:

RDF.config.uri_cache_size = 10_000

The default for creating new caches without a specific initialization size can be set using:

RDF.config.cache_size = 100_000

## Differences between RDF 1.0 and RDF 1.1

This version of RDF.rb is fully compatible with [RDF 1.1][], but it creates some
Expand Down Expand Up @@ -246,17 +262,10 @@ By default, the N-Triples reader will reject a document containing a subject res
end
# => RDF::ReaderError

Readers support a `rdfstar` option with either `:PG` (Property Graph) or `:SA` (Separate Assertions) modes. In `:PG` mode, statements that are used in the subject or object positions are also implicitly added to the graph:

graph = RDF::Graph.new do |graph|
RDF::NTriples::Reader.new(nt, rdfstar: :PG) {|reader| graph << reader}
end
graph.count #=> 2

When using the `:SA` mode, only one statement is asserted, although the reified statement is contained within the graph.
Readers support a boolean valued `rdfstar` option.

graph = RDF::Graph.new do |graph|
RDF::NTriples::Reader.new(nt, rdfstar: :SA) {|reader| graph << reader}
RDF::NTriples::Reader.new(nt, rdfstar: true) {|reader| graph << reader}
end
graph.count #=> 1

Expand Down Expand Up @@ -478,7 +487,7 @@ see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
[RDF::TriX]: https://ruby-rdf.github.com/rdf-trix
[RDF::Turtle]: https://ruby-rdf.github.com/rdf-turtle
[RDF::Raptor]: https://ruby-rdf.github.com/rdf-raptor
[RDF*]: https://lists.w3.org/Archives/Public/public-rdf-star/
[RDF*]: https://w3c.github.io/rdf-star/rdf-star-cg-spec.html
[LinkedData]: https://ruby-rdf.github.com/linkeddata
[JSON::LD]: https://ruby-rdf.github.com/json-ld
[RestClient]: https://rubygems.org/gems/rest-client
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.7
3.1.8
24 changes: 24 additions & 0 deletions lib/rdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'bigdecimal'
require 'date'
require 'time'
require "ostruct"

require 'rdf/version'
require 'rdf/extensions'
Expand Down Expand Up @@ -79,6 +80,29 @@ module RDF
# CLI
autoload :CLI, 'rdf/cli'

##
# Configuration, used open for configuring constants used within the codebase.
#
# @example set default cache size to be at most 10,000 entries
#
# RDF.config.cache_size = 10_000
#
# @example set cache size for interned URIs to 5,000 entries
#
# RDF.config.uri_cache_size = 5_000
#
# Defaults:
# * `cache_size`: -1
# * `uri_cache_size`: `cache_size`
# * `node_cache_size`: `cache_size`
#
# @note cache configurations must be set before initial use, when the caches are allocated.
# @see RDF::Util::Cache.new
# @return [Object]
def self.config
@config ||= OpenStruct.new(cache_size: -1, uri_cache_size: nil, node_cache_size: nil)
end

##
# Alias for `RDF::Resource.new`.
#
Expand Down
17 changes: 13 additions & 4 deletions lib/rdf/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def to_hash
# * `lambda` code run to execute command.
# * `filter` Option values that must match for command to be used
# * `control` Used to indicate how (if) command is displayed
# * `repository` Use this repository, if set
# * `options` an optional array of `RDF::CLI::Option` describing command-specific options.
# * `option_use`: A hash of option symbol to option usage, used for overriding the default status of an option for this command.
# @return [Hash{Symbol => Hash{Symbol => Object}}]
Expand Down Expand Up @@ -493,6 +494,9 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options
raise ArgumentError, "Incompatible command #{c} used with option #{opt}=#{options[opt]}"
end
end

# The command may specify a repository instance to use
options[:repository] ||= COMMANDS[c.to_sym][:repository]
end

# Hacks for specific options
Expand All @@ -501,9 +505,11 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options
options[:format] = options[:format].to_sym if options[:format]
options[:output_format] = options[:output_format].to_sym if options[:output_format]

@repository = options[:ordered] ?
[].extend(RDF::Enumerable, RDF::Queryable) :
RDF::Repository.new
# Allow repository to be set via option.
@repository = options[:repository] ||
(options[:ordered] ?
[].extend(RDF::Enumerable, RDF::Queryable) :
RDF::Repository.new)

# Parse input files if any command requires it
if cmds.any? {|c| COMMANDS[c.to_sym][:parse]}
Expand All @@ -518,7 +524,10 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options

# Run each command in sequence
cmds.each do |command|
COMMANDS[command.to_sym][:lambda].call(args, output: output, **options.merge(messages: messages))
COMMANDS[command.to_sym][:lambda].call(args,
output: output,
messages: messages,
**options.merge(repository: repository))
end

# Normalize messages
Expand Down
33 changes: 29 additions & 4 deletions lib/rdf/model/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,23 @@ def self.[](*values)
# g = RDF::Graph.new << l
# g.count # => l.count
#
# @example use a transaction for block initialization
# l = RDF::List(graph: graph, wrap_transaction: true) do |list|
# list << RDF::Literal(1)
# # list.graph.rollback will rollback all list changes within this block.
# end
# list.count #=> 1
#
# @param [RDF::Resource] subject (RDF.nil)
# Subject should be an {RDF::Node}, not a {RDF::URI}. A list with an IRI head will not validate, but is commonly used to detect if a list is valid.
# @param [RDF::Graph] graph (RDF::Graph.new)
# @param [Array<RDF::Term>] values
# Any values which are not terms are coerced to `RDF::Literal`.
# @param [Boolean] wrap_transaction (false)
# Wraps the callback in a transaction, and replaces the graph with that transaction for the duraction of the callback. This has the effect of allowing any list changes to be made atomically, or rolled back.
# @yield [list]
# @yieldparam [RDF::List] list
def initialize(subject: nil, graph: nil, values: nil, &block)
def initialize(subject: nil, graph: nil, values: nil, wrap_transaction: false, &block)
@subject = subject || RDF.nil
@graph = graph || RDF::Graph.new
is_empty = @graph.query({subject: subject, predicate: RDF.first}).empty?
Expand All @@ -78,9 +87,25 @@ def initialize(subject: nil, graph: nil, values: nil, &block)
end

if block_given?
case block.arity
when 1 then block.call(self)
else instance_eval(&block)
if wrap_transaction
old_graph = @graph
begin
Transaction.begin(@graph, graph_name: @graph.graph_name, mutable: @graph.mutable?) do |trans|
@graph = trans
case block.arity
when 1 then block.call(self)
else instance_eval(&block)
end
trans.execute if trans.mutated?
end
ensure
@graph = old_graph
end
else
case block.arity
when 1 then block.call(self)
else instance_eval(&block)
end
end
end
end
Expand Down
8 changes: 2 additions & 6 deletions lib/rdf/model/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ class Node
include RDF::Resource

##
# Defines the maximum number of interned Node references that can be held
# cached in memory at any one time.
# Cache size may be set through {RDF.config} using `node_cache_size`.
#
# @note caching interned nodes means that two different invocations using the same symbol will result in the same node, which may not be appropriate depending on the graph from which it is used. RDF requires that bnodes with the same label are, in fact, different bnodes, unless they are used within the same document.
CACHE_SIZE = -1 # unlimited by default

##
# @return [RDF::Util::Cache]
# @private
def self.cache
require 'rdf/util/cache' unless defined?(::RDF::Util::Cache)
@cache ||= RDF::Util::Cache.new(CACHE_SIZE)
@cache ||= RDF::Util::Cache.new(RDF.config.node_cache_size)
end

##
Expand Down
9 changes: 3 additions & 6 deletions lib/rdf/model/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ module RDF
class URI
include RDF::Resource

##
# Defines the maximum number of interned URI references that can be held
# cached in memory at any one time.
CACHE_SIZE = -1 # unlimited by default

# IRI components
UCSCHAR = Regexp.compile(<<-EOS.gsub(/\s+/, ''))
[\\u00A0-\\uD7FF]|[\\uF900-\\uFDCF]|[\\uFDF0-\\uFFEF]|
Expand Down Expand Up @@ -117,11 +112,13 @@ class URI
).freeze

##
# Cache size may be set through {RDF.config} using `uri_cache_size`.
#
# @return [RDF::Util::Cache]
# @private
def self.cache
require 'rdf/util/cache' unless defined?(::RDF::Util::Cache)
@cache ||= RDF::Util::Cache.new(CACHE_SIZE)
@cache ||= RDF::Util::Cache.new(RDF.config.uri_cache_size)
end

##
Expand Down
4 changes: 2 additions & 2 deletions lib/rdf/nquads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def read_triple

begin
unless blank? || read_comment
subject = read_uriref || read_node || read_rdfstar || fail_subject
subject = read_uriref || read_node || read_embTriple || fail_subject
predicate = read_uriref(intern: true) || fail_predicate
object = read_uriref || read_node || read_literal || read_rdfstar || fail_object
object = read_uriref || read_node || read_literal || read_embTriple || fail_object
graph_name = read_uriref || read_node
if validate? && !read_eos
log_error("Expected end of statement (found: #{current_line.inspect})", lineno: lineno, exception: RDF::ReaderError)
Expand Down
12 changes: 6 additions & 6 deletions lib/rdf/ntriples/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def read_value
begin
read_statement
rescue RDF::ReaderError
value = read_uriref || read_node || read_literal || read_rdfstar
value = read_uriref || read_node || read_literal || read_embTriple
log_recover
value
end
Expand All @@ -229,9 +229,9 @@ def read_triple

begin
unless blank? || read_comment
subject = read_uriref || read_node || read_rdfstar || fail_subject
subject = read_uriref || read_node || read_embTriple || fail_subject
predicate = read_uriref(intern: true) || fail_predicate
object = read_uriref || read_node || read_literal || read_rdfstar || fail_object
object = read_uriref || read_node || read_literal || read_embTriple || fail_object

if validate? && !read_eos
log_error("Expected end of statement (found: #{current_line.inspect})", lineno: lineno, exception: RDF::ReaderError)
Expand All @@ -247,11 +247,11 @@ def read_triple

##
# @return [RDF::Statement]
def read_rdfstar
def read_embTriple
if @options[:rdfstar] && match(ST_START)
subject = read_uriref || read_node || read_rdfstar || fail_subject
subject = read_uriref || read_node || read_embTriple || fail_subject
predicate = read_uriref(intern: true) || fail_predicate
object = read_uriref || read_node || read_literal || read_rdfstar || fail_object
object = read_uriref || read_node || read_literal || read_embTriple || fail_object
if !match(ST_END)
log_error("Expected end of statement (found: #{current_line.inspect})", lineno: lineno, exception: RDF::ReaderError)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rdf/ntriples/writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def format_statement(statement, **options)
# @param [RDF::Statement] statement
# @param [Hash{Symbol => Object}] options ({})
# @return [String]
def format_rdfstar(statement, **options)
def format_embTriple(statement, **options)
"<<%s %s %s>>" % statement.to_a.map { |value| format_term(value, **options) }
end
##
Expand Down
2 changes: 1 addition & 1 deletion lib/rdf/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def optimize(**options)
# @see RDF::Query::Pattern#cost
# @since 0.3.0
def optimize!(**options)
optional, required = @patterns.partition(&:optional?)
optional, required = @patterns.uniq.partition(&:optional?)
required.sort! do |a, b|
(a.cost || 0) <=> (b.cost || 0)
end
Expand Down

0 comments on commit e6800d0

Please sign in to comment.