) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument •...

24
MDK: Modern Database Concepts hƩp://www.ksi.mff.cuni.cz/~svoboda/courses/192-MDK/ PracƟcal Class 1 Formats MarƟn Svoboda [email protected]ff.cuni.cz 3. 4. 2020 Charles University, Faculty of MathemaƟcs and Physics OTH Regensburg, Faculty of Computer Science and MathemaƟcs

Transcript of ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument •...

Page 1: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 2: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

XML

Page 3: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 4: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 5: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 6: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 7: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 8: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 9: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 10: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

JSON

Page 11: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 12: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 13: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 14: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 15: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 16: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

RDF

Page 17: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 18: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 19: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 20: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 21: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 22: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 23: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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

Page 24: ) - Version 2svoboda/courses/192-MDK/...Exercise2 ExtendthepreviousXMLdocument • Adddataaboutoneparcular user Id:u121 Name:Peter Age:35 Email:peter@friends.cz • Useaributesforidandage,useelementsotherwise

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