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.
The LanguageTagValidation
property specifies what sort of validation to apply to the language specifier of a literal node. The property currently supports three values:
LangaugeTagValidationMode.None
- no validation is performedLangaugeTagValidationMode.Turtle
- langauge tags are validated to be conformant with the Turtle 1.1 specification. This allows a language tag to match the regular expression [a-zA-Z]+(-[a-zA-Z0-9]+])*. This is less restrictive than the WellFormed mode which imposes some length constraints and other constraints on individual sub-tags. This is the default mode and is restrictive enough to ensure that other RDF processing tools will handle the langauge tags in your data.LangaugeTagValidationMode.WellFormed
- language tags are validated to be well-formed according to the productions of the BCP-47 specification. This includes allowing the grandfathered regular and irregular tags. Use this mode if you are expecting to process or parse the langauge tags in your data with tools that expect to be dealing with BCP-47 language tags.
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.