rdf_core 0.6.0
rdf_core: ^0.6.0 copied to clipboard
A type-safe, modular Dart library for modeling, parsing, and serializing RDF data.
rdf_core #
RDF Core #
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));
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.