@@ -12,15 +12,15 @@ module RDF
1212 # enumerable.count
1313 #
1414 # @example Checking whether a specific statement exists
15- # enumerable.has_statement ?(RDF::Statement(subject, predicate, object))
16- # enumerable.has_triple ?([subject, predicate, object])
17- # enumerable.has_quad ?([subject, predicate, object, graph_name])
15+ # enumerable.statement ?(RDF::Statement(subject, predicate, object))
16+ # enumerable.triple ?([subject, predicate, object])
17+ # enumerable.quad ?([subject, predicate, object, graph_name])
1818 #
1919 # @example Checking whether a specific value exists
20- # enumerable.has_subject ?(RDF::URI("https://rubygems.org/gems/rdf"))
21- # enumerable.has_predicate ?(RDF::RDFS.label)
22- # enumerable.has_object ?(RDF::Literal("A Ruby library for working with Resource Description Framework (RDF) data.", language: :en))
23- # enumerable.has_graph ?(RDF::URI("http://ar.to/#self"))
20+ # enumerable.subject ?(RDF::URI("https://rubygems.org/gems/rdf"))
21+ # enumerable.predicate ?(RDF::RDFS.label)
22+ # enumerable.object ?(RDF::Literal("A Ruby library for working with Resource Description Framework (RDF) data.", language: :en))
23+ # enumerable.graph ?(RDF::URI("http://ar.to/#self"))
2424 #
2525 # @example Enumerating all statements
2626 # enumerable.each_statement do |statement|
@@ -127,14 +127,20 @@ def statements(**options)
127127 end
128128
129129 ##
130- # Returns `true` if `self` contains the given RDF statement.
130+ # @overload statement?
131+ # Returns `false` indicating this is not an RDF::Statemenet.
132+ # @return [Boolean]
133+ # @see RDF::Value#statement?
134+ # @overload statement?(statement)
135+ # Returns `true` if `self` contains the given RDF statement.
131136 #
132- # @param [RDF::Statement] statement
133- # @return [Boolean]
134- def has_statement ?( statement )
135- !enum_statement . find { |s | s . eql? ( statement ) } . nil?
137+ # @param [RDF::Statement] statement
138+ # @return [Boolean]
139+ def statement ?( statement = nil )
140+ statement && !enum_statement . find { |s | s . eql? ( statement ) } . nil?
136141 end
137- alias_method :include? , :has_statement?
142+ alias_method :has_statement? , :statement?
143+ alias_method :include? , :statement?
138144
139145 ##
140146 # Iterates the given block for each RDF statement.
@@ -194,9 +200,10 @@ def triples(**options)
194200 #
195201 # @param [Array(RDF::Resource, RDF::URI, RDF::Term)] triple
196202 # @return [Boolean]
197- def has_triple ?( triple )
203+ def triple ?( triple )
198204 triples . include? ( triple )
199205 end
206+ alias_method :has_triple? , :triple?
200207
201208 ##
202209 # Iterates the given block for each RDF triple.
@@ -255,9 +262,10 @@ def quads(**options)
255262 #
256263 # @param [Array(RDF::Resource, RDF::URI, RDF::Term, RDF::Resource)] quad
257264 # @return [Boolean]
258- def has_quad ?( quad )
265+ def quad ?( quad )
259266 quads . include? ( quad )
260267 end
268+ alias_method :has_quad? , :quad?
261269
262270 ##
263271 # Iterates the given block for each RDF quad.
@@ -321,9 +329,10 @@ def subjects(unique: true)
321329 #
322330 # @param [RDF::Resource] value
323331 # @return [Boolean]
324- def has_subject ?( value )
332+ def subject ?( value )
325333 enum_subject . include? ( value )
326334 end
335+ alias_method :has_subject? , :subject?
327336
328337 ##
329338 # Iterates the given block for each unique RDF subject term.
@@ -386,9 +395,10 @@ def predicates(unique: true)
386395 #
387396 # @param [RDF::URI] value
388397 # @return [Boolean]
389- def has_predicate ?( value )
398+ def predicate ?( value )
390399 enum_predicate . include? ( value )
391400 end
401+ alias_method :has_predicate? , :predicate?
392402
393403 ##
394404 # Iterates the given block for each unique RDF predicate term.
@@ -451,9 +461,10 @@ def objects(unique: true)
451461 #
452462 # @param [RDF::Term] value
453463 # @return [Boolean]
454- def has_object ?( value )
464+ def object ?( value )
455465 enum_object . include? ( value )
456466 end
467+ alias_method :has_object? , :object?
457468
458469 ##
459470 # Iterates the given block for each unique RDF object term.
@@ -511,7 +522,7 @@ def enum_object
511522 def terms ( unique : true )
512523 unless unique
513524 enum_statement .
514- map ( &:to_quad ) .
525+ map ( &:terms ) .
515526 flatten .
516527 compact
517528 else
@@ -520,14 +531,20 @@ def terms(unique: true)
520531 end
521532
522533 ##
523- # Returns `true` if `self` contains the given RDF subject term.
534+ # @overload term?
535+ # Returns `false` indicating this is not an RDF::Statemenet.
536+ # @see RDF::Value#statement?
537+ # @return [Boolean]
538+ # @overload term?(value)
539+ # Returns `true` if `self` contains the given RDF subject term.
524540 #
525- # @param [RDF::Resource] value
526- # @return [Boolean]
527- # @since 2.0
528- def has_term ?( value )
529- enum_term . include? ( value )
541+ # @param [RDF::Resource] value
542+ # @return [Boolean]
543+ # @since 2.0
544+ def term ?( value = nil )
545+ value && enum_term . include? ( value )
530546 end
547+ alias_method :has_term? , :term?
531548
532549 ##
533550 # Iterates the given block for each unique RDF term (subject, predicate, object, or graph_name).
@@ -551,8 +568,8 @@ def each_term
551568 if block_given?
552569 values = { }
553570 each_statement do |statement |
554- statement . to_quad . each do |value |
555- unless value . nil? || values . include? ( value . hash )
571+ statement . terms . each do |value |
572+ unless values . include? ( value . hash )
556573 values [ value . hash ] = true
557574 yield value
558575 end
@@ -595,9 +612,10 @@ def graph_names(unique: true)
595612 # @param [RDF::Resource, false] graph_name
596613 # Use value `false` to query for the default graph_name
597614 # @return [Boolean]
598- def has_graph ?( graph_name )
615+ def graph ?( graph_name )
599616 enum_statement . any? { |s | s . graph_name == graph_name }
600617 end
618+ alias_method :has_graph? , :graph?
601619
602620 ##
603621 # Limits statements to be from a specific graph.
0 commit comments