Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web – technologies / weekly exercises Answers (1/1)

Similar presentations


Presentation on theme: "Web – technologies / weekly exercises Answers (1/1)"— Presentation transcript:

1 Web – technologies / weekly exercises Answers (1/1)
<person> <name> <first_name>Alan</first_name> <last_name>Turing></last_name> </name> <profession>computer scientists</profession> <profession>mathematician</profession> <profession>cryptographer</profession> </person>

2 Web – technologies / Weekly exercises Number 1
1. Give an XML-document (by not using attributes), which includes the information that the first name of a person is Alan, his last name is Turing, and his professions are computer scientist, mathematician and cryptographer. Give the tree diagram of the document given in 1. Modify the document given in exercise 1 such that the “first” and “last” are the attributes of the name element

3 Web – technologies / weekly exercises Answers (1/2)
person name profession profession profession computer scientist first_name last-name mathematician cryptographer Alan Turing

4 Web – technologies / weekly exercises Answers (1/3)
<person first_name=“Alan” last_name=“Turing”> <profession>computer scientists</profession> <profession>mathematician</profession> <profession>cryptographer</profession> </person>

5 Web – technologies / Weekly exercises Number 2
Give an XML-document (by not using attributes), which includes the following information: the social security number ( A), the first name of a person is Jack, and his last name is Taylor, his address is composed of postcode (0500), city (Boston) and street (Hamilton street), and his telephone numbers are and 6789. Give the tree diagram of the document given in exercise 1. 3. Give a DTD (Document Type Definition) for the XML-document specified in exercise 1. Give an XML Schema for the information specified in exercise 1. Validate the schema using the validator located at : 5. Give an instance of a the XML Schema specified in exercise 4.

6 Web – technologies / weekly exercises Answers (1/2)
<person> <social_security_number> A</social_security_number> <name> <first_name>Jack</first_name> <last_name>Taylor</last_name> </name> <address> <city>Boston</city> <postcode>0500</postcode> <street>Hamilton Street></street> </address> <telephone_number>12345</telephone_number> </person>

7 Web – technologies / weekly exercises Answers (2/2)
Person name Social_ security- number Telephone_ number Telephone_ number address first_ name last_ name postcode street city 12345 6789 A Boston Hamilton street Jack Taylor

8 Web – technologies / weekly exercises Answers (3/2)
<!ELEMENT person (social_security_number, name address, telephone_number*)> <!ELEMENT social_security_number (#PCDATA)> <!ELEMENT name (first_name, last_name)> <!ELEMENT first_name (#PCDATA)> <!ELEMENT last_name (#PCDATA)> <!ELEMENT address (city, postcode, street)> <!ELEMENT city (#PCDATA)> <!ELEMENT postcode (#PCDATA)> <!ELEMENT street (#PCDATA)> <!ELEMENT telephone_number (#PCDATA)>

9 Web – technologies / weekly exercises Answers (4/2)
<xsd: element name = “person”> <xsd: complexType> <xsd: element name = “ name”> <xsd: element name = “first_name” type = “xsd: string” /> <xsd: element name = “last_name” type = “xsd: string” /> </xsd: complexType> </XSD:element> <xsd: element name = “ address”> <xsd: element name = “city” type = “xsd: string” /> <xsd: element name = “postcode” type = “xsd: integer” /> <xsd: element name = “street” type = “xsd: string” /> <xsd: element name = “telephone_number” type “xsd:string” minoccurs=“1” maxOccurs=“unbounded” /> <xsd: attribute name = “social_security_number” type “xsd:string” />

10 Web – technologies / weekly exercises Answers (5/2)
<person social_security_number = “ A”> <name> <first_name>Jack</first_name> <last_name>Taylor</last_name> </name> <address> <city>Boston</city> <postcode>0500</postcode> <street>Hamilton </Street> </address> <telephone_number>12345</telephone_number> </person>

11 Web – technologies / Weekly exercises Number 3
Give a conceptual schema (using ER-design) about teams, players, and their fans, including For each team, its name, its players, its team captain (one of its players), and the colors of its uniform. For each player, his/her name. For each fan, his/her name, favorite teams, favorite players, and favorite color. Do exercise 1 using UML-design Capture the knowledge, using the graph of N3 notation, of the following English statements: Jack Smith studies at Helsinki University Helsinki University has a web site at Jack is a friend of Elisa Ford Elisa Ford studies at Lappeenranta University of Technology Lappeenranta University of Technology has a website at Elisa Ford has a website at 4. Using UML give a schema for the statements given in exercise 3.

12 Web – technologies / Weekly exercises Answers 3
name name plays Player Team is-captain uniforms- colors favorite- players favorite- teams Color favorite- color Fan color-name name

13 Web – technologies / Weekly exercises Answers 3
Player name plays-in is_captain Team name uniform_colors Fan name favorite color favorite_palyer favorite_teams

14 Web – technologies / Weekly exercises Answers 3
#studies_at #Jack Smith #has-website #Helsinki University #friend-of #studies-at #has-website #Elisa Ford #Lappeenranta University of Technology #has-website

15 Web – technologies / Weekly exercises Answers 3
Person name has-website friend-of studies-at University name has-website

16 Web – technologies / Weekly exercises Number 4
1. Modify the xml file of the slide page 198 and the style sheet presented at pages 201 and 202 such that the final layout would look as follows Project: Trumantruck.com Work Schedule Date Description Taking Truck Body Apart Sandblasting Dismantling Cab Sanding, Priming Hood and Fender Hours 2 3 4

17 Web – technologies / Weekly exercises Answers Number 4
<?xml version=“1.0” encoding=“UTF-8”?> <?xml-stylesheet href=“simple.xsl” type=“text/XSL”?> <project name=Trumantruck.com”> <description>Rebuilding a 1967 Chevy Pickup Truck</description> <schedule> <workday> <date> ></date> <description>Taking Truck Body Apart</description> <hours>2</hours> </workday> <date> ></date> <description>Sandblasting, Dismantling Cab</description> <hours>3</hours> <date> ></date> <description>Sanding, Priming Hood and Fender</description> <hours>4</hours> </schedule> </project>

18 Web – technologies / Weekly exercises Answers Number 4
Answer 4.1 continues <xsl:stylesheet xmln:xsl= <xsl:template match=“/”> <html> <TITLE> Schedule For <xsl:value-of <xsl: value-of select=“/project/description”/> </TITLE> <CENTER> <TABLE border=“1”> <TR> <TD><B>Date</B></TD> <TD><B>Description</B></TD> <TD><B>Hours</B></TD> </TR> <xsl:apply-templates/> </TABLE> </CENTRE> </html> </xsl:template>

19 Web – technologies / Weekly exercises Answers Number 4
Answer 4.1 continues <xsl: template match=“project”> <H1> Project : <xsl: value-of </H1> <HR/> <xsl : apply-template/> <xsl : template match = “schedule”> <H2> Work Schedule</H2> <xsl:apply-templates/> </xsl : template> <xsl : template match = “workday”> <TR> <TD> <xsl : value –of select =“date”/> </TD> <xsl : value -of select=“description”/> <xsl : value -of select=“hours”/> </TR> </xsl : stylesheet>

20 Web – technologies / Weekly exercises Number 5
Give an a taxonomy, which can be used in classifying learning objects of computer science. 2. Give a thesarus that describes information entities such as course, laboratory course, exercise, exam, class room, course course book, laboratory, lecturer and laboratory room. 3. Give a conceptual schema using ER-schema notation that models the entities stated in exercise 2 and their relationships. 4. State using first order predicate logic “everyone who has enrolment of the Java course has a registration on that course”.

21 RDF-exercises

22 RDF-Exercise 1. Give an RDF_description that states the following: Resource http: // is a homepage and it is owned by Jack Taylor. Answer RDF-Excercise 1. <?xml version =”1.0” encoding_”UTF-16”?> <rdf : RDF xmlns : rdf=” xmlns : mydomain = <rdf : Description rdf : about = ” http: // <mydomain : homepage-owner> Jack Taylor </mydomain : homepage-owner> </rdf : Description> </rfd: RDF>

23 RDF-Exercise 2. Give an RDF_description that states the following: Resource http: // is a course named Java-programming and is lectured by Lisa Smith at room T2. Answer RDF-Excercise 2. <?xml version =”1.0” encoding_”UTF-16”?> <rdf : RDF xmlns : rdf=” xmlns : mydomain = <rdf : Description rdf : about = ” http: // <mydomain : course-name> Java-programming </mydomain : course-name> <mydomain : course-lecturer> Lisa Smith </mydomain : course-lecturer> <mydomain : lecture-room> T2 </mydomain : lecture-room> </rdf : Description> </rfd: RDF>

24 RDF-Exercise 3. By using container elemn rdf :Bag, give an RDF_description that states the following: Mary and John owns the car ABC-99 Answer RDF-Excercise 3. <?xml version =”1.0” encoding_”UTF-16”?> <rdf : RDF xmlns : rdf=” xmlns : mydomain = <rdf : Description rdf : about = ” #ABC-99”> <mydomain : owns> <rdf : Bag> <rdf : _li rdf : resource= ”#Mary”/> <rdf : _li rdf : resource= ”#John”/> </mydomain : owns> </rdf : Description> </rfd: RDF>

25 RDF-Exercise 4. By using the ”collection” value of the rdf : parseType attribute give an RDF_description that states the following: Mary and John owns the car ABC-99 Answer RDF-Excercise 4. <?xml version =”1.0” encoding_”UTF-16”?> <rdf : RDF xmlns : rdf=” xmlns : mydomain = <rdf : Description rdf : about = ” #ABC-99”> <mydomain: owns rdf : parseType = ”Collection”> <rdf : Description rdf: about = ”#Mary”/> <rdf : Description rdf: about = ”#John”/> </mydomain : owns> </rdf : Description> </rfd: RDF>

26 RDF Schema-exercises

27 RDFS-Exercise 1. Give a graphical presentation and RDF Schema that describe the following: Professors and assistants are subclasses of teachers. Each techer has a name. Each course has a course_id. Professors lecture courses while assistants suprervise courses. domain Assistant range Course supervises teacher_name subClassOf domain range domain range Teacher lectures course_id Literal subClassOf domain range Professor Literal

28 <rdf : RDF xmlns : rdf=” xmlns : rdfs= <rdfs:Class rdf:ID=”assistant”> <rdfs:comment>The class of assistants.</rdfs:comment> <rdfs:subClassOf rdf:resource=“teacher”/> </rdfs:Class> <rdfs:Class rdf:ID=”professor”> <rdfs:comment>The class of professors.</rdfs:comment> <rdfs:Class rdf:ID=”teacher”> <rdfs:comment>The class of teachers</rdfs:comment> <rdfs:Class rdf:ID=”course”> <rdfs:comment>The class of courses</rdfs:comment>

29 <rdfs:Property rdf:ID=”lectures”>
<rdfs:comment> It relates professors to courses </rdfs:comment> <rdfs:domain rdf:resource=“#professor”/> <rdfs:range rdf:resource=“#course”/> </rdfs:Property> <rdfs:Property rdf:ID=”supervises”> It relates assistants to courses <rdfs:domain rdf:resource=“#assistant”/>

30 <rdfs:Property rdf:ID=”lecturer_name”>
<rdfs:comment> It is a property of teachers and takes literals as values. </rdfs:comment> <rdfs:domain rdf:resource=“#teacher”/> <rdfs:range rdf:resource=“&rdf;Literal”/> </rdfs:Propert> <rdfs:Property rdf:ID=”course_id”> It is a property of courses and takes literals as values. <rdfs:domain rdf:resource=“#course”/> </rdf:RDF>

31 Execise 2. RQL-Exercise . By using RQL and the RDF Schema of the previous exercise give the following queries: Retrieve all the instances of the class Teacher Retrieve aal the inatances of the class Teacher that are iether profwssors or assistanra. Retrieve the names of the assistants. Answers: teacher ^teacher select X, Y from assistant{X} . teacher_name {Y}

32 Execise 3. Discuss the difference vbetween the following statements, and draw graphs to illustrate the difference: X supports the proposal; Y supports the propodsal; Z supports the proposal. The group of X, Y, and Z supports the proposal. Draw graphs to illustrate the difference. supports the proposal X supports the proposal Y supports the proposal Z

33 X belongs belongs supports Y the group the proposal belongs Z

34 Exercise 4. Compare rdfs:subClassOf with type extension in XML Schema

35 Exercise 5. Try to map the relational database model on RDF.

36 Exercise 6. Compare entity-relationship modelling to RDF.

37 Exercise 7.Model part of a library in RDF Schema: books, authors, publishers, years, copies, dates, and so on. Then write some statements in RDF, and query them using RQL. literal Author range year range writtenBy domain domain literal domain Book ISBN range domain range publishedBy publishretName literal range presents domain Publisher Copy domain copyNumber range literal

38 <rdf:RDF xmlns:rdf=“http.w3.org/1999/02/22-rdf-syntax-ns#” xmlns:rdfs=“http.w3.org/2000/01/rdf-schema#”> <rdfs:Class rdf:ID=”book”> <rdfs:comment>The class of books</rdfs:comment> </rdfs:Class> <rdfs:Class rdf:ID=”publisher”> <rdfs:comment>The class of publishers</rdfs:comment> <rdfs:Property rdf:ID=”publishedBy”> <rdfs:comment> It relates books to publishers </rdfs:comment> <rdfs:domain rdf:resource=“#book”/> <rdfs:range rdf:resource=“#publisher”/> </rdfs:Property>

39 <rdfs:Property rdf:ID=”ISBN”>
<rdfs:comment> It is a property of books and takes literals as values. </rdfs:comment> <rdfs:domain rdf:resource=“#book”/> <rdfs:range rdf:resource=“&rdf;Literal”/> </rdfs:Propert> </rdf:RDF>

40 RDF-satatements <mydomain: book rdf:ID=”12345”
mydomain: ISBN = ”abc567”> <mydomain: publishedBy rdf:resource=”#Prenticee_Hall”/> <mydomain: writternBy rdf:resourcre= ”#Jack_Smith”/> </mydomain:book> The same RDF-description by not using abbreviated syntax <rdf: Description rdf: ID=”12345”> <rdf : type rdf : resource=”&mydomain ; book”/> <mydomain : ISBN> abc567 </mydomain : ISBN> </rdf : Description>

41 a) Retrieve all the instances of the book class? Anwer: book
Queries: a) Retrieve all the instances of the book class? Anwer: book b) Retrieve all books and their ISBN:s: Answer: select X, Y from book {X} . ISBN {y} Retrieve all the ISBN:s of the books published by Prentice-Hall Answer: select N from book {X} . publishedBy {Y}, {C} ISBN {N} where Y= ”Prentice-Hall” and X=C

42 Exercise 8. Write an ontology about geography: cities, countries, capitals, borders, states, and so on. domain domain countryName country border range range range range literal belongs isPartOf domain domain state city locates isSubClassOff capital

43 <rdf:RDF xmlns:rdf=“http.w3.org/1999/02/22-rdf-syntax-ns#” xmlns:rdfs=“http.w3.org/2000/01/rdf-schema#”> <rdfs:Class rdf:ID=”country”> <rdfs:comment>The class of countries</rdfs:comment> </rdfs:Class> <rdfs:Class rdf:ID=”city”> <rdfs:comment>The class of cities</rdfs:comment> <rdfs:Class rdf:ID=”state”> <rdfs:comment>The class of states</rdfs:comment> <rdfs:Property rdf:ID=”belongs”> <rdfs:comment> It relates cities to countries </rdfs:comment> <rdfs:domain rdf:resource=“#city”/> <rdfs:range rdf:resource=“#country”/> </rdfs:Property>

44 <rdfs:Property rdf:ID=”locates”>
<rdfs:comment> It relates cities to states </rdfs:comment> <rdfs:domain rdf:resource=“#city”/> <rdfs:range rdf:resource=“#state”/> </rdfs:Property> <rdfs:Property rdf:ID=”isPartOf”> It relates states to countries <rdfs:domain rdf:resource=“#state”/> <rdfs:range rdf:resource=“#country”/> <rdfs:Class rdf:ID=”capital”> The class of capitals <rdfs:subClassOf rdf:resource=“city”/> </rdfs:Class>

45 <rdfs:Property rdf:ID=”border”>
<rdfs:comment> It relates bordersto countries </rdfs:comment> <rdfs:domain rdf:resource=“#country”/> <rdfs:range rdf:resource=“#country”/> </rdfs:Property> <rdfs:Property rdf:ID=”countryName”> It is a property of countries and takes literals as values. <rdfs:range rdf:resource=“&rdf;Literal”/> </rdfs:Propert> </rdf:RDF>

46 Exercise 9. Consider the classes of males and females
Exercise 9. Consider the classes of males and females. Name a relationship between them that should be included in an ontology. Answer: relationship husbendOf; inverse wifeOf

47 Exercise 10. Consider the classes of persons, males and females
Exercise 10. Consider the classes of persons, males and females. Name a relationship between all the three that should be included in an ontology. Which part of this relationship can be expressed in RDF Schema. Answer. Husband, Wife, Mother, Father

48 Exercise 11. Suppose we declare Bob and Peter to be the father of Mary
Exercise 11. Suppose we declare Bob and Peter to be the father of Mary. Obviously there is a semantic error here. How should the semantic model make this error impossible? Answer: by a cardinality restriction.

49 Exercise 12. What relationship exist between ”is child of” and ”is parent of” ?
Answer: inverse relationship

50 Exercise 13. Consider the property eats with domain animal and range animal or plant. Suppose we define a new class vegetarian. Name a desirable restriction on eats for this class. Do you think that this restriction can be expressed in RDF Schema by using rdfs : range ? Answer: Specifying a subclass by restrictiong the range of a property is outside the expression power of RDF Schema. In particular, rdfs : range defines the range, e.g., eats, for all classes.

51 OWL-exercises

52 OWL-Exercise 1. Give an OWL-ontology that describes the following:
There are courses and laboratory courses. Homeworks are part of courses. Courses are organized by teachers. Teachers are either professors or assistants. Professors teach courses while assistants only teach laboratory courses. organize teacher course teach subClassOf subClassOf isPartOf subClassOf professor assistant laboratory-course homework teach

53 <rdf:RDF xmlns:rdf= xmlns:rdfs= xmlns:owl= <owl:Ontology rdf:about=“”/> <owl:Class rdf:ID=“course”> <rdfs:comment>Courses form a class.</rdfs:comment> </owl:Class> <owl:Class rdf:ID=“laboratoryCourse”> <rdfs:comment>Laboratory course is a type of course.</rdfs:comment> <rdfs:subClassOf rdf:resource=“#course”/> <owl:Class rdf:ID=“homework”> <rdfs:subClassOf> <owl:Restriction> <owl:onProperty rdf:resoyrce=“#is_part_of”/> <owl:allValuesFrom rdf:resource=“#course”/> </owl:Restriction> </rdfs:subClassOf>

54 <owl:Class rdf:ID=“teacher”>
<rdfs:comment>Teachers form a class.</rdfs:comment> </owl:Class> <owl:Class rdf:ID=“assistant”> <rdfs:comment>Assistants are exactly those teachers that teach laboratory courses.</rdfs:comment> <owl:intersectionOf rdf:parseType=“Collection”> <owl:Class rdf:about=“#teacher”/> <owl:Restriction> <owl:onProperty rdf:resoyrce=“#teach”/> <owl:allValuesFrom rdf:resorce=“#laboratoryCourse”/> </owl:Restriction> </owl:intersectionOf >

55 <owl:Class rdf:ID=“professor”>
<rdfs:comment>Professors are exactly those teachers that teach laboratory courses.</rdfs:comment> <owl:intersectionOf rdf:parseType=“Collection”> <owl:Class rdf:about=“#teacher”/> <owl:Restriction> <owl:onProperty rdf:resoyrce=“#teach”/> <owl:someValuesFrom rdf:resorce=“#course”/> </owl:Restriction> </owl:intersectionOf > </owl:Class> <owl:TransitiveProperty rdf:ID=“is_part_of”/> <owl:ObjectProperty rdf:ID=“teachs”> <rdfs:domain rdf:resource=“#teacher”/> </owl:ObjectProperty> </rdf:RDF>

56 OWL-Exercise 2. Give an OWL-ontology that describes the following:
a) Medicinal products are either over the counter drugs or prescription based drugs. Each medicinal product includes an active substance. In addition each medicinal product is substitutable by zero or more medicinal products. b) Panadol is an instance of over the counter drug, Tramadol is an instance of prescription based drug, and Loperamide is an instance of active substance.

57 Answer a) <rdf:RDF xmlns:rdf= xmlns:rdfs= xmlns:owl= <owl:Ontology rdf:about=“”/> <owl:Class rdf:ID=“medicinalProduct”> <rdfs:comment>Medicinal products form a class.</rdfs:comment> </owl:Class> <owl:Class rdf:ID=“overTheCounterDrug”> <rdfs:subClassOf rdf:resource=“#medicinalProduct”/> <owl : disjointWith rdf : resource= ”#prescriptionBasedDrug”/> <owl:Class rdf:ID=“prescriptionBasedDrug”> <owl : disjointWith rdf : resource= ”#overTheCounterDrug”/> <owl:Class rdf:ID=“activeSubstance”> <owl : disjointWith rdf : resource= ”#medicinalProduct”/>

58 <owl:ObjectProperty rdf:ID=“includes”>
<rdfs:domain rdf:resource=“#medicinalProduct”/> <rdfs:range rdf:resource=“#activeSubstance”/> </owl:ObjectProperty> <owl:TransitiveProperty rdf:ID=“substitutes”> <rdfs:range rdf:resource=“#medicinalProduct”/> </rdf:RDF

59 Answer b) <rdf Description rdf : ID=”Panadol”/> <rdf : type rdf : resource= ”#overTheCounterDrug”/> </rdf : Description> <rdf Description rdf : ID=”Tramadoldol”/> <rdf : type rdf : resource= ”#prescriptionBasedDrug”/> <rdf Description rdf : ID=”Lopermide”/> <rdf : type rdf : resource= ”# activeSubstance”/>


Download ppt "Web – technologies / weekly exercises Answers (1/1)"

Similar presentations


Ads by Google