mdesalvo/RDFSharp

Inequality "rdf:type" and turtle "a"

Closed this issue · 2 comments

Hi Marco!

  1. We have two Turtle files, each of them contains two axioms.
    Both are identical, except for using "a" in the first axiom in one of them instead of the full URI "rdf:type"

Test1.ttl.txt

<http://my.test/Data#He> a <http://my.test/Data#Human> . 
<http://my.test/Data#He> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://my.test/Data#Man> .

Test2.ttl.txt

<http://my.test/Data#He> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://my.test/Data#Human> .
<http://my.test/Data#He> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://my.test/Data#Man> .
  1. Code:
        RDFGraph rdfGraph1 = RDFGraph.FromFile(RDFSharp.Model.RDFModelEnums.RDFFormats.Turtle, test1);
        RDFGraph rdfGraph2 = RDFGraph.FromFile(RDFSharp.Model.RDFModelEnums.RDFFormats.Turtle, test2);

        Console.WriteLine(rdfGraph1.First());
        Console.WriteLine(rdfGraph2.First());
        Console.WriteLine(rdfGraph1.First() == rdfGraph2.First()); // expected True, received False

        Console.WriteLine(rdfGraph1.Last());
        Console.WriteLine(rdfGraph2.Last());
        Console.WriteLine(rdfGraph1.Last() == rdfGraph2.Last()); // expected True, received False
        
        Console.WriteLine(rdfGraph1.Last().Predicate == RDFVocabulary.RDF.TYPE); // True AS EXPECTED
        Console.WriteLine(rdfGraph2.Last().Predicate == RDFVocabulary.RDF.TYPE); // expected True, received False

Hi Constnick,
the "==" operator is suitable for comparing object references or strings. In order to check for RDF terms equality you should go with .Equals() methods which we support at almost every modeling level (graphs, triples, resources, literals and so on). Don't rely on "==" because it is not the way to go. Well, we may provide an override of == operator on RDFPatternMember wrapping to .Equals but I think it's not convenient to add this kind of overhaul.

Kind regards,
Marco

Thanks, my mistake :)