Full text
Shaping Linked Data and Knowledge Graphs Jose Emilio Labra Gayo WESO Research group University of Oviedo, Spain Presenter:
About me… Main researcher at WESO (Web Semantics Oviedo) Some books: "Web semántica" (in Spanish), 2012 "Validating RDF data", 2017 "Knowledge Graphs", 2021 …and some software: RDFShape (RDF playground) rudof 2017 HTML version: http://book.validatingrdf.com http://labra.weso.es 2012 2021, HTML version https://kgbook.org/
About Oviedo, Asturias Princess of Asturias Awards 2002, Tim Berners-Lee, together with Vinton Cerf, Lawrance Roberts and Robert Kahn
Tutorial materials Interactive –through the web RDFShape: RDF playground Wikishape: Tailored to Wikibase Command line Rudof Binaries in Windows, Linux, Mac Interactive (Jupyter) rudof Python bindings https://rudof-project.github.io/tutorials
Contents Introduction to Knowledge graphs Types of Knowledge Graphs: RDF, Property graphs, Wikibase, RDF-Star Shaping RDF: ShEx & SHACL Shaping other types of Knowledge graphs: Wikibase and Wikidata graphs Property Graphs RDF-1.2
Knowledge Graphs Current notion of Knowledge Graphs, popular after Google, 2012* Link: https://www.blog.google/products/search/introducing-knowledge-graph-things-not/
Knowledge Graphs birthPlace name: London population: 8,908,081 name: United Kingdom population: 67,326,569 name: Tim Berners-Lee birthDate: 1955 name: Princess of Asturias Awards name: Vint Cerf birthDate: 1943 name: Spain population:47,415,750 name: Switzerland name: France name: CERN Inception: 1954 name: USA
Knowledge Graphs Knowledge graph = a graph of data intended to accumulate and convey knowledge of the real world whose nodes represent entities of interest and whose edges represent relations between these entities. https://kgbook.org/
Applications of Knowledge Graphs Improve search results Question answering Data governance Handling heterogenous data Recommender systems Chatbots, NLP, LLMs Explainability in AI . . .
Labeled Property graphs Since ~2007, very popular model in industry Neo4j, Amazon Neptune, Oracle, etc Several query languages: Cypher, Gremlin, PGQL, … 2024 - GQL has been published Recent publication of ISO/IEC FDIS 39075 Developed by the “SQL” committee Influenced by Cypher, PGQL, etc.
Graph structure with nodes and relationships (edges) Nodes and edges can have: - Labels - A set of property-value pairs Edges can be directed/undirected Property graphs birthPlace n1 Human name: Tim Berners-Lee birthDate: 1955 n2 r1 City, Metropolis name: London n3 country r2Country name: UK start: 1980 end: 1980 employer start: 1984 end: 1994 r4 n4 r3 employer Organization name: CERN
Wikidata Created in 2012 as a collaborative knowledge graph https://www.wikidata.org/ Developed and supported by Wikimedia Deutschland Initial goal: Support multilingual infoboxes in Wikipedia
Wikidata http://www.wikidata.org/entity/Q80 Bihari Wikipedia of Tim Berners-Lee English Wikipedia page of Tim Berners-Lee
Wikidata Wikidata as a commons Knowledge Graph 114,425,761 ítems, 2,271,032,314 edits (11/2024): https://www.wikidata.org/wiki/Wikidata:Statistics Free and open license: CC0 Multilingual Collaborative (Humans and bots) Public SPARQL endpoint Software that supports Wikidata = Wikibase
Wikibase graphs timBl birthDate: 1955 vintCerf Human CERN PA awarded - pointTime: 2002 - togetherWith: instanceOf instanceOf employer -start: 1984 - end: 1994 employer -start: 1980 - end: 1980 London UK birthPlace country Spain country awarded - pointTime: 2013 NewHaven birthPlace Example: Tim Berners Lee http://www.wikidata.org/entity/Q80
Wikibase graphs and RDF Wikibase graphs generate RDF serializations for each item SPARQL endpoint and Query service available RDF dumps RDF serialization SPARQL Query service Wikibase select ?name ?date?country where { wd:Q80 wdt:P1559 ?name . wd:Q80 wdt:P569 ?date . wd:Q80 wdt:P19 ?place . ?place wdt:P17 ?country } ? name ?date ?country Tim Berners-lee 1955 -06-08 : UK Try it: https://w.wiki/5yGu
RDF1.2 Currently under discussion (https://github.com/w3c/rdf-star-wg/wiki) Add statements about triples Reifiers :timbl rdfs:label "Tim Berners Lee" ; :employer :CERN . _:r rdf:reifies << :timbl :employer :CERN >> . _:r :start "1984" ; :end "1994" . _:s rdf:reifies << :timbl :employer :CERN >> . _:s :start "1980" ; :end "1980" . :timbl rdfs:label "Tim Berners Lee“ ; :employer :CERN {| :start "1984" ; :end "1994" |} {| :start "1980" ; :end "1980" |} . "Tim Berners Lee" :timbl :CERN rdf:label :employer :start 1984 1994 :end :reifies :start 1980 1980 :end :reifies
RDF1.2 RDF 1.2 also supports Wikibase style models :timbl rdfs:label "Tim Berners Lee" . _:r rdf:reifies <<(:timbl :employer :CERN )>> ; :start "1984" ; :end "1994" . _:s rdf:reifies <<(:timbl :employer :CERN )>> ; :start "1980" ; :end "1980" . _:t rdf:reifies <<(:timbl :employer :PA )>> ; :time "2002" ; :togetherWith :vint . :vint rdfs:label "Vinton Cerf" . :timbl rdfs:label "Tim Berners Lee" ; :employer :CERN {| :start "1984" ; :end "1994" |} {| :start "1980" ; :end "1980" |} ; :award :PA {| :time "2002" ; :togetherWith :vint |} . :vint rdfs:label "Vinton Cerf" . :timbl :CERN :employer :start 1984 1994 :end :reifies :start 1980 1980 :end :reifies "Tim Berners Lee" rdf:label :PA :award :reifies 2002 :time :vint :togetherWith rdf:label "Vinton Cerf"
Contents Introduction to Knowledge graphs Types of Knowledge Graphs: RDF, Property graphs, Wikibase, RDF-Star Shaping RDF: ShEx & SHACL Shaping other types of Knowledge graphs: Wikibase and Wikidata graphs Property Graphs RDF-1.2
SHACL W3C recommendation: https://www.w3.org/TR/shacl/ (July 2017) Inspired by SPIN, OSLC & ShEx 2 parts: SHACL-Core, SHACL-SPARQL Syntax = RDF vocabulary
SHACL example Try it. RDFShape https://rdfshape.weso.es/link/17344297955 :Researcher ash:NodeShape ; sh:property [ sh:path :name ; sh:datatype xsd:string; sh:minCount 1; sh:maxCount 1] ; sh:property [ sh:path :birthDate ; sh:datatype xsd:date; sh:maxCount 1] ; sh:property [ sh:path :birthPlace ; sh:node :Place; sh:maxCount 1] ; sh:property [ sh:path :employer ; sh:node :Organization ] . :Place ash:NodeShape . :Organization a sh:NodeShape . SHACL Shapes graph In ShEx <Researcher> { :name xsd:string ; :birthPlace @<Place> ? ; :birthDate xsd:date ? ; :employer @<Organization> * ; }
ShEx and SHACL compared More information in chapter 7 of Validating RDF data book Or in some talks like: https://labra.weso.es/talk/2018_validatingrdfdata_stanford/ 2017 HTML version: http://book.validatingrdf.com
ShEx and SHACL description - validation - constraints Description Tell what something is about What data we want/expect Constraint Rule that something has to obey What data we don’t want/expect ShEx SHACL Validation Check that data conforms with expectations
DCTAP Metadata model Tabular: CSV, Spreadsheets Easy to understand and edit by domain experts It can be used as a template and a single-source-of-truth DCTAP can be converted to Shapes (ShEx/SHACL/etc.) Shapes
DCTAP example shapeID propertyID propertyLabel mandatory repeatable valueDataType valueShape Researcher rdfs:label Label TRUE FALSE xsd:string :birthPlace Place of birth FALSE FALSE Place :birthDate Date of birth FALSE FALSE xsd:date :employer Employer FALSE TRUE Organization Place Organization In ShEx <Researcher> { :name xsd:string ; :birthPlace @<Place> ? ; :birthDate xsd:date ? ; :employer @<Organization> * ; }
Contents Introduction to Knowledge graphs Types of Knowledge Graphs: RDF, Property graphs, Wikibase, RDF-Star Shaping RDF: ShEx & SHACL Shaping other types of Knowledge graphs: Wikibase and Wikidata graphs Property Graphs RDF-1.2
Wikibase and RDF Wikibase graphs are also available through SPARQL endpoint Internally, Wikibase has 2 DBs: - Relational database (MariaDB) - RDF Triplestore (Blazegraph) -Plans to update select ?name ?date?country where { wd:Q80 wdt:P1559 ?name . wd:Q80 wdt:P569 ?date . wd:Q80 wdt:P19 ?place . ?place wdt:P17 ?country } ? name ?date ?country Tim Berners-lee 1955 -06-08 : UK Try it: https://w.wiki/5yGu RDF dumps RDF serialization SPARQL Query service Wikibase
Entity schemas ShEx describe RDF dumps RDF serialization SPARQL Query service Wikibase Wikibase and RDF: Entity Schemas If we have RDF, we can use ShEx to describe and validate entities
Entity Schemas They can be used to describe Wikidata entities Adopted in 2019 as a new Wikidata namespace Exxx Example: https://www.wikidata.org/wiki/EntitySchema:E10 Directory of entity schemas: https://www.wikidata.org/wiki/Wikidata:Database_reports/EntitySchema_directory
Property graphs Graph structure with nodes and relationships (edges) Nodes and edges can have: - Labels - A set of property-value pairs Edges can be directed/undirected birthPlace n1 Human label: Tim Berners-Lee birthDate: 1955 n2 r1 City, Metropolis label: London n3 country r2Country label: UK start: 1980 end: 1980 employer start: 1984 end: 1994 r4 n4 r3 employer Organization label: CERN
Shaping Property graphs with GQL GQL defines the concept of Graph Types It describes the graph in terms of restrictions on labels, properties, nodes, edges and topology Graph types constrain the set of nodes that can be contained in a graph Multiple graphs can refer to the same graph type Graph types can be created independently: CREATE GRAPH TYPE name { graph type spec } Or when creating the graph: CREATE GRAPH …content… TYPED { graph type spec }
CREATE GRAPH TYPE example { (researcher :Human => { name String, birthDate Date } ) (place :City & :Metropolis => { name String }) (country :Country => { name String }) (org :Organization => { name String }) (researcher) -[ :birthPlace ]-> (place), (place) -[ :country ]-> (country), (researcher) -[:employer => { start Date, end Date}] -> (org), } Shaping property graphs with GQL: Example birthPlace n1 Human name: Tim Berners-Lee birthDate: 1955 n2 r1 City, Metropolis name: London n3 country r2Country name: UK start: 1980 end: 1980 employer start: 1984 end: 1994 r4 n4 r3 employer Organization name: CERN No Cardinality constraints about the topology of the graph Example: - How can we indicate that a researcher can work for zero or more employers?
PShEx Proposal to extend ShEx to handle property graphs Similar to WShEx, but adapted for Property graphs We add a new description level for property-value pairs (in nodes and edges) It allows to declare cardinality constraints on the topology of the graph Extending Shape Expressions for different types of knowledge graphs ,Jose Emilio Labra Gayo, In 1st Workshop on Data Quality meets Machine Learning and Knowledge Graphs, DQMLKG, part of Extended Semantic Web Conference 2024, ESWC24. - 2024, http://labra.weso.es/publication/2024_shex_extensions/
<Researcher> [( Human )] [| name: String ; birthDate: Date ? |] AND { birthPlace: @<Place> ? ; employer: @<Org> {| start: Date; end: Date |} * } <Place> [( City)]{ country: @<Country> } <Country> { name: String } <Org> { name: String } Shaping property graphs: PShEx PShEx = ShEx extension that allows to describe property graphs birthPlace n1 Human name: Tim Berners-Lee birthDate: 1955 n2 r1 City, Metropolis name: London n3 country r2Country name: UK start: 1980 end: 1980 employer start: 1984 end: 1994 r4 n4 r3 employer Organization name: CERN
PGSchema PC Recent proposal: PGSchema with property constraints Accepted at K-Cap conference 2025 (https://www.k-cap.org/) More information: https://www.weso.es/pgschemapc
Contents Introduction to Knowledge graphs Types of Knowledge Graphs: RDF, Property graphs, Wikibase, RDF-Star Shaping RDF: ShEx & SHACL Shaping other types of Knowledge graphs: Wikibase and Wikidata graphs Property Graphs RDF-1.2
RDF1.2 Current working draft: https://www.w3.org/TR/rdf12-concepts/ Main novelty: Add statements about triples: reifiers :timbl :name "Tim Berners Lee“ ; :employer :CERN . _:r1 rdf:reifies << :timbl :employer :CERN >> . _:r1 :start 1980 ; :end 1980 . _:r2 rdf:reifies << :timbl :employer :CERN >> . _:r2 :start 1984 ; :end 1994 . :timbl :name "Tim Berners Lee"; :employer :CERN {| :start 1980;:end 1980 |} {| :start 1984;:end 1994 |} . Alternative syntax "Tim Berners Lee" :timbl :CERN :name :employee :start 1980 1980 :end :start 1984 1994 :end :reifies :reifies
ShEx-Star Proposal: ShEx-Star (Not yet implemented in rudof) :timbl :name "Tim Berners Lee"; :employer :CERN {| :start 1980; :end 1980 |} {| :start 1984; :end 1994 |} . "Tim Berners Lee" :timbl :CERN :name :employer <Researcher> { :name xsd:string ; :employer @<Org> {| :start xsd:date, :start xsd:date |} * } <Org> {} :start 1980 1980 :end :start 1984 1994 :end :reifies :reifies
SHACL 1.2 Currently under development at W3C: https://www.w3.org/TR/shacl12-core/ :timbl :name "Tim Berners Lee"; :employer :CERN {| :start 1980; :end 1980 |} {| :start 1984; :end 1994 |} . :UserShape ash:NodeShape ; sh:targetClass :User ; sh:property [ sh:path :employer ; sh:reificationRequired true ; sh:reifierShape [ sh:property [ sh:path :start ; sh:datatype xsd:integer ; sh:minCount 1; sh:maxCount 1 ] ; sh:property [ sh:path :end ; sh:datatype xsd:integer ; sh:minCount 1; sh:maxCount 1 ]]] .