RDF.dart is a Dart library designed to make it easy to work with RDF (Resource Description Framework) data structures and concepts. It provides core data structures for representing RDF triples, graphs, datasets, and literals, along with utilities for managing datatypes and IRIs.
- Core RDF 1.2 Data Structures:
IRI
: Represents an Internationalized Resource Identifier string.IRITerm
: Represents an IRI used as an RDF term (subject, predicate, object, or graph name).Literal
: Represents an RDF literal with datatype and optional language tag.BlankNode
: Represents an RDF blank node.TripleTerm
: Represents an RDF triple used as an RDF term (subject or object) as defined in RDF 1.2.RdfTerm
: The abstract base class for all RDF terms (IRITerm
,BlankNode
,Literal
,TripleTerm
).Triple
: Represents an RDF triple (subject, predicate, object - where object can be anyRdfTerm
, including aTripleTerm
).Graph
: Represents a collection of RDF triples.Dataset
: Represents a collection consisting of one default graph and zero or more named graphs.
- Datatype Handling:
- Built-in support and validation for common XSD datatypes (e.g.,
xsd:string
,xsd:integer
,xsd:double
,xsd:dateTime
,xsd:boolean
,xsd:date
,xsd:duration
, and more). SeeXSD
class. - Support for
rdf:langString
. - (Planned)
DatatypeRegistry
for managing custom datatypes.
- Built-in support and validation for common XSD datatypes (e.g.,
- IRI Validation & Parsing:
- Robust IRI parsing based on RFC 3987.
- Validation checks for IRIs.
- Access to IRI components (scheme, authority, path, query, fragment).
- Immutability: Core data structures (
IRITerm
,BlankNode
,Literal
,TripleTerm
,Triple
,IRI
) are immutable. - Well-Tested: Core features have comprehensive unit tests.
-
Add the Dependency: Open your
pubspec.yaml
file and addrdf_dart
to your dependencies:dependencies: rdf_dart: ^1.0.0 # Replace with the latest version
-
Install the Package: Run this command in your terminal:
dart pub get
-
Import the Library: In your Dart code, import the
rdf_dart
library:import 'package:rdf_dart/rdf_dart.dart';
Here's a simple example demonstrating how to create RDF objects:
import 'package:rdf_dart/rdf_dart.dart';
void main() {
// Create some IRIs
final subject = IRITerm(IRI('http://example.org/subject'));
final predicate = IRITerm(IRI('http://example.org/predicate'));
final object = IRITerm(IRI('http://example.org/object'));
// Create a string literal
final stringLiteral = Literal('Hello, world!', XSD.string);
print(stringLiteral); // Output: "Hello, world!"
// Create a triple
final triple = Triple(subject, predicate, object);
// Create a Dataset
final dataset = Dataset();
// Add the Triple to the Dataset
dataset.defaultGraph.add(triple);
}