From: Rob V. <rv...@do...> - 2014-01-30 06:25:37
|
Christopher This is unintuitive although by design, the Nodes collection only returns things that are in the Subject/Object position in a triple and not things that are predicates This question and my answer at http://stackoverflow.com/questions/17967686/retrieving-specific-rdf-graph-tr iples-based-on-predicate-nodes discusses the thinking behind this and the eventual planned changes around this feature Rob From: "Penny, Christopher" <Chr...@ds...> Reply-To: dotNetRDF Bug Report tracking and resolution <dot...@li...> Date: Wednesday, 29 January 2014 20:28 To: "dot...@li..." <dot...@li...> Subject: [dotNetRDF-bugs] UriNodes in predicate position only don't appear in Graph.Nodes [SEC=UNCLASSIFIED] > UNCLASSIFIED > > Hello again all, > > I believe I¹ve stumbled across another (possible) bug. UriNodes which only > appear in the predicate position do not seem to find their way into > Graph.Nodes.UriNodes(), Graph.Nodes or become returnable via getUriNode. The > code below demonstrates the problem I¹m having. > > privatevoid getUriNodeProblemExample() > { > //Create graph and add namespace + nodes > Graph graph = newGraph(); > graph.NamespaceMap.AddNamespace("test", > newUri("http://test.com/test#")); > IUriNode subjectNode = graph.CreateUriNode("test:subject"); > IUriNode predicateNode = graph.CreateUriNode("test:predicate"); > IUriNode objectNode = graph.CreateUriNode("test:object"); > > //The UriNode is null > IUriNode uriNode = graph.GetUriNode("test:subject"); > if(uriNode == null) > { > System.Console.WriteLine("Urinode is null"); > } > else > { > System.Console.WriteLine("Returned IUriNode is: " + uriNode); > } > > //Source indicates that GetUriNode iterates over > graph.Nodes.UriNodes() > System.Console.WriteLine("Printing URINodes before first > triple:"); > foreach (IUriNode node in graph.Nodes.UriNodes()) > { > System.Console.WriteLine(">Node in graph.Nodes.UriNodes() is: > " +node.ToString()); > } > > //Iterate over all nodes > System.Console.WriteLine("Printing ALL Nodes before first > triple:"); > foreach (INode node in graph.Nodes) > { > System.Console.WriteLine(">Node: "+node.ToString()+" has type: > "+node.NodeType); > } > > //Adding a triple seems necessary to get nodes to appear in the > graph. However, only the subject and object nodes appear after the triple is > created. > graph.Assert(newTriple(subjectNode,predicateNode,objectNode)); > > //Source indicates that GetUriNode iterates over > graph.Nodes.UriNodes() > System.Console.WriteLine("Printing URINodes after first triple:"); > foreach (IUriNode node in graph.Nodes.UriNodes()) > { > System.Console.WriteLine(">Node in graph.Nodes.UriNodes() is: > " + node.ToString()); > } > > //Iterate over all nodes > System.Console.WriteLine("Printing All nodes after first > triple:"); > foreach (INode node in graph.Nodes) > { > System.Console.WriteLine(">Node: " + node.ToString() + " has > type: " + node.NodeType); > } > > //Only the subject and object nodes were found. Lets switch the > order. All nodes get printed this time. > graph.Assert(newTriple(predicateNode, subjectNode, objectNode)); > > //Source indicates that GetUriNode iterates over > graph.Nodes.UriNodes() > System.Console.WriteLine("Printing URINodes after second > triple:"); > foreach (IUriNode node in graph.Nodes.UriNodes()) > { > System.Console.WriteLine(">Node in graph.Nodes.UriNodes() is: > " + node.ToString()); > } > > //Iterate over all nodes > System.Console.WriteLine("Printing All nodes after second > triple:"); > foreach (INode node in graph.Nodes) > { > System.Console.WriteLine(">Node: " + node.ToString() + " has > type: " + node.NodeType); > } > > System.Console.WriteLine("End of function"); > } > > I get the following output for the above code: > Urinode is null > Printing URINodes before first triple: > Printing ALL Nodes before first triple: > Printing URINodes after first triple: >> >Node in graph.Nodes.UriNodes() is: http://test.com/test#subject >> >Node in graph.Nodes.UriNodes() is: http://test.com/test#object > Printing All nodes after first triple: >> >Node: http://test.com/test#subject has type: Uri >> >Node: http://test.com/test#object has type: Uri > Printing URINodes after second triple: >> >Node in graph.Nodes.UriNodes() is: http://test.com/test#subject >> >Node in graph.Nodes.UriNodes() is: http://test.com/test#predicate >> >Node in graph.Nodes.UriNodes() is: http://test.com/test#object > Printing All nodes after second triple: >> >Node: http://test.com/test#subject has type: Uri >> >Node: http://test.com/test#predicate has type: Uri >> >Node: http://test.com/test#object has type: Uri > End of function > > I poked around a bit more in the source. Might the problem be in BaseGraph.cs: > public virtual IEnumerable<INode> Nodes > { > get > { > return (from t in this._triples > select t.Subject).Concat(from t in this._triples > select t.Object).Distinct(); > } > } > Needing to also .Concat t.Predicate? > > Unless the reasoning is that a graph is composed of subject/object nodes with > predicate links¹. However, it would be nice to retrieve an IUriNode for a > predicate from a graph for use with > Graph.GetTriplesWithSubjectPredicate(INode, INode). To get the rdf:type of the > subject, for example. > > Let me know if more information is required. > > Regards, Chris. > IMPORTANT: This email remains the property of the Department of Defence and is > subject to the jurisdiction of section 70 of the Crimes Act 1914. If you have > received this email in error, you are requested to contact the sender and > delete the email. > ------------------------------------------------------------------------------ > WatchGuard Dimension instantly turns raw network data into actionable security > intelligence. It gives you real-time visual feedback on key security issues > and trends. Skip the complicated setup - simply import a virtual appliance > and go from zero to informed in seconds. > http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk__ > _____________________________________________ dotNetRDF-bugs mailing list > dot...@li... > https://lists.sourceforge.net/lists/listinfo/dotnetrdf-bugs |