Beruflich Dokumente
Kultur Dokumente
KalAhmed(kal@brightstardb.com,@kal_ahmed)
GrahamMoore(gra@brightstardb.com,@gra_moore)
WrittenasapositionpaperfortheW3COpenDataontheWebworkshop:
http://www.w3.org/2013/04/odw/
Intro
WehavebeenworkingonexposingSPARQLendpointsasODataendpoints.Thesourcecode
isnowavailableonGitHubathttps://github.com/BrightstarDB/odatasparql.Thefollowingisa
descriptionofourmotivationandsomeofthetechnicaldetailsabouthowweareapproaching
theproblem.
AtsomelevelthereisnodoubtthattheSPARQL,RDF,LinkedDataPlatform1 stackcompetes
withtheODatastack.Bothprovideaccesstogenericdatamodels,bothattempttoplaywellas
aRESTFularchitecture,bothofferupquerylanguagesforusebyremoteclientsoverHTTP.
ODatadoesabetterjobofexposingdataasentitiesandODatasupportforcontainersandentity
levelupdateismorematurethantheLDPeffort.RDFontheotherhandhasametamodelthatis
moreaccessibletheunwaveringuseofURIsforaddressingandidentification,bothatthelevel
ofinstancedataandthelevelofontologyisarealbenefitasistheinherentabilitytomerge
homogenousdata.
However,competesisinscarequotesbecauseitisnotusefultothinkofpublicopendata
standardscompetingwithoneanotherwitheachtryingtooperatetotheexclusionoftheother.
Ratherweshouldbefocussingonthewaysinwhichinteroperabilitycanbeachievedas
runningcodebutalsoatthelevelofthestandardsmakingprocess.Wehavebeenworkingwith
bothODataandRDFnowformanyyearsandtryingtohelpbridgethegapbetweentheseweb
dataworldsatthelevelofrunningcode.Basedonthatexperience,wehavestartedaprojectto
provideanODataendpointthatsitsontopofanySPARQLcompliantendpoint.Technicallythis
isacoolthingtoplaywith,butitisalsoawaytogetafeelforissuesinopendataprotocol
interoperabilitythatcouldbenefitfromfurtherstandardswork.
TheApproach
1
http://www.w3.org/TR/2012/WDldp20121025/
ThetechnicalapproachwehavetakenistoimplementaproxythatparsesODataoperations
andrewritesthemasequivalentSPARQLoperationsthatcanthenbeexecutedagainsta
SPARQLendpoint.TheSPARQLresultsetisthenparsedandrewrittenasanODataresultset.
ThemainhurdletoovercomeisthatanODataserviceisdrivenbytheunderlyingdomainmodel.
AnODataserviceexposesitsontologyandentitycollectionsasametadatadocument2 witha
wellknownURI3 ,andallqueriesareexpressedintermsofthismetadata.Forageneric
SPARQLendpoint,thisisnotnecessarilythecase.
AstheserviceweareexposingisODatawehavechosentoapproachthisproblembymaking
useoftheannotationsextensionpointintheODataservicemetadatadocument.Bytakingthis
approachweenabletheODataservicethattheproxyprovidestobedefinedeither:
1. AsamanuallyconfiguredODataservicemetadatadocument.
2. ByconversionfromaknownRDFschemaorOWLontology
3. ByintrospectionoftheSPARQLendpointusingSPARQLqueriesthatmakeuseofRDF
Schema/OWLtypesandproperties.
Atpresentwehavenotimplementedeither(2)or(3)butwearefairlyconfidentthatsomelevelof
useableODataservicemetadatacouldbeautomaticallygeneratedinthisway.Theother
potentialadvantageisthattheODataservicemetadataissimplyanotherresourcethatcanbe
published,soitwouldbepossiblefortheownerofaSPARQLendpointtomakeanofficial
ODataservicedescriptionavailableeveniftheywereunwilling/unabletohosttheODataproxy
themselves.
ODataAnnotations
Togetthingsworkingwecreatedasmallsetofannotationsthatcanbeusedtodecoratethe
modeldescribedinanODataservicemetadatadocument.Theannotationsareusedtohelp
mapODataentityandpropertytypestotheirequivalentRDFtypes.
WeusethefollowingannotationnamespaceforallSPARQLODataannotations:
<UsingNamespace="ODataSparqlLib.Annotations"Alias="Sparql"/>
ThisisjustawayofsayingthattheAnnotationODataSparqlLib.Annotations.Uricanbe
referencedinthemetadatadocumentusingtheshortnameSparql.Uri.
IdentityPrefixAnnotation
TheIdentityPrefixAnnotationisusedtohelpmapsimplebetweenRDFResourceURIsto
2
3
http://www.odata.org/media/30002/OData%20CSDL%20Definition.html
http://www.odata.org/media/30002/OData.html#metadatadocumentrequest
ODatasimpleidentityattributes.ForexampleinRDFwewanttobeusingaURIsuchas
http://www.brightstardb.com/products/1whereasintheODataentitywewanttotalkaboutthis
asproductwithIdof1,andconnectedtothisas/products(1).
NOTE:whileitwouldbepossibletousethefullURIofanRDFresourceasitsODataidentifier,it
hasimplicationsforconsistentURIescapingandforthelengthoftheresultingODataURIs.
ToachievethisweusetheIdentifierPrefixannotationonthepropertyidentifiedastheKey
propertyfortheODataEntityType.Thefollowingsampleshowitsusage.
<EntityTypeName="Film">
<Key>
<PropertyRefName="Id"/>
</Key>
<PropertyName="Id"Type="Edm.String"Nullable="false">
<ValueAnnotationTerm="Sparql.IdentifierPrefix"
String="http://dbpedia.org/resource/"/>
</Property>
</EntityType>
IntheaboveexampleanRDFresourcewithaURIlike
http://dbpedia.org/resource/Un_Chien_AndaloucanbereferencedthroughtheODataproxyas
http://example.org/odata/Films(Un_Chien_Andalou)
TheidentityprefixmappingisspecifictoanODataentitytype,soeachtypecanuseadifferent
prefixifrequired.
EntityTypeMappingAnnotation
ToindicatehowtypesinODatamaptotypesinRDFweuseaUriannotationontheOData
EntityTypedefinition.InthiscontexttheUriannotationsimplyprovidesthefullURIoftheRDF
resourcethatdefinestheentitytype.
Thefollowingsampleshowsitsusage:
<EntityTypeName="Person">
<ValueAnnotation
Term=Sparql.Uri
String=http://mappings.dbpedia.org/server/ontology/classes/Person/>
</EntityType>
WealsoallowadefaultnamespaceURIforentitytypestobedefinedintheproxyconfiguration
file,anyEntityTypewithoutanexplicitmappingreceivesamappingbasedonappendingthe
EntityTypenametothenamespaceURI.Weallowfordifferentstringcasemappingstoalsobe
appliedwhenresolvingthenametoaURIe.g.forcetolower/uppercaseforcetolower/upper
camelcase.
LiteralPropertyTypeAnnotation
AsimilarapproachisusedtomapODatapropertiestoRDFproperties.
<PropertyName="Name"Type="Edm.String"Nullable="true">
<ValueAnnotationTerm="Sparql.Uri"String="http://dbpedia.org/property/name"/>
</Property>
Again,wealsoallowadefaultnamespaceURIforpropertytypestobedefinedintheproxy
configurationfile(separatefromthedefaultnamespaceforentitytypes),anyPropertywithoutan
explicitmappingreceivesamappingbasedonappendingthePropertyname(withcase
conversionapplied)tothenamespaceURI.
AssociationPropertyTypeAnnotations
InOData,propertiesthatreferenceotherentitiesaredescribedbyaNavigationPropertythat
definesatraversalofaseparatelydefinedAssociationtype.ThisallowsODatatosupport
bidirectionaltraversaloftherelationshipsbetweenentities.InRDFresourcetoresource
relationshipsaredirected.ToaccomodateODatasbidirectionalityweintroduceanadditional
IsInverseannotationwhichcanbeusedinconjunctionwithaUriannotationtospecifyboththe
RDFpropertytypeandthedirectioninwhichthepropertyistraversed(subjecttoobjector
objecttosubject).
<EntityTypeName=Place>
<NavigationPropertyName=BirthPlaceOf
Relationship=DBPedia.Person_BirthPlace
FromRole=BirthPlaceToRole=Person>
<ValueAnnotationTerm=Sparql.UriString=http://dbpedia.org/ontology/birthPlace/>
<ValueAnnotationTerm=Sparql.IsInverseBoolean=True/>
</NavigationProperty>
</EntityType>
<AssociationName="Person_DeathPlace">
<EndRole="Person"Type="DBPedia.Person"Multiplicity="*"/>
<EndRole="DeathPlace"Type="DBPedia.Place"Multiplicity="1"/>
</Association>
NotethattheAssociationdefinitioniscurrentlyunannotatedasallthenecessaryinformationis
conveyedbytheannotationsontheNavigationProperty.
Onceagain,theNavigationPropertyNamecanbecombinedwiththedefaultontologybaseURI
specifiedintheproxyconfigurationtoavoidtheneedtoprovideexplicitUriannotations.
ALargerExample
PuttingthisalltogetherhereisacompleteODataservicemetadatadocumentwithannotations
thatwecanusetoexposeasubsetofDBPediaasOData.
Inthisexample,abasetypenamespaceURIofhttp://dbpedia.org/ontology/andabaseproperty
namespaceofhttp://dbpedia.org/property/isusedandnamesaremappedtoURIcomponents
byforcingthemtolowercamelcase.Inthisexample,thismeansthatmanypropertiesandentity
typesdonotrequireaUriannotationtobemapped.
<?xmlversion="1.0"encoding="utf8"?>
<edmx:Edmxxmlns:edmx="http://schemas.microsoft.com/ado/2009/11/edmx"Version="3.0">
<edmx:DataServices
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
m:DataServiceVersion="2.0">
<Schemaxmlns="http://schemas.microsoft.com/ado/2009/11/edm"Namespace="DBPedia">
<UsingNamespace="ODataSparqlLib.Annotations"Alias="Sparql"/>
<!Thing:http://www.w3.org/2002/07/owl#Thing>
<EntityTypeName="Thing">
<Key>
<PropertyRefName="Id"/>
</Key>
<PropertyName="Id"Type="Edm.String"Nullable="false">
<ValueAnnotationTerm="Sparql.IdentifierPrefix"
String="http://dbpedia.org/resource/"/>
</Property>
<ValueAnnotationTerm="Sparql.Uri"String="http://www.w3.org/2002/07/owl#Thing"/>
</EntityType>
<!Work:http://dbpedia.org/ontology/Work>
<EntityTypeName="Work"BaseType="DBPedia.Thing">
<!Title:GetsdefaultURImapping:http://dbpedia.org/property/title>
<PropertyName="Title"Type="Edm.String"Nullable="true"/>
<!Director:GetsdefaultURImapping:http://dbpedia.org/property/director>
<NavigationPropertyName="Director"Relationship="DBPedia.Work_Director"
FromRole="Work"ToRole="Director"/>
</EntityType>
<!Film:http://dbpedia.org/ontology/Film>
<!DerivedfromWork>
<EntityTypeName="Film"BaseType="DBPedia.Work">
<PropertyName="Name"Type="Edm.String"Nullable="true">
<!Notstrictlynecessary,butshownasanexample>
<ValueAnnotationTerm="Sparql.Uri"String="http://dbpedia.org/property/name"/>
</Property>
<PropertyName="Runtime"Type="Decimal"Nullable="true"/>
<PropertyName="ImdbId"Type="Edm.String"Nullable="true"/>
<!Notstrictlynecessary,butshownasanexample>
<ValueAnnotationTerm="Sparql.Uri"String="http://dbpedia.org/ontology/Film"/>
</EntityType>
<!http://mappings.dbpedia.org/server/ontology/classes/Person>
<EntityTypeName="Person"BaseType="DBPedia.Thing">
<PropertyName="Name"Type="Edm.String"Nullable="true">
<!HereweuseFOAFvocabforaproperty>
<ValueAnnotationTerm="Sparql.Uri"String="http://xmlns.com/foaf/0.1/name"/>
</Property>
<PropertyName="BirthDate"Type="Edm.DateTimeOffset"Nullable="true">
<ValueAnnotationTerm="Sparql.Uri"
String="http://dbpedia.org/ontology/birthDate"/>
</Property>
<PropertyName="DeathDate"Type="Edm.DateTimeOffset"Nullable="true">
<ValueAnnotationTerm="Sparql.Uri"
String="http://dbpedia.org/ontology/deathDate"/>
</Property>
<NavigationPropertyName="BirthPlace"Relationship="DBPedia.Person_BirthPlace"
FromRole="Person"ToRole="BirthPlace"/>
<NavigationPropertyName="DeathPlace"Relationship="DBPedia.Person_DeathPlace"
FromRole="Person"ToRole="DeathPlace"/>
<NavigationPropertyName="RestingPlace"
Relationship="DBPedia.Person_RestingPlace"
FromRole="Person"ToRole="RestingPlace"/>
</EntityType>
<!Place:http://dbpedia.org/ontology/Place>
<EntityTypeName="Place"BaseType="DBPedia.Thing">
<PropertyName="Abbreviation"Type="Edm.String"Nullable="true"/>
<PropertyName="Abstract"Type="Edm.String"Nullable="true"/>
<PropertyName="AnnualTemperature"Type="Edm.Decimal"Nullable="true"/>
<PropertyName="Elevation"Type="Edm.Decimal"Nullable="true"/>
<PropertyName="PopulationTotal"Type="Edm.Int32"Nullable="true"/>
</EntityType>
<AssociationName="Work_Director">
<EndRole="Work"Type="DBPedia.Work"Multiplicity="*"/>
<EndRole="Director"Type="DBPedia.Person"Multiplicity="1"/>
</Association>
<AssociationName="Person_BirthPlace">
<EndRole="Person"Type="DBPedia.Person"Multiplicity="*"/>
<EndRole="BirthPlace"Type="DBPedia.Place"Multiplicity="1"/>
</Association>
<AssociationName="Person_DeathPlace">
<EndRole="Person"Type="DBPedia.Person"Multiplicity="*"/>
<EndRole="DeathPlace"Type="DBPedia.Place"Multiplicity="1"/>
</Association>
<AssociationName="Person_RestingPlace">
<EndRole="Person"Type="DBPedia.Person"Multiplicity="*"/>
<EndRole="RestingPlace"Type="DBPedia.Place"Multiplicity="1"/>
</Association>
<EntityContainerName="Contents"m:IsDefaultEntityContainer="true">
<EntitySetName="Films"EntityType="DBPedia.Film"/>
<EntitySetName="Persons"EntityType="DBPedia.Person"/>
<EntitySetName="Places"EntityType="DBPedia.Place"/>
<AssociationSetName="Film_Director"Association="DBPedia.Film_Director">
<EndRole="Film"EntitySet="Films"/>
<EndRole="Director"EntitySet="Persons"/>
</AssociationSet>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
RequestTransforms
TypicalODatarequestsareforeitherasingleentity,asetofentitiesoraselectformatthat
retrievesaresultthatappearsasadatatable.TomapthisintoaSPARQLqueryweusethe
aboveannotationsandthendependingonthetargetresultuseeithertheSELECTor
CONSTRUCTkeywords.
ODataselectqueriesworkinasimilarfashiontoSELECTinSPARQLbyreturningatabular
result.SowegenerateaSPARQLSELECTqueryandmaptheresultingSPARQLtabletoan
ODataresultsset.
WhenprocessingODataqueriesthatresultinanentityorcollectionofentities,weuseSPARQL
CONSTRUCTqueries.ThisallowsustoretrieveanRDFgraphfromtheSPARQLendpointthat
representstheentities,theirpropertiesandrelationships.Thegraphisthenprocessedbythe
proxyintoalistofentitiesand,ifnecessarythelistissortedbythesortcriteriaspecifiedinthe
originalODataquery.
Update
Fornowupdateisoutofscopeforthisproject,butitcouldpotentiallybeimplementedusingthe
samesetofannotationsweuseforread.Themaindifferenceisthatweneedtomakeuseof
SPARQLUPDATE,whichisaseparatespecificationandmoreimportantlyusuallylivesina
differentplaceontheserver,mostlikely,behindthefirewall.Weseetheinitialbenefitofthiswork
asopeningupexistingRDFtriplestoreswithpublicSPARQLendpointstoODataapplications.
Veryfewofthese,forobviousreasons,offerawriteableSPARQLupdateendpoint.For
enterpriseswithRDFstorestheadditionalupdateoptionmaybeofinterest.
Futurework
Initscurrentstate,thelibraryisbestdescribedasaminimalproofofconceptwithbasicsupport
forselectingentitiesbytheirIDorwithafewsimplepropertyoperatorssuchasEqualsand
GreaterThan.Wealsohavesomebasicsortingimplemented.
ThemainworktodoistocreateacompleteimplementationofallODatapathsemantics,filters
options,andprojectionoperators.InadditionweneedtofindawayofimplementingOData
pagingideallywithoutrequiringtheproxytoretrievethecompleteunpagedsetofentitiesfrom
theSPARQLendpoint.FinallywewouldliketoprovidetoolsforgeneratinganODataservice
metadatadocumentfromaSPARQLendpointoritsontologyandtogenerate/writemappings
forsomeoftheexistingpublicSPARQLendpoints.
DiscussionPoints
Proxyingasawaytobridgeopendatastandards.Seemstomakesenseforread/query,
butperhapslesssoforwrite/update.Isthisgoingtobeaprobleminthelongrun?
OData/LinkedDataPlatforminteropthisseemslikeitcouldbeaneasierpathtofollow,
butdoesitmakesenseforthedevelopmentofthesestandardstohappeninisolation.
WhatcouldLDPlearnfromODataandviceversa?
IsthereametamodelforanentityorientedviewofresourcesthatbothODataandLDP
couldshare?