rdf_core 0.6.3 copy "rdf_core: ^0.6.3" to clipboard
rdf_core: ^0.6.3 copied to clipboard

A type-safe, modular Dart library for modeling, parsing, and serializing RDF data.

rdf_core logo

rdf_core #

pub package build codecov license


RDF Core #

🌐 Official Homepage

A type-safe, and extensible Dart library for representing and manipulating RDF data without any further dependencies.


Looking for mapping Dart Objects ↔️ RDF? #

=> Discover our companion project rdf_mapper now on GitHub!


✨ Features #

  • Type-safe RDF model: IRIs, Literals, Triples, Graphs, and more
  • Serialization-agnostic: Clean separation from Turtle/JSON-LD
  • Extensible & modular: Build your own adapters, plugins, and integrations
  • Spec-compliant: Follows W3C RDF 1.1 and related standards

πŸš€ Quick Start #

Manual Graph Creation #

import 'package:rdf_core/rdf_core.dart';

void main() {
  final subject = IriTerm('http://example.org/alice');
  final predicate = IriTerm('http://xmlns.com/foaf/0.1/name');
  final object = LiteralTerm.withLanguage('Alice', 'en');
  final triple = Triple(subject, predicate, object);
  final graph = RdfGraph(triples: [triple]);

  print(graph);
}

Parsing and Serializing Turtle #

import 'package:rdf_core/rdf_core.dart';

void main() {
  // Example: Parse a simple Turtle document
  final turtle = '''
    @prefix foaf: <http://xmlns.com/foaf/0.1/> .
    <http://example.org/alice> foaf:name "Alice"@en .
  ''';

  final rdf = RdfCore.withStandardFormats();
  final graph = rdf.parse(turtle, contentType: 'text/turtle');

  // Print parsed triples
  for (final triple in graph.triples) {
    print('${triple.subject} ${triple.predicate} ${triple.object}');
  }

  // Serialize the graph back to Turtle
  final serialized = rdf.serialize(graph, contentType: 'text/turtle');
  print('\nSerialized Turtle:\n$serialized');
}

πŸ§‘β€πŸ’» Advanced Usage #

Graph Merging #

final merged = graph1.merge(graph2);

Pattern Queries #

final results = graph.findTriples(subject: subject);

Blank Node Handling #

final bnode = BlankNodeTerm();
final newGraph = graph.withTriple(Triple(bnode, predicate, object));

Non-Standard Turtle Parsing #

import 'package:rdf_core/rdf_core.dart';

// Configure a TurtleFormat with specific parsing flags
final turtleFormat = TurtleFormat(
  parsingFlags: {
    TurtleParsingFlag.allowDigitInLocalName,
    TurtleParsingFlag.allowMissingDotAfterPrefix,
    TurtleParsingFlag.autoAddCommonPrefixes,
  }
);

// Create an RDF Core instance with the custom format
final rdf = RdfCore.withFormats(formats: [turtleFormat]);

// Parse a document with non-standard Turtle syntax
final nonStandardTurtle = '''
  @prefix ex <http://example.org/> // Missing dot after prefix
  ex:resource123 a ex:Type . // Digit in local name
''';

final graph = rdf.parse(nonStandardTurtle, contentType: 'text/turtle');

Serialization/Parsing #

final turtleSerializer = TurtleSerializer();
final turtle = turtleSerializer.write(graph);

final jsonLdParser = JsonLdParser(jsonLdSource);
final parsedGraph = jsonLdParser.parse();

⚠️ Error Handling #

  • All core methods throw Dart exceptions (e.g., ArgumentError, RdfValidationException) for invalid input or constraint violations.
  • Catch and handle exceptions for robust RDF processing.

🚦 Performance #

  • Triple, Term, and IRI equality/hashCode are O(1)
  • Graph queries (findTriples) are O(n) in the number of triples
  • Designed for large-scale, high-performance RDF workloads

πŸ—ΊοΈ API Overview #

Type Description
IriTerm Represents an IRI (Internationalized Resource Identifier)
LiteralTerm Represents an RDF literal value
BlankNodeTerm Represents a blank node
Triple Atomic RDF statement (subject, predicate, object)
RdfGraph Collection of RDF triples
RdfParser Interface for parsing RDF from various formats
RdfSerializer Interface for serializing RDF

πŸ“š Standards & References #


πŸ›£οΈ Roadmap / Next Steps #

  • Remove vocab directory and replace it with a much cleaner and more discoverable generated alternative, maybe in a separate project. This should also support generating discoverable vocab classes for arbitrary Vocabularies.
  • Support base uri in jsonld and turtle serialization
  • More serialization formats (N-Triples, RDF/XML)
  • SHACL and schema validation
  • Performance optimizations for large graphs

🀝 Contributing #

Contributions, bug reports, and feature requests are welcome!

  • Fork the repo and submit a PR
  • See CONTRIBUTING.md for guidelines
  • Join the discussion in GitHub Issues

πŸ€– AI Policy #

This project is proudly human-led and human-controlled, with all key decisions, design, and code reviews made by people. At the same time, it stands on the shoulders of LLM giants: generative AI tools are used throughout the development process to accelerate iteration, inspire new ideas, and improve documentation quality. We believe that combining human expertise with the best of AI leads to higher-quality, more innovative open source software.


© 2025 Klas Kalaß. Licensed under the MIT License.

4
likes
0
points
1.3k
downloads

Publisher

unverified uploader

Weekly Downloads

A type-safe, modular Dart library for modeling, parsing, and serializing RDF data.

Homepage
Repository (GitHub)
View/report issues

Topics

#rdf #linked-data #semantic-web #graph #serialization

Documentation

Documentation

License

unknown (license)

Dependencies

http, logging

More

Packages that depend on rdf_core