Type-safe RDF vocabulary constants for both newcomers and experts
rdf_vocabularies
provides a type-safe, ergonomic way to work with RDF vocabularies in Dart applications that
use rdf_core.
Instead of dealing with string literals for IRIs, this package offers compile-time constants organized in an
intuitive class structure, making RDF development in Dart more productive and less error-prone.
Nearly all content is composed of compile-time constants, resulting in no runtime performance penalty.
Explore vocabularies through IDE autocompletion - no more guessing which predicates you can use.
Each vocabulary term includes its original description, accessible right in your editor and through our extensive API Reference.
Catch vocabulary errors at compile time, not at runtime when it's too late.
Use class-specific terms for guided development or full vocabulary access for flexibility.
Includes constants for the most widely used RDF vocabularies in the Semantic Web.
To use rdf_vocabularies
in your Dart project, you'll need to add it to your dependencies in pubspec.yaml
:
dependencies:
rdf_vocabularies: ^0.3.0
rdf_core: ^0.9.0 # Required for RDF data structures
Then run:
dart pub get
Import the vocabularies you need in your Dart files:
// For beginners using class-specific approach
import 'package:rdf_vocabularies/schema.dart';
import 'package:rdf_vocabularies/src/generated/schema/classes/person.dart';
import 'package:rdf_vocabularies/src/generated/schema/classes/postal_address.dart';
// For experts using full vocabulary approach
import 'package:rdf_vocabularies/schema.dart';
import 'package:rdf_vocabularies/rdf.dart';
import 'package:rdf_vocabularies/foaf.dart';
If you're new to RDF or prefer guided development, the class-specific approach provides:
SchemaPerson
, your IDE will only show
relevant properties for Person objects, making discovery easier.
import 'package:rdf_core/rdf_core.dart';
import 'package:rdf_vocabularies/schema.dart';
import 'package:rdf_vocabularies/src/generated/schema/classes/person.dart';
import 'package:rdf_vocabularies/src/generated/schema/classes/postal_address.dart';
import 'package:rdf_vocabularies/xsd.dart';
void main() {
final personIri = IriTerm('http://example.org/person/jane_doe');
final addressNode = BlankNodeTerm();
// Create a graph with triples using class-specific constants
final graph = RdfGraph.fromTriples([
// Declare the resource type
Triple(personIri, SchemaPerson.rdfType, SchemaPerson.classIri),
// Use properties specific to Person
Triple(personIri, SchemaPerson.name, LiteralTerm.string('Jane Doe')),
Triple(personIri, SchemaPerson.email, LiteralTerm.string('jane.doe@example.com')),
Triple(personIri, SchemaPerson.birthDate, LiteralTerm('1990-01-01', datatype: Xsd.date)),
// Even those defined in other vocabularies, if their relationship is known to the library
Triple(personIri, SchemaPerson.foafAge, LiteralTerm.integer(42)),
// For properties from foreign vocabularies that are not restricted to a specific class,
// but are designed to be used universally, you can use the generated UniversalProperties
// classes.
Triple(personIri, DcUniversalProperties.creator, LiteralTerm.string('System')),
// Create a complex structure with an address
Triple(personIri, SchemaPerson.address, addressNode),
Triple(addressNode, SchemaPostalAddress.rdfType, SchemaPostalAddress.classIri),
Triple(addressNode, SchemaPostalAddress.streetAddress, LiteralTerm.string('123 Main St')),
Triple(addressNode, SchemaPostalAddress.addressLocality, LiteralTerm.string('Anytown')),
Triple(addressNode, SchemaPostalAddress.postalCode, LiteralTerm.string('12345')),
]);
// Your IDE will help you discover valid properties for each class
}
For experienced RDF developers who know exactly which vocabulary terms they need, the full vocabulary approach provides:
import 'package:rdf_core/rdf_core.dart';
import 'package:rdf_vocabularies/schema.dart';
import 'package:rdf_vocabularies/rdf.dart';
import 'package:rdf_vocabularies/foaf.dart';
import 'package:rdf_vocabularies/xsd.dart';
void main() {
final personIri = IriTerm('http://example.org/person/jane_doe');
final addressNode = BlankNodeTerm();
// Create a graph with direct vocabulary access
final graph = RdfGraph.fromTriples([
Triple(personIri, Rdf.type, Schema.Person),
// Mix properties from different vocabularies freely
Triple(personIri, Schema.name, LiteralTerm.string('Jane Doe')),
Triple(personIri, Foaf.age, LiteralTerm.integer(42)),
Triple(personIri, Schema.email, LiteralTerm.string('jane.doe@example.com')),
// Create a complex structure with an address
Triple(personIri, Schema.address, addressNode),
Triple(addressNode, Rdf.type, Schema.PostalAddress),
Triple(addressNode, Schema.streetAddress, LiteralTerm.string('123 Main St')),
Triple(addressNode, Schema.addressLocality, LiteralTerm.string('Anytown')),
Triple(addressNode, Schema.postalCode, LiteralTerm.string('12345')),
]);
}
Our comprehensive API Documentation is a key resource for developers:
Including rdf_vocabularies
in your project has minimal impact on performance and size:
This package includes constants for many popular RDF vocabularies:
Using the vocabulary constants makes query patterns both safer and more readable:
// Find all schema:Person objects in a graph
final allPersons = graph.findTriples(
predicate: Rdf.type,
object: Schema.Person
).map((triple) => triple.subject);
// Query for all email addresses of a person
final emails = graph.findTriples(
subject: personIri,
predicate: Schema.email
).map((triple) => triple.object);
// Find a person by name
final janeNode = graph.findTriples(
predicate: Schema.name,
object: LiteralTerm.string('Jane Doe')
).map((triple) => triple.subject).firstOrNull;
The library excels at helping you integrate data from multiple sources:
// Create a person using both Schema.org and FOAF terms
graph.addAll([
Triple(personIri, Rdf.type, Schema.Person),
Triple(personIri, Schema.name, LiteralTerm.string('Jane Doe')),
Triple(personIri, Foaf.mbox, IriTerm('mailto:jane.doe@example.com')),
Triple(personIri, Foaf.knows, IriTerm('http://example.org/person/john_smith')),
Triple(personIri, Dc.creator, LiteralTerm.string('System')),
]);
Contributions, bug reports, and feature requests are welcome! Here's how you can contribute:
git checkout -b feature/amazing-feature
)git commit -m 'Add some amazing feature'
)git push origin feature/amazing-feature
)For more details, see the CONTRIBUTING.md file.