Skip to content

uholzer/RDFFresnel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

===================================
  RDF Fresnel Renderer for RDFLib
===================================

IMPORTANT: File formats and interfaces are not yet stable! Significant
changes to the Python interface and the XML output will be made!

RDFFresnel is a partial implementation of Fresnel[1] on top of
RDFLib[2]. It supports SPARQL selectors, but not FSL selectors. Some
enhancements beyond [1] have been added.

Requirements:
- Python 3
- rdflib
- rdflib-sparql
- lxml

Recommended:
- Any XSLT 1.0 processor (for example xsltproc[3])

Installation:
    python3 setup.py install
If you want to install to your home directory instead, use
    python3 setup.py install --user

Usage of the command line tool rdffresnel-render:
    rdffresnel-render --instances stuff.rdf \
                      --lenses lenses.n3 --lenses-format n3 \
                      http://example.org/thing > out.xml

You likely want to transform the output with an XSLT processor using
one of the stylesheets shipped with this package. By default they are
installed in /usr/local/share/RDFFresnel/transforms or
~/.local/share/RDFFresnel/transforms. For example:
    xsltproc /usr/local/share/RDFFresnel/transforms/fresneltoxhtml5.xsl \
             out.xml > final.xhtml

Usage of the library:
    import rdflib
    from RDFFresnel import Context, ContainerBox

    # A graph containing the lenses and one containing instance data
    fresnelGraph = rdflib.Graph()
    instanceGraph = rdflib.Graph()
    
    # Fill graphs with triples
    ...

    # Create an initial context
    ctx = Context(fresnelGraph=fresnelGraph, instanceGraph=instanceGraph)

    # A container which holds rendered resources
    box = ContainerBox(ctx)
    box.append(rdflib.URIRef("http://example.org/some_resource_to_render"))

    # Select a subtree of the RDF graph according to the lenses
    box.select()
    # Apply formats to the tree according to Fresnel formats
    box.portray()
    # Transform resulting data structure to XML
    tree = box.transform()
    # Write XML to a file
    somefile.write(etree.tostring(tree,encoding="UTF-8",xml_declaration=True)

XML output format:

The result of RDFFresnel can be serialized as XML. This is especially
useful if you want to use tools like an XSLT processor for further
processing instead of writing a Python script around RDFFresnel.

The namespace is http://www.andonyar.com/rec/2012/sempipe/fresnelxml
and ft: is usually used as prefix.

Element fresnelresult
    Root element. Corresponds to the class ContainerBox.
    Only contains resource elements.

Element resource
    Represents a rendered resource. Corresponds to ResourceBox.
    Can only be contained in fresnelresult and value elements.
    Attribute lens: URI of the employed lens
    Attribute uri: URI of the resource

Element property
    Corresponds to PropertyBox.
    Is always a child of resource or label.
    Attribute uri: URI of the RDF property (may be missing)

Element value
    Corresponds to ValueBox.
    Contains the value of a property.
    Is always a child of property.
    Attribute type: 'literal' for stings, 'xml' for xml content.

Element label
    A label of a property or a resource.
    Is always a child of property or resource.

Element format
    Provides information about the chosen format.
    Can turn up in any element that can be formatted.
    Can contain the elements described below, depending on whether the
    format has the corresponding property. Note that it is the
    responsibility of the user to decide whether and how the contents
    of these elements should be shown to the user.
    Attribute fmt: Contains the URI of the applied format.
    Attribute class: Contains the value of the format's
                     fresnel:resourceStyle, fresnel:propertyStyle, 
                     fresnel:valueStyle, or fresnel:labelStyle property
                     which if it is of type fresnel:styleClass.
    Attribute class: Contains the value of the format's
                     fresnel:resourceStyle, fresnel:propertyStyle,
                     fresnel:valueStyle, or fresnel:labelStyle property
                     which if it is of type fresnel:stylingInstruction.
    
Element contentBefore
    Contains the format's fresnel:contentBefore

Element contentAfter
    Contains the format's fresnel:contentAfter

Element contentFirst
    Contains the format's fresnel:contentFirst

Element contentLast
    Contains the format's fresnel:contentLast

Element contentNoValue
    Contains the format's fresnel:contentNoValue




[1] http://www.w3.org/2005/04/fresnel-info/manual/
[2] https://github.com/RDFLib/rdflib
[3] http://xmlsoft.org/XSLT/xsltproc.html

-- Urs Holzer <urs@andonyar.com>

About

Fresnel processor for RDFLib

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published