Cheshire3 Object Model - Transformer

API

class cheshire3.baseObjects.Transformer(session, config, parent=None)[source]

A Transformer transforms a Record into a Document.

A Transformer may be seen as the opposite of a Parser. It takes a Record and produces a Document. In many cases this can be handled by an XSLT stylesheet, but other instances might include one that returns a binary file based on the information in the Record.

Transformers may be used in the processing chain of an Index, but are more likely to be used to render a Record in a format or schema for delivery to the end user.

process_record(session, rec)[source]

Take a Record, transform it and return a new Document object.

Implementations

The following implementations are included in the distribution by default:

class cheshire3.transformer.XmlTransformer(session, config, parent=None)[source]

Return a Document containing the raw XML string of the record

class cheshire3.transformer.Bzip2XmlTransformer(session, config, parent=None)[source]

Return a Document containing bzip2 compressed XML.

Return a Document containing the raw XML string of the record, compressed using the bzip2 algorithm.

class cheshire3.transformer.SaxTransformer(session, config, parent=None)[source]
class cheshire3.transformer.WorkflowTransformer(session, config, parent)[source]

Transformer to execute a workflow.

class cheshire3.transformer.LxmlXsltTransformer(session, config, parent)[source]

XSLT transformer using Lxml implementation. Requires LxmlRecord.

Use Record’s resultSetItem’s proximity information to highlight query term matches.

class cheshire3.transformer.LxmlOffsetQueryTermHighlightingTransformer(session, config, parent)[source]

Return Document with search hits higlighted based on character offsets.

Use character offsets from Record’s resultSetItem’s proximity information to highlight query term matches.

class cheshire3.transformer.TemplatedTransformer(session, config, parent)[source]

Trasnform a Record using a Selector and a Python string.Template.

Transformer to insert the output of a Selector into a template string containing place-holders.

Template can be specified directly in the configuration using the template setting (whitespace is respected), or in a file using the templatePath path. If the template is specified in the configuration, XML reserved characters (<, >, & etc.) must be escaped.

This can be useful for Record types that are not easily transformed using more standard mechanism (e.g. XSLT), a prime example being GraphRecords

Example

config:

<subConfig type=”transformer” id=”myTemplatedTransformer”>

<objectType>cheshire3.transformer.TemplatedTransformer</objectType> <paths>

<object type=”selector” ref=”mySelector”/> <object type=”extractor” ref=”SimpleExtractor”/>

</paths> <options>

<setting type=”template”>
This is my document. The title is {0}. The author is {1}

</setting>

</options>

</subConfig>

selector config:

<subConfig type=”selector” id=”mySelector”>

<objectType>cheshire3.selector.XpathSelector</objectType> <source>

<location type=”xpath”>//title</location> <location type=”xpath”>//author</location>

</source>

</subConfig>

class cheshire3.transformer.MarcTransformer(session, config, parent)[source]

Transformer to converts records in marc21xml to marc records.