public void GraphDiffRemovedMSG() { Graph g = new Graph(); Graph h = new Graph(); FileLoader.Load(g, "InferenceTest.ttl"); FileLoader.Load(h, "InferenceTest.ttl"); //Remove MSG from 2nd Graph INode toRemove = h.Nodes.BlankNodes().FirstOrDefault(); if (toRemove == null) { Assert.Inconclusive("No MSGs in test graph"); } h.Retract(h.GetTriplesWithSubject(toRemove).ToList()); GraphDiffReport report = g.Difference(h); TestTools.ShowDifferences(report); Assert.IsFalse(report.AreEqual, "Graphs should not have been reported as equal"); Assert.IsTrue(report.RemovedMSGs.Any(), "Difference should have reported some Removed MSGs"); }
public override StorageContent CreateContent(CatalogContext context) { IGraph catalogEntry = new Graph(); INode catalogEntrySubject = catalogEntry.CreateUriNode(GetItemAddress()); // catalog infrastructure fields catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Type), catalogEntry.CreateUriNode(GetItemType())); catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Type), catalogEntry.CreateUriNode(_itemType)); catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Type), catalogEntry.CreateUriNode(Schema.DataTypes.Permalink)); catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.CatalogTimeStamp), catalogEntry.CreateLiteralNode(TimeStamp.ToString("O"), Schema.DataTypes.DateTime)); catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.CatalogCommitId), catalogEntry.CreateLiteralNode(CommitId.ToString())); catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Published), catalogEntry.CreateLiteralNode(_publicationDetails.Published.ToString("O"), Schema.DataTypes.DateTime)); catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.TenantId), catalogEntry.CreateLiteralNode(_publicationDetails.TenantId)); catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Tenant), catalogEntry.CreateLiteralNode(_publicationDetails.TenantName)); Uri ownerUri = _publicationDetails.Owner.GetUri(GetItemAddress()); INode ownerSubject = catalogEntry.CreateUriNode(ownerUri); catalogEntry.Assert(ownerSubject, catalogEntry.CreateUriNode(Schema.Predicates.NameIdentifier), catalogEntry.CreateLiteralNode(_publicationDetails.Owner.NameIdentifier)); //catalogEntry.Assert(ownerSubject, catalogEntry.CreateUriNode(Schema.Predicates.Name), catalogEntry.CreateLiteralNode(_publicationDetails.Owner.Name)); catalogEntry.Assert(ownerSubject, catalogEntry.CreateUriNode(Schema.Predicates.GivenName), catalogEntry.CreateLiteralNode(_publicationDetails.Owner.GivenName)); catalogEntry.Assert(ownerSubject, catalogEntry.CreateUriNode(Schema.Predicates.Surname), catalogEntry.CreateLiteralNode(_publicationDetails.Owner.Surname)); //catalogEntry.Assert(ownerSubject, catalogEntry.CreateUriNode(Schema.Predicates.Iss), catalogEntry.CreateLiteralNode(_publicationDetails.Owner.Iss)); catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Owner), ownerSubject); // visibility catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Visibility), catalogEntry.CreateLiteralNode(_publicationDetails.Visibility.Visibility.ToString())); switch (_publicationDetails.Visibility.Visibility) { case PublicationVisibility.VisibilityScope.Organization: catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Organization), catalogEntry.CreateLiteralNode(_publicationDetails.Visibility.Organization)); break; case PublicationVisibility.VisibilityScope.Subscription: catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Subscription), catalogEntry.CreateLiteralNode(_publicationDetails.Visibility.Subscription)); break; } // listed catalogEntry.Assert(catalogEntrySubject, catalogEntry.CreateUriNode(Schema.Predicates.Listed), catalogEntry.CreateLiteralNode(_isListed.ToString(), Schema.DataTypes.Boolean)); // add the nuspec metadata Uri nuspecSubject = _nuspec["@id"].ToObject<Uri>(); IGraph nuspecGraph = Utils.CreateGraph(_nuspec); // Any statements made about this @id in the nuspec we want to make about the catalog items @id // - catalog readers can then apply this logic in reverse // - by so doing the catalog entry becomes an audit entry for the data catalogEntry.Merge(nuspecGraph, false); foreach (Triple triple in catalogEntry.GetTriplesWithSubject(catalogEntry.CreateUriNode(nuspecSubject))) { catalogEntry.Assert(catalogEntrySubject, triple.Predicate.CopyNode(catalogEntry), triple.Object.CopyNode(catalogEntry)); } GraphHelpers.MaterializeInference(catalogEntry); SetIdVersionFromGraph(catalogEntry); // create JSON content string json = Utils.CreateJson(catalogEntry, _context); StorageContent content = new StringStorageContent(json, "application/json", "no-store"); return content; }
public void GraphSubGraphMatching() { Graph parent = new Graph(); FileLoader.Load(parent, "InferenceTest.ttl"); Graph subgraph = new Graph(); subgraph.NamespaceMap.Import(parent.NamespaceMap); subgraph.Assert(parent.GetTriplesWithSubject(parent.CreateUriNode("eg:FordFiesta"))); //Check method calls Dictionary<INode, INode> mapping; Console.WriteLine("Doing basic sub-graph matching with no BNode tests"); Assert.IsTrue(parent.HasSubGraph(subgraph, out mapping), "Failed to match the sub-graph as expected"); Assert.IsFalse(parent.IsSubGraphOf(subgraph, out mapping), "Parent should not be a sub-graph of the sub-graph"); Assert.IsFalse(subgraph.HasSubGraph(parent, out mapping), "Sub-graph should not have parent as its sub-graph"); Assert.IsTrue(subgraph.IsSubGraphOf(parent, out mapping), "Failed to match the sub-graph as expected"); Console.WriteLine("OK"); Console.WriteLine(); //Add an extra triple into the Graph which will cause it to no longer be a sub-graph Console.WriteLine("Adding an extra Triple so the sub-graph is no longer such"); subgraph.Assert(new Triple(subgraph.CreateUriNode("eg:Rocket"), subgraph.CreateUriNode("rdf:type"), subgraph.CreateUriNode("eg:AirVehicle"))); Assert.IsFalse(parent.HasSubGraph(subgraph, out mapping), "Sub-graph should no longer be considered a sub-graph"); Assert.IsFalse(subgraph.IsSubGraphOf(parent, out mapping), "Sub-graph should no longer be considered a sub-graph"); Console.WriteLine("OK"); Console.WriteLine(); //Reset the sub-graph Console.WriteLine("Resetting the sub-graph"); subgraph = new Graph(); subgraph.NamespaceMap.Import(parent.NamespaceMap); subgraph.Assert(parent.GetTriplesWithSubject(parent.CreateUriNode("eg:FordFiesta"))); Console.WriteLine("Adding additional information to the parent Graph, this should not affect the fact that the sub-graph is a sub-graph of it"); Assert.IsTrue(parent.HasSubGraph(subgraph, out mapping), "Failed to match the sub-graph as expected"); Assert.IsFalse(parent.IsSubGraphOf(subgraph, out mapping), "Parent should not be a sub-graph of the sub-graph"); Assert.IsFalse(subgraph.HasSubGraph(parent, out mapping), "Sub-graph should not have parent as its sub-graph"); Assert.IsTrue(subgraph.IsSubGraphOf(parent, out mapping), "Failed to match the sub-graph as expected"); Console.WriteLine("OK"); Console.WriteLine(); //Remove stuff from parent graph so it won't match any more Console.WriteLine("Removing stuff from parent graph so that it won't have the sub-graph anymore"); parent.Retract(parent.GetTriplesWithSubject(parent.CreateUriNode("eg:FordFiesta"))); Assert.IsFalse(parent.HasSubGraph(subgraph, out mapping), "Parent should no longer contian the sub-graph"); Assert.IsFalse(subgraph.IsSubGraphOf(parent, out mapping), "Parent should no longer contain the sub-graph"); Console.WriteLine("OK"); Console.WriteLine(); }
private static void ProcessList(INode listNode, Graph g, Action<INode, Graph> processAction) { var first = g.GetTriplesWithSubject(listNode).Where( t => (t.Predicate as UriNode).Uri.ToString().Equals(RdfFirst.ToString())).Select(t => t.Object). FirstOrDefault(); var rest = g.GetTriplesWithSubject(listNode).Where( t => (t.Predicate as UriNode).Uri.ToString().Equals(RdfRest.ToString())).Select(t => t.Object). FirstOrDefault(); if (first != null) { processAction(first, g); } if (rest != null) { ProcessList(rest, g, processAction); } }