diff --git a/src/SQL2Linked/Implementations/UserStructuralData.cs b/src/SQL2Linked/Implementations/UserStructuralData.cs index 02865a1f7f7982cec430fb9ff90b97bde6c6e691..29f811134e4aca5bf73595e276555698fa2ed524 100644 --- a/src/SQL2Linked/Implementations/UserStructuralData.cs +++ b/src/SQL2Linked/Implementations/UserStructuralData.cs @@ -10,6 +10,7 @@ namespace SQL2Linked.Implementations public readonly string UserUrlPrefix = "https://purl.org/coscine/users"; public readonly Uri rdf = new("http://www.w3.org/1999/02/22-rdf-syntax-ns#"); public readonly Uri foaf = new("http://xmlns.com/foaf/0.1/"); + public override IEnumerable<IGraph> ConvertToLinkedData(IEnumerable<User> entries) { var graphs = new List<IGraph>(); @@ -21,11 +22,16 @@ namespace SQL2Linked.Implementations // check if a triple with a foaf:Person already exists in the user graph var getTriples = graph.GetTriplesWithObject(new Uri(foaf + "Person")); + // check if the current display name is already applied in the user graph + var getTriplesName = graph.GetTriplesWithPredicate(new Uri(foaf + "name")); - if (!getTriples.Any()) + if (!getTriples.Any() || !getTriplesName.Any((triple) => triple.Object.ToString() == entry.DisplayName)) { AssertToGraphUriNode(graph, userGraphName, rdf + "type", foaf + "Person"); + graph.Retract(getTriplesName); + AssertToGraphLiteralNode(graph, userGraphName, foaf + "name", entry.DisplayName); + graphs.Add(graph); Console.WriteLine($"Will migrate user '{entry.DisplayName}' with id '{entry.Id}'."); @@ -33,7 +39,7 @@ namespace SQL2Linked.Implementations else { Console.WriteLine($"Will NOT migrate user '{entry.DisplayName}' with id '{entry.Id}'."); - } + } } return graphs; }