rdfs Package

rdfs Package

Separate module to handle vocabulary expansions. The L{cache} module takes care of caching vocabulary graphs; the L{process} module takes care of the expansion itself.

@organization: U{World Wide Web Consortium<http://www.w3.org>} @author: U{Ivan Herman<a href=”http://www.w3.org/People/Ivan/“>} @license: This software is available for use under the U{W3C® SOFTWARE NOTICE AND LICENSE<href=”http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231“>}

cache Module

Managing Vocab Caching.

@summary: RDFa parser (distiller) @requires: U{RDFLib<http://rdflib.net>} @organization: U{World Wide Web Consortium<http://www.w3.org>} @author: U{Ivan Herman<a href=”http://www.w3.org/People/Ivan/“>} @license: This software is available for use under the U{W3C® SOFTWARE NOTICE AND LICENSE<href=”http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231“>}

class rdflib.plugins.parsers.pyRdfa.rdfs.cache.CachedVocab(URI, options=None)[source]

Bases: rdflib.plugins.parsers.pyRdfa.rdfs.cache.CachedVocabIndex

Cache for a specific vocab. The content of the cache is the graph. These are also the data that are stored on the disc (in pickled form)

@ivar graph: the RDF graph @ivar URI: vocabulary URI @ivar filename: file name (not the complete path) of the cached version @ivar creation_date: creation date of the cache @type creation_date: datetime @ivar expiration_date: expiration date of the cache @type expiration_date: datetime @cvar runtime_cache : a run time cache for already ‘seen’ vocabulary files. Apart from (marginally) speeding up processing, this also prevents recursion @type runtime_cache : dictionary

__init__(URI, options=None)[source]

@param URI: real URI for the vocabulary file @param options: the error handler (option) object to send warnings to @type options: L{options.Options}

__module__ = 'rdflib.plugins.parsers.pyRdfa.rdfs.cache'
class rdflib.plugins.parsers.pyRdfa.rdfs.cache.CachedVocabIndex(options=None)[source]

Class to manage the cache index. Takes care of finding the vocab directory, and manages the index to the individual vocab data.

The vocab directory is set to a platform specific area, unless an environment variable sets it explicitly. The environment variable is “PyRdfaCacheDir”

Every time the index is changed, the index is put back (via pickle) to the directory.

@ivar app_data_dir: directory for the vocabulary cache directory @ivar index_fname: the full path of the index file on the disc @ivar indeces: the in-memory version of the index (a directory mapping URI-s to tuples) @ivar options: the error handler (option) object to send warnings to @type options: L{options.Options} @ivar report: whether details on the caching should be reported @type report: Boolean @cvar vocabs: File name used for the index in the cache directory @cvar preference_path: Cache directories for the three major platforms (ie, mac, windows, unix) @type preference_path: directory, keyed by “mac”, “win”, and “unix” @cvar architectures: Various ‘architectures’ as returned by the python call, and their mapping on one of the major platforms. If an architecture is missing, it is considered to be “unix” @type architectures: directory, mapping architectures to “mac”, “win”, or “unix”

__init__(options=None)[source]

@param options: the error handler (option) object to send warnings to @type options: L{options.Options}

__module__ = 'rdflib.plugins.parsers.pyRdfa.rdfs.cache'
add_ref(uri, vocab_reference)[source]

Add a new entry to the index, possibly removing the previous one.

@param uri: the URI that serves as a key in the index directory @param vocab_reference: tuple consisting of file name, modification date, and expiration date

architectures = {'win32': 'win', 'darwin': 'mac', 'nt': 'win', 'cygwin': 'win'}
get_ref(uri)[source]

Get an index entry, if available, None otherwise. The return value is a tuple: file name, modification date, and expiration date

@param uri: the URI that serves as a key in the index directory

preference_path = {'win': 'pyRdfa-cache', 'mac': 'Library/Application Support/pyRdfa-cache', 'unix': '.pyRdfa-cache'}
vocabs = 'cache_index'
rdflib.plugins.parsers.pyRdfa.rdfs.cache.offline_cache_generation(args)[source]

Generate a cache for the vocabulary in args.

@param args: array of vocabulary URIs.

process Module

@organization: U{World Wide Web Consortium<http://www.w3.org>} @author: U{Ivan Herman<a href=”http://www.w3.org/People/Ivan/“>} @license: This software is available for use under the U{W3C® SOFTWARE NOTICE AND LICENSE<href=”http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231“>}

class rdflib.plugins.parsers.pyRdfa.rdfs.process.MiniOWL(graph, schema_semantics=False)[source]

Class implementing the simple OWL RL Reasoning required by RDFa in managing vocabulary files. This is done via a forward chaining process (in the L{closure} method) using a few simple rules as defined by the RDF and the OWL Semantics specifications.

@ivar graph: the graph that has to be expanded @ivar added_triples: each cycle collects the triples that are to be added to the graph eventually. @type added_triples: a set, to ensure the unicity of triples being added

__init__(graph, schema_semantics=False)[source]
__module__ = 'rdflib.plugins.parsers.pyRdfa.rdfs.process'
closure()[source]

Generate the closure the graph. This is the real ‘core’.

The processing rules store new triples via the L{separate method<store_triple>} which stores them in the L{added_triples<added_triples>} array. If that array is emtpy at the end of a cycle, it means that the whole process can be stopped.

rules(t)[source]

Go through the OWL-RL entailement rules prp-spo1, prp-eqp1, prp-eqp2, cax-sco, cax-eqc1, and cax-eqc2 by extending the graph. @param t: a triple (in the form of a tuple)

store_triple(t)[source]

In contrast to its name, this does not yet add anything to the graph itself, it just stores the tuple in an L{internal set<added_triples>}. (It is important for this to be a set: some of the rules in the various closures may generate the same tuples several times.) Before adding the tuple to the set, the method checks whether the tuple is in the final graph already (if yes, it is not added to the set).

The set itself is emptied at the start of every processing cycle; the triples are then effectively added to the graph at the end of such a cycle. If the set is actually empty at that point, this means that the cycle has not added any new triple, and the full processing can stop.

@param t: the triple to be added to the graph, unless it is already there @type t: a 3-element tuple of (s,p,o)

rdflib.plugins.parsers.pyRdfa.rdfs.process.process_rdfa_sem(graph, options)[source]

Expand the graph through the minimal RDFS and OWL rules defined for RDFa.

The expansion is done in several steps:
  1. the vocabularies are retrieved from the incoming graph (there are RDFa triples generated for that)
  2. all vocabularies are merged into a separate vocabulary graph
  3. the RDFS/OWL expansion is done on the vocabulary graph, to take care of all the subproperty, subclass, etc, chains
  4. the (expanded) vocabulary graph content is added to the incoming graph
  5. the incoming graph is expanded
  6. the triples appearing in the vocabulary graph are removed from the incoming graph, to avoid unnecessary extra triples from the data

@param graph: an RDFLib Graph instance, to be expanded @param options: options as defined for the RDFa run; used to generate warnings @type options: L{pyRdfa.Options}

rdflib.plugins.parsers.pyRdfa.rdfs.process.return_graph(uri, options, newCache=False)[source]

Parse a file, and return an RDFLib Graph. The URI’s content type is checked and either one of RDFLib’s parsers is invoked (for the Turtle, RDF/XML, and N Triple cases) or a separate RDFa processing is invoked on the RDFa content.

The Accept header of the HTTP request gives a preference to Turtle, followed by RDF/XML and then HTML (RDFa), in case content negotiation is used.

This function is used to retreive the vocabulary file and turn it into an RDFLib graph.

@param uri: URI for the graph @param options: used as a place where warnings can be sent @param newCache: in case this is used with caching, whether a new cache is generated; that modifies the warning text @return: A tuple consisting of an RDFLib Graph instance and an expiration date); None if the dereferencing or the parsing was unsuccessful