/// <summary> /// Creates a new Open Connection Form /// </summary> /// <param name="g">Graph contaning Connection Definitions</param> public OpenConnectionForm(IGraph g) { InitializeComponent(); //Find connections defined in the Configuration Graph this._g = g; INode genericManager = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.ClassGenericManager); INode rdfsLabel = g.CreateUriNode(new Uri(NamespaceMapper.RDFS + "label")); SparqlParameterizedString getConnections = new SparqlParameterizedString(); getConnections.QueryText = "SELECT ?obj ?label WHERE { ?obj a @type . OPTIONAL { ?obj @label ?label } } ORDER BY ?label"; getConnections.SetParameter("type", genericManager); getConnections.SetParameter("label", rdfsLabel); Object results = this._g.ExecuteQuery(getConnections.ToString()); if (results is SparqlResultSet) { SparqlResultSet rset = (SparqlResultSet)results; foreach (SparqlResult r in rset) { this._connectionNodes.Add(r["obj"]); if (r.HasValue("label")) { this.lstConnections.Items.Add(r["label"]); } else { this.lstConnections.Items.Add(r["obj"]); } } } }
private IEnumerable<SparqlUpdateCommand> GetDeleteDataCommands(IEnumerable<RomanticWeb.Model.EntityQuad> quads) { foreach (var quad in quads) { SparqlParameterizedString insert = new SparqlParameterizedString(DeleteDataCommandText); insert.SetParameter("subject", quad.Subject.UnWrapNode(_nodeFactory)); insert.SetParameter("predicate", quad.Predicate.UnWrapNode(_nodeFactory)); insert.SetParameter("object", quad.Object.UnWrapNode(_nodeFactory)); insert.SetUri("graph", quad.Graph.UnWrapGraphUri()); foreach (var command in _parser.ParseFromString(insert).Commands) { yield return command; } } }
public void SetParameterShouldIgnoreParameterPrefixChar() { var sut = new SparqlParameterizedString("SELECT * WHERE { ?s a @o }"); sut.SetParameter("@o", new NodeFactory().CreateLiteralNode("test")); Assert.Equal("SELECT * WHERE { ?s a \"test\" }", sut.ToString()); }
public void ShouldReplaceParameterStartingWithUnderscore() { var sut = new SparqlParameterizedString("SELECT * WHERE { ?s a @_o }"); sut.SetParameter("_o", new NodeFactory().CreateLiteralNode("test")); Assert.Equal("SELECT * WHERE { ?s a \"test\" }", sut.ToString()); }
public void Core445_ParsingTest() { Random randomizer = new Random(); SparqlParameterizedString command = new SparqlParameterizedString("SELECT * FROM <urn:with@char> FROM <urn:with?or$char> WHERE { ?subject rdfs:subClassOf ? $c . $c rdfs:label \"string literal with lang tag @inLiteralParamPattern \"@en }"); command.SetVariable("subject", g.CreateUriNode(UriFactory.Create("urn:some-uri"))); command.SetVariable("c", g.CreateUriNode(UriFactory.Create("urn:some-uri"))); command.SetVariable("or", g.CreateUriNode(UriFactory.Create("urn:some-uri"))); command.SetVariable("char", g.CreateUriNode(UriFactory.Create("urn:some-uri"))); command.SetParameter("char", g.CreateUriNode(UriFactory.Create("urn:some-uri"))); command.SetParameter("en", g.CreateUriNode(UriFactory.Create("urn:some-uri"))); command.SetParameter("inLiteralParamPattern", g.CreateUriNode(UriFactory.Create("urn:some-uri"))); String output = command.ToString(); Assert.True(output.Contains("<urn:with@char>"), "In IRI @ characters should not start a parameter capture"); Assert.True(output.Contains("<urn:with?or$char>"), "In IRI ? and $ characters should not start a variable capture"); Assert.True(output.Contains("rdfs:subClassOf ? "), "Property path ? quantifier should not start a variable capture"); Assert.True(output.Contains("@en"), "Language tags should not start a parameter capture"); Assert.True(output.Contains("@inLiteralParamPattern"), "In string literal @ characters should not start a parameter capture"); }
public void SparqlParameterizedStringWithNulls() { SparqlParameterizedString query = new SparqlParameterizedString(); query.CommandText = "SELECT * WHERE { @s ?p ?o }"; //Set a URI to a valid value query.SetUri("s", new Uri("http://example.org")); Console.WriteLine(query.ToString()); Console.WriteLine(); //Set the parameter to a null query.SetParameter("s", null); Console.WriteLine(query.ToString()); }
/// <summary> /// Queries the Store using the Graph Pattern specified by the set of Statement Patterns /// </summary> /// <param name="graph">Graph Pattern</param> /// <param name="options">Query Options</param> /// <param name="sink">Results Sink</param> /// <remarks> /// <para> /// Implemented by converting the Statement Patterns into a SPARQL SELECT query and executing that against the underlying Store's SPARQL engine /// </para> /// <para> /// The only Query Option that is supported is the Limit option /// </para> /// </remarks> public void Query(Statement[] graph, SW.Query.QueryOptions options, SW.Query.QueryResultSink sink) { //Implement as a SPARQL SELECT SparqlParameterizedString queryString = new SparqlParameterizedString(); queryString.QueryText = "SELECT * WHERE {"; int p = 0; foreach (Statement stmt in graph) { //Add Subject queryString.QueryText += "\n"; if (stmt.Subject is Variable) { queryString.QueryText += stmt.Subject.ToString(); } else { queryString.QueryText += "@param" + p; queryString.SetParameter("param" + p, SemWebConverter.FromSemWeb(stmt.Subject, this._mapping)); p++; } queryString.QueryText += " "; //Add Predicate if (stmt.Predicate is Variable) { queryString.QueryText += stmt.Predicate.ToString(); } else { queryString.QueryText += "@param" + p; queryString.SetParameter("param" + p, SemWebConverter.FromSemWeb(stmt.Predicate, this._mapping)); p++; } queryString.QueryText += " "; //Add Object if (stmt.Object is Variable) { queryString.QueryText += stmt.Object.ToString(); } else { queryString.QueryText += "@param" + p; queryString.SetParameter("param" + p, SemWebConverter.FromSemWeb(stmt.Object, this._mapping)); p++; } queryString.QueryText += " ."; } queryString.QueryText += "}"; //Execute the Query and convert the Results Object results = this._store.ExecuteQuery(queryString.ToString()); if (results is SparqlResultSet) { SparqlResultSet rset = (SparqlResultSet)results; sink.Init(rset.Variables.Select(v => new Variable(v)).ToArray()); if (rset.Count > 0) { int c = 0; foreach (SparqlResult r in rset) { //Apply Limit if applicable if (options.Limit > 0 && c >= options.Limit) { sink.Finished(); return; } //Convert the Set to VariableBindings for SemWeb Variable[] vars = r.Variables.Select(v => new Variable(v)).ToArray(); Resource[] resources = r.Variables.Select(v => SemWebConverter.ToSemWeb(r[v], this._mapping)).ToArray(); SW.Query.VariableBindings bindings = new SW.Query.VariableBindings(vars, resources); //Keep adding results until the sink tells us to stop if (!sink.Add(bindings)) { sink.Finished(); return; } c++; } sink.Finished(); } else { sink.Finished(); } } else { throw new RdfQueryException("Query returned an unexpected result where a SPARQL Result Set was expected"); } }
/// <summary> /// Internal method which generates the HTML Output for the Graph /// </summary> /// <param name="context">Writer Context</param> private void GenerateOutput(HtmlWriterContext context) { Object results; //Add the Namespaces we want to use later on context.QNameMapper.AddNamespace("owl", new Uri(NamespaceMapper.OWL)); context.QNameMapper.AddNamespace("rdf", new Uri(NamespaceMapper.RDF)); context.QNameMapper.AddNamespace("rdfs", new Uri(NamespaceMapper.RDFS)); context.QNameMapper.AddNamespace("dc", new Uri("http://purl.org/dc/elements/1.1/")); context.QNameMapper.AddNamespace("dct", new Uri("http://purl.org/dc/terms/")); context.QNameMapper.AddNamespace("vann", new Uri("http://purl.org/vocab/vann/")); context.QNameMapper.AddNamespace("vs", new Uri("http://www.w3.org/2003/06/sw-vocab-status/ns#")); //Find the Node that represents the Schema Ontology //Assumes there is exactly one thing given rdf:type owl:Ontology IUriNode ontology = context.Graph.CreateUriNode(new Uri(NamespaceMapper.OWL + "Ontology")); IUriNode rdfType = context.Graph.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)); IUriNode rdfsLabel = context.Graph.CreateUriNode(new Uri(NamespaceMapper.RDFS + "label")); INode ontoNode = context.Graph.GetTriplesWithPredicateObject(rdfType, ontology).Select(t => t.Subject).FirstOrDefault(); INode ontoLabel = (ontoNode != null) ? context.Graph.GetTriplesWithSubjectPredicate(ontoNode, rdfsLabel).Select(t => t.Object).FirstOrDefault() : null; //Stuff for formatting //We'll use the Turtle Formatter to get nice QNames wherever possible context.NodeFormatter = new TurtleFormatter(context.QNameMapper); context.UriFormatter = (IUriFormatter)context.NodeFormatter; //Page Header context.HtmlWriter.Write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML+RDFa 1.0//EN\" \"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd\">"); context.HtmlWriter.WriteLine(); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Html); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Head); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Title); context.HtmlWriter.WriteEncodedText("Schema"); if (ontoNode != null && ontoLabel != null) { context.HtmlWriter.WriteEncodedText(" - " + ontoLabel.ToSafeString()); } else if (context.Graph.BaseUri != null) { context.HtmlWriter.WriteEncodedText(" - " + context.Graph.BaseUri.ToString()); } context.HtmlWriter.RenderEndTag(); if (!this.Stylesheet.Equals(String.Empty)) { context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Href, this.Stylesheet); context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Type, "text/css"); context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Rel, "stylesheet"); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Link); context.HtmlWriter.RenderEndTag(); } context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif //Start Body context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Body); //Title context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.H2); context.HtmlWriter.WriteEncodedText("Schema"); if (ontoNode != null && ontoLabel != null) { context.HtmlWriter.WriteEncodedText(" - " + ontoLabel.ToSafeString()); } else if (context.Graph.BaseUri != null) { context.HtmlWriter.WriteEncodedText(" - " + context.Graph.BaseUri.ToString()); } context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif //Show the Description of the Schema (if any) if (ontoNode != null) { SparqlParameterizedString getOntoDescrip = new SparqlParameterizedString(); getOntoDescrip.Namespaces = context.QNameMapper; getOntoDescrip.CommandText = "SELECT * WHERE { @onto a owl:Ontology . OPTIONAL { @onto rdfs:comment ?description } . OPTIONAL { @onto vann:preferredNamespacePrefix ?nsPrefix ; vann:preferredNamespaceUri ?nsUri } . OPTIONAL { @onto dc:creator ?creator . ?creator (foaf:name | rdfs:label) ?creatorName } }"; getOntoDescrip.SetParameter("onto", ontoNode); try { results = context.Graph.ExecuteQuery(getOntoDescrip); if (results is SparqlResultSet) { if (!((SparqlResultSet)results).IsEmpty) { SparqlResult ontoInfo = ((SparqlResultSet)results)[0]; //Show rdfs:comment on the Ontology if (ontoInfo.HasValue("description")) { INode descrip = ontoInfo["description"]; if (descrip.NodeType == NodeType.Literal) { context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.P); context.HtmlWriter.Write(((ILiteralNode)descrip).Value); context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif } } //Show Author Information if (ontoInfo.HasValue("creator")) { INode author = ontoInfo["creator"]; INode authorName = ontoInfo["creatorName"]; context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.P); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Em); context.HtmlWriter.WriteEncodedText("Schema created by "); if (author.NodeType == NodeType.Uri) { context.HtmlWriter.AddAttribute("href", ((IUriNode)author).Uri.ToString()); context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClassUri); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.A); } switch (authorName.NodeType) { case NodeType.Uri: context.HtmlWriter.WriteEncodedText(((IUriNode)authorName).Uri.ToString()); break; case NodeType.Literal: context.HtmlWriter.WriteEncodedText(((ILiteralNode)authorName).Value); break; default: context.HtmlWriter.WriteEncodedText(authorName.ToString()); break; } if (author.NodeType == NodeType.Uri) context.HtmlWriter.RenderEndTag(); context.HtmlWriter.RenderEndTag(); context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif } //Show the Namespace information for the Schema if (ontoInfo.HasValue("nsPrefix")) { if (ontoInfo["nsPrefix"].NodeType == NodeType.Literal && ontoInfo["nsUri"].NodeType == NodeType.Uri) { //Add this QName to the QName Mapper so we can get nice QNames later on String prefix = ((ILiteralNode)ontoInfo["nsPrefix"]).Value; context.QNameMapper.AddNamespace(prefix, ((IUriNode)ontoInfo["nsUri"]).Uri); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.H4); context.HtmlWriter.WriteEncodedText("Preferred Namespace Definition"); context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif //Show human readable description of preferred Namespace Settings context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.P); context.HtmlWriter.WriteEncodedText("Preferred Namespace Prefix is "); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Strong); context.HtmlWriter.WriteEncodedText(prefix); context.HtmlWriter.RenderEndTag(); context.HtmlWriter.WriteEncodedText(" and preferred Namespace URI is "); context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Href, context.QNameMapper.GetNamespaceUri(prefix).ToString()); context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClassUri); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.A); context.HtmlWriter.WriteEncodedText(context.QNameMapper.GetNamespaceUri(prefix).ToString()); context.HtmlWriter.RenderEndTag(); context.HtmlWriter.RenderEndTag(); //RDF/XML Syntax context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.H5); context.HtmlWriter.WriteEncodedText("RDF/XML Syntax"); context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif context.HtmlWriter.AddStyleAttribute(HtmlTextWriterStyle.Width, "90%"); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Pre); context.HtmlWriter.WriteEncodedText("<?xml version=\"1.0\" charset=\"utf-8\"?>"); context.HtmlWriter.WriteLine(); context.HtmlWriter.WriteEncodedText("<rdf:RDF xmlns:rdf=\"" + NamespaceMapper.RDF + "\" xmlns:" + prefix + "=\"" + context.UriFormatter.FormatUri(context.QNameMapper.GetNamespaceUri(prefix)) + "\">"); context.HtmlWriter.WriteLine(); context.HtmlWriter.WriteEncodedText(" <!-- Your RDF here... -->"); context.HtmlWriter.WriteLine(); context.HtmlWriter.WriteEncodedText("</rdf:RDF>"); context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif //Turtle/N3 Syntax context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.H5); context.HtmlWriter.WriteEncodedText("Turtle/N3 Syntax"); context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif context.HtmlWriter.AddStyleAttribute(HtmlTextWriterStyle.Width, "90%"); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Pre); context.HtmlWriter.WriteEncodedText("@prefix " + prefix + ": <" + context.UriFormatter.FormatUri(context.QNameMapper.GetNamespaceUri(prefix)) + "> ."); context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif //SPARQL Syntax context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.H5); context.HtmlWriter.WriteEncodedText("SPARQL Syntax"); context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif context.HtmlWriter.AddStyleAttribute(HtmlTextWriterStyle.Width, "90%"); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Pre); context.HtmlWriter.WriteEncodedText("PREFIX " + prefix + ": <" + context.UriFormatter.FormatUri(context.QNameMapper.GetNamespaceUri(prefix)) + ">"); context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif } } } } else { throw new RdfOutputException("Tried to make a SPARQL Query to determine Schema Information but an unexpected Query Result was returned"); } } catch (RdfQueryException queryEx) { throw new RdfOutputException("Tried to make a SPARQL Query to determine Schema Information but a Query Error occurred", queryEx); } } //Show lists of all Classes and Properties in the Schema context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.H4); context.HtmlWriter.WriteEncodedText("Class and Property Summary"); context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.P); context.HtmlWriter.WriteEncodedText("This Schema defines the following classes:"); context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif context.HtmlWriter.AddStyleAttribute("width", "90%"); context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClassBox); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.P); //Get the Classes and Display SparqlParameterizedString getClasses = new SparqlParameterizedString(); getClasses.Namespaces = context.QNameMapper; getClasses.CommandText = "SELECT DISTINCT ?class WHERE { { ?class a rdfs:Class } UNION { ?class a owl:Class } FILTER(ISURI(?class)) } ORDER BY ?class"; try { results = context.Graph.ExecuteQuery(getClasses); if (results is SparqlResultSet) { SparqlResultSet rs = (SparqlResultSet)results; for (int i = 0; i < rs.Count; i++) { SparqlResult r = rs[i]; //Get the QName and output a Link to an anchor that we'll generate later to let //users jump to a Class/Property definition String qname = context.NodeFormatter.Format(r["class"]); context.HtmlWriter.AddAttribute("href", "#" + qname); context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClassUri); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.A); context.HtmlWriter.WriteEncodedText(qname); context.HtmlWriter.RenderEndTag(); if (i < rs.Count - 1) { context.HtmlWriter.WriteEncodedText(" , "); } } } else { throw new RdfOutputException("Tried to make a SPARQL Query to find Classes in the Schema but an unexpected Query Result was returned"); } } catch (RdfQueryException queryEx) { throw new RdfOutputException("Tried to make a SPARQL Query to find Classes in the Schema but a Query Error occurred", queryEx); } context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.P); context.HtmlWriter.WriteEncodedText("This Schema defines the following properties:"); context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif context.HtmlWriter.AddStyleAttribute("width", "90%"); context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClassBox); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.P); //Get the Properties and Display SparqlParameterizedString getProperties = new SparqlParameterizedString(); getProperties.Namespaces = context.QNameMapper; getProperties.CommandText = "SELECT DISTINCT ?property WHERE { { ?property a rdf:Property } UNION { ?property a owl:DatatypeProperty } UNION { ?property a owl:ObjectProperty } FILTER(ISURI(?property)) } ORDER BY ?property"; try { results = context.Graph.ExecuteQuery(getProperties); if (results is SparqlResultSet) { SparqlResultSet rs = (SparqlResultSet)results; for (int i = 0; i < rs.Count; i++) { SparqlResult r = rs[i]; //Get the QName and output a Link to an anchor that we'll generate later to let //users jump to a Class/Property definition String qname = context.NodeFormatter.Format(r["property"]); context.HtmlWriter.AddAttribute("href", "#" + qname); context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClassUri); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.A); context.HtmlWriter.WriteEncodedText(qname); context.HtmlWriter.RenderEndTag(); if (i < rs.Count - 1) { context.HtmlWriter.WriteEncodedText(" , "); } } } else { throw new RdfOutputException("Tried to make a SPARQL Query to find Properties in the Schema but an unexpected Query Result was returned"); } } catch (RdfQueryException queryEx) { throw new RdfOutputException("Tried to make a SPARQL Query to find Properties in the Schema but a Query Error occurred", queryEx); } context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif //Show details for each class context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.H3); context.HtmlWriter.WriteEncodedText("Classes"); context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif //Now create the URI Nodes we need for the next stage of Output IUriNode rdfsDomain = context.Graph.CreateUriNode(new Uri(NamespaceMapper.RDFS + "domain")); IUriNode rdfsRange = context.Graph.CreateUriNode(new Uri(NamespaceMapper.RDFS + "range")); IUriNode rdfsSubClassOf = context.Graph.CreateUriNode(new Uri(NamespaceMapper.RDFS + "subClassOf")); IUriNode rdfsSubPropertyOf = context.Graph.CreateUriNode(new Uri(NamespaceMapper.RDFS + "subPropertyOf")); IUriNode owlDisjointClass = context.Graph.CreateUriNode(new Uri(NamespaceMapper.OWL + "disjointWith")); IUriNode owlEquivalentClass = context.Graph.CreateUriNode(new Uri(NamespaceMapper.OWL + "equivalentClass")); IUriNode owlEquivalentProperty = context.Graph.CreateUriNode(new Uri(NamespaceMapper.OWL + "equivalentProperty")); IUriNode owlInverseProperty = context.Graph.CreateUriNode(new Uri(NamespaceMapper.OWL + "inverseOf")); //Alter our previous getClasses query to get additional details getClasses.CommandText = "SELECT ?class (SAMPLE(?label) AS ?classLabel) (SAMPLE(?description) AS ?classDescription) WHERE { { ?class a rdfs:Class } UNION { ?class a owl:Class } FILTER(ISURI(?class)) OPTIONAL { ?class rdfs:label ?label } OPTIONAL { ?class rdfs:comment ?description } } GROUP BY ?class ORDER BY ?class"; try { results = context.Graph.ExecuteQuery(getClasses); if (results is SparqlResultSet) { foreach (SparqlResult r in (SparqlResultSet)results) { String qname = context.NodeFormatter.Format(r["class"]); //Use a <div> for each Class context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClassBox); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Div); //Add the Anchor to which earlier Class summary links to context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Name, qname); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.A); context.HtmlWriter.RenderEndTag(); //Show Basic Class Information context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.H4); context.HtmlWriter.WriteEncodedText("Class: " + qname); context.HtmlWriter.RenderEndTag(); //Show "Local Name - Label" context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Em); if (TurtleSpecsHelper.IsValidQName(qname)) { context.HtmlWriter.WriteEncodedText(qname); } else { Uri temp = new Uri(qname, UriKind.RelativeOrAbsolute); if (!temp.Fragment.Equals(String.Empty)) { context.HtmlWriter.WriteEncodedText(temp.Fragment); } else { #if !SILVERLIGHT context.HtmlWriter.WriteEncodedText(temp.Segments.Last()); #else context.HtmlWriter.WriteEncodedText(temp.Segments().Last()); #endif } } context.HtmlWriter.RenderEndTag(); if (r.HasValue("classLabel")) { if (r["classLabel"] != null && r["classLabel"].NodeType == NodeType.Literal) { context.HtmlWriter.WriteEncodedText(" - "); context.HtmlWriter.WriteEncodedText(((ILiteralNode)r["classLabel"]).Value); } } context.HtmlWriter.WriteLine(); context.HtmlWriter.WriteBreak(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif //Output further information about the class IEnumerable<Triple> ts; //Output any Subclasses ts = context.Graph.GetTriplesWithSubjectPredicate(rdfsSubClassOf, r["class"]); this.GenerateCaptionedInformation(context, "Has Sub Classes", ts, t => t.Object); //Output Properties which have this as domain/range ts = context.Graph.GetTriplesWithPredicateObject(rdfsDomain, r["class"]); this.GenerateCaptionedInformation(context, "Properties Include", ts, t => t.Subject); ts = context.Graph.GetTriplesWithPredicateObject(rdfsRange, r["class"]); this.GenerateCaptionedInformation(context, "Used With", ts, t => t.Subject); //Output any Equivalent Classes ts = context.Graph.GetTriplesWithSubjectPredicate(r["class"], owlEquivalentClass).Concat(context.Graph.GetTriplesWithPredicateObject(owlEquivalentClass, r["class"])); this.GenerateCaptionedInformation(context, "Equivalent Classes", ts, t => t.Subject.Equals(r["class"]) ? t.Object : t.Subject); //Output any Disjoint Classes ts = context.Graph.GetTriplesWithSubjectPredicate(r["class"], owlDisjointClass).Concat(context.Graph.GetTriplesWithPredicateObject(owlDisjointClass, r["class"])); this.GenerateCaptionedInformation(context, "Disjoint Classes", ts, t => t.Subject.Equals(r["class"]) ? t.Object : t.Subject); //Show the Class Description if (r.HasValue("classDescription")) { if (r["classDescription"] != null && r["classDescription"].NodeType == NodeType.Literal) { context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.P); context.HtmlWriter.Write(((ILiteralNode)r["classDescription"]).Value); context.HtmlWriter.RenderEndTag(); } } //End the </div> for the Class context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif } } else { throw new RdfOutputException("Tried to make a SPARQL Query to get Class Information from the Schema but an unexpected Query Result was returned"); } } catch (RdfQueryException queryEx) { throw new RdfOutputException("Tried to make a SPARQL Query to get Class Information from the Schema but a Query Error occurred", queryEx); } //Show details for each property context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.H3); context.HtmlWriter.WriteEncodedText("Properties"); context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif //Alter our previous getClasses query to get additional details getProperties.CommandText = "SELECT ?property (SAMPLE(?label) AS ?propertyLabel) (SAMPLE(?description) AS ?propertyDescription) WHERE { { ?property a rdf:Property } UNION { ?property a owl:ObjectProperty } UNION { ?property a owl:DatatypeProperty } FILTER(ISURI(?property)) OPTIONAL { ?property rdfs:label ?label } OPTIONAL { ?property rdfs:comment ?description } } GROUP BY ?property ORDER BY ?property"; try { results = context.Graph.ExecuteQuery(getProperties); if (results is SparqlResultSet) { foreach (SparqlResult r in (SparqlResultSet)results) { String qname = context.NodeFormatter.Format(r["property"]); //Use a <div> for each Property context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClassBox); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Div); //Add the Anchor to which earlier Property summary links to context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Name, qname); context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.A); context.HtmlWriter.RenderEndTag(); //Show Basic Property Information context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.H4); context.HtmlWriter.WriteEncodedText("Property: " + qname); context.HtmlWriter.RenderEndTag(); //Show "Local Name - Label" context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Em); if (TurtleSpecsHelper.IsValidQName(qname)) { context.HtmlWriter.WriteEncodedText(qname); } else { Uri temp = new Uri(qname, UriKind.RelativeOrAbsolute); if (!temp.Fragment.Equals(String.Empty)) { context.HtmlWriter.WriteEncodedText(temp.Fragment); } else { #if !SILVERLIGHT context.HtmlWriter.WriteEncodedText(temp.Segments.Last()); #else context.HtmlWriter.WriteEncodedText(temp.Segments().Last()); #endif } } context.HtmlWriter.RenderEndTag(); if (r.HasValue("propertyLabel")) { if (r["propertyLabel"] != null && r["propertyLabel"].NodeType == NodeType.Literal) { context.HtmlWriter.WriteEncodedText(" - "); context.HtmlWriter.WriteEncodedText(((ILiteralNode)r["propertyLabel"]).Value); } } context.HtmlWriter.WriteLine(); context.HtmlWriter.WriteBreak(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif //Output further information about the property IEnumerable<Triple> ts; //Output any Subproperties ts = context.Graph.GetTriplesWithSubjectPredicate(rdfsSubPropertyOf, r["property"]); this.GenerateCaptionedInformation(context, "Has Sub Properties", ts, t => t.Object); //Output Domain and Range ts = context.Graph.GetTriplesWithSubjectPredicate(r["property"], rdfsDomain); this.GenerateCaptionedInformation(context, "Has Domain", ts, t => t.Object); ts = context.Graph.GetTriplesWithSubjectPredicate(r["property"], rdfsRange); this.GenerateCaptionedInformation(context, "Has Range", ts, t => t.Object); //Output any Equivalent Properties ts = context.Graph.GetTriplesWithSubjectPredicate(r["property"], owlEquivalentProperty).Concat(context.Graph.GetTriplesWithPredicateObject(owlEquivalentProperty, r["property"])); this.GenerateCaptionedInformation(context, "Equivalent Properties", ts, t => t.Subject.Equals(r["property"]) ? t.Object : t.Subject); //Output any Disjoint Classes ts = context.Graph.GetTriplesWithSubjectPredicate(r["property"], owlInverseProperty).Concat(context.Graph.GetTriplesWithPredicateObject(owlInverseProperty, r["property"])); this.GenerateCaptionedInformation(context, "Inverse Property", ts, t => t.Subject.Equals(r["property"]) ? t.Object : t.Subject); //Show the Property Description if (r.HasValue("propertyDescription")) { if (r["propertyDescription"] != null && r["propertyDescription"].NodeType == NodeType.Literal) { context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.P); context.HtmlWriter.Write(((ILiteralNode)r["propertyDescription"]).Value); context.HtmlWriter.RenderEndTag(); } } //End the </div> for the Property context.HtmlWriter.RenderEndTag(); #if !NO_WEB context.HtmlWriter.WriteLine(); #endif } } else { throw new RdfOutputException("Tried to make a SPARQL Query to get Property Information from the Schema but an unexpected Query Result was returned"); } } catch (RdfQueryException queryEx) { throw new RdfOutputException("Tried to make a SPARQL Query to get Property Information from the Schema but a Query Error occurred", queryEx); } //End of Page context.HtmlWriter.RenderEndTag(); //End Body context.HtmlWriter.RenderEndTag(); //End Html }
protected override bool HasTripleInternal(Triple t) { if (this._manager is IQueryableGenericIOManager) { SparqlParameterizedString queryString = new SparqlParameterizedString("ASK WHERE { @subject @predicate @object}"); queryString.SetParameter("subject", t.Subject); queryString.SetParameter("predicate", t.Predicate); queryString.SetParameter("object", t.Object); Object results = ((IQueryableGenericIOManager)this._manager).Query(queryString.ToString()); if (results is SparqlResultSet) { SparqlResultSet rset = (SparqlResultSet)results; return rset.ResultsType == SparqlResultsType.Boolean && rset.Result; } else { return false; } } else { throw new dotSesameRepo.RepositoryException("This dotNetRDF Generic Repository does not support detecting whether a given Statement exists in the Store"); } }
private IEnumerable<SparqlUpdateCommand> GetInsertCommands(Uri entityGraphUri, EntityId entityId, string entityPatterns, IDictionary<string, INode> variables, bool withDelete = true) { SparqlParameterizedString modify = new SparqlParameterizedString( (withDelete ? DeleteEntityGraphCommandText : System.String.Empty) + (entityId is BlankId ? InsertBlankNodeCommandText : InsertEntityCommandText).Replace("@subject @predicate @object . ", entityPatterns)); modify.SetUri("metaGraph", _metaGraphUri); modify.SetUri("graph", entityGraphUri); if (!(entityId is BlankId)) { modify.SetUri("entityId", entityId.Uri); } foreach (var variable in variables) { modify.SetParameter(variable.Key, variable.Value); } foreach (var command in _parser.ParseFromString(modify).Commands) { yield return command; } }
public void RunTest(String[] args) { if (args.Length < 2) { Console.Error.WriteLine("rdfWebDeploy: Error: 2 Arguments are required in order to use the -test mode"); return; } if (!File.Exists(args[1])) { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot test " + args[1] + " since the file does not exist"); return; } Graph g = new Graph(); try { FileLoader.Load(g, args[1]); } catch (Exception ex) { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot parse the configuration file"); Console.Error.WriteLine("rdfWebDeploy: Error: " + ex.Message); return; } Console.WriteLine("rdfWebDeploy: Opened the configuration file successfully"); Graph vocab = new Graph(); try { TurtleParser ttlparser = new TurtleParser(); ttlparser.Load(vocab, new StreamReader(Assembly.GetAssembly(typeof(IGraph)).GetManifestResourceStream("VDS.RDF.Configuration.configuration.ttl"))); } catch (Exception ex) { Console.Error.WriteLine("rdfWebDeploy: Error: Cannot parse the configuration vocabulary"); Console.Error.WriteLine("rdfWebDeploy: Error: " + ex.Message); return; } Console.WriteLine("rdfWebDeploy: Loaded the configuration vocabulary successfully"); Console.WriteLine(); Console.WriteLine("rdfWebDeploy: Tests Started..."); Console.WriteLine(); //Now make some tests against it int warnings = 0, errors = 0; IInMemoryQueryableStore store = new TripleStore(); store.Add(vocab); if (g.BaseUri == null) g.BaseUri = new Uri("dotnetrdf:config"); store.Add(g); Object results; SparqlResultSet rset; //Unknown vocabulary term test Console.WriteLine("rdfWebDeploy: Testing for URIs in the vocabulary namespace which are unknown"); results = store.ExecuteQuery(RdfWebDeployHelper.NamespacePrefixes + UnknownVocabularyTermsTest); if (results is SparqlResultSet) { rset = (SparqlResultSet)results; foreach (SparqlResult r in rset) { Console.Error.WriteLine("rdfWebDeploy: Error: The configuration file uses the URI '" + r["term"] + "' for a property/type and this does not appear to be a valid term in the Configuration vocabulary"); errors++; } } Console.WriteLine(); #region General dnr:type Tests //Missing dnr:type test Console.WriteLine("rdfWebDeploy: Testing for missing dnr:type properties"); results = g.ExecuteQuery(RdfWebDeployHelper.NamespacePrefixes + MissingConfigurationTypeTest); if (results is SparqlResultSet) { rset = (SparqlResultSet)results; foreach (SparqlResult r in rset) { Console.Error.WriteLine("rdfWebDeploy: Warning: The Node '" + r["s"].ToString() + "' has an rdf:type but no dnr:type which may be needed by the Configuration Loader"); warnings++; } } Console.WriteLine(); //Invalid dnr:type test Console.WriteLine("rdfWebDeploy: Testing that values given for dnr:type property are literals"); results = g.ExecuteQuery(RdfWebDeployHelper.NamespacePrefixes + InvalidTypePropertyTest); if (results is SparqlResultSet) { rset = (SparqlResultSet)results; foreach (SparqlResult r in rset) { Console.Error.WriteLine("rdfWebDeploy: Error: The node '" + r["s"].ToString() + "' has a dnr:type of '" + r["type"].ToString() + "' which is not given as a string literal"); errors++; } } Console.WriteLine(); //Multiple dnr:type test Console.WriteLine("rdfWebDeploy: Testing that no object has multiple dnr:type values"); results = g.ExecuteQuery(RdfWebDeployHelper.NamespacePrefixes + MultipleTypeTest); if (results is SparqlResultSet) { rset = (SparqlResultSet)results; foreach (SparqlResult r in rset) { Console.Error.WriteLine("rdfWebDeploy: Error: The node '" + r["s"].ToString() + "' has multiple dnr:type values which is not valid"); errors++; } } Console.WriteLine(); //Unknown Library Types test Console.WriteLine("rdfWebDeploy: Testing that values given for dnr:type property in the VDS.RDF namespace are valid"); results = g.ExecuteQuery(RdfWebDeployHelper.NamespacePrefixes + LibraryTypesTest); if (results is SparqlResultSet) { rset = (SparqlResultSet)results; Assembly dotnetrdf = Assembly.GetAssembly(typeof(IGraph)); foreach (SparqlResult r in rset) { Type t = dotnetrdf.GetType(((ILiteralNode)r["type"]).Value); if (t == null) { Console.Error.WriteLine("rdfWebDeploy: Error: The node '" + r["s"].ToString() + "' has a dnr:type of '" + r["type"].ToString() + "' which does not appear to be a valid type in dotNetRDF"); errors++; } } } Console.WriteLine(); #endregion #region dnr:HttpHandler Tests including specific dnr:type Tests //Bad Handler URI test Console.WriteLine("rdfWebDeploy: Testing for bad URIs given the rdf:type of dnr:HttpHandler"); results = g.ExecuteQuery(RdfWebDeployHelper.NamespacePrefixes + BadHandlerUriTest); if (results is SparqlResultSet) { rset = (SparqlResultSet)results; foreach (SparqlResult r in rset) { Console.Error.WriteLine("rdfWebDeploy: Error: The Handler node '" + r["s"].ToString() + "' is not a URI of the form <dotnetrdf:/path> which is required for correct detection of handler configuration"); errors++; } } Console.WriteLine(); //Missing Handler type test Console.WriteLine("rdfWebDeploy: Testing for missing dnr:type for dnr:HttpHandler objects"); results = g.ExecuteQuery(RdfWebDeployHelper.NamespacePrefixes + MissingHandlerTypeTest); if (results is SparqlResultSet) { rset = (SparqlResultSet)results; foreach (SparqlResult r in rset) { Console.Error.WriteLine("rdfWebDeploy: Error: The Handler node '" + r["s"].ToString() + "' has an rdf:type but no dnr:type which is requiring for automated deployment via this tool"); errors++; } } Console.WriteLine(); //Invalid Handler Type test Console.WriteLine("rdfWebDeploy: Testing that values given for dnr:type for dnr:HttpHandler objects in the VDS.RDF namespace are valid IHttpHandlers"); results = g.ExecuteQuery(RdfWebDeployHelper.NamespacePrefixes + InvalidHandlerTypeTest); if (results is SparqlResultSet) { rset = (SparqlResultSet)results; Assembly dotnetrdf = Assembly.GetAssembly(typeof(IGraph)); foreach (SparqlResult r in rset) { Type t = dotnetrdf.GetType(((ILiteralNode)r["type"]).Value); if (t != null) { if (!t.GetInterfaces().Any(i => i.Equals(typeof(System.Web.IHttpHandler)))) { Console.Error.WriteLine("rdfWebDeploy: Error: The node '" + r["s"].ToString() + "' has a dnr:type of '" + r["type"].ToString() + "' which does not appear to be a valid IHttpHandler implementation in dotNetRDF"); errors++; } } } } Console.WriteLine(); #endregion #region Property Tests //Range test Console.WriteLine("rdfWebDeploy: Testing for bad ranges for properties"); results = store.ExecuteQuery(RdfWebDeployHelper.NamespacePrefixes + InvalidRangeTest); if (results is SparqlResultSet) { rset = (SparqlResultSet)results; foreach (SparqlResult r in rset) { SparqlParameterizedString hasValidRange = new SparqlParameterizedString(); hasValidRange.QueryText = RdfWebDeployHelper.NamespacePrefixes + ValidRangeTest; hasValidRange.SetParameter("property", r["property"]); hasValidRange.SetParameter("s", r["s"]); Object temp = store.ExecuteQuery(hasValidRange.ToString()); if (temp is SparqlResultSet) { if (!((SparqlResultSet)temp).Result) { Console.Error.WriteLine("rdfWebDeploy: Error: The Node '" + r["s"].ToString() + "' has a value for the property '" + r["property"].ToString() + "' which is '" + r["obj"].ToString() + "' which does not appear to be valid for the range of this property which is '" + r["range"].ToString() + "'"); errors++; } } } } Console.WriteLine(); //Domain test Console.WriteLine("rdfWebDeploy: Testing for bad domains for properties"); results = store.ExecuteQuery(RdfWebDeployHelper.NamespacePrefixes + InvalidDomainTest); if (results is SparqlResultSet) { rset = (SparqlResultSet)results; foreach (SparqlResult r in rset) { SparqlParameterizedString hasValidDomain = new SparqlParameterizedString(); hasValidDomain.QueryText = RdfWebDeployHelper.NamespacePrefixes + ValidDomainTest; hasValidDomain.SetParameter("property", r["property"]); hasValidDomain.SetParameter("s", r["s"]); Object temp = store.ExecuteQuery(hasValidDomain.ToString()); if (temp is SparqlResultSet) { if (!((SparqlResultSet)temp).Result) { Console.Error.WriteLine("rdfWebDeploy: Error: The Node '" + r["s"].ToString() + "' has a value for the property '" + r["property"].ToString() + "' and the type given is '" + r["type"].ToString() + "' which does not match the domain of this property which is '" + r["domain"].ToString() + "'"); errors++; } } } } Console.WriteLine(); #endregion #region Clear Text Password Tests Console.WriteLine("rdfWebDeploy: Testing for clear text passwords used with dnr:password property"); results = store.ExecuteQuery(RdfWebDeployHelper.NamespacePrefixes + ClearTextPasswordTest); if (results is SparqlResultSet) { foreach (SparqlResult r in (SparqlResultSet)results) { Console.Error.WriteLine("rdfWebDeploy: Warning: The Node '" + r["s"].ToString() + "' has a value for the dnr:password property specified as a Literal in clear text. It is recommended that you specify any passwords as AppSetting URIs e.g. <appsetting:MyPassword> and then create an AppSetting in the <appSettings> section of your Web.config file to store your password. The Web.config file can then have the <appSettings> section encrypted to help protect your password"); warnings++; } } Console.WriteLine(); #endregion //Show Test Results Console.WriteLine("rdfWedDeploy: Tests Completed - " + warnings + " Warning(s) - " + errors + " Error(s)"); }
public static IEnumerable<NamespaceTerm> LoadNamespaceTerms(String namespaceUri) { //Don't load if already loaded if (_loadedNamespaces.Contains(namespaceUri)) return GetNamespaceTerms(namespaceUri); try { Graph g = new Graph(); try { UriLoader.Load(g, new Uri(namespaceUri)); } catch { //Try and load from our local copy if there is one String prefix = GetDefaultPrefix(namespaceUri); if (!prefix.Equals(String.Empty)) { Stream localCopy = Assembly.GetExecutingAssembly().GetManifestResourceStream("rdfEditor.AutoComplete.Vocabularies." + prefix + ".ttl"); if (localCopy != null) { TurtleParser ttlparser = new TurtleParser(); ttlparser.Load(g, new StreamReader(localCopy)); } } } List<NamespaceTerm> terms = new List<NamespaceTerm>(); String termUri; //UriNode rdfType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)); IUriNode rdfsClass = g.CreateUriNode(new Uri(NamespaceMapper.RDFS + "Class")); IUriNode rdfsLabel = g.CreateUriNode(new Uri(NamespaceMapper.RDFS + "label")); IUriNode rdfsComment = g.CreateUriNode(new Uri(NamespaceMapper.RDFS + "comment")); IUriNode rdfProperty = g.CreateUriNode(new Uri(NamespaceMapper.RDF + "Property")); IUriNode rdfsDatatype = g.CreateUriNode(new Uri(NamespaceMapper.RDFS + "Datatype")); SparqlParameterizedString queryString = new SparqlParameterizedString(); queryString.CommandText = "SELECT ?term STR(?label) AS ?RawLabel STR(?comment) AS ?RawComment WHERE { {{?term a @class} UNION {?term a @property} UNION {?term a @datatype}} OPTIONAL {?term @label ?label} OPTIONAL {?term @comment ?comment} }"; queryString.SetParameter("class", rdfsClass); queryString.SetParameter("property", rdfProperty); queryString.SetParameter("datatype", rdfsDatatype); queryString.SetParameter("label", rdfsLabel); queryString.SetParameter("comment", rdfsComment); Object results = g.ExecuteQuery(queryString.ToString()); if (results is SparqlResultSet) { foreach (SparqlResult r in ((SparqlResultSet)results)) { termUri = r["term"].ToString(); if (termUri.StartsWith(namespaceUri)) { //Use the Comment as the label if available if (r.HasValue("RawComment")) { if (r["RawComment"] != null) { terms.Add(new NamespaceTerm(namespaceUri, termUri.Substring(namespaceUri.Length), r["RawComment"].ToString())); continue; } } //Use the Label as the label if available if (r.HasValue("RawLabel")) { if (r["RawLabel"] != null) { terms.Add(new NamespaceTerm(namespaceUri, termUri.Substring(namespaceUri.Length), r["RawLabel"].ToString())); continue; } } //Otherwise no label terms.Add(new NamespaceTerm(namespaceUri, termUri.Substring(namespaceUri.Length))); } } } lock (_terms) { terms.RemoveAll(t => _terms.Contains(t)); _terms.AddRange(terms.Distinct()); } } catch { //Ignore Exceptions - just means we won't have those namespace terms available } try { _loadedNamespaces.Add(namespaceUri); } catch (NullReferenceException) { //For some reason .Net sometimes throws a NullReferenceException here which we shall ignore } return GetNamespaceTerms(namespaceUri); }