Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
Projektseminar "Texttechnologische Informationsmodellierung"
Formatierung und Transformation – XPath
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
Wiederholung: DTD
• Eine DTD enthält die textuelle Struktur einer Textgruppe in Form von Elementen und Attributen
• DTDs beschreiben die Syntax einer Markupsprache• DTDs sichern die strukturelle Validität einer Instanz
• DTDs spezifizieren das erste Element einer Instanz• Wurzelelement
• DTDs sind die fundamentale Basis zur Verarbeitung von in XML annotierten Daten
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
How to write a DTD?
Vorüberlegungen:• Linguistischer Level der Annotation
• Textebene, Satzebene, Wortebene, Phrasenstruktur, Rhetorische Struktur, …
• Wird eine DTD benötigt?• geht es nur um Aufgaben, die auch automatisiert gemacht werden können
(Texttagging)• Wer annotiert?• Was passiert mit den annotierten Daten?
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
How to write a DTD?
Vorgehensweise:• Sammeln von repräsentativen Daten, die annotiert werden sollen• Identifizierung der atomaren Einheiten• Identifizierung der Hierarchien• Bezeichnung der Einheiten• Entscheidung: Element oder Attribut?• Erweiterung: was für mögliche Ausnahmen gibt es, die nicht Teil der
Stichprobe sind?
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
How to write a DTD?
Alternative 1:• Structuring XML Documents
Megginson, Prentice Hall, 1998• > 400 Seiten• Analyse von fünf DTDs
(ISO 12083, DocBook, TEI, CALS, HTML)
• einige relevante Kapitel• eher technisch geschrieben
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
How to write a DTD?
Alternative 2:• Developing SGML DTDs – From Text to Model to Markup
Maler und El Andaloussi, Prentice Hall, 1996• > 500 Seiten• Standardwerk für DTD-Modellierung• Maler ist einer der Co-Autoren von XML
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
Ziel dieser Sitzung
Nach dieser Sitzung sollten Sie:• Mit Hilfe von XPath in der Baumrepräsentation einer XML-Instanz
navigieren und Knoten selektieren können
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
XML Path Language (XPath)
XPath dient…• zur Navigation in XML Dokumenten• zur Adressierung und Auswahl von Informationen Und ist damit Voraussetzung für Transformationen mit XSLT
Merkmale von XPath:• Abstrakte, logische Baum-Metapher• Sehr mächtige, aber einfache Syntax
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
XML Path Language (XPath)
Das Datenmodell:• Ein Baum besteht aus Knoten• Sieben Typen von Knoten:
1. Wurzelknoten (einmalig)
2. Elementknoten
3. Attributknoten
4. Namespaceknoten
5. Textknoten[kursiv]
6. Kommentarknoten7. Processing Instruction Knoten
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
XML Path Language (XPath)
XPath Ausdrücke• primäres syntaktisches Konstrukt
• Strings (Zeichenketten)• (Gleitkomma-) Zahlen• Variablen• Operatoren (arithmetisch/logisch)• Gruppierungen (Klammerung)• Funktionen (für Knoten, Strings, Zahlen, Booleans)• Lokalisierungspfade
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
XML Path Language (XPath)
XPath Ausdrücke• selektieren null oder mehr Knoten (Node Set)• können aus mehreren Schritten bestehen (getrennt durch "/")• können absolut oder relativ sein• werden von links nach rechts abgearbeitet
Text TechnologicalModelling of Information
<bib> <book> <publisher>Addison-Wesley</publisher> <author>Serge Abiteboul</author> <author> <first-name>Rick</first-name> <last-name>Hull</last-name> </author> <author>Victor Vianu</author> <title>Foundations of Databases</title> <year>1995</year> </book> <book price='55'> <publisher>Freeman</publisher> <author>Jeffrey D. Ullman</author> <title>Principles of Database and Knowledge Base Systems</title> <year>1998</year> </book></bib>
Eine XML-Instanz
Text TechnologicalModelling of Information
root
book book
publisher
bib
author author author title year
first-name
last-name
Addison-Wesley
SergeAbite-boul
Rick Hull
VictorVianu
Foundationsof Databases
1995
publisher author title year
Freeman
JeffreyD. Ullman
Principles ofDatabase and
Knowledge BaseSystems
price: 55
Eine XML-Instanz
1998
Text TechnologicalModelling of Information
root
book book
publisher
bib
author author author title year
first-name
last-name
Addison-Wesley
SergeAbite-boul
Rick Hull
VictorVianu
Foundationsof Databases
1995
publisher author title year
Freeman
JeffreyD. Ullman
Principles ofDatabase and
Knowledge BaseSystems
price: 55
XPath Ausdruck:/
Eine XML-Instanz
1998
Text TechnologicalModelling of Information
root
book book
publisher
bib
author author author title year
first-name
last-name
Addison-Wesley
SergeAbite-boul
Rick Hull
VictorVianu
Foundationsof Databases
1995
publisher author title year
Freeman
JeffreyD. Ullman
Principles ofDatabase and
Knowledge BaseSystems
price: 55
XPath Ausdruck:/bib
Eine XML-Instanz
1998
Text TechnologicalModelling of Information
root
book book
publisher
bib
author author author title year
first-name
last-name
Addison-Wesley
SergeAbite-boul
Rick Hull
VictorVianu
Foundationsof Databases
1995
publisher author title
Freeman
JeffreyD. Ullman
Principles ofDatabase and
Knowledge BaseSystems
price: 55
XPath Ausdruck:/bib/book/year
Eine XML-Instanz
1998
year
Text TechnologicalModelling of Information
root
book book
publisher
bib
author author author title year
first-name
last-name
Addison-Wesley
SergeAbite-boul
Rick Hull
VictorVianu
Foundationsof Databases
1995
publisher author title year
Freeman
JeffreyD. Ullman
Principles ofDatabase and
Knowledge BaseSystems
price: 55
XPath Ausdruck://author
Eine XML-Instanz
1998
Text TechnologicalModelling of Information
root
book book
publisher
bib
author author author title year
first-name
last-name
Addison-Wesley
SergeAbite-boul
Rick Hull
VictorVianu
Foundationsof Databases
1995
publisher author title year
Freeman
JeffreyD. Ullman
Principles ofDatabase and
Knowledge BaseSystems
price: 55
XPath Ausdruck://author/*
Eine XML-Instanz
1998
Text TechnologicalModelling of Information
root
book book
publisher
bib
author author author title year
first-name
last-name
Addison-Wesley
SergeAbite-boul
Rick Hull
VictorVianu
Foundationsof Databases
1995
publisher author title year
Freeman
JeffreyD. Ullman
Principles ofDatabase and
Knowledge BaseSystems
1998
price: 55
XPath Ausdruck://book/@*
Eine XML-Instanz
Text TechnologicalModelling of Information
root
book book
publisher
bib
author author author title year
first-name
last-name
Addison-Wesley
SergeAbite-boul
Rick Hull
VictorVianu
Foundationsof Databases
1995
publisher author title year
Freeman
JeffreyD. Ullman
Principles ofDatabase and
Knowledge BaseSystems
1998
price: 55
XPath Ausdruck:/bib/book/author/text()
Eine XML-Instanz
Text TechnologicalModelling of Information
root
book book
publisher
bib
author author author title year
first-name
last-name
Addison-Wesley
SergeAbite-boul
Rick Hull
VictorVianu
Foundationsof Databases
1995
publisher author title year
Freeman
JeffreyD. Ullman
Principles ofDatabase and
Knowledge BaseSystems
1998
price: 55
XPath Ausdruck:/bib/book/@price
Eine XML-Instanz
Text TechnologicalModelling of Information
root
book book
publisher
bib
author author author title year
first-name
last-name
Addison-Wesley
SergeAbite-boul
Rick Hull
VictorVianu
Foundationsof Databases
1995
publisher author title year
Freeman
JeffreyD. Ullman
Principles ofDatabase and
Knowledge BaseSystems
1998
price: 55
XPath Ausdruck:/bib/book/author[first-name]
Eine XML-Instanz
Text TechnologicalModelling of Information
root
book book
publisher
bib
author author author title year
first-name
last-name
Addison-Wesley
SergeAbite-boul
Rick Hull
VictorVianu
Foundationsof Databases
1995
publisher author title year
Freeman
JeffreyD. Ullman
Principles ofDatabase and
Knowledge BaseSystems
1998
price: 55
XPath Ausdruck:/bib/book[1]/author[3]
Eine XML-Instanz
Text TechnologicalModelling of Information
root
book book
publisher
bib
author author author title year
first-name
last-name
Addison-Wesley
SergeAbite-boul
Rick Hull
VictorVianu
Foundationsof Databases
1995
publisher author title year
Freeman
JeffreyD. Ullman
Principles ofDatabase and
Knowledge BaseSystems
1998
price: 55
XPath Ausdruck:/bib/book[year="1995"]
Eine XML-Instanz
Text TechnologicalModelling of Information
root
book book
publisher
bib
author author author title year
first-name
last-name
Addison-Wesley
SergeAbite-boul
Rick Hull
VictorVianu
Foundationsof Databases
1995
publisher author title year
Freeman
JeffreyD. Ullman
Principles ofDatabase and
Knowledge BaseSystems
1998
price: 55
XPath Ausdrücke:/bib/book[@price < 60]/bib/book[author/@age < 25]/bib/book[author/text()]/bib/book[...][...][...]
Eine XML-Instanz
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
Lokalisierungspfade
bib*//bibbib/paperbib//paper//paperpaper|book@pricebib/book/@price
jedes bib Elementjedes ElementWurzelknotenjedes bib Element unter der Wurzeljedes paper Element unter bibjedes paper Element irgendwo unter bibjedes paper Element im Baumpaper oder book Elementprice Attributprice Attribute von book unter bib
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
Lokalisierungspfade
Lokalisierungspfade• beschreiben einen Weg von einem Knoten zu 1…n anderen Knoten
(Node Set)• selektieren ein Node Set relativ vom Ausgangsknoten in Form von
• relativen Pfaden (Schritt1/Schritt2)
• absoluten Pfaden (/Schritt1/Schritt2)
• können bestehen aus mehreren Schritten, die durch "/" getrennt sind
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
Schritte
Schritte bestehen aus drei Teilen:• Achse
• Relation zwischen dem Kontextknoten und dem/der zu selektierenden Knoten
• Knotentest• Art des zu selektierenden Knotens
• Prädikat
child::book[position()=1]
Achse Knotentest Prädikat
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
Achsen
• self• parent• ancestor, ancestor-or-self• child• descendant, descendant-or-self• following, following-sibling• preceding, preceding-sibling• attribute• namespace
Text TechnologicalModelling of Information
Kontextknoten
Achsen
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
Abkürzungen
[nichts]@//.../
child::attribute::/descendant-or-self::node()/self::node()parent::node()Node tree root
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
Abkürzungen
Beispiele:• child::author/child::last-name
author/last-name• child::author/descendant::zip
author//zip• child::author/parent::*
author/..• child::author/attribute::age
author/@age• /bib//*[name()=book]
/bib//book
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
Knotentests
Knotentests verfeinern die Auswahl• Name eines Elements: chapter, book• alle Elementknoten: *• alle Attributknoten: @*• Textknoten: text()• Element-, Text- oder Attributknoten: node()• Kommentarknoten: comment()• PI: processing-instruction([name])
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
Prädikate
Prädikate• schränken eine Knotenmenge weiter ein• wenn erfüllt, dann ist dieser Knoten Teil des Result Node Set• bei Zahlen wird der Knoten mit der entsprechenden Position Teil des
Result Node Sets• /bib/book[1]/author[3]
• logische Operatoren: and, or• weitere Operatoren: <, <=, !=, ...• mathematisch Operatoren: +, -, mod, div• Vereinigung: |
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
Funktionen
Funktionen in XPath lassen sich unterteilen in:• Node Set Funktionen• Zeichenkettenfunktionen• Wahrheitsfunktionen (Booleans)• Zahlenfunktionen
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
Funktionen – Beispiele
• //chapter[count(section)=2] • concat('The',' ','XML') • true(contains(//title, 'Semantic'))• /library/book/chapter[last()]• /library/book/chapter[last()-1]• //chapter[not(@num)]• //chapter[not(@*)]• //*[starts-with(name(), 'sec')]• //*[contains(name(), 'ect')]
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
Node Set Funktionen
name(node-set?)namespace-uri(node-set?)
local-name(node-set?)id(object)
count(node-set)
position()
last()
Der Name eines Knotens*stringDie Namespace-URI eines Knotens*string
Der lokale Name eines Knotens (also ohne Namepace-Präfix)*
stringAuswahl eines Elements per IDnode-set
Anzahl der Knoten der verarbeiteten Knotenliste
number
Nummer (Position) in der Knotenliste des verarbeiteten Knotens
number
Nummer des letzten Knotens in der verarbeiteten Knotenliste
number
* fehlt das Argument, wird mit dem Kontextknoten gearbeitet
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
Zeichenkettenfunktionen – Auswahl
Entfernt vorangehenden und folgenden Whitespace*
normalize-space(string?)string
translate(string1, string2, string3)
string-length(string?)
substring-after(string, string)
substring-before(string1, string2)
contains(string1, string2)
starts-with(string1, string2)concat(string, string, string*)
Zeichen-für-Zeichen-Ersetzung. Alle Vorkommen von string2 in string1 werden durch string3 ersetzt
string
Anzahl Zeichen einer Zeichenkette*number
Die Teilzeichenkette von string1 nach string2
string
Die Teilzeichenkette von string1 vor string2
string
Wahr, wenn string2 in string1 enthalten ist
boolean
Wahr, wenn string1 mit string2 beginnt, sonst falsch
booleanKonkatenation aller Zeichenkettenstring
* fehlt das Argument, wird mit dem Stringwert des Kontextknotens gearbeitet
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
Wahrheitsfunktionen (Booleans)
lang(string)false()true()
not(object)boolean(object)
Liefert wahr, wenn das Argument mit dem Wert des Attributs xml:lang übereinstimmt
Liefert falsch zurückLiefert wahr zurück
Liefert wahr zurück, wenn das Argument falsch ist, sonst falsch
Konvertiert das Argument zu einem Wahrheitswert
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
Zahlenfunktionen
round(number)
ceiling(number)
floor(number)sum(node-set)number(object?)
Rundung
Die kleinste ganze Zahl, die nicht kleiner als das Argument ist
Die größte ganze Zahl, die nicht größer als das Argument ist
Gesamtwert aller Zahlen in einem Node SetKonvertiert das Argument zu einer Zahl*
* fehlt das Argument, wird der Stringwert des Kontextknotens konvertiert
http://www.text-technology.de/projects/sekimo.html
Text TechnologicalModelling of Information
XPath
Zusammenfassung:• XPath enthält einige mächtige Funktionen, um
• Elementknoten,• Attributknoten und• Textknoten
zu selektieren• Durch Prädikate und Funktionen lässt sich das Result Node Set weiter
eingrenzen