# File 'lib/sparql/algebra/operator/compare.rb', line 34defapply(left,right)case# @see http://www.w3.org/TR/rdf-sparql-query/#OperatorMapping# @see http://www.w3.org/TR/rdf-sparql-query/#modOrderBywhenleft.is_a?(RDF::Literal)&&right.is_a?(RDF::Literal)case# @see http://www.w3.org/TR/xpath-functions/#string-compare# @see http://www.w3.org/TR/xpath-functions/#comp.numeric# @see http://www.w3.org/TR/xpath-functions/#op.boolean# @see http://www.w3.org/TR/xpath-functions/#comp.duration.datetimewhen(left.simple?&&right.simple?)||(left.is_a?(RDF::Literal::Numeric)&&right.is_a?(RDF::Literal::Numeric))||(left.datatype==right.datatype&&left.language==right.language)RDF::Literal(left.send(self.class.const_get(:NAME),right))# A plain literal is lower than an RDF literal with type xsd:string of the same lexical form.whenleft.simple?&&right.datatype==RDF::XSD.string&&left.value==right.valueRDF::Literal(-1)whenright.simple?&&left.datatype==RDF::XSD.string&&right.value==left.valueRDF::Literal(-1)elseraiseTypeError,"unable to compare #{left.inspect} and #{right.inspect}"endwhenleft.is_a?(RDF::URI)&&right.is_a?(RDF::URI)# Pairs of IRIs are ordered by comparing them as simple literals.RDF::Literal(RDF::Literal(left.to_s).send(self.class.const_get(:NAME),RDF::Literal(right.to_s)))whenleft.is_a?(RDF::Node)&&right.is_a?(RDF::Node)# BNode comparison is undefined.RDF::Literal(0)whenleft.nil?&&right.nil?RDF::Literal(0)# SPARQL also fixes an order between some kinds of RDF terms that would not otherwise be ordered:# 2. Blank nodeswhenleft.is_a?(RDF::Node)&&right.is_a?(RDF::Term)RDF::Literal(-1)whenright.is_a?(RDF::Node)&&left.is_a?(RDF::Term)RDF::Literal(1)# 3. IRIswhenleft.is_a?(RDF::URI)&&right.is_a?(RDF::Term)RDF::Literal(-1)whenright.is_a?(RDF::URI)&&left.is_a?(RDF::Term)RDF::Literal(1)elseraiseTypeError,"expected two RDF::Term operands, but got #{left.inspect} and #{right.inspect}"endend