rdflib 0.2.11 copy "rdflib: ^0.2.11" to clipboard
rdflib: ^0.2.11 copied to clipboard

A pure Dart package for working with RDF (resource description framework).

example/main.dart

import 'package:rdflib/rdflib.dart';

main() {
  // the following example is modified from <https://rdflib.readthedocs.io/en/stable/gettingstarted.html#a-more-extensive-example>

  // Initialize a Graph
  Graph g = Graph();

  // Create a new URIRef instance for a person
  final donna = URIRef('http://example.org/donna');

  // Add triples to the Graph using [Graph.addTriplesToGroups] method
  g.addTripleToGroups(donna, RDF.type, FOAF.Person);
  g.addTripleToGroups(donna, FOAF.nick, Literal('donna', lang: 'en'));
  g.addTripleToGroups(donna, FOAF.name, Literal('Donna Fales'));
  g.addTripleToGroups(donna, FOAF.mbox, URIRef('mailto:donna@example.org'));
  // Adding a duplicate triple should be ignored
  g.addTripleToGroups(donna, FOAF.mbox, URIRef('mailto:donna@example.org'));

  // Create another URIRef instance
  final ed = URIRef('http://example.org/edward');

  // Add triples to the Graph
  g.addTripleToGroups(ed, RDF.type, FOAF.Person);
  g.addTripleToGroups(ed, FOAF.nick, Literal('ed', datatype: XSD.string));
  g.addTripleToGroups(ed, FOAF.name, Literal('Edward Scissorhands'));
  g.addTripleToGroups(
      ed, FOAF.mbox, Literal('mailto:ed@example.org', datatype: XSD.anyURI));

  // Bind the long namespace to shorter string for better readability
  g.bind('example', Namespace(ns: 'http://example.org/'));

  // Serialize the Graph to the standard turtle format, and the result is stored
  // in [Graph.serializedString]
  g.serialize(format: 'ttl', abbr: 'short');
  print('-------\nSerialized content:\n${g.serializedString}');

  // Print out every added triple in the graph by iterating through the set
  print('-------\nTriples updated in the graph:');
  for (Triple t in g.triples) {
    print(t);
  }

  // Print out each person's mailbox value
  print('-------\nMailboxes:');
  for (var sub in g.subjects(pre: a, obj: FOAF.Person)) {
    for (var mbox in g.objects(sub: sub, pre: FOAF.mbox)) {
      print('${sub}\'s mailbox: ${mbox.value}');
    }
  }

  // Print out predicates of triples having donna
  print('-------\nDonna predicates values:');
  for (Triple tri in g.matchTriples(donna.value)) {
    print(tri.pre.value);
  }
}
6
likes
150
points
292
downloads

Publisher

unverified uploader

Weekly Downloads

A pure Dart package for working with RDF (resource description framework).

Repository (GitHub)
View/report issues

Documentation

API reference

License

GPL-3.0 (license)

Dependencies

http, logging, petitparser, universal_io, uuid

More

Packages that depend on rdflib