rdf_vocabularies_schema 0.4.5 copy "rdf_vocabularies_schema: ^0.4.5" to clipboard
rdf_vocabularies_schema: ^0.4.5 copied to clipboard

Schema.org vocabulary (HTTPS variant) as Dart constants for type-safe RDF development

example/main.dart

// Example for experienced RDF developers
// This example shows how to use the full Schema vocabulary

import 'package:rdf_core/rdf_core.dart';
import 'package:rdf_vocabularies_schema/schema.dart';

/// Example how our rdf:class specific dart classes can be used to
/// guide you through the vocabulary.
///
/// Note how we use SchemaPerson to access the predicates available
/// for the Person class and how we use SchemaPostalAddress to access
/// the predicates available for the PostalAddress class.
///
/// Your IDE will help you to find the right predicates and
/// you will get compile time errors if you use a predicate
/// that is not available for the class you are using.
///
/// Just play around with the code and let your IDE show you the documentation
/// for the predicates to get a better understanding of the vocabulary.
void main() {
  // Create a person with a specific IRI
  final personIri = IriTerm('http://example.org/person/jane_doe');

  final addressNode = BlankNodeTerm();

  // Create a graph to hold our data
  final graph = RdfGraph.fromTriples([
    Triple(personIri, SchemaPerson.rdfType, SchemaPerson.classIri),
    Triple(personIri, SchemaPerson.name, LiteralTerm.string('Jane Doe')),
    Triple(personIri, SchemaPerson.foafAge, LiteralTerm.integer(42)),
    Triple(
      personIri,
      SchemaPerson.foafMbox,
      IriTerm('mailto:[email protected]'),
    ),
    Triple(
      personIri,
      SchemaPerson.foafKnows,
      IriTerm('http://example.org/person/john_smith'),
    ),
    Triple(
      personIri,
      SchemaPerson.email,
      LiteralTerm.string('[email protected]'),
    ),
    Triple(
      personIri,
      SchemaPerson.birthDate,
      LiteralTerm(
        '1990-01-01',
        datatype: IriTerm('http://www.w3.org/2001/XMLSchema#date'),
      ),
    ),

    // For properties that are not in this vocabularies, you can use constants
    // from rdf_vocabularies_core or use IriTerm directly.
    Triple(
      personIri,
      IriTerm('http://purl.org/dc/terms/creator'),
      LiteralTerm.string('System'),
    ),

    // Create a complex structure: a postal address
    Triple(personIri, SchemaPerson.address, addressNode),
    Triple(
      addressNode,
      SchemaPostalAddress.rdfType,
      SchemaPostalAddress.classIri,
    ),
    Triple(
      addressNode,
      SchemaPostalAddress.streetAddress,
      LiteralTerm.string('Somewhere St 123'),
    ),
    Triple(
      addressNode,
      SchemaPostalAddress.addressLocality,
      LiteralTerm.string('Anytown'),
    ),
    Triple(
      addressNode,
      SchemaPostalAddress.postalCode,
      LiteralTerm.string('12345'),
    ),
    Triple(
      addressNode,
      SchemaPostalAddress.addressCountry,
      LiteralTerm.string('Country'),
    ),
  ]);

  // Print the RDF data
  print('Person data using the specific Schema Class vocabulary:');
  print(RdfCore.withStandardCodecs().encode(graph));
}
0
likes
160
points
14
downloads

Publisher

unverified uploader

Weekly Downloads

Schema.org vocabulary (HTTPS variant) as Dart constants for type-safe RDF development

Homepage
Repository (GitHub)
View/report issues

Topics

#rdf #schema-org #linked-data #semantic-web #vocabularies

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

rdf_core

More

Packages that depend on rdf_vocabularies_schema