Node Factory
As already discussed in Core Concepts, the INodeFactory
interface is the preferred way to create new nodes in a graph.
This interface is already implemented by or inherited by key APIs in dotNetRDF such as IGraph
, IRdfHandler
and ISparqlResultsHandler
, meaning that it is already quite readibly accessile from most places you would need to create new nodes.
However, you can also create your own NodeFactory
instance should you need a stand-alone instance of the factory.
BlankNodes and Node Factories
The INodeFactory
interface allows you to create a blank node either with or without specifying a blank node identifier string.
When you do not specify a blank node identifier, a new one will be generated by the factory.
When you do provide an identifier, it will be used as the identifier of the returned blank node only if the factory has not already created a blank node with that identifier. If the factory has already created such a blank node, it will instead generate a blank node with a new identifier based on the provided one, but which does not match any already generated identifier.
Note
It is important to note that this logic can still only ensure unique blank nodes within the scope of the same Node Factory.
INodeFactory Properties
There are a number of properties exposed by the INodeFactory
interface that can be used to modify its behaviour.
The BaseUri
property can be used to get or set the base URI used to resolve any relative URIs passed to the Create...
methods into absolute URIs.
The NamespaceMap
property provides access to the INamespaceMapper
used to convert prefixed URI strings into full URIs.
The UriFactory
property can be used to get or set the IUriFactory
used to generate any new URIs needed for nodes created by the factory.
The NormalizeLiteralValues
property is a flag that can be set to control whether or not the factory applies Unicode normalization to string literals when creating new literal nodes.
Unicode normalization can aid in more meaningful string comparison when dealing with strings with composing characters.
NodeFactory class
The NodeFactory
class provides the default library implementation of the INodeFactory
interface.
It provides a constructor that allows you to configure the options for the factory as well as to provide the specific INamespaceMapper
and IUriFactory
instances that the factory should use.
These default to a new empty namespace map, and the UriFactory.Root
URI factory respectively.