Skip to content

UserGuide Configuration Graphs

Kal Ahmed edited this page Sep 25, 2016 · 15 revisions

Home > User Guide > Configuration API > Graphs

Configuring Graphs

Graphs can be specified using the Configuration Vocabulary in a variety of ways. Graphs can be specified as empty or they can be specified as the merge of multiple data sources.

Graphs are loaded from Configuration in the following way:

  1. Instantiate a Graph of the correct type as specified by the dnr:type property
  2. Fill Graph with data from specified sources in the following order:
    1. Other Graphs
    2. Files
    3. Strings (RDF Fragments encoded as Literal Nodes)
    4. Datasets
    5. 3rd Party Triple Stores
    6. URIs
  3. Assign a specific URI as the Base URI of the Graph 1.# Apply any specified reasoners

Note: If any of the data sources fails to load then the loading of the Graph will fail.

Basic Configuration

At it's most basic a Graph is specified as follows:

@prefix dnr: <http://www.dotnetrdf.org/configuration#> .

_:graph a dnr:Graph ;
  dnr:type "VDS.RDF.Graph" .

With the built in loader you can specify any type which implements the IGraph interface and has a public unparameterized constructor.

Data Source Configuration

As already detailed there are multiple types of data source which you can fill a Graph with data from. Any combination of these may be used for a Graph and the resulting Graph will be the merge of all the data sources with the sources being loaded in the order specified earlier.

Other Graphs

Loading data from other graphs is specified as follows using the dnr:fromGraph property:

@prefix dnr: <http://www.dotnetrdf.org/configuration#> .

_:graph a dnr:Graph ;
  dnr:type "VDS.RDF.Graph" ;
  dnr:fromGraph _:otherGraph .

_:otherGraph a dnr:Graph ;
  dnr:type "VDS.RDF.Graph" .

Note: While it is possible to potentially introduce circular references by this mechanism the ConfigurationLoader is designed such that these references are detected during the loading process and an error will be thrown.

Files

Loading data from files is specified as shown below using the dnr:fromFile property. File paths can either be absolute or may be relative. In the case of relative paths the resolution of the path can be controlled by introducing an IPathResolver implementation by setting the PathResolver property of the ConfigurationLoader. Files are expected to be RDF graphs in formats which dotNetRDF understands.

@prefix dnr: <http://www.dotnetrdf.org/configuration#> .

_:graph a dnr:Graph ;
  dnr:type "VDS.RDF.Graph" ;
  dnr:fromFile "example.rdf" .

Strings (RDF Fragments)

You can encode the source of data for your Graph directly as a string using the dnr:fromString property like so:

@prefix dnr: <http://www.dotnetrdf.org/configuration#> .

_:graph a dnr:Graph ;
  dnr:type "VDS.RDF.Graph" ;
  dnr:fromString """@prefix : <http://example.org/> .
                    :this :is "RDF data encoded in a Literal" . """ .

Datasets

Graphs can be filled with data from named graphs held in a SPARQL dataset specified using a combination of the dnr:fromDataset and dnr:withUri properties. The dnr:fromDataset property is used to point to a SPARQL Dataset (see Configuration API - SPARQL Datasets) from which data should be loaded and the dnr:withUri property is used to specify the URI of the Graph from the dataset which should be loaded. Multiple dnr:withUri properties may be specified to load multiple graphs from the dataset.

If you specify multiple dnr:fromDataset properties then every URI specified with the dnr:withUri property will be loaded from every dataset. To load different graphs from different datasets use the dnr:fromGraph property to point to other graphs and setup those graphs to load the specific graphs from the specific databases you need.

3rd Party Triple Stores

Graphs can be filled with data from named graphs held in 3rd party triple stores using a combination of the dnr:fromStore property and the dnr:withUri property in an identical manner to that described above for Databases. Example configuration is as follows:

@prefix dnr: <http://www.dotnetrdf.org/configuration#> .

_:graph a dnr:Graph ;
  dnr:type "VDS.RDF.Graph" ;
  # Get the Graph with URI http://nasa.dataincubator.org/spacecraft/SHUTTLE from the store _:store
  dnr:fromStore _:store ;
  dnr:withUri <http://example.org/graph> .

# Specifies a connection to a Fuseki store
_:store a dnr:StorageProvider ;
  dnr:type "VDS.RDF.Storage.FusekiConnector" ;
  dnr:server <http://localhost:3030/dataset> .

URIs

Graphs can be loaded from URIs using the dnr:fromUri property:

@prefix dnr: <http://www.dotnetrdf.org/configuration#> .

_:graph a dnr:Graph ;
  dnr:type "VDS.RDF.Graph" ;
  # Gets the Graph of DBPedia's description of Southampton
  dnr:fromUri <http://dbpedia.org/resource/Southampton> .

Assigning a Base URI

Since Graphs loaded in this way will either have no Base URI or have a Base URI of one of their data sources it is often useful to assign a property URI to this Graph. This URI is the URI used if the Graph is subsequently saved/loaded or otherwise manipulated. A Base URI can be assigned using the dnr:assignUri property like so:

@prefix dnr: <http://www.dotnetrdf.org/configuration#> .

_:graph a dnr:Graph ;
  dnr:type "VDS.RDF.Graph" ;
  dnr:assignUri <http://example.org/assignedUri> .

Applying Reasoners

You can also apply reasoners to Graphs loaded in this way with the triples that the reasoner produces being materialised in the Graph. To learn how to configure a reasoner see Configuration API - Reasoners.

Linking a reasoner to a Graph is as easy as using the dnr:reasoner property as the following example in which an RDF Schema reasoner is applied to the Graph.

@prefix dnr: <http://www.dotnetrdf.org/configuration#> .

_:graph a dnr:Graph ;
  dnr:type "VDS.RDF.Graph" ;
  dnr:reasoner _:rdfs .

_:rdfs a dnr:Reasoner ;
  dnr:type "VDS.RDF.Query.Inference.RdfsReasoner" .

Basic Tutorial

  1. Getting Started
  2. Library Overview
  3. Hello World
  4. Reading RDF
  5. Writing RDF
  6. Working With Graphs
  7. Typed Values and Lists
  8. Working with Triple Stores
  9. Building SPARQL
  10. Querying with SPARQL
  11. Updating with SPARQL
  1. Exceptions
  2. Equality and Comparison
  3. Event Model
  4. Utility Methods
  5. Extension Methods
  6. Using the Namespace Mapper
  7. Storage API
    1. Triple Store Integration
    2. Storage Providers
    3. Servers API
    4. Transactions API
  8. Advanced SPARQL
    1. Result Formatting
    2. SPARQL Datasets
    3. Full Text Querying with SPARQL
    4. Advanced SPARQL Operations
  9. Ontology API
  10. Inference and Reasoning
  11. ASP.NET Integration
    1. Creating SPARQL Endpoints
    2. Deploying with rdfWebDeploy
  12. Global Options
  13. Dynamic API
  14. Formatting API
  15. Configuration API
    1. Graphs
    2. Triple Stores
    3. Object Factories
    4. Readers and Writers
    5. SPARQL Endpoints
    6. Query Processors
    7. Update Processors
    8. Protocol Processors
    9. SPARQL Datasets
    10. SPARQL Expression Factories
    11. SPARQL Operators
    12. SPARQL Optimisers
    13. Full Text Query
    14. Reasoners
    15. Storage Providers
    16. User Groups
    17. Permissions
    18. Users
    19. Static Options
    20. Proxy Servers
  16. Handlers API
  17. JSON-LD API
  18. Tools
    1. rdfConvert
    2. rdfEditor
    3. rdfOptStats
  1. Architecture
  2. Design
  3. Namespaces
  4. SPARQL Engine
  5. SPARQL Optimization
  6. Implementing Custom Optimizers
  7. SPARQL Extensions
  8. SPARQL Performance
  9. URI Interning
  10. Notes for Silverlight and WP7 Developers
  11. Developing for dotNetRDF
  12. Compiling
  13. Code Style
  14. Deprecation Policy
  15. Test Environment
  1. Debug HTTP Communication
  2. Debug SPARQL Queries
  3. Load OWL
  4. Load RDF from a File
  5. Load RDF from the Web
  6. Minimize Memory Usage
  7. Reify Triples
Clone this wiki locally