From: Penny, C. <Chr...@ds...> - 2014-01-30 05:30:45
|
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. private void getUriNodeProblemExample() { //Create graph and add namespace + nodes Graph graph = new Graph(); graph.NamespaceMap.AddNamespace("test", new Uri("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(new Triple(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(new Triple(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. |