Class Extensions
Provides useful Extension Methods for use elsewhere in the Library.
Inheritance
Inherited Members
Namespace: VDS.RDF
Assembly: dotNetRdf.dll
Syntax
public static class Extensions
Methods
| Improve this Doc View SourceAddToList(IGraph, INode, IEnumerable<INode>)
Adds new items to the end of a list (aka a RDF collection).
Declaration
public static void AddToList(this IGraph g, INode listRoot, IEnumerable<INode> objects)
Parameters
Type | Name | Description |
---|---|---|
IGraph | g | Graph to assert in. |
INode | listRoot | Root Node for the list. |
System.Collections.Generic.IEnumerable<T><INode> | objects | Objects to add to the collection. |
AddToList<T>(IGraph, INode, IEnumerable<T>, Func<T, INode>)
Adds new items to the end of a list (aka a RDF collection).
Declaration
public static void AddToList<T>(this IGraph g, INode listRoot, IEnumerable<T> objects, Func<T, INode> mapFunc)
Parameters
Type | Name | Description |
---|---|---|
IGraph | g | Graph to assert in. |
INode | listRoot | Root Node for the list. |
System.Collections.Generic.IEnumerable<T><T> | objects | Objects to add to the collection. |
System.Func<T, TResult><T, INode> | mapFunc | Mapping from Object Type to INode. |
Type Parameters
Name | Description |
---|---|
T | Type of Objects. |
AppendIndented(StringBuilder, string, int)
Appends a String to the StringBuilder with an indent of indent
spaces.
Declaration
public static void AppendIndented(this StringBuilder builder, string line, int indent)
Parameters
Type | Name | Description |
---|---|---|
System.Text.StringBuilder | builder | String Builder. |
string | line | String to append. |
int | indent | Indent. |
AppendLineIndented(StringBuilder, string, int)
Appends a String to the StringBuilder with an indent of indent
spaces.
Declaration
public static void AppendLineIndented(this StringBuilder builder, string line, int indent)
Parameters
Type | Name | Description |
---|---|---|
System.Text.StringBuilder | builder | String Builder. |
string | line | String to append. |
int | indent | Indent. |
Remarks
Strings containing new lines are split over multiple lines.
AsEnumerable<T>(T)
Takes a single item and generates an IEnumerable containing only it.
Declaration
public static IEnumerable<T> AsEnumerable<T>(this T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to wrap in an IEnumerable. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><T> |
Type Parameters
Name | Description |
---|---|
T | Type of the enumerable. |
Remarks
This method taken from Stack Overflow - see. here
Assert(IGraph, INode, INode, INode)
Asserts a new Triple in the Graph.
Declaration
public static void Assert(this IGraph g, INode subj, INode pred, INode obj)
Parameters
Type | Name | Description |
---|---|---|
IGraph | g | Graph to assert in. |
INode | subj | Subject. |
INode | pred | Predicate. |
INode | obj | Object. |
Remarks
Handy method which means you can assert a Triple by specifying the Subject, Predicate and Object without having to explicity declare a new Triple.
AssertList(IGraph, IEnumerable<INode>)
Asserts a list as a RDF collection and returns the node that represents the root of the RDF collection.
Declaration
public static INode AssertList(this IGraph g, IEnumerable<INode> objects)
Parameters
Type | Name | Description |
---|---|---|
IGraph | g | Graph to assert in. |
System.Collections.Generic.IEnumerable<T><INode> | objects | Objects to place in the collection. |
Returns
Type | Description |
---|---|
INode | Either the blank node which is the root of the collection or rdf:nil for empty collections. |
AssertList(IGraph, INode, IEnumerable<INode>)
Asserts a list as a RDF collection using an existing node as the list root.
Declaration
public static void AssertList(this IGraph g, INode listRoot, IEnumerable<INode> objects)
Parameters
Type | Name | Description |
---|---|---|
IGraph | g | Graph to assert in. |
INode | listRoot | Root Node for List. |
System.Collections.Generic.IEnumerable<T><INode> | objects | Objects to place in the collection. |
AssertList<T>(IGraph, IEnumerable<T>, Func<T, INode>)
Asserts a list as a RDF collection and returns the node that represents the root of the RDF collection.
Declaration
public static INode AssertList<T>(this IGraph g, IEnumerable<T> objects, Func<T, INode> mapFunc)
Parameters
Type | Name | Description |
---|---|---|
IGraph | g | Graph to assert in. |
System.Collections.Generic.IEnumerable<T><T> | objects | Objects to place in the collection. |
System.Func<T, TResult><T, INode> | mapFunc | Mapping from Object Type to INode. |
Returns
Type | Description |
---|---|
INode | Either the blank node which is the root of the collection or rdf:nil for empty collections. |
Type Parameters
Name | Description |
---|---|
T | Type of Objects. |
AssertList<T>(IGraph, INode, IEnumerable<T>, Func<T, INode>)
Asserts a list as a RDF collection using an existing node as the list root.
Declaration
public static void AssertList<T>(this IGraph g, INode listRoot, IEnumerable<T> objects, Func<T, INode> mapFunc)
Parameters
Type | Name | Description |
---|---|---|
IGraph | g | Graph to assert in. |
INode | listRoot | Root Node for List. |
System.Collections.Generic.IEnumerable<T><T> | objects | Objects to place in the collection. |
System.Func<T, TResult><T, INode> | mapFunc | Mapping from Object Type to INode. |
Type Parameters
Name | Description |
---|---|
T | Type of Objects. |
BlankNodes(IEnumerable<INode>)
Gets the Blank Nodes.
Declaration
public static IEnumerable<IBlankNode> BlankNodes(this IEnumerable<INode> ns)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T><INode> | ns | Nodes. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><IBlankNode> |
ChunkBy<T>(IEnumerable<T>, int)
Splits a sequence into bounded chunks.
Declaration
public static IEnumerable<T[]> ChunkBy<T>(this IEnumerable<T> source, int size)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T><T> | source | An Enumerable. |
int | size | Max Chunk Size. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><T[]> |
Type Parameters
Name | Description |
---|---|
T | Type Parameter. |
EffectiveBooleanValue(INode)
Calculates the Effective Boolean Value of a given Node according to the Sparql specification.
Declaration
public static bool EffectiveBooleanValue(this INode n)
Parameters
Type | Name | Description |
---|---|---|
INode | n | Node to computer EBV for. |
Returns
Type | Description |
---|---|
System.Boolean |
GetEnhancedHashCode(Uri)
Gets an Enhanced Hash Code for a Uri.
Declaration
public static int GetEnhancedHashCode(this Uri u)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | u | Uri to get Hash Code for. |
Returns
Type | Description |
---|---|
int |
Remarks
The .Net System.Uri class Hash Code ignores the Fragment ID when computing the Hash Code which means that URIs with the same basic URI but different Fragment IDs have identical Hash Codes. This is perfectly acceptable and sensible behaviour for normal URI usage since Fragment IDs are only relevant to the Client and not the Server. But in the case of URIs in RDF the Fragment ID is significant and so we need in some circumstances to compute a Hash Code which includes this information.
GetListAsTriples(IGraph, INode)
Gets all the Triples that make up a list (aka a RDF collection).
Declaration
public static IEnumerable<Triple> GetListAsTriples(this IGraph g, INode listRoot)
Parameters
Type | Name | Description |
---|---|---|
IGraph | g | Graph. |
INode | listRoot | Root Node for List. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><Triple> | Triples that make up the List. |
GetListItems(IGraph, INode)
Gets all the Nodes which are the items of the list (aka the RDF collection).
Declaration
public static IEnumerable<INode> GetListItems(this IGraph g, INode listRoot)
Parameters
Type | Name | Description |
---|---|---|
IGraph | g | Graph. |
INode | listRoot | Root Node for List. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><INode> | Nodes that are the items in the list. |
GetListNodes(IGraph, INode)
Gets all the Nodes which are the intermediate nodes in the list (aka the RDF collection). These represents the nodes used to link the actual items of the list together rather than the actual items of the list.
Declaration
public static IEnumerable<INode> GetListNodes(this IGraph g, INode listRoot)
Parameters
Type | Name | Description |
---|---|---|
IGraph | g | Graph. |
INode | listRoot | Root Node for List. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><INode> | Nodes that are the intermediate nodes of the list. |
GetSha256Hash(string)
Gets a SHA256 Hash for a String.
Declaration
public static string GetSha256Hash(this string s)
Parameters
Type | Name | Description |
---|---|---|
string | s | String to hash. |
Returns
Type | Description |
---|---|
string |
GetSha256Hash(Uri)
Gets an SHA256 Hash for a URI.
Declaration
public static string GetSha256Hash(this Uri u)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | u | URI to get Hash Code for. |
Returns
Type | Description |
---|---|
string |
GraphLiteralNodes(IEnumerable<INode>)
Gets the Graph Literal Nodes.
Declaration
public static IEnumerable<IGraphLiteralNode> GraphLiteralNodes(this IEnumerable<INode> ns)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T><INode> | ns | Nodes. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><IGraphLiteralNode> |
IsAscii(string)
Determines whether a string is ASCII.
Declaration
public static bool IsAscii(this string value)
Parameters
Type | Name | Description |
---|---|---|
string | value |
Returns
Type | Description |
---|---|
System.Boolean |
IsDisjoint<T>(IEnumerable<T>, IEnumerable<T>)
Determines whether the contents of two enumerables are disjoint.
Declaration
public static bool IsDisjoint<T>(this IEnumerable<T> x, IEnumerable<T> y)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T><T> | x | An Enumerable. |
System.Collections.Generic.IEnumerable<T><T> | y | Another Enumerable. |
Returns
Type | Description |
---|---|
System.Boolean |
Type Parameters
Name | Description |
---|---|
T | Type Parameter. |
IsListRoot(INode, IGraph)
Gets whether a given Node is valid as a List Root, this does not guarantee that the list itself is valid simply that the Node appears to be the root of a list.
Declaration
public static bool IsListRoot(this INode n, IGraph g)
Parameters
Type | Name | Description |
---|---|---|
INode | n | Node to check. |
IGraph | g | Graph. |
Returns
Type | Description |
---|---|
System.Boolean |
Remarks
We consider a node to be a list root if there are no incoming rdf:rest triples and only a single outgoing rdf:first triple.
LiteralNodes(IEnumerable<INode>)
Gets the Literal Nodes.
Declaration
public static IEnumerable<ILiteralNode> LiteralNodes(this IEnumerable<INode> ns)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T><INode> | ns | Nodes. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><ILiteralNode> |
MapTriple(Triple, IGraph, Dictionary<INode, INode>)
Copies a Triple from one Graph mapping Nodes as appropriate.
Declaration
public static Triple MapTriple(this Triple t, IGraph target, Dictionary<INode, INode> mapping)
Parameters
Type | Name | Description |
---|---|---|
Triple | t | Triple to copy. |
IGraph | target | TargetGraph. |
System.Collections.Generic.Dictionary<TKey, TValue><INode, INode> | mapping | Mapping of Nodes. |
Returns
Type | Description |
---|---|
Triple |
RemoveFromList(IGraph, INode, IEnumerable<INode>)
Removes the given items from a list (aka a RDF collection), if an item occurs multiple times in the list all occurrences will be removed.
Declaration
public static void RemoveFromList(this IGraph g, INode listRoot, IEnumerable<INode> objects)
Parameters
Type | Name | Description |
---|---|---|
IGraph | g | Graph to retract from. |
INode | listRoot | Root Node for the list. |
System.Collections.Generic.IEnumerable<T><INode> | objects | Objects to remove from the collection. |
RemoveFromList<T>(IGraph, INode, IEnumerable<T>, Func<T, INode>)
Removes the given items from a list (aka a RDF collection), if an item occurs multiple times in the list all occurrences will be removed.
Declaration
public static void RemoveFromList<T>(this IGraph g, INode listRoot, IEnumerable<T> objects, Func<T, INode> mapFunc)
Parameters
Type | Name | Description |
---|---|---|
IGraph | g | Graph to retract from. |
INode | listRoot | Root Node for the list. |
System.Collections.Generic.IEnumerable<T><T> | objects | Objects to remove from the collection. |
System.Func<T, TResult><T, INode> | mapFunc | Mapping from Object Type to INode. |
Type Parameters
Name | Description |
---|---|
T | Type of Objects. |
Retract(IGraph, INode, INode, INode)
Retracts a Triple from the Graph.
Declaration
public static void Retract(this IGraph g, INode subj, INode pred, INode obj)
Parameters
Type | Name | Description |
---|---|---|
IGraph | g | Graph to retract from. |
INode | subj | Subject. |
INode | pred | Predicate. |
INode | obj | Object. |
Remarks
Handy method which means you can retract a Triple by specifying the Subject, Predicate and Object without having to explicity declare a new Triple.
RetractList(IGraph, INode)
Retracts a List (aka a RDF collection).
Declaration
public static void RetractList(this IGraph g, INode listRoot)
Parameters
Type | Name | Description |
---|---|---|
IGraph | g | Graph. |
INode | listRoot | Root Node for List. |
ToSafeString(object)
Gets either the String representation of the Object or the Empty String if the object is null.
Declaration
public static string ToSafeString(this object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | Object. |
Returns
Type | Description |
---|---|
string |
ToSafeString(Uri)
Gets either the String representation of the URI or the Empty String if the URI is null.
Declaration
public static string ToSafeString(this Uri u)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | u | URI. |
Returns
Type | Description |
---|---|
string |
ToSafeUri(string, IUriFactory)
Turns a string into a safe URI.
Declaration
public static Uri ToSafeUri(this string str, IUriFactory uriFactory = null)
Parameters
Type | Name | Description |
---|---|---|
string | str | String. |
IUriFactory | uriFactory | Factor to use when creating the URI. If not specified, the Root instance will be used. |
Returns
Type | Description |
---|---|
System.Uri | Either null if the string is null/empty or a URI otherwise. |
ToString(Uri, IUriFormatter)
Gets the String representation of the URI formatted using the given Formatter.
Declaration
public static string ToString(this Uri u, IUriFormatter formatter)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | u | URI. |
IUriFormatter | formatter | URI Formatter. |
Returns
Type | Description |
---|---|
string |
UriNodes(IEnumerable<INode>)
Gets the URI Nodes.
Declaration
public static IEnumerable<IUriNode> UriNodes(this IEnumerable<INode> ns)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T><INode> | ns | Nodes. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><IUriNode> |
VariableNodes(IEnumerable<INode>)
Gets the Variable Nodes.
Declaration
public static IEnumerable<IVariableNode> VariableNodes(this IEnumerable<INode> ns)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T><INode> | ns | Nodes. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><IVariableNode> |
WithObject(IEnumerable<Triple>, INode)
Gets the Subset of Triples from an existing Enumerable that have a given Object.
Declaration
public static IEnumerable<Triple> WithObject(this IEnumerable<Triple> ts, INode obj)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T><Triple> | ts | Enumerable of Triples. |
INode | obj | Object to match. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><Triple> |
WithPredicate(IEnumerable<Triple>, INode)
Gets the Subset of Triples from an existing Enumerable that have a given Predicate.
Declaration
public static IEnumerable<Triple> WithPredicate(this IEnumerable<Triple> ts, INode predicate)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T><Triple> | ts | Enumerable of Triples. |
INode | predicate | Predicate to match. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><Triple> |
WithSubject(IEnumerable<Triple>, INode)
Gets the Subset of Triples from an existing Enumerable that have a given Subject.
Declaration
public static IEnumerable<Triple> WithSubject(this IEnumerable<Triple> ts, INode subject)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T><Triple> | ts | Enumerable of Triples. |
INode | subject | Subject to match. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><Triple> |