From: Rob V. <rv...@vd...> - 2011-04-10 10:54:40
|
Hi Ian Thanks for the feedback, I have updated the example to note that Ontology.rdf is an example filename and you should substitute your own filename there. The NullReferenceException on the GetTriplesWithSubjectPredicate() call is due to the fact that someclass2 is populated using the GetUriNode() method which returns null if there is no such node in the Graph, either check someclass2 for null as I have done in the updated example or use CreateUriNode() instead. With regards to the formatter parameter that should be optional, INode's have an overload of ToString() which takes the formatter parameter to allow you to control exactly how the Node is converted into a String. But they should also have the default ToString() method which all .Net objects have. Not sure if this is some VB compiler specific issue as I do all my coding in C# these days and the C# compiler doesn't insist on the formatter parameter, will look into this and get back to you. In the meantime if the compiler insists on the formatter parameter I would use an NTriplesFormatter e.g. Dim formatter As VDS.RDF.Writing.Formatting.INodeFormatter formatter = new VDS.RDF.Writing.Formatting.NTriplesFormatter(); If you have any further questions/issues please let me know Rob Vesse ---------------------------------------- From: "Ian R Fry" <ia...@fr...> Sent: 10 April 2011 11:33 To: dot...@li... Subject: SPAM-LOW: [dotNetRDF-Support] Ontology API example In the second version (showing detail Graphs and Triples) I am getting some errors. Note I have used VB.Net for a web applicaiton a) Console.WriteLine("Super Class: " + t.Object.ToString()); The tostring requires a "formatter" parameter which I have never seen before b) foreach (Triple t in g.GetTriplesWithSubjectPredicate(someClass, subClassOf)) gives Object reference not set to an instance of an object. I have imported all the classes. Here is the code Dim g1 = New Graph() FileLoader.Load(g, Server.MapPath( "data/Ontology.rdf" )) Dim someclass2, subclassof As INode someclass2 = g.GetUriNode( New Uri( "http://example.org/someClass" )) Dim t1, t2 As Triple Dim formatter As VDS.RDF.Writing.Formatting.INodeFormatter subclassof = g.CreateUriNode( New Uri(NamespaceMapper.RDFS + "subClassOf" )) For Each t1 In g.GetTriplesWithSubjectPredicate(someclass2, subclassof) <---- error Response.Write( "<br>Super Class: " + t1.Object.ToString(formatter)) <---- compiler complains if no formatter For Each t2 In g.GetTriplesWithPredicateObject(subclassof, someclass) Response.Write( "<br>Sub Class: " + t2.Subject.ToString(formatter)) Next Next love the product though Ian Fry Fry Systems |