) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument •...
Transcript of ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument •...
MDK:Modern Database Conceptsh p://www.ksi.mff.cuni.cz/~svoboda/courses/192-MDK/
Prac cal Class 1
FormatsMar n [email protected]
3. 4. 2020
Charles University, Faculty of Mathema cs and PhysicsOTH Regensburg, Faculty of Computer Science and Mathema cs
XML
Sample XML Document
<?xml version="1.1" encoding="UTF-8"?><movie year="2007">
<title>Medvídek</title><actors>
<actor><firstname>Jiří</firstname><lastname>Macháček</lastname>
</actor><actor>
<firstname>Ivan</firstname><lastname>Trojan</lastname>
</actor></actors><director>
<firstname>Jan</firstname><lastname>Hřebejk</lastname>
</director></movie>
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 3
Exercise 1Create a new XML document for data of a simple social network
• Use, e.g., the following editor and validatorh ps://codebeau fy.org/xmlvalidator
• Add the following basic constructsXML prologueRoot element friendsIts only empty element users
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 4
Exercise 2Extend the previous XML document
• Add data about one par cular userId: u121Name: PeterAge: 35Email: [email protected]
• Use a ributes for id and age, use elements otherwise
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 5
Exercise 3Extend the previous XML document
• Add data about two addi onal usersId u654, name Rachel, 25 yearsId u357, name John, 30 years,email addresses [email protected] [email protected],phone number +420 777 555 111
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 6
Exercise 4Extend the previous XML document
• Create groups element a er the exis ng users element• Add data about the following two groups
Id g11, name PhotographersId g24, name Librarians
• Note that groups can be recursively nested into each other• Add the following group as a sub-group of group g11
Id g15, name Landscape Photographers
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 7
Exercise 5Extend the previous XML document
• Add friend rela onships between individual usersUser u654 knows users u121 and u357User u357 knows user u987
• Addmember rela onships between groups and usersGroup g15 contains users u121 and u357Group g24 contains user u121
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 8
Exercise 6Extend the previous XML document
• Create posts element a er the exis ng groups element• Add the following posts published by user u121
Id p530035, date me 2018-10-08 09:30:00,tle New trends in libraries
Id p530045, date me 2018-10-08 09:45:00,tle Great photos of my family
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 9
JSON
Sample JSON Document
{"title" : "Medvídek","year" : 2007,"actors" : [
{"firstname" : "Jiří","lastname" : "Macháček"
},{
"firstname" : "Ivan","lastname" : "Trojan"
}],"director" : {
"firstname" : "Jan","lastname" : "Hřebejk"
}}
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 11
Exercise 7Create a new JSON document for data of our social network
• Use, e.g., the following editor and validatorh ps://codebeau fy.org/jsonvalidator
• Add the following proper es of the main objectusers, groups, and postsAssociate all of them with empty values (null)
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 12
Exercise 8Extend the previous JSON document
• Add data about our three usersId: u121, name Peter, age 35,email address [email protected] u654, name Rachel, 25 yearsId u357, name John, 30 years,email addresses [email protected] [email protected],phone number +420 777 555 111
• Also add all friendshipsUser u654 knows users u121 and u357User u357 knows user u987
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 13
Exercise 9Extend the previous JSON document
• Add data about the following groupsId g11, name PhotographersId g15, sub-group of g11, name Landscape PhotographersId g24, name Librarians
• Also add all membershipsGroup g15 contains users u121 and u357Group g24 contains user u121
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 14
Exercise 10Extend the previous JSON document
• Add the following posts published by user u121Id p530035, date me 2018-10-08 09:30:00,tle New trends in libraries
Id p530045, date me 2018-10-08 09:45:00,tle Great photos of my family
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 15
RDF
Sample RDF Document
<http://db.cz/movies/medvidek><http://db.cz/terms#actor> <http://db.cz/actors/machacek> .
<http://db.cz/movies/medvidek><http://db.cz/terms#actor> <http://db.cz/actors/trojan> .
<http://db.cz/movies/medvidek><http://db.cz/terms#year> "2007" .
<http://db.cz/movies/medvidek><http://db.cz/terms#director> _:n18 .
_:n18<http://db.cz/terms#firstname> "Jan" .
_:n18<http://db.cz/terms#lastname> "Hřebejk" .
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 17
Exercise 11Create a new RDF document for our data
• Use, e.g., the following editor and validatorh p:// l.summerofcode.be/
• Add statements about the following userName Peter, age 35, email [email protected] http://www.friends.cz/users/u121as an IRI iden fier for this userAssume all proper es (e.g. name, …) belong to a prefixhttp://www.friends.cz/schema#Also add an RDF type descrip on, i.e. associate our user withhttp://www.friends.cz/schema#User using propertyhttp://www.w3.org/1999/02/22-rdf-syntax-ns#type
• Only use full triples and IRI iden fiers
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 18
Exercise 12Modify the previous RDF document
• Define and use prefix declara ons provided by Turtlerdf forhttp://www.w3.org/1999/02/22-rdf-syntax-ns#schema for http://www.friends.cz/schema#user for http://www.friends.cz/users/
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 19
Exercise 13Extend the previous RDF document
• Add data about the following usersId u654, name Rachel, 25 yearsId u357, name John, 30 years,email addresses [email protected] [email protected],phone number +420 777 555 111
• Include rdf:type statements as well
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 20
Exercise 14Modify the previous RDF document
• Compact all your statements using object andpredicate-object lists
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 21
Exercise 15Extend the previous RDF document
• Add data about the following groupsId g11, name PhotographersId g15, sub-group of g11, name Landscape PhotographersId g24, name Librarians
• Use the following prefix for groupshttp://www.friends.cz/groups/
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 22
Exercise 16Extend the previous RDF document
• Add the following friendshipsUser u654 knows users u121 and u357User u357 knows user u987
• Also add the following membershipsGroup g15 contains users u121 and u357Group g24 contains user u121
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 23
Exercise 17Extend the previous RDF document
• Add the following posts published by user u121Id p530035, date me 2018-10-08 09:30:00,tle New trends in libraries
Id p530045, date me 2018-10-08 09:45:00,tle Great photos of my family
• Represent both the post as blank nodesUse _:… approach for the first oneUse [ … ] Turtle shortcut for the second one
MDK: Modern Database Concepts | Prac cal Class 1: Formats | 3. 4. 2020 24