More Related Content
Similar to Chapter 2 semantic web
Similar to Chapter 2 semantic web (20)
More from R A Akerkar (20)
Chapter 2 semantic web
- 2. Introduction
• Definition 2.1: XML is used to improve
compatibility between the desperate
systems of business partners by defining
the meaning of data in business
documents.
• Definition 2.2: XML is a language
allowing the exchange of structured data.
Akerkar: Foundations of © Narosa Publishing House, 2009 2
Semantic Web.
- 3. The design goals for XML
– XML shall be straightforwardly usable over the Internet.
– XML shall support a wide variety of applications.
– XML shall be compatible with SGML.
– It shall be easy to write programs which process XML
documents.
– The number of optional features in XML is to be kept to the
absolute minimum, ideally zero.
– XML documents should be human-legible and reasonably clear.
– The XML design should be prepared quickly.
– The design of XML shall be formal and concise.
– XML documents shall be easy to create.
– Terseness in XML markup is of minimal importance.
Akerkar: Foundations of © Narosa Publishing House, 2009 3
Semantic Web.
- 4. W3C Understanding XML
• XML is for structuring data
• XML looks a bit like HTML
• XML is text, but isn’t meant to be read
• XML is verbose by design
• XML is a family of technologies
• XML is new, but not that new
• XML leads HTML to XHTML
• XML is modular
• XML is the basis for Resource Description Format (RDF)
and the Semantic Web
• XML is license-free, platform-independent and well-
supported
Akerkar: Foundations of © Narosa Publishing House, 2009 4
Semantic Web.
- 5. XML Processing
• Example 2.1: gopal.xml is an XML document
containing Gopal's resume. The document
contains educational background, earlier work
experience, references, and contact information
by markup tags:
<resume>
<contact-info> ... </contact-info>
<education> ... </education>
<experience> ... </experience>
<references> ... </references>
</resume>
Akerkar: Foundations of © Narosa Publishing House, 2009 5
Semantic Web.
- 6. XML Processing
XML
Processor
gopal.xml gopal.html
Akerkar: Foundations of © Narosa Publishing House, 2009 6
Semantic Web.
- 7. HTML & XML
<p> The lecture notes on: <br />
<i> Semantic Web. </i>
Author of the notes <br />
<b> R. Akerkar. </b>
<book_title> Semantic Web </book_title>
<author> R. Akerkar </author>
<publisher> Narosa Publishing House </publisher>
<copydate> 2008 </copydate>
Akerkar: Foundations of © Narosa Publishing House, 2009 7
Semantic Web.
- 8. XML Prolog
prolog ::= (declaration, misc*, dtd?, misc*)
misc ::= (comment | pi)
Here is a sample XML declaration:
<?xml version = "1.0" encoding = "UTF-16"
standalone = "yes"?>
Akerkar: Foundations of © Narosa Publishing House, 2009 8
Semantic Web.
- 9. XML Comment
– An XML comment has the same form as an HTML
comment:
<!-- this is an XML comment -->
– XML processors ignore XML comments.
– A processing instruction (PI) provides processing
directions in the form of attribute values to a target
XML processor. For example, the following PI tells a
style sheet processor which style sheet should be
used to process this document:
<?xml:stylesheet type = "text/xsl" href = "outline.xsl"?>
Akerkar: Foundations of © Narosa Publishing House, 2009 9
Semantic Web.
- 10. Elements
element ::= (start-tag, content?, end-tag) | empty-elem-tag
start-tag ::= <(name, attribute*)>
end-tag ::= </name>
empty-elem-tag ::= <(name, attribute+)/>
content ::= (text | comment | pi | entity-ref | element)+
<memo> <from> Gopal <to> Gita </from> </to> Dinner tonight?
</memo>
Akerkar: Foundations of © Narosa Publishing House, 2009 10
Semantic Web.
- 11. Document Declaration
• An XML document consists of a
declaration followed by a single element
called the root:
<?xml version = "1.0"?>
<ROOT>
CONTENT
</ROOT>
Akerkar: Foundations of © Narosa Publishing House, 2009 11
Semantic Web.
- 12. XML Overview
XML Concepts
Elements &
DTDs Namespaces
Attributes
Akerkar: Foundations of © Narosa Publishing House, 2009 12
Semantic Web.
- 13. Public Languages
• A registry of public languages is
maintained by xml.org at:
http://www.xml.org/xml/registry.jsp
W3C recommendations also include a number
of public languages including XHTML,
MathML, and SVG.
Akerkar: Foundations of © Narosa Publishing House, 2009 13
Semantic Web.
- 14. Foreign Elements
• A LabML report has the format:
<experiment date = "...">
<introduction>...</introduction>
<equipment-list>...</equipment-list>
<procedure>...</procedure>
<data>...</data>
<analysis>...</analysis>
<summary>...</summary>
</experiment>
Akerkar: Foundations of © Narosa Publishing House, 2009 14
Semantic Web.
- 15. XML Design Patterns
• Document-Oriented
<html> ... </html>
<report> ... </report>
<invoice> ... </invoice>
<chapter> ... </chapter>
• Data Oriented
<employee> ... </employee>
<measurement> ... </measurement>
<organization> ... </organization>
• Command Oriented
<deposit> ... </deposit>
<transfer> ... </transfer>
<invoke> ... </invoke>
<render> ... </render>
Akerkar: Foundations of © Narosa Publishing House, 2009 15
Semantic Web.
- 16. Data Structures
• Records
• <record type = "student">
<field name = "name"> Gopal </field>
<field name = "gpa"> 1.2 </field>
<field name = "class"> B. Sc. Second Year </field>
<!-- etc -->
</record>
• Or, less generically:
• <student>
<name> Gopal </name>
<gpa> 1.2 </gpa>
<class> B. Sc. Second Year </class>
<!-- etc -->
</student>
Akerkar: Foundations of © Narosa Publishing House, 2009 16
Semantic Web.
- 17. Data Structures
• Lists can be implicitly ordered by their position in the document
(document order):
<items>
<item> 100 </item>
<item> 200 </item>
<item> 300 </item>
<item> 400 </item>
<item> 500 </item>
</items>
• Or the order can be made explicit:
<items>
<item id = "id4">
<data> 400 </data>
<prev ref = "id3"/>
<next ref = "id5"/>
</item>
….
….
Akerkar: Foundations of © Narosa Publishing House, 2009 17
Semantic Web.
- 18. • Example 2.2: Let us consider a document
containing Rita Mathur’s address. This
information can be represented as:
<label>
<name> Rita Mathur </name>
<address>
<street> 12 Jaiprakash nagar, Goregaon </street>
<city> Mumbai </city>
<state> Maharashtra </state>
</address>
</label>
Akerkar: Foundations of © Narosa Publishing House, 2009 18
Semantic Web.
- 19. • Example 2.3: Attributes are used to
represent the information.
<address
Street = “12 Jaiprakash nagar, Goregaon”
City = “Mumbai”
State = “Maharashtra”
/>
Akerkar: Foundations of © Narosa Publishing House, 2009 19
Semantic Web.
- 20. Namespaces
• Namespaces are a simple mechanism for
creating globally unique names for the elements
and attributes of your markup language
xmlns : prefix=”location”
<xsd:integer>
A sample namespace declaration:
<xsd:schema
xmlns:xsd=”http://www.w3.org/2001/XMLSchema”>
Akerkar: Foundations of © Narosa Publishing House, 2009 20
Semantic Web.
- 21. Namespaces
• A default namespace is declared by
eliminating the prefix from the declaration:
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head> <title> Default namespace </title> </head>
<body> Web Programming </body>
</html>
Akerkar: Foundations of © Narosa Publishing House, 2009 21
Semantic Web.
- 22. Example 2.5
<?xml version="1.0" standalone="yes"?> ?>
<DATARECORD>
<PERSON>
<FIRSTNAME>Ram</FIRSTNAME>
<MEDDLENAME>Manohar</MIDDLENAME>
<LASTNAME>Patel</LASTNAME>
<CITY>Pune</CITY>
<SALARY>Rs. 35000</SALARY>
</PERSON>
<PERSON> <PERSON>
<FIRSTNAME>Jagan</FIRSTNAME> <FIRSTNAME>Raja</FIRSTNAME>
<MEDDLENAME>Jeevan</MIDDLENAME> <MEDDLENAME>Ram</MIDDLENAME>
<LASTNAME>Rai</LASTNAME> <LASTNAME>Venugopal</LASTNAME>
<CITY>Mumbai</CITY> <CITY>Mumbai</CITY>
<SALARY>Rs. 50000</SALARY> <SALARY>Rs. 80000</SALARY>
</PERSON> </PERSON>
<PERSON> <PERSON>
<FIRSTNAME>Reema</FIRSTNAME> <FIRSTNAME>Pankaj</FIRSTNAME>
<MEDDLENAME>Ravi</MIDDLENAME> <MEDDLENAME>Kumar</MIDDLENAME>
<LASTNAME>Verma</LASTNAME> <LASTNAME>Sen</LASTNAME>
<CITY>Delhi</CITY> <CITY>Pune</CITY>
<SALARY>Rs. 65000</SALARY> <SALARY>Rs. 50000</SALARY>
</PERSON> </PERSON>
<DATARECORD>
Akerkar: Foundations of © Narosa Publishing House, 2009 22
Semantic Web.
- 23. Document Type Definitions
<!DOCTYPE name external-id? [internal-decs]?>
Examples 2.6: Suppose we want to represent our
books, records, CDs and DVDs in a library
element. The following declaration requires that
all books are listed before all records:
<!ELEMENT library (book*, record*, cd*, dvd*)>
By contrast, the following declaration allows us to list books,
records, CDs, and DVDs in any order:
<!ELEMENT library (book | record | cd | dvd)*>
Akerkar: Foundations of © Narosa Publishing House, 2009 23
Semantic Web.
- 24. Attribute Types
• There are three attribute types:
attType ::= CDATA | token | enumerated
– where CDATA is any quoted string.
• There seven token types:
token ::=
ID | IDREF | IDREFS | ENTITY | ENTITIES |
NMTOKEN | NMTOKENS
Akerkar: Foundations of © Narosa Publishing House, 2009 24
Semantic Web.
- 25. Entity Declarations
Example 2.8:
<?xml version = "1.0" standalone = "no"?>
<!DOCTYPE course SYSTEM "course.dtd"
[<!ENTITY mt1 "midterm1">
<!ENTITY mt2 "midterm2">
]>
<course>
<title> Web Programming </title>
<semester> Fall 2008 </semester>
<exams>
<exam exam-id = "&mt1;" date = "2008-09-12" total = "100"/>
<exam exam-id = "&mt2;" date = "2008-10-15" total = "100"/>
<exam exam-id = "final" date = "2008-11-20" total = "200"/>
</exams>
<students>
<student name = "Gopal Sharma" student-id = "A123" grade =
Akerkar: Foundations of © Narosa Publishing House, 2009 25
Semantic Web.
- 26. Entity Declarations
"A">
<score exam-ref = "&mt1;" total = "90"/>
<score exam-ref = "&mt2;" total = "95"/>
<score exam-ref = "final" total = "182"/>
</student>
<student name = "Rita Mathur" student-id = "A124" grade = "B">
<score exam-ref = "&mt1;" total = "90"/>
<score exam-ref = "&mt2;" total = "78"/>
<score exam-ref = "final" total = "155"/>
</student>
<student name = "Shila Soman" student-id = "A125" grade = "C">
<score exam-ref = "&mt1;" total = "70"/>
<score exam-ref = "&mt2;" total = "70"/>
<score exam-ref = "final" total = "140"/>
</student>
<!-- etc. -->
</students>
</course>
Akerkar: Foundations of © Narosa Publishing House, 2009 26
Semantic Web.
- 27. XML Schema
<?xml version = "1.0"?>
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- global declarations go here -->
</xsd:schema>
<xsd:element name = "tag1" type = "Tag1Type"/>
<xsd:element name = "tag2" type = "Tag2Type"/>
<xsd:element name = "tag3" type = "Tag3Type"/>
Akerkar: Foundations of © Narosa Publishing House, 2009 27
Semantic Web.
- 28. XML Schema
xsd:string ::= <char>+
xsd:boolean ::= false | true
xsd:decimal ::= (+ | -)?<digit>+(.<digit>*)?
xsd:double ::= IEEE double precision float
xsd:float ::= IEEE single precision float
xsd:integer ::= (+|-)?<digit>+
xsd:duration ::= P<int>Y<int>M<int>DT<int>H<int>M<int>S
xsd:time ::= <hours>:<mins>:<secs>
<hours>, <mins> ::= <int>, <secs> ::= <decimal>
xsd:date ::= <CCYY>-<MM>-<DD>
xsd:anyURI ::= <URI>
xsd:ID ::= <NCName>
xsd:IDREF ::= <NCName>
xsd:QName ::= <URI>:<NCName>
xsd:Name ::= <XMLName>
Akerkar: Foundations of © Narosa Publishing House, 2009 28
Semantic Web.
- 29. XML Schema
<xsd:complexType name = "Tag1Type">
<!-- tag1 elements and attributes declared here -->
</xsd:complexType>
<xsd:complexType name = "Tag2Type">
<!-- tag2 elements and attributes declared here -->
</xsd:complexType>
<xsd:complexType name = "Tag3Type">
<!-- tag3 elements and attributes declared here -->
</xsd:complexType>
Akerkar: Foundations of © Narosa Publishing House, 2009 29
Semantic Web.
- 30. XML Schema
• A default value (content) may also be
specified:
<xsd:element name = "tag" type = "TYPE"
minOccurs = "N"
maxOccurs = "M"
default = "J"/>
where:
0 <= N <= M <= "unbounded"
Akerkar: Foundations of © Narosa Publishing House, 2009 30
Semantic Web.
- 31. Example 2.9
<review id="100">
<!-- movies.xml -->
<movie-id>1</movie-id>
<?xml version="1.0"?>
<stars>5</stars>
<!DOCTYPE movies SYSTEM "movies.dtd">
<comment>You can't call
<movies>
yourself a geek
<movie id="1">
unless you've seen this
<title>The Matrix</title>
<b>amazing</b>
</movie>
movie.</comment>
<movie id="2">
</review>
<title>The Matrix: Reloaded</title>
<review id="101">
</movie>
<movie-id>1</movie-id>
</movies>
<stars>3</stars>
<!-- movie-reviews.xml -->
<comment><a href=
<?xml version="1.0"?>
<!DOCTYPE reviews SYSTEM "reviews.dtd">
"http://www.keanunet.com">Kean
<reviews>
u</a>
can act!</comment>
</review>
</reviews>
Akerkar: Foundations of © Narosa Publishing House, 2009 31
Semantic Web.
- 32. XPath
Root Node
Element Node
Element Node
Content Node Attribute Node Attribute Node Attribute Node Attribute Node
Akerkar: Foundations of © Narosa Publishing House, 2009 32
Semantic Web.
- 33. Path Expression
Consider the XML document library.xml:
<library location =”Kolhapur”>
<author name=”R. Akerkar”>
<book title=”Artificial Intelligence”>
<book title=”Building an Intelligent Web”>
<book title=”Discrete Mathematics”>
</author>
<author name=”P. Winston”>
<book title=”Artificial Intelligence”>
</author>
<author name=”V. Rajaraman”>
<book title=”Information Technology”>
<book title=”Supercomputing”>
Akerkar: Foundations of © Narosa Publishing House, 2009 33
Semantic Web.
- 34. Path Expression
V.
author @name
Rajaraman
Information
book @title
Technology
book Supercomp
@title
uting
author @name
P. Winston
Artificial
book @title
Intelligence
root library
@name R. Akerkar
Discrete
author book @title
Mathematics
Building an
book @title Intelligent
Web
Artificial
book @title
Intelligence
@location Kolhapur
Akerkar: Foundations of © Narosa Publishing House, 2009 34
Semantic Web.
- 37. XQuery
• Example 2.10: This example searches the
books.xml document and returns every
chapter node's title child value.
document("books.xml")//chapter/title
• Example 2.11: Generates a new element
<report> for each value for title.
<report>
{$b/title}
</report>
Akerkar: Foundations of © Narosa Publishing House, 2009 37
Semantic Web.
- 38. Example 2.12
• Perform a simple search that returns all books
published by Narosa Publishers after 1998,
inclusive of each book year and title.
<bib>
{
for $b in doc("http://book.sample.org/bib.xml")/bib/book
where $b/publisher = "Narosa Publishers" and $b/@year >
1998
return
<book year="{$b/@year}">
{$b/title}
</book>
}
</bib>
Akerkar: Foundations of © Narosa Publishing House, 2009 38
Semantic Web.
- 39. Example 2.12
• The result follows:
<bib>
<book year="1999">
<title>Nonlinear Functional Analysis</title>
</book>
…
…
…
<book year="2008">
<title>Foundations of Semantic Web</title>
</book>
</bib>
Akerkar: Foundations of © Narosa Publishing House, 2009 39
Semantic Web.
- 40. Example 2.13
• Let us use the function min() to determine the
minimum price for each book.
– We generate the <minprice> element, with the book
title as its attribute.
<results>
{
let $doc := doc("prices.xml")
for $t in distinct-values($doc//book/title)
let $p := $doc//book[title = $t]/price
return
<minprice title="{$t}">
<price>{min($p)}</price>
</minprice>
}
</results>
Akerkar: Foundations of © Narosa Publishing House, 2009 40
Semantic Web.
- 41. Suggested Readings
1. R. Akerkar and P. Lingras. Building an Intelligent Web: Theory & Practice.
Johns & Bartlett, 2008.
2. P. V. Biron, A. Malhotra (eds.): XML Schema Part 2: Datatypes, W3C
Working Draft 07 April 2000, http://www.w3.org/TR/2000/WD-xmlschema-
2-20000407/.
3. T. Bray, J. Paoli, and C.M. Sperberg-McQueen (eds.): Extensible Markup
Language (XML) 1.0, W3C Recommendation 10-February-1998,
http://www.w3.org/TR/REC-xml.
4. T. Bray, D. Hollander, and A. Layman (eds.): Namespaces in XML, World
Wide Web Consortium Recommendation, 14-January-1999,
http://www.w3.org/TR/REC-xml-names/.
5. J. Clark (ed): XSL Transformations (XSLT), W3C Recommandation 16
November 1999, http://www.w3.org/TR/xslt.
6. J. Davidson: Java API for XML Parsing, Version 1.0 Final Release,
http://java.sun.com/aboutJava/communityprocess/final/jsr005/index.html.
7. XQuery1.0: An XML Query Language, http://www.w3.org/TR/xquery/
8. XML Query Use Cases, http://www.w3.org/TR/xmlquery-use-cases
9. What is XQuery: Katz, 2004. http://www.gnu.org/software/qexo/XQuery-
Intro.html.
Akerkar: Foundations of © Narosa Publishing House, 2009 41
Semantic Web.