mdesalvo / RDFSharp

Lightweight and friendly .NET library for realizing Semantic Web applications
Apache License 2.0
118 stars 26 forks source link

Inequality "rdf:type" and turtle "a" #322

Closed constnick closed 10 months ago

constnick commented 10 months ago

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
mdesalvo commented 10 months ago

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

constnick commented 10 months ago

Thanks, my mistake :)