Class Extensions
Provides useful Extension Methods for use elsewhere in the Library.
Inherited Members
Namespace: VDS.RDF
Assembly: dotNetRdf.dll
Syntax
public static class Extensions
Methods
| Edit this page 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. |
| IEnumerable<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. |
| IEnumerable<T> | objects | Objects to add to the collection. |
| Func<T, INode> | mapFunc | Mapping from Object Type to INode. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of Objects. |
AppendBlockIndented(StringBuilder, string, string, bool)
Append all of the lines in block to this StringBuilder with the specified indent
as space characters.
Declaration
public static void AppendBlockIndented(this StringBuilder builder, string block, string indent, bool indentFirst = false)
Parameters
| Type | Name | Description |
|---|---|---|
| StringBuilder | builder | The StringBuilder to append the block to. |
| string | block | The block to be appended. |
| string | indent | The string to prepend to each indented line. |
| bool | indentFirst | Whether to indent the first line of the block or not. |
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 |
|---|---|---|
| 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 |
|---|---|---|
| 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 |
|---|---|
| IEnumerable<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. |
| IEnumerable<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. |
| IEnumerable<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. |
| IEnumerable<T> | objects | Objects to place in the collection. |
| Func<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. |
| IEnumerable<T> | objects | Objects to place in the collection. |
| Func<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 |
|---|---|---|
| IEnumerable<INode> | ns | Nodes. |
Returns
| Type | Description |
|---|---|
| IEnumerable<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 |
|---|---|---|
| IEnumerable<T> | source | An Enumerable. |
| int | size | Max Chunk Size. |
Returns
| Type | Description |
|---|---|
| IEnumerable<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 |
|---|---|
| bool |
GetEnhancedHashCode(Uri)
Gets an Enhanced Hash Code for a Uri.
Declaration
public static int GetEnhancedHashCode(this Uri u)
Parameters
| Type | Name | Description |
|---|---|---|
| Uri | u | Uri to get Hash Code for. |
Returns
| Type | Description |
|---|---|
| int |
Remarks
The .Net 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 |
|---|---|
| IEnumerable<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 |
|---|---|
| IEnumerable<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 |
|---|---|
| IEnumerable<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 |
|---|---|---|
| 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 |
|---|---|---|
| IEnumerable<INode> | ns | Nodes. |
Returns
| Type | Description |
|---|---|
| IEnumerable<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 |
|---|---|
| bool |
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 |
|---|---|---|
| IEnumerable<T> | x | An Enumerable. |
| IEnumerable<T> | y | Another Enumerable. |
Returns
| Type | Description |
|---|---|
| bool |
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 |
|---|---|
| bool |
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 |
|---|---|---|
| IEnumerable<INode> | ns | Nodes. |
Returns
| Type | Description |
|---|---|
| IEnumerable<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. |
| Dictionary<INode, INode> | mapping | Mapping of Nodes. |
Returns
| Type | Description |
|---|---|
| Triple |
RemoveAllFromList(IGraph, INode, IEnumerable<INode>)
Removes the given items from a list (aka an RDF collection).
Declaration
public static void RemoveAllFromList(this IGraph g, INode listRoot, IEnumerable<INode> objects)
Parameters
| Type | Name | Description |
|---|---|---|
| IGraph | g | Graph to retract from. |
| INode | listRoot | Root node of the list to be modified. |
| IEnumerable<INode> | objects | Nodes to remove from the collection. |
Remarks
If an item occurs multiple times in the list, all instances of that item will be removed.
RemoveAllFromList<T>(IGraph, INode, IEnumerable<T>, Func<T, INode>)
Removes the given items from a list (aka an RDF collection).
Declaration
public static void RemoveAllFromList<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 of the list to be modified. |
| IEnumerable<T> | objects | Objects to remove from the collection. |
| Func<T, INode> | mapFunc | Mapping from object type |
Type Parameters
| Name | Description |
|---|---|
| T | Type of objects to be removed. |
Remarks
If an item occurs multiple times in the list, all instances of that item will be removed.
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, only the first occurrence 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. |
| IEnumerable<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, only the first occurrence 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. |
| IEnumerable<T> | objects | Objects to remove from the collection. |
| Func<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 |
|---|---|---|
| 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 |
|---|---|---|
| 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 |
|---|---|
| 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 |
|---|---|---|
| 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 |
|---|---|---|
| IEnumerable<INode> | ns | Nodes. |
Returns
| Type | Description |
|---|---|
| IEnumerable<IUriNode> |
VariableNodes(IEnumerable<INode>)
Gets the Variable Nodes.
Declaration
public static IEnumerable<IVariableNode> VariableNodes(this IEnumerable<INode> ns)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<INode> | ns | Nodes. |
Returns
| Type | Description |
|---|---|
| IEnumerable<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 |
|---|---|---|
| IEnumerable<Triple> | ts | Enumerable of Triples. |
| INode | obj | Object to match. |
Returns
| Type | Description |
|---|---|
| IEnumerable<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 |
|---|---|---|
| IEnumerable<Triple> | ts | Enumerable of Triples. |
| INode | predicate | Predicate to match. |
Returns
| Type | Description |
|---|---|
| IEnumerable<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 |
|---|---|---|
| IEnumerable<Triple> | ts | Enumerable of Triples. |
| INode | subject | Subject to match. |
Returns
| Type | Description |
|---|---|
| IEnumerable<Triple> |