Skip to main content

Ordered Turtle Serializer for rdflib

Project description

Build status Code health Latest version MIT license

Ordered Turtle Serializer for rdflib

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.1.tar.gz (3.0 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for otsrdflib-0.2.1.tar.gz
Algorithm Hash digest
SHA256 c319d0d497bf41085c6feb38ad0cbe9e01662f9b9da9c884207bd9292e1aef43
MD5 75352d3730d93481e7fe52112fc8e3ab
BLAKE2b-256 00549bf7b972e29b15ae08d01ebd6038f8769ae1c4fdafc9f8b18eb0c82efdf4

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