Utility Methods
The library provides a number of useful Utility Methods embodied in a single static VDS.VDS.RDF
you'll be able to use the static methods described in this article.
CopyNode
The Copy
using System;
using VDS.RDF;
using VDS.RDF.Query;
public class CopyNodeExample
{
public static void Main(String[] args)
{
//First we load in the Graph we want to get information from
Graph g = new Graph();
UriLoader.Load(g, new Uri("http://example.org/animals"));
//We're going to look for things that are carnivores from this Graph and make another Graph
//which just lists the carnivores but we're going to class them simply as animals
//Need the Nodes for the lookup
IUriNode rdfType = g.CreateUriNode("rdf:type");
IUriNode carnivore = g.CreateUriNode("ex:Carnivore");
//Get the animals which are carnivores
HasPropertyValueSelector sel = new HasPropertyValueSelector(rdfType, carnivore);
IEnumerable<Triple> carnivores = g.GetTriples(sel);
//Now create our new Graph for listing them
Graph ourlist = new Graph();
ourlist.NamespaceMap.AddNamespace("ex",new Uri("http://example.org/"));
//Create the Nodes for our new Graph
IUriNode rdfType2 = ourlist.CreateUriNode("rdf:type");
IUriNode animal = ourlist.CreateUriNode("ex:Animal");
//Now copy the data across
foreach (Triple t in carnivores)
{
//Have to copy the Subject since that's a node in the source Graph
ourlist.Assert(new Triple(Tools.CopyNode(t.Subject, ourlist), rdfType2, animal));
}
}
}
The Copy
CopyTriple
The CopyCopyNode()
except it copies entire triples from one graph to another. Usage is functionally equivalent to the example for Copy
Note: Both of these methods have Extension Methods defined which invoke them, in the above example the call to Tools.CopyNode()
could be replaced with the following and still have the same meaning:
t.Subject.CopyNode(ourlist);
HttpDebugRequest
The Http
HttpDebugResponse
The Http
IsValidBaseUri
The Is
Note that this method is only used when it is necessary to resolve a relative URI against a Base URI. It is perfectly acceptable to have a Base URI against which you cannot resolve relative URIs providing no relative URIs are used.
ResolveQName
The Resolve
ResolveUri
The Resolve
ResolveUriOrQName
The Resolve