rdf_core 0.4.0 copy "rdf_core: ^0.4.0" to clipboard
rdf_core: ^0.4.0 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


🌐 Official Homepage

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


✨ 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
  • Built-in vocabularies: FOAF, Dublin Core (DC), SKOS, Schema.org, and more for easy discovery and usage, fully linked to the respective ontologies

πŸš€ 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');
}

Use Built-in RDF Vocabularies #

The vocab/ directory provides ready-to-use, type-safe access to many well-known RDF vocabularies and ontologies, including FOAF, Dublin Core (DC), SKOS, Schema.org, and more. This makes it easy to build interoperable RDF graphs without having to look up or type out long IRIs by hand.

Why does this matter?

  • Less boilerplate: Use FoafClasses.person or DcPredicates.title instead of raw strings.
  • Fewer mistakes: Avoid typos in IRIs and get autocompletion in your IDE.
  • Interoperability: Build RDF graphs that follow standards, making your data more portable and reusable.

Example: Using Vocabularies

import 'package:rdf_core/vocab.dart';

final alice = IriTerm('http://example.org/alice');

final graph = RdfGraph(
  triples: [
    Triple(alice, RdfPredicates.type, FoafClasses.person),
    Triple(alice, FoafPredicates.knows, IriTerm('http://example.org/bob')),
    Triple(alice, FoafPredicates.name, LiteralTerm.string('Alice')),
  ],
);

See the vocab/ directory for all available vocabularies and their terms.


πŸ§‘β€πŸ’» 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));

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 #

  • 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.39k
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

logging

More

Packages that depend on rdf_core