Skip to content

Commit

Permalink
Finish 3.1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Feb 2, 2021
2 parents e3c20c8 + 5251d69 commit b3a258f
Show file tree
Hide file tree
Showing 33 changed files with 275 additions and 167 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ group :test do
gem "equivalent-xml"
gem 'fasterer'
gem 'simplecov', require: false, platforms: :mri
gem 'coveralls', require: false, platforms: :mri
gem 'coveralls', '~> 0.8', require: false, platforms: :mri
end
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This is a pure-Ruby library for working with [Resource Description Framework

[![Gem Version](https://badge.fury.io/rb/rdf.png)](https://badge.fury.io/rb/rdf)
[![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)
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf/badge.svg?branch=develop)](https://coveralls.io/github/ruby-rdf/rdf?branch=develop)
[![Gitter chat](https://badges.gitter.im/ruby-rdf/rdf.png)](https://gitter.im/ruby-rdf/rdf)

## Features
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.9
3.1.10
7 changes: 7 additions & 0 deletions etc/n-triples-star.ebnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[1] ntriplesDoc ::= triple? (EOL triple)* EOL?
[2] triple ::= subject predicate object '.'
[3] subject ::= IRIREF | BLANK_NODE_LABEL | embTriple
[4] predicate ::= IRIREF
[5] object ::= IRIREF | BLANK_NODE_LABEL | literal | embTriple
[6] literal ::= STRING_LITERAL_QUOTE ('^^' IRIREF | LANGTAG)?
[7] embTriple ::= '<<' subject predicate object '>>'
6 changes: 6 additions & 0 deletions etc/n-triples.ebnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[1] ntriplesDoc ::= triple? (EOL triple)* EOL?
[2] triple ::= subject predicate object '.'
[3] subject ::= IRIREF | BLANK_NODE_LABEL
[4] predicate ::= IRIREF
[5] object ::= IRIREF | BLANK_NODE_LABEL | literal
[6] literal ::= STRING_LITERAL_QUOTE ('^^' IRIREF | LANGTAG)?
6 changes: 3 additions & 3 deletions lib/rdf/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def to_hash

# Add format-specific reader options
reader.options.each do |cli_opt|
next if options.options.has_key?(cli_opt.symbol)
next if options.options.key?(cli_opt.symbol)
on_args = cli_opt.on || []
on_args << cli_opt.description if cli_opt.description
options.on(*on_args) do |opt_arg|
Expand All @@ -355,7 +355,7 @@ def to_hash

# Add format-specific writer options
writer.options.each do |cli_opt|
next if options.options.has_key?(cli_opt.symbol)
next if options.options.key?(cli_opt.symbol)
on_args = cli_opt.on || []
on_args << cli_opt.description if cli_opt.description
options.on(*on_args) do |opt_arg|
Expand Down Expand Up @@ -419,7 +419,7 @@ def self.options(argv, format: nil)
end

cli_opts.each do |cli_opt|
next if opts.has_key?(cli_opt.symbol)
next if opts.key?(cli_opt.symbol)
on_args = cli_opt.on || []
on_args << cli_opt.description if cli_opt.description
options.on(*on_args) do |arg|
Expand Down
74 changes: 46 additions & 28 deletions lib/rdf/mixin/enumerable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ module RDF
# enumerable.count
#
# @example Checking whether a specific statement exists
# enumerable.has_statement?(RDF::Statement(subject, predicate, object))
# enumerable.has_triple?([subject, predicate, object])
# enumerable.has_quad?([subject, predicate, object, graph_name])
# enumerable.statement?(RDF::Statement(subject, predicate, object))
# enumerable.triple?([subject, predicate, object])
# enumerable.quad?([subject, predicate, object, graph_name])
#
# @example Checking whether a specific value exists
# enumerable.has_subject?(RDF::URI("https://rubygems.org/gems/rdf"))
# enumerable.has_predicate?(RDF::RDFS.label)
# enumerable.has_object?(RDF::Literal("A Ruby library for working with Resource Description Framework (RDF) data.", language: :en))
# enumerable.has_graph?(RDF::URI("http://ar.to/#self"))
# enumerable.subject?(RDF::URI("https://rubygems.org/gems/rdf"))
# enumerable.predicate?(RDF::RDFS.label)
# enumerable.object?(RDF::Literal("A Ruby library for working with Resource Description Framework (RDF) data.", language: :en))
# enumerable.graph?(RDF::URI("http://ar.to/#self"))
#
# @example Enumerating all statements
# enumerable.each_statement do |statement|
Expand Down Expand Up @@ -127,14 +127,20 @@ def statements(**options)
end

##
# Returns `true` if `self` contains the given RDF statement.
# @overload statement?
# Returns `false` indicating this is not an RDF::Statemenet.
# @return [Boolean]
# @see RDF::Value#statement?
# @overload statement?(statement)
# Returns `true` if `self` contains the given RDF statement.
#
# @param [RDF::Statement] statement
# @return [Boolean]
def has_statement?(statement)
!enum_statement.find { |s| s.eql?(statement) }.nil?
# @param [RDF::Statement] statement
# @return [Boolean]
def statement?(statement = nil)
statement && !enum_statement.find { |s| s.eql?(statement) }.nil?
end
alias_method :include?, :has_statement?
alias_method :has_statement?, :statement?
alias_method :include?, :statement?

##
# Iterates the given block for each RDF statement.
Expand Down Expand Up @@ -194,9 +200,10 @@ def triples(**options)
#
# @param [Array(RDF::Resource, RDF::URI, RDF::Term)] triple
# @return [Boolean]
def has_triple?(triple)
def triple?(triple)
triples.include?(triple)
end
alias_method :has_triple?, :triple?

##
# Iterates the given block for each RDF triple.
Expand Down Expand Up @@ -255,9 +262,10 @@ def quads(**options)
#
# @param [Array(RDF::Resource, RDF::URI, RDF::Term, RDF::Resource)] quad
# @return [Boolean]
def has_quad?(quad)
def quad?(quad)
quads.include?(quad)
end
alias_method :has_quad?, :quad?

##
# Iterates the given block for each RDF quad.
Expand Down Expand Up @@ -321,9 +329,10 @@ def subjects(unique: true)
#
# @param [RDF::Resource] value
# @return [Boolean]
def has_subject?(value)
def subject?(value)
enum_subject.include?(value)
end
alias_method :has_subject?, :subject?

##
# Iterates the given block for each unique RDF subject term.
Expand Down Expand Up @@ -386,9 +395,10 @@ def predicates(unique: true)
#
# @param [RDF::URI] value
# @return [Boolean]
def has_predicate?(value)
def predicate?(value)
enum_predicate.include?(value)
end
alias_method :has_predicate?, :predicate?

##
# Iterates the given block for each unique RDF predicate term.
Expand Down Expand Up @@ -451,9 +461,10 @@ def objects(unique: true)
#
# @param [RDF::Term] value
# @return [Boolean]
def has_object?(value)
def object?(value)
enum_object.include?(value)
end
alias_method :has_object?, :object?

##
# Iterates the given block for each unique RDF object term.
Expand Down Expand Up @@ -511,7 +522,7 @@ def enum_object
def terms(unique: true)
unless unique
enum_statement.
map(&:to_quad).
map(&:terms).
flatten.
compact
else
Expand All @@ -520,14 +531,20 @@ def terms(unique: true)
end

##
# Returns `true` if `self` contains the given RDF subject term.
# @overload term?
# Returns `false` indicating this is not an RDF::Statemenet.
# @see RDF::Value#statement?
# @return [Boolean]
# @overload term?(value)
# Returns `true` if `self` contains the given RDF subject term.
#
# @param [RDF::Resource] value
# @return [Boolean]
# @since 2.0
def has_term?(value)
enum_term.include?(value)
# @param [RDF::Resource] value
# @return [Boolean]
# @since 2.0
def term?(value = nil)
value && enum_term.include?(value)
end
alias_method :has_term?, :term?

##
# Iterates the given block for each unique RDF term (subject, predicate, object, or graph_name).
Expand All @@ -551,8 +568,8 @@ def each_term
if block_given?
values = {}
each_statement do |statement|
statement.to_quad.each do |value|
unless value.nil? || values.include?(value.hash)
statement.terms.each do |value|
unless values.include?(value.hash)
values[value.hash] = true
yield value
end
Expand Down Expand Up @@ -595,9 +612,10 @@ def graph_names(unique: true)
# @param [RDF::Resource, false] graph_name
# Use value `false` to query for the default graph_name
# @return [Boolean]
def has_graph?(graph_name)
def graph?(graph_name)
enum_statement.any? {|s| s.graph_name == graph_name}
end
alias_method :has_graph?, :graph?

##
# Limits statements to be from a specific graph.
Expand Down
2 changes: 1 addition & 1 deletion lib/rdf/mixin/mutable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def update(*statements)

statements.each do |statement|
if (statement = Statement.from(statement))
if statement.has_object?
if statement.object?
delete_insert([[statement.subject, statement.predicate, nil]], [statement])
else
delete([statement.subject, statement.predicate, nil])
Expand Down
2 changes: 1 addition & 1 deletion lib/rdf/model/dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def isolation_level
# @private
# @see RDF::Enumerable#supports?
def supports?(feature)
return true if [:graph_name, :rdfstar].include?(feature)
return true if %i(graph_name rdfstar).include?(feature)
super
end

Expand Down
21 changes: 14 additions & 7 deletions lib/rdf/model/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,25 @@ def count
end

##
# Returns `true` if this graph contains the given RDF statement.
# @overload statement?
# Returns `false` indicating this is not an RDF::Statemenet.
# @see RDF::Value#statement?
# @return [Boolean]
# @overload statement?(statement)
# Returns `true` if this graph contains the given RDF statement.
#
# A statement is in a graph if the statement if it has the same triples without regard to graph_name.
# A statement is in a graph if the statement if it has the same triples without regard to graph_name.
#
# @param [Statement] statement
# @return [Boolean]
# @see RDF::Enumerable#has_statement?
def has_statement?(statement)
# @param [Statement] statement
# @return [Boolean]
# @see RDF::Enumerable#statement?
def statement?(statement = nil)
return false if statement.nil?
statement = statement.dup
statement.graph_name = graph_name
@data.has_statement?(statement)
@data.statement?(statement)
end
alias_method :has_statement?, :statement?

##
# Enumerates each RDF statement in this graph.
Expand Down
28 changes: 14 additions & 14 deletions lib/rdf/model/literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module RDF
#
# @example Creating a language-tagged literal (1)
# value = RDF::Literal.new("Hello!", language: :en)
# value.has_language? #=> true
# value.language? #=> true
# value.language #=> :en
#
# @example Creating a language-tagged literal (2)
Expand All @@ -35,12 +35,12 @@ module RDF
#
# @example Creating an explicitly datatyped literal
# value = RDF::Literal.new("2009-12-31", datatype: RDF::XSD.date)
# value.has_datatype? #=> true
# value.datatype? #=> true
# value.datatype #=> RDF::XSD.date
#
# @example Creating an implicitly datatyped literal
# value = RDF::Literal.new(Date.today)
# value.has_datatype? #=> true
# value.datatype? #=> true
# value.datatype #=> RDF::XSD.date
#
# @example Creating implicitly datatyped literals
Expand Down Expand Up @@ -225,7 +225,7 @@ def compatible?(other)
# * The arguments are simple literals or literals typed as xsd:string
# * The arguments are plain literals with identical language tags
# * The first argument is a plain literal with language tag and the second argument is a simple literal or literal typed as xsd:string
has_language? ?
language? ?
(language == other.language || other.datatype == RDF::URI("http://www.w3.org/2001/XMLSchema#string")) :
other.datatype == RDF::URI("http://www.w3.org/2001/XMLSchema#string")
end
Expand Down Expand Up @@ -289,7 +289,7 @@ def ==(other)
case
when self.eql?(other)
true
when self.has_language? && self.language.to_s == other.language.to_s
when self.language? && self.language.to_s == other.language.to_s
# Literals with languages can compare if languages are identical
self.value_hash == other.value_hash && self.value == other.value
when self.simple? && other.simple?
Expand Down Expand Up @@ -335,10 +335,10 @@ def simple?
#
# @return [Boolean] `true` or `false`
# @see http://www.w3.org/TR/rdf-concepts/#dfn-plain-literal
def has_language?
def language?
datatype == RDF.langString
end
alias_method :language?, :has_language?
alias_method :has_language?, :language?

##
# Returns `true` if this is a datatyped literal.
Expand All @@ -347,12 +347,12 @@ def has_language?
#
# @return [Boolean] `true` or `false`
# @see http://www.w3.org/TR/rdf-concepts/#dfn-typed-literal
def has_datatype?
def datatype?
!plain? && !language?
end
alias_method :datatype?, :has_datatype?
alias_method :typed?, :has_datatype?
alias_method :datatyped?, :has_datatype?
alias_method :has_datatype?, :datatype?
alias_method :typed?, :datatype?
alias_method :datatyped?, :datatype?

##
# Returns `true` if the value adheres to the defined grammar of the
Expand Down Expand Up @@ -386,16 +386,16 @@ def validate!
# This behavior is intuited from SPARQL data-r2/expr-equal/eq-2-2
# @return [Boolean]
def comperable_datatype?(other)
return false unless self.plain? || self.has_language?
return false unless self.plain? || self.language?

case other
when RDF::Literal::Numeric, RDF::Literal::Boolean,
RDF::Literal::Date, RDF::Literal::Time, RDF::Literal::DateTime
# Invald types can be compared without raising a TypeError if literal has a language (open-eq-08)
!other.valid? && self.has_language?
!other.valid? && self.language?
else
# An unknown datatype may not be used for comparison, unless it has a language? (open-eq-8)
self.has_language?
self.language?
end
end

Expand Down
8 changes: 5 additions & 3 deletions lib/rdf/model/literal/date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ def valid?
#
# @return [Boolean]
# @since 1.1.6
def has_timezone?
def timezone?
md = self.to_s.match(GRAMMAR)
md && !!md[2]
end
alias_method :has_tz?, :has_timezone?
alias_method :tz?, :timezone?
alias_method :has_tz?, :timezone?
alias_method :has_timezone?, :timezone?

##
# Returns the value as a string.
Expand All @@ -72,7 +74,7 @@ def to_s
# @since 1.1.6
def humanize(lang = :en)
d = object.strftime("%A, %d %B %Y")
if has_timezone?
if timezone?
d += if self.tz == 'Z'
" UTC"
else
Expand Down

0 comments on commit b3a258f

Please sign in to comment.