mdesalvo / RDFSharp

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

Data.FactsCount #185

Closed constnick closed 3 years ago

constnick commented 3 years ago

Hi Marco, why the ontology.Data.FactsCount value doesn't increase when relation added with new RDFOntologyFact? And this value is correct in exactly the same ontology parsed from graph.

var ontology = new RDFOntology(new RDFResource("http://test.net/stuff"));
var ontoClass = new RDFOntologyClass(new RDFResource("http://test.net/stuff#Class1"));
var item = new RDFOntologyFact(new RDFResource("http://test.net/stuff#Item1"));
ontology.Model.ClassModel.AddClass(ontoClass);
ontology.Data.AddClassTypeRelation(item, ontoClass);

Console.WriteLine($"ontology.Data.FactsCount == {ontology.Data.FactsCount}"); // ontology.Data.FactsCount == 0

ontology = RDFOntology.FromRDFGraph(ontology.ToRDFGraph(RDFSemanticsEnums.RDFOntologyInferenceExportBehavior.ModelAndData));

Console.WriteLine($"ontology.Data.FactsCount == {ontology.Data.FactsCount}"); // ontology.Data.FactsCount == 1

I know and use the Data.AddFact method, but question is not "how to do": I mean, there is some inconsistency when two identical ontologies can have different values of the same property describing their content.

mdesalvo commented 3 years ago

Hi, relation methods only add the specified relation to the ontology, not the involved class/property/fact definitions: these are in scope of AddClass/AddProperty/AddFact methods on which you have full control when modeling. This is the reason of the 0 counter for facts. The inconsistency you describe is that during the graph->ontology process the fact definitions can only be obtained along with rdf:type relations: when it gets "item rdf:type ontoClass" it also gets "item" fact, this is the reason of the 1 counter for facts.

If this inconsistency is some way hard or blocking you, I may consider automatic addition of fact in AddClassTypeRelation to harmonize the behavior. At least for facts this would be quite safe.

constnick commented 3 years ago

As far as I understand, there is a difference between class/property definition and definition of individual in any ontology. The first must be explicite, e.g. ontoClass rdf:type owl:Class, but the second is not: assertion item rdf:type owl:NamedIndividual is not mandatory, so assertion item rdf:type ontoClass is sufficient for defining item. It is clear in ontology point of view, what AddClass or AddProperty do, unlike AddFact which looks like making only program sense (imho). For example if invoke AddFact for empty just created ontology, no triples will be added to it's corresponding rdf graph. So, maybe, automatic addition of individual in AddClassTypeRelation would be logically right. (Sorry, I'm a little confused by unusual naming of RDFSharp classes using "Fact" and "Taxonomy" terms, although it is clear that nothing can be done about it :)

mdesalvo commented 3 years ago

Ok, I'll adjust AddClassTypeRelation to also add the individual to the ontology data.