-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
139 lines (106 loc) · 4.61 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
===================================
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 <[email protected]>