Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Chapter3RDFSyntax2
Topics• BasicconceptsofRDF
• Resources,proper3es,values,statements,triples• URIsandURIrefs• RDFgraphs• Literals,qnames
• Vocabulariesandmodeling• Vocabularies• Blanknodes,datamodeling,types,reifica3on• Lists,bags,collec3ons
• Serializa3onofRDFgraphs• XML,Turtle,Ntriples
• Cri3queofRDF
Types
RDFtype
l RDFhasatypepredicatethatlinksaresourcetoanotherthatdenotesitstype– ex:johnrdf:typefoaf:Person.– <hQp://example.org/john><hQp://www.w3.org/1999/02/22-rdf-syntax-ns#type><hQp://xmlns.com/foaf/0.1/Person>.
l RDFSaddssub-typeconcept&constraintsbetweenpredicates&typesoftheirarguments
l OWLaddss3llmoreconceptsopera3ngontypes
DataModeling
StructuredValuesinRDF
l Giventhetriplelike:ex:857exstaff:address"15GrantAve,Bedford,MA01730".
l Howcanwebestrepresentseparateinforma-3onforthestreet,city,stateandzipcode?
l Twopossibili3es:– Usefourpredicates(e.g.,exstaff:street_address,…)toassociatevalueswithexstaff:857
– CreateanaddressresourcetoaQachthefourpredicatestoandlinkthattoexstaff:addresswiththeex:addresspredicate
StructuredValuesinRDF
StructuredValuesinRDF
Orintriplesnota3on:
exstaff:85740exterms:addressexaddressid:85740.exaddressid:85740exterms:street"1501GrantAve".exaddressid:85740exterms:city"Bedford".exaddressid:85740exterms:state"MD".exaddressid:85740exterms:postalCode"01730".
StructuredValuesinRDF
l Thisapproachinvolvesaddingmany“inter-mediate”URIrefs(e.g.,exaddressid:85740)foraggregateconceptslikeJohn'saddress
l Suchconceptsmayneverneedtobereferredtodirectlyfromoutsideapar3culargraph,andhencemaynotrequire“universal”idenDfiers
l RDFallowsustouseblanknodesandblanknodeidenDfierstodealwiththisissue– NodeIDsinthe_namespacearebnodes,e.g._:
KnowledgeTechnologiesManolisKoubarakis
10
BlankNode,akabnode
BlankNodesUsingTriples
exstaff:85740exterms:address??.??exterms:postalCode"01730".Exstaff:72120exterms:address???.???exterms:postalCode"01702".
l Wewanttoensurethatthebnodesfor85740’sand72120’saddressesaredis3nct
l Thegraphicalnota3ondoesthisbyusingtwodifferentobjectsforthebnodes
l RDFallowsustoassignanspecialIDtoabnodewhiles3llmaintainingitsblanknodenature
BlankNodeIdenDfiersexstaff:85740exterms:address_:johnaddress._:johnaddressexterms:street"1501GrantAvenue"._:johnaddressexterms:postalCode"01730".
l Dis3nctbnodemusthavedifferentbnodeidsl Bnodeidshavesignificanceonlyinasinglegraph– dbpedia:Alan_Turingreferstothesamethingineverygraph,butabnode_:1intwodifferentgraphsmaynot
– Mergingtwographsrequiresustorenametheirbnodeidstoavoidaccidentalconfla3on(e.g.,_:1=>_:100)
l Bnodeidsmayonlyappearassubjectsorobjectsandnotaspredicatesintriples
SemanDcsofBlankNodes
l Intermsoffirst-orderlogic,blanknodescorrespondtoexisten3allyquan3fiedvariables
l Anotherexample:“John’smotheris50”l FOL:∃xmother(john,x)∧age(x,50)l RDF::john:mother_32.:_32:age“50”.
:john “50”:mother :age
Blanknodesaregoodfor
l Represen3ngn-aryrelaDonshipsinRDFe.g.,therela3onshipbetweenJohnSmithandthestreet,city,state,andpostalcodecomponentsofhisaddress
l Tomakestatementsaboutresourcesthatdon’thaveURIsbutaredescribedbyrela3onshipswithotherresourcesthatdoe.g.,John’smother
Example
l TomakestatementsaboutJaneSmithwecoulduseheremailaddressURI(mailto:[email protected])todenoteher
l Well,ifwedoso,howarewegoingtorecordinforma3onbothaboutJane'smailbox(e.g.,theserveritison)aswellasaboutJaneherself(e.g.,hercurrentphysicaladdress)?Similarly,ifweuseherWebpageURIetc.
BnodeExample
WhenJaneherselfdoesnothaveaURI,ablanknodeprovidesabeQerwayofmodelingthissitua3on
_:janeexterms:mailbox<mailto:[email protected]>._:janerdf:typeexterms:Person._:janeexterms:name"JaneSmith"._:janeexterms:empID"23748"._:janeexterms:age"26".
Anotherusecase:Measurements
l Whatdoesthismean?dbr:Niledbp:length"6853"^^xsd:integer
l Wecanclickondbp:lengthtoseeitsdefini3on
Anotherusecase:Measurements
l Whatdoesthismean?dbr:Niledbp:length"6853"^^xsd:integer
l Wecanclickondbp:lengthtoseeitsdefini3ondbp:lengthrdf:typerdf:Property.dbp:lengthrdfs:label"Length"@en.
l Unfortunately,thedefini3ondoesn’tspecifytheunitofmeasurement.L
Anotherusecase:Measurements
l Whatdoesthismean?dbr:Niledbp:length"6853"^^xsd:integer
l Measurementstypicallyhaveanumericvalueandaunit– Weight:2.4poundsvs.2.4kilograms– Length:5milesvs.5kilometers– Price:29.00inUSDollarsvs.21.16Euro– Time:30yearsvs.3milliseconds
l Wecanuseabnodetorepresentameasurementasapairwithavalueandunit
Measurements
l Whatdoesthismean?dbr:Niledbp:length_:1._:1rdf:typeex:Measure._:1rdf:value”6853"^^xsd:integer._:1un:unitsdbr:Kilometre.
l TheRDFnamespacehasavaluepropertybutassignsnospecificmeaningtoit
Nile
dbr:Kiometre 6853
un:unit
rdf:type
ex:Measure dbp:length
rdf:value
Serializa3on
RDFSerializaDon• AbstractmodelforRDFisagraph• Serializeastextforexchange,storage,viewingandedi3ngintexteditors
• Thebigthree• XML/RDF–theoriginal• Ntriples–simple,butverbose;goodforprocessing• Turtle–compact,easyforpeopletoreadandwrite
• Specialformats• Trig–aformatfornamedgraphs• RDFa–embedRDFinHTMLaQributes• JSON-LD–RDFstatementsasaJSONobject
XMLencodingforRDF
<rdf:RDFxmlns:rdf="hQp://www.w3.org/1999/02/22-rdf-syntax-ns#"xmlns:dc="hQp://purl.org/dc/elements/1.1/"xmlns:bib="hQp://daml.umbc.edu/ontologies/bib/"><rdf:Descrip3onabout="hQp://umbc.edu/~finin/talks/idm02/"><dc:3tle>IntelligentInforma3onSystemsontheWeb</dc:Title><dc:creator><rdf:Descrip3on><bib:name>TimFinin</bib:Name><bib:email>[email protected]</bib:Email><bib:affresource="hQp://umbc.edu/"/></rdf:Descrip3on></dc:creator></rdfdescrip3on></rdf:RDF>
RDF/XMLisaW3CStandardwidelyusedforstorageandexchangeBeingsupplantedbyotherformsComplexandconfusingsowewon’tspend3meonit
Ntriples
l Goodforinges3ngintoaprogramorstorel Sequenceoftripleseachterminatedwitha.l URIsencasedinanglebrackets;noQNames;literalsindoublequotes
l Trivialtoparse/generate;mostcommondown-loadformatforRDFdatasets(e.g.,DBpedia)
l UseslotsofcharactersduetorepeatedURLs,butcompresseswell
<hQp://example.org/Turing><hQp://www.w3.org/1999/02/22-rdf-syntax-ns#type><hQp://xmlns.com/foaf/0.1/Person>.<hQp://example.org/Turing><hQp://xmlns.com/foaf/0.1/name>"AlanTuring".<hQp://www.w3.org/2001/sw/RDFCore/ntriples/><hQp://xmlns.com/foaf/0.1/mbox><mailto:[email protected]>.
W3CSpecifica3on
Turtle
l Ntriples⊂Turtle⊂N3l Compact,easytoreadandwriteandparsel Qnames,[]nota3onforblanknodes,;and,@prefixrdf:<hQp://www.w3.org/1999/02/22-rdf-syntax-ns#>.@prefixdc:<hQp://purl.org/dc/elements/1.1/>.@prefixfoaf:<hQp://xmlns.com/foaf/0.1/>.
<hQp://www.w3.org/TR/rdf-syntax-grammar>dc:3tle"RDF/XMLSyntaxSpecifica3on(Revised)";dc:creator[foaf:name"DaveBeckeQ";foaf:mbox<mailto:[email protected]>,<mailto:[email protected]>].
Somedetails
l @PREFIXlinesdefinenamespaceabbrevia3onsl BasicpaQernis
Subjpred1value1;pred2value2;pred3value3,value4.
l Specialnota3onfortherdf:typepredicate:johnafoaf:Person;foaf:name"JohnSmith".
l Specialnota3onforanonymousbnodes:johnfoaf:knows[afoaf:Person;foaf:nick"Bob"].
NotaDon3orN3
l N3wasanearlyturtle-likenota3ondevelopedbyTim_BernersLeehimself
l Includedsupportforinferencerules– SeeCWMforso~ware
l NeverbecamearecommendedW3Cstandard– Someofitsfeatureswereproblema3cforOWL– SupplantedbyTurtle
Try…
l RDFexamples:hQp://bit.ly/691rdfl Simple.Ql#AsimpleTurtleexample
@prefixfoaf:<hQp://xmlns.com/foaf/0.1/>.@prefix:<#>.
:johnafoaf:Person;foaf:gender"Male";foaf:name"JohnSmith","JohnnySmith";foaf:knows:mary,[afoaf:Person;foaf:mbox<mailto:[email protected]>].
:maryafoaf:Person;foaf:name"MarySmith".
NotaDontranslaDon
l MostmodernSeman3cWebso~warecanreadandwriteinputinthethreemajorserializa3onnota3ons– E.g.,Protégé,Jena,Sesame,…
l Therearealsosimpleprobramsthatcanconvertbetweenthem
l rdf2rdfisagoodexample– WriQeninJava
Reifica3on
ReificaDon
l Some3meswewishtomakestatementsaboutotherstatementsE.g.,torecordprovenancedata,probability,ortoassert:john:believes{:mary:loves:john}
l Wemustbeabletorefertoastatementusinganiden3fier
l RDFallowssuchreferencethroughareifica3onmechanismwhichturnsastatementintoaresource
Reify
l Etymology:La3nresthingl Date:1854l Toregard(somethingabstract)asamaterialorconcretething
Wikipedia:reificaDon(computerscience)
Reifica3onistheactofmakinganabstractcon-ceptorlow-levelimplementa3ondetailofapro-gramminglanguageaccessibletotheprogram-mer,o~enasafirst-classobject.Forexample,– TheCprogramminglanguagereifiesthelow-leveldetailofmemoryaddresses.
– TheSchemeprogramminglanguagereifiescon3nua-3ons(approximately,thecallstack).
– InC#,reifica3onisusedtomakeparametricpolymor-phismimplementedasgenericsafirst-classfeatureofthelanguage.
– …
ReificaDonExample
:949352uni:name“GrigorisAntoniou”.
reifiesas
[ardf:Statement;rdf:subject::949352rdf:predicateuni:name;rdf:object“GrigorisAntoniou”].
ReificaDonExample
<rdf:Descrip3onrdf:about="#949352”><uni:name>GrigorisAntoniou</uni:name></rdf:Descrip3on>
reifiesas
<rdf:Statementrdf:ID="StatementAbout949352"><rdf:subjectrdf:resource="#949352"/><rdf:predicaterdf:resource="hQp://example.org/uni-
ns#name"/><rdf:object>GrigorisAntoniou</rdf:object></rdf:Statement>
AnotherreificaDonexample
“AlicesuspectsthatBoblovesCarol”@prefixep:<hQp://example.com/epis3mology>@prefixrdf:<hQp://www.w3.org/1999/02/22-rdf-syntax-ns#>.@prefixxsd:hQp://www.w3.org/2001/XMLSchema:bob:loves:carol.[:aliceep:believes[ardf:Statement;rdf:subject:bob;rdf:predicate:loves;rdf:object:carol;ex:certainty“0.50”^^xsd:integer]
ReificaDon
l rdf:subject,rdf:predicate&rdf:objectallowustoaccessthepartsofastatement
l TheIDofthestatementcanbeusedtorefertoit,ascanbedoneforanydescrip3on
l Wewriteanrdf:DescripDonifwedon’twanttotalkaboutastatementfurther
l Wewriteanrdf:Statementifwewishtorefertoastatement
Containers
ContainerElements
l RDFhassomevocabularytodescribecollec3onsofthingsandmakestatementsaboutthem
l E.g.,wemaywishtotalkaboutthecoursesgivenbyapar3cularlecturer
l Thecontentofcontainerelementsarenamedrdf:_1,rdf:_2,etc.– Alterna3velyrdf:li
l ContainersseemabitmessyinRDF,butareneededl :john:teaches[ardf:Bag;rdf:li:cmsc201,:cmsc202,cmsc345.].
ThreeTypesofContainerElements
l rdf:Baganunorderedcontainer,allowingmul3pleoccurrencese.g.,membersofthefaculty,documentsinafolder
l rdf:Seqanorderedcontainer,whichmaycontainmul3pleoccurrencese.g.,modulesofacourse,itemsonanagenda,alphabe3zedlistofstaffmembers
l rdf:Altasetofalterna3vese.g.,thedocumenthomesiteanditsmirrors,transla3onsofadocumentinvariouslanguages
ExampleforaBagLet’sdescribeacoursewithacollec3onofstudents
ExampleforaBag
@prefixrdf:<hQp://www.w3.org/1999/02/22-rdf-syntax-ns#>.@prefixs:<hQp://example.org/students/vocab#>.<hQp://example.org/courses/6.001>s:students[ardf:Bag;rdf:_1<hQp://example.org/students/Amy>;rdf:_2<hQp://example.org/students/Mohamed>;rdf:_3<hQp://example.org/students/Johann>;rdf:_4<hQp://example.org/students/Maria>;rdf:_5<hQp://example.org/students/Phuong>.].
ExampleforAlternaDve
<uni:courserdf:ID="CIT1111" uni:courseName="DiscreteMathema3cs"><uni:lecturer> <rdf:Alt> <rdf:lirdf:resource="#949352"/> <rdf:lirdf:resource="#949318"/> </rdf:Alt></uni:lecturer>
</uni:course>
Rdf:IDAkributeforContainerElements
<uni:lecturerrdf:ID="949318" uni:name="DavidBillington"><uni:coursesTaught> <rdf:Bagrdf:ID="DBcourses"> <rdf:_1rdf:resource="#CIT1111"/> <rdf:_2rdf:resource="#CIT3112"/> </rdf:Bag></uni:coursesTaught>
</uni:lecturer>
BagsandSeqsareneverfull!l RDF’sseman3csis“openworld”,so…
– Notpossible”toclose”thecontainer,tosay:“theseareallelements,therearenomore”
– RDFisagraph,withnowaytoexcludethepossibilitythatthereisanothergraphsomewheredescribingaddi3onalmembers
l Listsarecollec3onswithonlythespecifiedmembersmen3oned.
l DescribedusingalinkedlistpaQernvia:– rdf:List,rdf:first,rdf:rest,rdf:nil
Openvs.closedworldsemanDcsl Reasoningsystemsmakeadis3nc3onbetweenopenandclosedworldseman3cs– OWS:beingunabletoprovethatsomethingistrueorfalsesaysnothingaboutitsveracity
– CWS:whatcannotbeproventobetrueisfalse
l DefaultmodelforSeman3cWebisOWSThiswasadesigndecisionmadeearlyon
Openvs.closedworldsemanDcsl ClassicallogicusesOpenWorldSeman3cs
BeingunabletoproveP=NPdoesn’tconvinceusthatit’sfalse
l DatabasesystemstypicallyassumeCWSTheDBincludesalltrainsbetweenNYCandDC
l Prolog’sunprovableoperator(notor\+)supportsCWSflys(x):-bird(x),\+flightless(x).flightless(x):-penguin(x);ostrich(x);emu(x).
l Somesystemsletusspecifyforwhichpredicateswehavecompleteknowledgeandforwhichwedon’t– IfUMBC’sDBdoesn’tlistyouasregisteredforCMSC691,youarenotregistered
– UMBC’sDBsystemknowssomeofyourminorsbutnotall
RDFListsAnorderedlistofthethreestudentsinaclass
RDFLists
@prefixrdf:<hQp://www.w3.org/1999/02/22-rdf-syntax-ns#>.@prefixs:<hQp://example.org/students/vocab#>.
<hQp://example.org/courses/6.001>s:students[ardf:List;rdf:first<hQp://example.org/students/Amy>;rdf:rest[ardf:listrdf:first<hQp://example.org/students/Mohamed>;rdf:rest[ardf:List;rdf:first<hQp://example.org/students/Johann>;rdf:restrdf:nil]]].
RDFLists
Turtlehasspecialsyntaxtorepresentlists:
@prefixrdf:<hQp://www.w3.org/1999/02/22-rdf-syntax-ns#>.@prefixs:<hQp://example.org/students/vocab#>.
<hQp://example.org/courses/6.001>s:students(<hQp://example.org/students/Amy><hQp://example.org/students/Mohamed><hQp://example.org/students/Johann>).
Cri3queofRDF
RDFCriDque:ProperDes
l Proper3esarespecialkindsofresources– Proper3escanbeusedastheobjectinanobject-aQribute-valuetriple(statement)
– Definedindependentofresources
l Thispossibilityoffersflexibility
l ButitisunusualformodellinglanguagesandOOprogramminglanguages
l Itcanbeconfusingformodellers
RDFCriDque:BinaryPredicates
l RDFusesonlybinaryproper3es– Thisisarestric3onbecauseo~enweusepredicateswithmorethantwoarguments
– Butbinarypredicatescansimulatethese
l Example:referee(X,Y,Z)– XistherefereeinachessgamebetweenplayersYandZ
RDFCriDque:BinaryPredicates
l Weintroduce:– anewauxiliaryresourcechessGame– thebinarypredicatesref,player1,andplayer2
l Wecanrepresentreferee(X,Y,Z)as:
RDFCriDque:ReificaDon
l Thereifica3onmechanismisquitepowerfull ItappearsmisplacedinasimplelanguagelikeRDF
l MakingstatementsaboutstatementsintroducesalevelofcomplexitythatisnotnecessaryforabasiclayeroftheSeman3cWeb
l Instead,itwouldhaveappearedmorenaturaltoincludeitinmorepowerfullayers,whichprovidericherrepresenta3onalcapabili3es
RDFCriDque:GraphRepresentaDon
l Thesimplegraphornetworkrepresenta3onhasmoredrawbacks
l Linearlanguagesintroducewaystorepresentthiswithparenthesesorawaytorepresentablockstructure
l Scoping,forexample,isclumsyatbestinRDFbelieve(john,and(love(bob,carol),love(carol,bob))
l Someoftheseareaddressedthroughtheno3onofanamedgraphinRDF
RDFgraphmodelissimple
l RDF’sgraphmodelisasimpleonel Neo4Jisapopulargraphdatabasewherebothnodesandlinkscanhaveproper3es
RDFCriDque:Summary
l RDFhasitsidiosyncrasiesandisnotanop3malmodelinglanguagebut
l Itisalreadyadefactostandardl Ithassufficientexpressivepower– Reasonablefounda3ononwhichtobuild
l UsingRDFoffersthebenefitthatinforma3onmapsunambiguouslytoamodel
Conclusion
Topics• BasicconceptsofRDF
• Resources,proper3es,values,statements,triples• URIsandURIrefs• RDFgraphs• Literals,qnames
• Vocabulariesandmodeling• Vocabularies• Blanknodes,datamodeling,types,reifica3on• Lists,bags,collec3ons
• Serializa3onofRDFgraphs• XML,Turtle,Ntriples
• Cri3queofRDF