public void GraphDiffRemovedGroundTriples() { Graph g = new Graph(); Graph h = new Graph(); g.LoadFromFile("resources\\InferenceTest.ttl"); h.LoadFromFile("resources\\InferenceTest.ttl"); //Remove Triples about Ford Fiestas from 2nd Graph h.Retract(h.GetTriplesWithSubject(new Uri("http://example.org/vehicles/FordFiesta")).ToList()); GraphDiffReport report = g.Difference(h); TestTools.ShowDifferences(report); Assert.False(report.AreEqual, "Graphs should not have been reported as equal"); Assert.True(report.RemovedTriples.Any(), "Difference should have reported some Removed Triples"); }
public void GraphEventBubbling() { try { this._graphAdded = false; this._graphRemoved = false; this._graphChanged = false; //Create Store and Graph add attach handlers to Store TripleStore store = new TripleStore(); Graph g = new Graph(); store.GraphAdded += this.HandleGraphAdded; store.GraphRemoved += this.HandleGraphRemoved; store.GraphChanged += this.HandleGraphChanged; //Add the Graph to the Store which should fire the GraphAdded event store.Add(g); Assert.IsTrue(this._graphAdded, "GraphAdded event of the Triple Store should have fired"); //Assert a Triple INode s = g.CreateBlankNode(); INode p = g.CreateUriNode("rdf:type"); INode o = g.CreateUriNode("rdfs:Class"); Triple t = new Triple(s, p, o); g.Assert(t); Assert.IsTrue(this._graphChanged, "GraphChanged event of the Triple Store should have fired"); //Retract the Triple this._graphChanged = false; g.Retract(t); Assert.IsTrue(this._graphChanged, "GraphChanged event of the Triple Store should have fired"); //Remove the Graph from the Store which should fire the GraphRemoved event store.Remove(g.BaseUri); Assert.IsTrue(this._graphRemoved, "GraphRemoved event of the Triple Store should have fired"); } catch (Exception ex) { throw; } }
public void GraphDiffRemovedMSG() { Graph g = new Graph(); Graph h = new Graph(); g.LoadFromFile("resources\\InferenceTest.ttl"); h.LoadFromFile("resources\\InferenceTest.ttl"); //Remove MSG from 2nd Graph INode toRemove = h.Nodes.BlankNodes().FirstOrDefault(); Skip.If(toRemove == null, "No MSGs in test graph"); h.Retract(h.GetTriplesWithSubject(toRemove).ToList()); GraphDiffReport report = g.Difference(h); TestTools.ShowDifferences(report); Assert.False(report.AreEqual, "Graphs should not have been reported as equal"); Assert.True(report.RemovedMSGs.Any(), "Difference should have reported some Removed MSGs"); }
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 static IDictionary<Uri, IGraph> Split(Uri originalUri, IGraph originalGraph) { IList<Uri> resources = GraphSplitting.GetResources(originalGraph); IDictionary<string, Uri> replacements = CreateReplacements(originalUri, resources); ISet<string> exclude = new HashSet<string>(); exclude.Add(originalUri.ToString()); IGraph modified = GraphSplitting.ReplaceResourceUris(originalGraph, replacements); IDictionary<Uri, IGraph> graphs = new Dictionary<Uri, IGraph>(); IGraph parent = new Graph(); foreach (Triple triple in modified.Triples) { triple.CopyTriple(parent); parent.Assert(triple); } foreach (Uri uri in replacements.Values) { INode subject = modified.CreateUriNode(uri); IGraph cutGraph = new Graph(); GraphSplitting.Collect(modified, subject, cutGraph, exclude); foreach (Triple triple in cutGraph.Triples) { triple.CopyTriple(parent); parent.Retract(triple); } IGraph rebasedGraph = new Graph(); GraphSplitting.Rebase(cutGraph, rebasedGraph, originalUri, uri); graphs.Add(uri, rebasedGraph); } graphs.Add(originalUri, parent); return graphs; }
private void CompareResultGraphs(string results, string expectedResultsPath, bool reduced) { var expectedResultGraph = new Graph(); FileLoader.Load(expectedResultGraph, expectedResultsPath); var resultSet = expectedResultGraph.GetUriNode(new Uri("http://www.w3.org/2001/sw/DataAccess/tests/result-set#ResultSet")); if (resultSet != null) { var rdfParser = new SparqlRdfParser(); var xmlParser = new SparqlXmlParser(); var actualResultSet = new SparqlResultSet(); var expectedResultSet = new SparqlResultSet(); using (var tr = new StringReader(results)) { xmlParser.Load(actualResultSet, tr); } rdfParser.Load(expectedResultSet, expectedResultsPath); var bnodeMap = new Dictionary<string, string>(); CompareSparqlResults(actualResultSet, expectedResultSet, reduced, bnodeMap); } else { // This is a constructed graph var actualGraph = new Graph(); actualGraph.LoadFromString(results); var toReplace = actualGraph.Triples.Where( t => IsGenid(t.Subject) || IsGenid(t.Predicate) || IsGenid(t.Object)).ToList(); foreach (var t in toReplace) { var mapped = MapGenidToBlank(t); actualGraph.Retract(t); actualGraph.Assert(mapped); } CompareTripleCollections(actualGraph.Triples, expectedResultGraph.Triples, reduced); } }
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(); }
public void GraphSubGraphMatchingWithBNodes() { Graph parent = new Graph(); FileLoader.Load(parent, "Turtle.ttl"); Graph subgraph = new Graph(); subgraph.Assert(parent.Triples.Where(t => !t.IsGroundTriple)); //Check method calls Dictionary<INode, INode> mapping; Console.WriteLine("Doing basic sub-graph matching with 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(); //Eliminate some of the Triples from the sub-graph Console.WriteLine("Eliminating some Triples from the sub-graph and seeing if the mapping still computes OK"); subgraph.Retract(subgraph.Triples.Skip(2).Take(5)); 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(); Console.WriteLine("Eliminating Blank Nodes from the parent Graph to check that the sub-graph is no longer considered as such afterwards"); parent.Retract(parent.Triples.Where(t => !t.IsGroundTriple)); Assert.IsFalse(parent.HasSubGraph(subgraph), "Sub-graph should no longer be considered as such"); Assert.IsFalse(subgraph.IsSubGraphOf(parent), "Sub-graph should no longer be considered as such"); }
protected void RemoveFavorClick(object sender, EventArgs e) { GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent; int index = gvRow.RowIndex; DataTable dt2Datas = (DataTable)ViewState["dt2Datas"]; //delete from rdf Graph g = new Graph(); FileLoader.Load(g, path_user + Session["UserId"].ToString() + ".rdf"); string Title = dt2Datas.Rows[index]["Title"].ToString(); string Name = dt2Datas.Rows[index]["Name"].ToString(); string Surname = dt2Datas.Rows[index]["Surname"].ToString(); string Email = dt2Datas.Rows[index]["E-mail"].ToString(); Email = "mailto:" + Email; string Phone = dt2Datas.Rows[index]["Phone"].ToString(); Phone = "tel:" + Phone; string dataid = dt2Datas.Rows[index]["dataid"].ToString(); string Comments = dt2Datas.Rows[index]["Comments"].ToString(); string Faculty = dt2Datas.Rows[index]["Faculty"].ToString(); g.NamespaceMap.AddNamespace("foaf", new Uri("http://xmlns.com/foaf/0.1/")); g.NamespaceMap.AddNamespace("rdfs", new Uri("http://www.w3.org/2000/01/rdf-schema#")); g.NamespaceMap.AddNamespace("v", new Uri("http://www.w3.org/2006/vcard/ns#")); IUriNode person = g.CreateUriNode(UriFactory.Create(dataid)); IUriNode ITitle = g.CreateUriNode("foaf:title"); IUriNode IName = g.CreateUriNode("foaf:name"); IUriNode ISurname = g.CreateUriNode("foaf:familyName"); IUriNode IEmail = g.CreateUriNode("foaf:mbox"); IUriNode IPhone = g.CreateUriNode("foaf:phone"); IUriNode IFaculty = g.CreateUriNode("rdfs:label"); IUriNode IComments = g.CreateUriNode("rdfs:comment"); IUriNode rdftype = g.CreateUriNode("rdf:type");//FOAFPERSON IUriNode foafPerson = g.CreateUriNode("foaf:Person");//FOAFPERSON // IUriNode NPhone = g.CreateUriNode(UriFactory.Create("tel:" + Session["Snumber"].ToString())); // IUriNode NEmail = g.CreateUriNode(UriFactory.Create("mailto:" + Session["Semail"].ToString().Split('>')[1].Split('<')[0].ToString())); g.Retract(person, ITitle, g.CreateLiteralNode(Title)); g.Retract(person, IName, g.CreateLiteralNode(Name)); g.Retract(person, ISurname, g.CreateLiteralNode(Surname)); g.Retract(person, IEmail, g.CreateUriNode(UriFactory.Create((Email)))); g.Retract(person, IPhone, g.CreateUriNode(UriFactory.Create((Phone)))); g.Retract(person, IComments, g.CreateLiteralNode(Comments)); g.Retract(person, IFaculty, g.CreateLiteralNode(Faculty)); g.Retract(new Triple(person, rdftype, foafPerson));//FOAFPERSON RdfXmlWriter rdfxmlwriter = new RdfXmlWriter(); rdfxmlwriter.Save(g, path_user + Session["UserId"].ToString() + ".rdf"); //remove from datatable dt2Datas.Rows[index].Delete(); dt2Datas.AcceptChanges(); GridView2.DataSource = dt2Datas; GridView2.DataBind(); /* if (faculty.Equals(" ")) faculty = ""; else if (faculty.Contains("&")) faculty = faculty.Replace("&", "&"); */ if (GridView1.Enabled) { for (int rows = 0; rows < GridView1.Rows.Count; rows++) { //System.Diagnostics.Debug.WriteLine("AHA! AHAAAAAAAAA" + Phone + "=" + GridView1.Rows[rows].Cells[4].Text + "=" + GridView1.Rows[rows].Cells[5].Text.Replace(" ", "")); if ((Title == GridView1.Rows[rows].Cells[0].Text) &&//title (Name == GridView1.Rows[rows].Cells[1].Text) && //name (Surname == GridView1.Rows[rows].Cells[2].Text) &&//surname (Phone.Split(':')[1] == GridView1.Rows[rows].Cells[4].Text) && //phone (Email == GridView1.Rows[rows].Cells[3].Text.Split('=')[1].Split('>')[0]) &&//email ((Faculty == GridView1.Rows[rows].Cells[5].Text.Replace("&", "&")) || (Faculty == GridView1.Rows[rows].Cells[5].Text.Replace(" ", "")) ) //faculty */ ) { // System.Diagnostics.Debug.WriteLine("AHA! AHAAAAAAAAA" + rows); (GridView1.Rows[rows].FindControl("btnAddFavor") as Button).Enabled = true; } } } }
protected void GV2_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = GridView2.Rows[e.RowIndex]; string UpdatedComments = ((TextBox)(row.Cells[7].Controls[0])).Text; if (UpdatedComments.Length > 30) { string script = "alert(\"Please use fewer than 30 letters for your comments\");"; ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true); return; } Graph g = new Graph(); FileLoader.Load(g, path_user + Session["UserId"].ToString() + ".rdf"); //Retrieve the table from the session object. DataTable dt2Datas = (DataTable)ViewState["dt2Datas"]; //Update the values. dt2Datas.Rows[row.DataItemIndex]["Comments"] = ((TextBox)(row.Cells[7].Controls[0])).Text; //RDF string Title = Session["STitle"].ToString(); string Name = Session["SName"].ToString(); string Surname = Session["SSurname"].ToString(); string Email = Session["SE-mail"].ToString(); Email = "mailto:" + Email; string Phone = Session["SPhone"].ToString(); Phone = "tel:" + Phone; string dataid = Session["Sdataid"].ToString(); string Comments = Session["SComments"].ToString(); string Faculty = Session["SFaculty"].ToString(); //System.Diagnostics.Debug.WriteLine(" Comments1=" + Comments); g.NamespaceMap.AddNamespace("foaf", new Uri("http://xmlns.com/foaf/0.1/")); g.NamespaceMap.AddNamespace("rdfs", new Uri("http://www.w3.org/2000/01/rdf-schema#")); g.NamespaceMap.AddNamespace("v", new Uri("http://www.w3.org/2006/vcard/ns#")); IUriNode person = g.CreateUriNode(UriFactory.Create(dataid)); IUriNode ITitle = g.CreateUriNode("foaf:title"); IUriNode IName = g.CreateUriNode("foaf:name"); IUriNode ISurname = g.CreateUriNode("foaf:familyName"); IUriNode IEmail = g.CreateUriNode("foaf:mbox"); IUriNode IPhone = g.CreateUriNode("foaf:phone"); IUriNode IFaculty = g.CreateUriNode("rdfs:label"); IUriNode IComments = g.CreateUriNode("rdfs:comment"); IUriNode rdftype = g.CreateUriNode("rdf:type");//FOAFPERSON IUriNode foafPerson = g.CreateUriNode("foaf:Person");//FOAFPERSON g.Retract(person, ITitle, g.CreateLiteralNode(Title)); g.Retract(person, IName, g.CreateLiteralNode(Name)); g.Retract(person, ISurname, g.CreateLiteralNode(Surname)); g.Retract(person, IEmail, g.CreateUriNode(UriFactory.Create((Email)))); g.Retract(person, IPhone, g.CreateUriNode(UriFactory.Create((Phone)))); g.Retract(person, IComments, g.CreateLiteralNode(Comments)); g.Retract(person, IFaculty, g.CreateLiteralNode(Faculty)); g.Retract(person, rdftype, foafPerson); //FOAFPERSON RdfXmlWriter rdfxmlwriter = new RdfXmlWriter(); rdfxmlwriter.Save(g, path_user + Session["UserId"].ToString() + ".rdf"); g.Assert(person, ITitle, g.CreateLiteralNode(Title)); g.Assert(person, IName, g.CreateLiteralNode(Name)); g.Assert(person, ISurname, g.CreateLiteralNode(Surname)); g.Assert(person, IEmail, g.CreateUriNode(UriFactory.Create((Email)))); g.Assert(person, IPhone, g.CreateUriNode(UriFactory.Create((Phone)))); g.Assert(person, IFaculty, g.CreateLiteralNode(Faculty)); g.Assert(person, rdftype, foafPerson); //FOAFPERSON g.Assert(person, IComments, g.CreateLiteralNode(UpdatedComments)); // System.Diagnostics.Debug.WriteLine(" Comments2=" + UpdatedComments); rdfxmlwriter.Save(g, path_user + Session["UserId"].ToString() + ".rdf"); LoadPersonalData(); //END RDF //Reset the edit index. GridView2.EditIndex = -1; GridView2.DataSource = dt2Datas; //Bind data to the GridView control. GridView2.DataBind(); //ViewState["dt2Datas"] = dt2Datas; }
private static void ProcessIncludes(Graph g) { var includeTriple = g.GetTriplesWithPredicate(new Uri("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#include")). FirstOrDefault(); while(includeTriple != null) { if (includeTriple.Object.NodeType == NodeType.Blank) { ProcessList(includeTriple.Object, g, ProcessInclude); } else { ProcessInclude(includeTriple.Object, g); } g.Retract(includeTriple); includeTriple = g.GetTriplesWithPredicate(new Uri("http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#include")). FirstOrDefault(); } }