====== Modeling and using knowledge in RDF ====== ^ Last verification: | 20180912 | ^ Tools required for this lab: | -- | ===== Before the lab ===== Reading: * [[http://www.w3.org/TR/rdf-schema/|RDF Schema 1.1]] * [[#if_you_want_to_know_more|If you want to know more...]] ===== Lab instructions ===== During this lab we will use [[http://any23.org/|Anything to Triples]] website. If it is down, there is also a possibility to download any23 service and run it on your own computer: * download **Apache Any23 Service (Standalone server embedded) 1.1** file from https://any23.apache.org/download.html (mirror: {{http://krzysztof.kutt.pl/didactics/semweb/apache-any23-service-1.1-server-embedded.tar.gz|apache-any23-service-1.1-server-embedded.tar.gz}}) and unpack the zip somewhere * execute command to start server with any23 service: [PATH-to-unpacked-archive]/apache-any23-service-1.1-server-embedded/bin/any23server * Note: use the any23server.bat file if you are using Windows OS * Change ''"$REPO"'' into ''%REPO%'' twice (line #79 in any23server.bat file) if ''Error: Unable to access jarfile $REPO/jetty-runner-8.1.4.v20120524.jar.'' message appears * after few seconds any23 service will appear on [[http://localhost:8080/apache-any23-service/]] address :) During this lab, you will serialize (using Turtle syntax) an RDF graph created before (The Bold and the Beautiful vs The Game of Thrones). ==== - Modeling knowledge with RDF triples [20 minutes] ==== RDF is a data model for which several syntaxes have been developed. RDF document is an RDF graph (describing some objects) serialized into chosen representation/syntax. In this task, you will convert the graph representation into so called Turtle syntax. - Create a new document with a ''*.ttl'' extension. - Create a document describing the graph created during the [[lab-rdfmodel#modeling_knowledge_with_rdf_graphs_25_minutes|previous lab]]. Use the [[http://www.w3.org/TR/turtle/|RDF Turtle]] for reference. - Define namespaces for your document URIs, e.g., a standard RDF namespace and one "your own" for this specific topic: @prefix rdf: . @prefix bb: . * You can also use a base namespace: @base . - Write down ~14 selected triples from your graph. Make sure you include each of the following at least once: - resources, - datatype values. - Notes: * Comments in Turtle begins with ''#'' symbol. * In RDF we are describing something (a subject) and giving it a unique ID, e.g.: ''''. To make notation more compact, we can use [[http://www.w3.org/TR/turtle/#prefixed-name|prefixes]] and/or [[http://www.w3.org/TR/turtle/#relative-iri|base namespace]]. * 8-) To separate statements we can use dot (.), semicolon (;) and comma (,). What is the difference between them? - Go to the [[http://any23.org/|Anything to Triples]] webpage: * Validate your document using this tool (section "Convert copy&pasted document"): * input format: **Turtle (text/turtle)** * output format: **turtle** * validation: **validate** * report: **checked** * annotate: **unchecked** * paste your code and click "Convert" button * if something is wrong, you can see details in report (in web browser), e.g.: \\ {{:pl:dydaktyka:semweb:any23_some_problems_web.png?400|}} * if code was successfully validated then you get an XML with a lot of empty tags and your Turtle code inside '''' (indentation may be changed) - 8-) Include model (''.ttl'' file) in the report archive. ==== - RDF: Containers and Collections [10 minutes] ==== In RDF there are two ways to describe set or sequences of objects: //[[http://www.w3.org/TR/rdf11-mt/#rdf-containers|Containters]]// and //[[http://www.w3.org/TR/rdf11-mt/#rdf-collections|Collections]]//. The container and collection are resources that contain things. The contained things are members. RDF defines three types of containers: * ''rdf:Bag'', * ''rdf:Seq'', * ''rdf:Alt'', and one type of collection: * ''rdf:List''. While "a //container// only says that certain identified resources are members; it does not say that other members do not exist." with a //Collection// we can describe groups containing __only__ the specified members. [[http://www.w3.org/TR/rdf11-mt/#rdf-containers|Read about them]] and then: - 8-) Describe shortly what is the difference between different types of containers. - Create a container in your database. - In your RDF file create also an //RDF Collection//. For hint and examples see the [[http://www.w3.org/TR/turtle/#collections|recommendation]]. ==== - RDF: Datatypes [10 minutes] ==== Add the references to [[http://www.w3.org/TR/xmlschema-2/|XML Schema datatypes]] to chosen information in your RDF file, e.g.: # ... @prefix xsd: . # ... # ... ; "1900-01-01"^^xsd:date; "Chemistry"^^xsd:string; # ... Use at least 3 different datatypes! ==== - RDF Visualization [3 minutes] ==== We are in the middle, so let's visualize our RDF files. - There are two ways to do this: - Using [[http://any23.org/|Anything to Triples]] service convert your file to RDF/XML (''rdfxml'') format. Do not analyze resulting code. Simply copy it :) \\ Go to the [[http://www.w3.org/RDF/Validator/|RDF Validator]] page and simply paste generated code into ''Check by Direct Input'' field. Select ''Graph only'' from dropdown list and click ''Parse RDF'' - Use the [[http://loki.ia.agh.edu.pl/wiki/docs:rdfeditor|RDF Editor]] developed at AGH UST (by Artur SmaroĊ„, EIS 2015-2016) - Analyze the results: - 8-) How containers are represented in the graph? - 8-) How collections are represented in the graph? ==== - Semantic vocabularies: FOAF, Dublin Core and FHKB [10 minutes] ==== Semantic vocabularies are sets of predefined properties for describing some domains. Examples include: * [[http://semanticweb.org/wiki/Dublin_Core|Dublin Core]] * [[http://semanticweb.org/wiki/FOAF|FOAF]] * [[http://semanticweb.org/wiki/SIOC|SIOC]] * etc. - Have a look at [[https://github.com/blokhin/genealogical-trees/blob/master/data/header.ttl|Family History Knowledge Base (FHKB)]] ontology, [[http://dublincore.org/documents/dc-rdf/|Expressing Dublin Core metadata using the Resource Description Framework]] and [[http://xmlns.com/foaf/spec/|FOAF Vocabulary Specification]]. - Modify your RDF file to use the properties from FHKB, Dublin Core and FOAF vocabulary, e.g.: # ... @prefix dc: . @prefix dcterms: . @prefix foaf: . @prefix fhkb: . # ... # ... fhkb:isDaughterOf ; "1900-01-01"^^xsd:date; "Chemistry"^^xsd:string; foaf:name "Brooke Logan", "Brooke Forrester", "Brooke Chambers", "Brooke Jones", "Brooke Marone", "Brooke Spencer". # ... * Hint: comprehensive list of ''dcterms:'' and ''dc:'' elements is [[http://dublincore.org/documents/dcmi-terms/|here]] ("Section 2: Properties in the /terms/ namespace" = ''dcterms:'', "Properties in the /elements/1.1/ namespace" = ''dc:'') ==== - RDF Schema: classes [10 minutes] ==== RDF Schema allows to organize objects into classes and define simple taxonomies. - Define classes of items in your database. Consider reusing the classes from dictionaries mentioned before, e.g. @base . @prefix rdf: . @prefix rdfs: . rdf:type rdfs:Class . rdf:type rdfs:Class ; rdfs:subClassOf . foaf:Person rdfs:subClassOf . Add the ''rdf:type'' statements to your RDF file, e.g.: a foaf:Person . rdf:type . Note that ''a'' is an alias for ''rdf:type'' so two statements: rdf:type . a . are equivalent. ==== - RDF Schema: properties [10 minutes] ==== RDF Schema also provides a way to define Properties as well as their domains and ranges. - In your file identify properties that are not defined in external dictionaries (e.g. Dublin Core), e.g. in this code: fhkb:isDaughterOf ; "1900-01-01"^^xsd:date; "Chemistry"^^xsd:string; foaf:name "Brooke Logan", "Brooke Forrester", "Brooke Chambers", "Brooke Jones", "Brooke Marone", "Brooke Spencer". '''' is not defined in external dictionary -- it is defined in our own namespace. - Describe each such property using RDF Schema capabilities: @base . @prefix rdf: . @prefix rdfs: . rdf:type rdfs:Property ; rdfs:domain foaf:person ; rdfs:range rdfs:Literal. You may find [[http://www.w3.org/TR/rdf-schema/|RDF Schema 1.1]] recommendation useful. ==== - RDF Schema: Non-modeling properties [3 minutes] ==== RDF Schema also provides some handful properties that are not used in inference process. These are: * ''rdfs:label'' -- used by convention to provide a human-readable name that is displayed by semantic web agents, * ''rdfs:seeAlso'' -- cross-referencing; provide links to supplementary information, * ''rdfs:isDefinedBy'' -- subPropertyOf rdfs:seeAlso; provides a link to the primary source of information, * ''rdfs:comment'' -- for everything you want :) . - Use each of them in your RDF file. - 8-) Include final RDF **Turtle** file in the report archive. * Check if your Turtle file passes validation on [[http://any23.org/|Anything to Triples]]! ===== Control questions ===== * What container elements are available in RDF? * What is RDF Schema? * What are core RDF Schema Classes and properties? * How constraints on domain and range of properties are added? ===== If you want to know more ===== {{section>.:lab-rdfmodel#if_you_want_to_know_more&noheader}}