Skip to main content

Ordered Turtle Serializer for rdflib

Project description

An extension to the rdflib Turtle serializer that adds order (at the price of speed). Useful when you need to generate diffs between Turtle files, or just to make it easier for human beings to inspect the files.

$ pip install otsrdflib

Usage:

from rdflib import graph
from otsrdflib import OrderedTurtleSerializer

my_graph = Graph()

out = open('out.ttl', 'wb')
serializer = OrderedTurtleSerializer(my_graph)
serializer.serialize(out)

Class order is imposed by setting serializer.topClasses. The default list is suitable for thesauri and other controlled vocabularies:

serializer.topClasses = [SKOS.ConceptScheme,
                       FOAF.Organization,
                       SD.Service,
                       SD.Dataset,
                       SD.Graph,
                       SD.NamedGraph,
                       ISOTHES.ThesaurusArray,
                       SKOS.Concept]

Instance order (within a class) is imposed by adding URI patterns to serializer.sorters:

serializer.sorters = {
  'http://dewey.info/class/(T?([0-9]+)\-\-)?([0-9.]+)': lambda x: (0 if x[1] is None else int(x[1])*1000) + float(x[2])
}

URIs that doesn’t match any of the specialized sorters are sorted alphabetically using the Python cmp method.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

otsrdflib-0.2.0.tar.gz (2.7 kB view details)

Uploaded Source

File details

Details for the file otsrdflib-0.2.0.tar.gz.

File metadata

  • Download URL: otsrdflib-0.2.0.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for otsrdflib-0.2.0.tar.gz
Algorithm Hash digest
SHA256 69a228702ca1b7ff3f4cb4583ce2201b666c882aeff1f1b5598c8b63400b5349
MD5 aad79b94e2f4b49ff453c87618e116d5
BLAKE2b-256 38454f7b1b263d311c82c5d885434bbd8377cecaf927a8bbcee569dc47cc7123

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page