var g = new Graph();
g.NamespaceMap.AddNamespace("fam", new Uri(FAM));
g.NamespaceMap.AddNamespace("rdf", new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#"));
static IUriNode U(IGraph graph, string qname) => graph.CreateUriNode(qname);
string[] persons = {
"Marie", "Pierre", "Jean", "Claire",
"Luc", "Sophie", "Paul", "Anne",
"Marc", "Lea", "Hugo", "Julie",
"Thomas", "Emma"
};
foreach (var p in persons)
g.Assert(U(g, "fam:" + p), U(g, "rdf:type"), U(g, "fam:Person"));
// parentOf(X, Y) : X est parent de Y (14 triples)
(string, string)[] parentTriples = {
("Marie", "Jean"), ("Marie", "Claire"),
("Pierre", "Jean"), ("Pierre", "Claire"),
("Jean", "Luc"), ("Jean", "Sophie"),
("Claire", "Paul"), ("Claire", "Anne"),
("Luc", "Marc"), ("Luc", "Lea"),
("Sophie", "Hugo"), ("Sophie", "Julie"),
("Paul", "Thomas"), ("Paul", "Emma"),
};
foreach (var (parent, child) in parentTriples)
g.Assert(U(g, "fam:" + parent), U(g, "fam:parentOf"), U(g, "fam:" + child));
// grandparentOf : SOUS-ENSEMBLE incomplet (5 triples sur 14 vraies paires)
// Vraies paires = 14 : Marie/Pierre -> {Luc,Sophie,Paul,Anne} (8), Jean -> {Marc,Lea,Hugo,Julie} (4), Claire -> {Thomas,Emma} (2).
// On n'ajoute que 5 triples (Marie/Pierre vers Luc/Sophie/Paul partiellement).
// standard confidence = 5/14 ~ 0.36 ; PCA confidence = 5/8 = 0.625
(string, string)[] grandparentTriples = {
("Marie", "Luc"), ("Marie", "Sophie"), ("Marie", "Paul"),
("Pierre", "Luc"), ("Pierre", "Sophie"),
};
foreach (var (gp, gc) in grandparentTriples)
g.Assert(U(g, "fam:" + gp), U(g, "fam:grandparentOf"), U(g, "fam:" + gc));
// siblingOf (12 triples, symetrique)
(string, string)[] siblingTriples = {
("Jean", "Claire"), ("Claire", "Jean"),
("Luc", "Sophie"), ("Sophie", "Luc"),
("Paul", "Anne"), ("Anne", "Paul"),
("Marc", "Lea"), ("Lea", "Marc"),
("Hugo", "Julie"), ("Julie", "Hugo"),
("Thomas", "Emma"), ("Emma", "Thomas"),
};
foreach (var (s1, s2) in siblingTriples)
g.Assert(U(g, "fam:" + s1), U(g, "fam:siblingOf"), U(g, "fam:" + s2));
// marriedTo (2 triples, symetrique)
(string, string)[] marriedTriples = { ("Marie", "Pierre"), ("Pierre", "Marie") };
foreach (var (h, w) in marriedTriples)
g.Assert(U(g, "fam:" + h), U(g, "fam:marriedTo"), U(g, "fam:" + w));
int Count(IGraph graph, IUriNode pred) => graph.GetTriplesWithPredicate(pred).Count();
Console.WriteLine("Knowledge Graph cree avec dotNetRDF");
int nPerson = persons.Length;
Console.WriteLine($" Person : {nPerson}");
Console.WriteLine($" parentOf : {Count(g, U(g, "fam:parentOf"))} triples");
Console.WriteLine($" grandparentOf : {Count(g, U(g, "fam:grandparentOf"))} triples");
Console.WriteLine($" siblingOf : {Count(g, U(g, "fam:siblingOf"))} triples");
Console.WriteLine($" marriedTo : {Count(g, U(g, "fam:marriedTo"))} triples");
Console.WriteLine($" Total triplets : {g.Triples.Count()}");