|
|
(6 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
|
| |
|
| =Examples from the lectures=
| | ''This page currently shows the examples used in the Spring of 2023. |
| | | It will be updated with examples from 2024 as the course progresses.'' |
| '''This page currently shows the examples used in the Spring of 2023.
| |
| It will be updated with examples from 2024 as the course progresses.''' | |
|
| |
|
| ==Lecture 1: Introduction to KGs== | | ==Lecture 1: Introduction to KGs== |
Line 17: |
Line 15: |
| </syntaxhighlight> | | </syntaxhighlight> |
|
| |
|
| | <!-- |
| ==Lecture 2: RDF== | | ==Lecture 2: RDF== |
| Blank nodes for anonymity, or when we have not decided on a URI: | | Blank nodes for anonymity, or when we have not decided on a URI: |
Line 144: |
Line 143: |
| ==Lecture 3: SPARQL== | | ==Lecture 3: SPARQL== |
|
| |
|
| The KG4News knowledge graph can be accessed [http://bg.newsangler.uib.no here (namespace ''kb'')] (read-only). To test updates, you can run your own Blazegraph server or try the [http://sandbox.i2s.uib.no I2S sandbox]. | | The KG4News knowledge graph can be accessed online [http://bg.newsangler.uib.no here (namespace ''kb'')] (read-only), or you can load the Turtle file into your own GraphDB repository. |
| | (Remember to save the file with ''.ttl'' extension. You can use ''http://i2s.uib.no/kg4news/'' as base URI.) |
|
| |
|
| ===Limit=== | | ===Limit=== |
Line 361: |
Line 361: |
| </syntaxhighlight> | | </syntaxhighlight> |
|
| |
|
| ==Lecture 7: SHACL== | | ==Lecture 8: SHACL== |
| The examples are for use with the [https://shacl.org/playground/ interactive SHACL Playground]. | | The examples are for use with the [https://shacl.org/playground/ interactive SHACL Playground]. |
|
| |
|
Line 559: |
Line 559: |
| </syntaxhighlight> | | </syntaxhighlight> |
|
| |
|
| ==Lecture 7: RDFS== | | ==Lecture 8: RDFS== |
| Create a new Blazegraph Namespace ''with inference'' and ''Use'' it. | | Create two new GraphDB Repositories, one with RDFS inference and one with No inference. Try the SPARQL statements on both, so you can compare them. |
|
| |
|
| ===rdfs:subClassOf===
| | To test ''rdfs:subClassOf'': |
| In the ''Update'' tab, insert the ''Final data graph'' from the SHACL example above. (Select ''Type: RDF data'' and ''Format: Turtle''.)
| |
| | |
| Go to the ''Query'' tab, and SELECT all papers of type ''kg:MainPaper''.
| |
| <syntaxhighlight lang="ttl"> | | <syntaxhighlight lang="ttl"> |
| | PREFIX kg: <http://i2s.uib.no/kg4news/> |
| PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> | | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> |
| PREFIX sh: <http://www.w3.org/ns/shacl#> | | PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> |
| PREFIX dcterm: <http://purl.org/dc/terms/>
| |
| PREFIX foaf: <http://xmlns.com/foaf/0.1/>
| |
| PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
| |
| PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
| |
| PREFIX kg: <http://i2s.uib.no/kg4news/>
| |
| PREFIX th: <http://i2s.uib.no/kg4news/theme/>
| |
| PREFIX ss: <http://semanticscholar.org/>
| |
|
| |
|
| SELECT ?paper WHERE {
| | INSERT DATA { |
| ?paper rdf:type kg:MainPaper
| | kg:LOD_paper rdf:type kg:MainPaper . |
| | kg:MainPaper rdfs:subClassOf kg:Paper . |
| } | | } |
| </syntaxhighlight> | | </syntaxhighlight> |
|
| |
|
| Change the query to select all papers first of type ''ss:Paper'' and then of type ''foaf:Document''.
| | <syntaxhighlight lang="ttl"> |
| | PREFIX kg: <http://i2s.uib.no/kg4news/> |
| | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> |
| | PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> |
|
| |
|
| In the ''Update'' tab:
| | ASK { |
| <syntaxhighlight lang="ttl">
| | kg:LOD_paper rdf:type kg:Paper . |
| kg:MainPaper rdfs:subClassOf ss:Paper . | | } |
| </syntaxhighlight> | | </syntaxhighlight> |
|
| |
|
| Back in the ''Query'' tab, rerun the query to select all papers first of type ''ss:Paper'' and then of type ''foaf:Document''.
| |
|
| |
|
| ===Transitive rdfs:subClassOf===
| | To test ''rdfs:domain'': |
| In the ''Update'' tab, add the following RDFS rule:
| |
| <syntaxhighlight lang="ttl"> | | <syntaxhighlight lang="ttl"> |
| ss:Paper rdfs:subClassOf foaf:Document .
| | PREFIX kg: <http://i2s.uib.no/kg4news/> |
| | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> |
| | PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> |
| | |
| | INSERT DATA { |
| | kg:TBL kg:author kg:LOD_paper . |
| | kg:author rdfs:domain kg:Author . |
| | } |
| </syntaxhighlight> | | </syntaxhighlight> |
|
| |
|
| Back in the ''Query'' tab, rerun the query to select all papers first of type ''ss:Paper'' and then of type ''foaf:Document''.
| |
|
| |
| ===rdfs:range===
| |
| In the ''Update'' tab, add another paper, which is cited (referenced) by the LOD paper:
| |
| <syntaxhighlight lang="ttl"> | | <syntaxhighlight lang="ttl"> |
| kg:SW_Paper | | PREFIX kg: <http://i2s.uib.no/kg4news/> |
| dcterm:title "The Semantic Web" ;
| | PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> |
| dcterm:contributor kg:TBL, kg:JH, kg:OL .
| | PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> |
|
| |
|
| kg:JH | | ASK { |
| foaf:name "J. Hendler" .
| | kg:TBL rdf:type kg:Author . |
| | | } |
| kg:OL | |
| foaf:name "O. Lassila" .
| |
| | |
| kg:LOD_Paper kg:cites kg:SW_Paper # the new SW paper is cited by the LOD paper
| |
| </syntaxhighlight> | | </syntaxhighlight> |
| Note that we have ''not'' stated the RDF types of the new paper and new authors.
| |
|
| |
|
| In the ''Query'' tab, rerun the SPARQL queries to check that ''kg:SW_Paper'' has no ''rdf:type''.
| |
|
| |
|
| In the ''Update'' tab add this RDFS rule:
| | To see all the triples in the KG: |
| <syntaxhighlight lang="ttl"> | | <syntaxhighlight lang="ttl"> |
| kg:cites rdfs:range ss:Paper . # any paper that is cited by a kg:MainPaper is an ss:Paper
| | SELECT * WHERE { |
| </syntaxhighlight>
| | ?s ?p ?o |
| | | } |
| Back in the ''Query'' tab, rerun the SPARQL queries to check that the new SW paper is now an ''ss:Paper'' and ''foaf:Document'', but not a ''kg:MainPaper''.
| |
| | |
| ==Lecture 10: OWL-DL==
| |
| Here is the OWL file with the minimal Protégé / HermiT example from S10. Save it with the ''.owl'' suffix, for example ''s10-example.owl'', and ''File -> Open'' it in Protégé.
| |
| <syntaxhighlight lang='owl'>
| |
| <?xml version="1.0"?>
| |
| <rdf:RDF xmlns="http://www.semanticweb.org/sinoa/ontologies/2023/2/untitled-ontology-3#"
| |
| xml:base="http://www.semanticweb.org/sinoa/ontologies/2023/2/untitled-ontology-3"
| |
| xmlns:owl="http://www.w3.org/2002/07/owl#"
| |
| xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
| |
| xmlns:xml="http://www.w3.org/XML/1998/namespace"
| |
| xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
| |
| xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
| |
| xmlns:untitled-ontology-3="http://www.semanticweb.org/sinoa/ontologies/2023/2/untitled-ontology-3#">
| |
| <owl:Ontology rdf:about="http://www.semanticweb.org/sinoa/ontologies/2023/2/untitled-ontology-3"/>
| |
| | |
| <!--
| |
| ///////////////////////////////////////////////////////////////////////////////////////
| |
| //
| |
| // Object Properties
| |
| //
| |
| ///////////////////////////////////////////////////////////////////////////////////////
| |
| -->
| |
| | |
| <!-- http://www.semanticweb.org/sinoa/ontologies/2023/2/untitled-ontology-3#hasSource -->
| |
| <owl:ObjectProperty rdf:about="http://www.semanticweb.org/sinoa/ontologies/2023/2/untitled-ontology-3#hasSource"/>
| |
| | |
| <!--
| |
| ///////////////////////////////////////////////////////////////////////////////////////
| |
| //
| |
| // Classes
| |
| //
| |
| ///////////////////////////////////////////////////////////////////////////////////////
| |
| -->
| |
| | |
| <!-- http://www.semanticweb.org/sinoa/ontologies/2023/2/untitled-ontology-3#Content -->
| |
| <owl:Class rdf:about="http://www.semanticweb.org/sinoa/ontologies/2023/2/untitled-ontology-3#Content"/>
| |
| | |
| <!-- http://www.semanticweb.org/sinoa/ontologies/2023/2/untitled-ontology-3#Source -->
| |
| <owl:Class rdf:about="http://www.semanticweb.org/sinoa/ontologies/2023/2/untitled-ontology-3#Source">
| |
| <owl:equivalentClass>
| |
| <owl:Restriction>
| |
| <owl:onProperty>
| |
| <rdf:Description>
| |
| <owl:inverseOf rdf:resource="http://www.semanticweb.org/sinoa/ontologies/2023/2/untitled-ontology-3#hasSource"/>
| |
| </rdf:Description>
| |
| </owl:onProperty>
| |
| <owl:someValuesFrom rdf:resource="http://www.semanticweb.org/sinoa/ontologies/2023/2/untitled-ontology-3#Content"/>
| |
| </owl:Restriction>
| |
| </owl:equivalentClass>
| |
| </owl:Class>
| |
| | |
| <!--
| |
| ///////////////////////////////////////////////////////////////////////////////////////
| |
| //
| |
| // Individuals
| |
| //
| |
| ///////////////////////////////////////////////////////////////////////////////////////
| |
| -->
| |
| | |
| <!-- http://www.semanticweb.org/sinoa/ontologies/2023/2/untitled-ontology-3#NYTimes -->
| |
| <owl:NamedIndividual rdf:about="http://www.semanticweb.org/sinoa/ontologies/2023/2/untitled-ontology-3#NYTimes"/>
| |
| | |
| <!-- http://www.semanticweb.org/sinoa/ontologies/2023/2/untitled-ontology-3#article_about_Trump_rally -->
| |
| <owl:NamedIndividual rdf:about="http://www.semanticweb.org/sinoa/ontologies/2023/2/untitled-ontology-3#article_about_Trump_rally">
| |
| <rdf:type rdf:resource="http://www.semanticweb.org/sinoa/ontologies/2023/2/untitled-ontology-3#Content"/>
| |
| <hasSource rdf:resource="http://www.semanticweb.org/sinoa/ontologies/2023/2/untitled-ontology-3#NYTimes"/>
| |
| </owl:NamedIndividual>
| |
| </rdf:RDF>
| |
| | |
| <!-- Generated by the OWL API (version 4.5.9.2019-02-01T07:24:44Z) https://github.com/owlcs/owlapi -->
| |
| </syntaxhighlight> | | </syntaxhighlight> |
|
| |
|
Line 756: |
Line 675: |
| vector_neighbours(embeddings['oslo'] - embeddings['norway'] + embeddings['france']) | | vector_neighbours(embeddings['oslo'] - embeddings['norway'] + embeddings['france']) |
| </syntaxhighlight> | | </syntaxhighlight> |
| | --> |