Download presentation
Presentation is loading. Please wait.
1
Data Modeling and Database Design
INF1343, Winter 2011 Data Modeling and Database Design Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution License, v To view a copy of this license, visit This presentation incorporates images from the Crystal Clear icon collection by Everaldo Coelho, available under LGPL from
2
Week 8 Relational Databases and Documents
3
(See handout on the website.)
Assignment 2 (See handout on the website.)
4
PHPMyAdmin
5
(See last week's slides.)
Web UI to MySQL (See last week's slides.)
6
Onto this week's topic: Documents
7
http://upload. wikimedia
pg
9
Digital can be digitally signed name: Barack Hussein Obama II
date_of_birth: August 4, 1961 sex: male location: Honolulu mother: Stanley Ann Dunham father: Barack Hussein Obama hour_of_birth: 7:24 pm ... can be digitally signed
10
Full Text Search Can be useful. SQL support is coming.
Matching sub-strings Can be done with LIKE Bag-of-words search Like doing LIKE for every term – very slow without a proper index! Natural language search Stop words (“the”, “of”, “to”, “end”) Stemming (“monkey” vs “monkeys”) Synonyms (“monkey” vs “simian” vs “Affe”) Ranking “tf-idf”, “Okapi BM25”, probabilistic models Can be useful. SQL support is coming.
11
http://commons.wikimedia.org/wiki/File:Invoice- Esso.jpg
12
order invoice payment Alice Bob
13
order payment Alice Bob invoice (HTML)
14
Alice Bob
15
machine-readable documents
Alice Bob order invoice payment machine-readable documents
16
XML <?xml version="1.0" encoding="UTF-8"?> <Invoice>
<ID> </ID> <IssueDate> </IssueDate> <Buyer> <Name>Bills Microdevices</Name> <StreetName>Spring St.</StreetName> <BuildingNumber>413</BuildingNumber> <CityName>Elgin</CityName> <PostalZone>60123</PostalZone> <CountrySubentityCode>IL</CountrySubentityCode> </Buyer> <Seller> <Name>Joes Office Supply</Name> <StreetName>Lakeshore Dr</StreetName> <BuildingNumber>32 W.</BuildingNumber> <CityName>Chicago</CityName> <PostalZone>60022</PostalZone> </Seller> Example.xml
17
XML <Total> <TotalAmount amountCurrencyID="USD">479.50</TotalAmount> <TaxExclusive amountCurrencyID="USD">479.50</TaxExclusive> <TaxInclusive amountCurrencyID="USD">527.45</TaxInclusive> </Total> <InvoiceLine> <ID>1</ID> <InvoicedQuantity unitCode="PKG">5</InvoicedQuantity> <Amount amountCurrencyID="USD">12.50</Amount> <Item> <Description>Pencils, box #2 red</Description> <SellersItemIdentification> <ID> </ID> </SellersItemIdentification> <BasePrice> <PriceAmount amountCurrencyID="USD">2.50</PriceAmount> </BasePrice> </Item> </InvoiceLine> ...
18
XML Anatomy <InvoiceLine> <ID>1</ID>
<InvoicedQuantity unitCode="PKG">5</InvoicedQuantity> <Amount amountCurrencyID="USD">12.50</Amount> <Item> <Description>Pencils, box #2 red</Description> <SellersItemIdentification> <ID> </ID> </SellersItemIdentification> <BasePrice> <PriceAmount amountCurrencyID="USD">2.50</PriceAmount> </BasePrice> </Item> </InvoiceLine>
19
XML Anatomy <InvoiceLine> <ID>1</ID>
<InvoicedQuantity unitCode="PKG">5</InvoicedQuantity> <Amount amountCurrencyID="USD">12.50</Amount> <Item> <Description>Pencils, box #2 red</Description> <SellersItemIdentification> <ID> </ID> </SellersItemIdentification> <BasePrice> <PriceAmount amountCurrencyID="USD">2.50</PriceAmount> </BasePrice> </Item> </InvoiceLine>
20
Validation Syntactic: form Semantic: meaning
<Amount amountCurrencyID="USD">12.50</Amount Semantic: meaning <Amount amountCurrencyID="USD">Male</Amount>
21
Namespaces <?xml version="1.0" encoding="UTF-8"?>
<Invoice xmlns:cbc="urn:oasis:names:specification:ubl:sc..."> <ID> </ID> <cbc:IssueDate> </cbc:IssueDate> <TaxPointDate> </TaxPointDate> <cac:OrderReference> <cac:BuyersID> </cac:BuyersID> <cac:SellersID> </cac:SellersID> <cbc:IssueDate> </cbc:IssueDate> </cac:OrderReference> <cac:BuyerParty> <cac:Party> <cac:PartyName> <cbc:Name>Bills Microdevices</cbc:Name> </cac:PartyName> <cac:Address> <cbc:StreetName>Spring St.</cbc:StreetName> <cbc:BuildingNumber>413</cbc:BuildingNumber> <cbc:CityName>Elgin</cbc:CityName> <cbc:PostalZone>60123</cbc:PostalZone> <cac:CountrySubentityCode>IL</cac:CountrySubentityCode> </cac:Address> </cac:Party> </cac:BuyerParty>
22
XML and RDBMS Externalization: export, import, messaging Internal use:
XML storage and retrieval (less common for now)
23
Alice Bob HTML application software (e.g., using PHP) database
24
Alice Bob database application software (e.g., using PHP) HTTP request
HTML HTML application software (e.g., using PHP) SQL database
25
Alice Bob database application software (e.g., using PHP) HTTP request
HTML HTML application software (e.g., using PHP) SQL database
26
Alice Bob database application software (e.g., using PHP) HTTP request
XML HTML application software (e.g., using PHP) SQL database
27
Alice Inc. Bob database application software (e.g., using PHP)
HTTP request HTTP request XML HTML application software (e.g., using PHP) SQL “Web services”, “APIs”, “REST”, “Semantic web,” “Service-oriented architecture” database
28
Examples Twitter: http://twitter.com/public_timeline vs.
34
Examples Yahoo! Geocoding API:
. %2C+Mississauga%2C+ON vs. appid=YD- 9G7bey8_JXxQP6rxl.fBFGgCdNjoDMACQA-- &street=3359+Mississauga+Rd+N&city=Mississauga &state=ON&country=Canada
36
<?xml version="1.0"?> <ResultSet xmlns:xsi=" xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps precision="address" warning="The exact location could not be found, here is the closest match: 3359 Mississauga Rd, Mississauga, ON L5L"><Latitude> </Latitude><Longitude> </Longitude><Address>3359 Mississauga Rd</Address><City>Mississauga</City><State>ON</State><Zip>L5L</Zip><Country>CA</Country></Result></ResultSet> <!-- ws05.ydn.ac4.yahoo.com compressed/chunked Tue Oct 26 09:20:09 PDT >
37
<?xml version="1.0"?> <ResultSet> <Result precision="address" warning="The exact location could not be found..."> <Latitude> </Latitude> <Longitude> </Longitude> <Address>3359 Mississauga Rd</Address> <City>Mississauga</City> <State>ON</State> <Zip>L5L</Zip> <Country>CA</Country> </Result> </ResultSet>
38
Examples Geonames Web Service
north=45&south=42&east=-78&west=-82
39
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<geonames> <entry> <lang>en</lang> <title>Toronto</title> <summary>Toronto (, local pronunciation ) is the largest city in Canada[ Canada], Greenwich Mean Time. Retrieved on and is the provincial capital of Ontario. It is located on the northwestern shore of Lake Ontario.[ Toronto, Ontario, Canada, North America] Retrieved on With over 2 (...)</summary> <feature/> <countryCode> </countryCode> <population>0</population> <elevation>0</elevation> <lat>43.65</lat> <lng> </lng> <wikipediaUrl> <thumbnailImg>
40
Alternatives JSON http://ws.geonames.org/wikipediaBoundingBoxJSON?
formatted=true&north=45&south=42 &east=-78&west=-82
41
{"geonames": [ { "summary": "Toronto (, local pronunciation ) is the largest city in Canada[ Canada], Greenwich Mean Time. Retrieved on and is the provincial capital of Ontario. It is located on the northwestern shore of Lake Ontario.[ Toronto, Ontario, Canada, North America] Retrieved on With over 2 (...)", "title": "Toronto", "wikipediaUrl": "en.wikipedia.org/wiki/Toronto", "elevation": 0, "countryCode": " ", "lng": , "feature": "", "thumbnailImg": " "lang": "en", "lat": 43.65, "population": 0 },
42
Examples Yahoo! Geocoding API:
. %2C+Mississauga%2C+ON vs. appid=YD- 9G7bey8_JXxQP6rxl.fBFGgCdNjoDMACQA-- &street=3359+Mississauga+Rd+N&city=Mississauga &state=ON&country=Canada
43
JSON [{"place":null,"geo":null,"truncated":false,"in_reply_to_status_id_str":null,"in_reply_to_status_id":null,"favorited":false,"in_reply_to_user_id_str":null,"source":"web","contributors":null,"in_reply_to_screen_name":null,"created_at":"Tue Oct 26 16:01: ","retweet_count":null,"in_reply_to_user_id":null,"user":{"statuses_count":1491,"description":"grafia","show_all_inline_media":false,"profile_use_background_image":true,"favourites_count":57,"followers_count":124,"contributors_enabled":false,"notifications":null,"profile_background_color":"0c3bf5","geo_enabled":false,"profile_background_image_url":" Jun 26 03:54: ","profile_link_color":"0fc3ff","location":"Brasil","protected":false,"profile_image_url":"
44
JSON [{"place":null,"geo":null,"truncated":false,"in_reply_to_status_id_str":null,"in_reply_to_status_id":null,"favorited":false,"in_reply_to_user_id_str":null,"source":"web","contributors":null,"in_reply_to_screen_name":null,"created_at":"Tue Oct 26 16:01: ","retweet_count":null,"in_reply_to_user_id":null,"user":{"statuses_count":1491,"description":"grafia","show_all_inline_media":false,"profile_use_background_image":true,"favourites_count":57,"followers_count":124,"contributors_enabled":false,"notifications":null,"profile_background_color":"0c3bf5","geo_enabled":false,"profile_background_image_url":" Jun 26 03:54: ","profile_link_color":"0fc3ff","location":"Brasil","protected":false,"profile_image_url":"
45
More PHPMyAdmin
46
XML <?xml version="1.0" encoding="utf-8" ?> <starwars>
<!-- Table persona --> <persona> <name>Obi-Wan Kenobi</name> <occupation>Jedi Master</occupation> <species>Human</species> <gender>M</gender> <homeworld>Stewjon</homeworld> <size>2</size> </persona> <name>Yoda</name> <size>1</size> <name>Jabba</name> <occupation>crime lord</occupation> <species>Hutt</species> <homeworld>Nal Hutta</homeworld> <size>4</size> <name>Chewbacca</name> <occupation>co-pilot</occupation> <species>Wookiee</species> <homeworld>Kashyyyk</homeworld> <name>Luke Skywalker</name> <occupation>Jedi Knight</occupation> <homeworld>Tatooine</homeworld> <name>Padmé Amidala</name> <occupation>queen</occupation> <gender>F</gender> <homeworld>Naboo</homeworld> <name>Han Solo</name> <occupation>smuggler</occupation> <homeworld>Corellia</homeworld> <name>Jango Fett</name> <occupation>bounty hunter</occupation> <homeworld>Concord Dawn</homeworld> <name>Leia Organa</name> <occupation>princess</occupation> <homeworld>Alderaan</homeworld> <name>Admiral Akbar</name> <occupation>admiral</occupation> <species>Mon Calamari</species> <homeworld>Dac</homeworld> <name>R2-D2</name> <occupation>astromech</occupation> <species>droid</species> <name>C-3PO</name> <occupation>protocol droid</occupation> <homeworld>Affa</homeworld> <name>Jar Jar Binks</name> <occupation>senator</occupation> <species>Gungan</species> <name>Chirpa</name> <occupation>tribal chief</occupation> <species>Ewok</species> <homeworld>Endor</homeworld> <name>Max Rebo</name> <occupation>musician</occupation> <species>Ortolan</species> <homeworld>Orto</homeworld> <name>Droopy McCool</name> <species>Kitonak</species> <name>Sy Snootles</name> <occupation>singer</occupation> <name>Anakin Skywalker</name> <!-- Table species --> <species> <type>humanoid</type> <sentient>1</sentient> <homeworld>Coruscant</homeworld> <lifespan>100</lifespan> </species> <type>furry biped</type>
47
YAML 1: name: Obi-Wan Kenobi occupation: Jedi Master species: Human
gender: M homeworld: Stewjon size: 2 2: name: Yoda size: 1 3: name: Jabba occupation: crime lord species: Hutt homeworld: Nal Hutta size: 4 4: name: Chewbacca occupation: co-pilot species: Wookiee homeworld: Kashyyyk 5: name: Luke Skywalker occupation: Jedi Knight homeworld: Tatooine 6: name: Padmé Amidala occupation: queen gender: F homeworld: Naboo 7: name: Han Solo occupation: smuggler homeworld: Corellia 8: name: Jango Fett occupation: bounty hunter homeworld: Concord Dawn 9: name: Leia Organa occupation: princess homeworld: Alderaan 10: name: Admiral Akbar occupation: admiral species: Mon Calamari homeworld: Dac 11: name: R2-D2 occupation: astromech species: droid 12: name: C-3PO occupation: protocol droid homeworld: Affa 13: name: Jar Jar Binks occupation: senator species: Gungan 14: name: Chirpa occupation: tribal chief species: Ewok homeworld: Endor 15: name: Max Rebo occupation: musician species: Ortolan homeworld: Orto 16: name: Droopy McCool species: Kitonak 17: name: Sy Snootles occupation: singer 18: name: Anakin Skywalker type: humanoid sentient: 1 homeworld: Coruscant lifespan: 100 type: furry biped lifespan: 600 lifespan: 80 type: gastropod homeworld: Varl lifespan: 1000 homeworld: Kirdo III type: pachydermoid biped species: Tusken Raider species: Falumpaset type: large mammal sentient: 0 size: 3 species: Tauntaun type: reptomammal homeworld: Hoth species: Sarlacc size: 100 lifespan: 30000 species: Krayt Dragon type: reptile size: 45 species: Bantha lifespan: 90 species: Wampa world_name: Tatooine region: Outer Rim distance_to_core: 43000 coordinates: R-16 diameter: 11456 percent_water: 1 population: world_name: Coruscant region: Core Worlds distance_to_core: 10000 coordinates: L-9 diameter: 12240 percent_water: 29 population: world_name: Endor coordinates: H-16 diameter: 4900 percent_water: 8 population: world_name: Naboo region: Mid Rim distance_to_core: 34000 coordinates: O-17 diameter: 12120 percent_water: 85 population: world_name: Dac coordinates: U-6 diameter: 11030 percent_water: 90 population: world_name: Kashyyyk distance_to_core: 32000 coordinates: P-9 diameter: 12765 percent_water: 60 population: world_name: Nal Hutta coordinates: S-12 diameter: 12150 population: world_name: Alderaan distance_to_core: 5000 coordinates: M-10 diameter: 12500 world_name: Dagobah distance_to_core: 50200 coordinates: M-19 diameter: 8900 population: 0 world_name: Corellia distance_to_core: 7000 coordinates: M-11 diameter: 11000 percent_water: 75 world_name: Kamino distance_to_core: 70000 coordinates: S-15 diameter: 19270 percent_water: 100 population: world_name: Hoth distance_to_core: 50250 coordinates: K-18 diameter: 7200 world_name: Test
48
SQL Support in RDBMS Direct XML export mysql --xml -e "use starwars; select * from persona;" mysqldump --xml kenobio monkeys Direct XML import LOAD XML command in MySQL 5.5 (to be installed soon). Storing XML as a datatype Available in some systems, but not in MySQL currently. (Meanwhile, you can store XML a BLOB.)
49
Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.