inductive triple graphs: a purely functional approach to represent rdf

26
Inductive Triple Graphs: A purely functional approach to represent RDF Johan Jeuring Utrecht University Open University of the Netherlands The Netherlands [email protected] Jose María Álvarez Rodríguez South East European Research Center The Netherlands [email protected] Jose Emilio Labra Gayo University of Oviedo Spain [email protected]

Upload: jose-emilio-labra-gayo

Post on 01-Nov-2014

579 views

Category:

Technology


1 download

DESCRIPTION

Slides of my presentation on 3rd International Workshop on Graph Structures for Knowledge Representation, part of the International Joint Conference on Artificial Intelligence, Beijing, China. 4 August 2013

TRANSCRIPT

Page 1: Inductive Triple Graphs: A purely functional approach to represent RDF

Inductive Triple Graphs: A purely functional approach to represent RDF

Johan JeuringUtrecht University

Open University of the Netherlands

The [email protected]

Jose María Álvarez RodríguezSouth East European Research

CenterThe Netherlands

[email protected]

Jose Emilio Labra GayoUniversity of Oviedo

[email protected]

Page 2: Inductive Triple Graphs: A purely functional approach to represent RDF

Motivation

Combine Purely Functional Programming and Semantic Web?

Purely Functional ProgrammingReferential transparency

Immutable datastructuresScalability

Concurrency, parallelismHigher-order functions

CombinatorsProgram transformation. . .

Semantic WebRDF Graphs

URIs as propertiesBlank nodes

Graph manipulationSPARQLInference

Big Data. . .

2 separate communities

Page 3: Inductive Triple Graphs: A purely functional approach to represent RDF

This talk in one slide

Review Inductive definitions of Graphs...so we can use the same techniques as with lists...this work was done by M. Erwig

1st Proposal: Inductive Triple graphs...predicates can be subjects and objects...no need for index handling (simplified API)

2nd Proposal: Inductive RDF Graphs...based on inductive triple graphs...higher-order functions like foldRDFGraph

Page 4: Inductive Triple Graphs: A purely functional approach to represent RDF

Inductive Graphs

Define the context of a nodeNodes are uniquely identified by an Int key

type Context a b = ([(Int,b)], ─ Predecessors Int, ─ Node index a, ─ Label [(Int,b)] ─ Succesors )

([(1,'p')], 2, 'b', [(1,'q'), (3,'r')])

Context of b =

a

c

b

p

q

rs

1 2

3

Martin Erwig, 01

Page 5: Inductive Triple Graphs: A purely functional approach to represent RDF

Inductive graphs

data Graph a b = Empty | Context a b :& Graph a b

([(2,'r')] ,3,'c',[(1,'s')]) :&

Empty([] ,1,'a',[] ) :&

([(1,'p')] ,2,'b',[(1,'q')]) :&

([(2,'q'),(3,'s')],1,'a',[(2,'p')]) :&

Empty([], 3,'c',[] ) :&

([], 2,'b',[(3,'r')]) :&

Same graph can be represented in different ways

a

c

b

p

q

rs

1 2

3

a

c

b

p

q

rs

1 2

3

Martin Erwig, 01

Page 6: Inductive Triple Graphs: A purely functional approach to represent RDF

Inductive graphs

FGL libraryWidely used in Haskell since 2001Users of the library handle node indexes (Int values)It is possible to create bad formed graphs.

Empty([], 1,'a',[] ) :&

([], 2,'b',[(42,'p')]) :&

?

a b1 2

42 ?

p

Martin Erwig, 01

Page 7: Inductive Triple Graphs: A purely functional approach to represent RDF

Inductive Triple Graphs

Simplified representation of Inductive Graphs

1st Proposal

Page 8: Inductive Triple Graphs: A purely functional approach to represent RDF

Assumptions

Each node/edge hava a labelLabels are uniqueLabel of an edge can also be the label of a nodeMotivation

No need for node indexesEdges that can also be nodes

a b

r

p

q

Inductive Triple Graphs

Page 9: Inductive Triple Graphs: A purely functional approach to represent RDF

Contexts

Context of node: list of predecessors, successors and related nodes

type TContext a = ( a, ─ Node [(a,a)], ─ Predecessors [(a,a)], ─ Successors [(a,a)] ─ Nodes Related )

a

c

b

p

q

rs

Context of b = ('b', [('a','p')], [('q','a'),('r','c')], [] )

Context of r = ('r',[],[],[('b','c')])

Inductive Triple Graphs

Page 10: Inductive Triple Graphs: A purely functional approach to represent RDF

Inductive definitiondata TGraph a = Empty | TContext a :& TGraph a

('a',[],[('p','b')],[]) :&

a b

r

p

q

('p',[],[('q','r')],[]) :&

a b

r

p

q

('r',[('p','q')],[],[]) :&

Empty

('p',[],[],[('a','b')]) :&

Empty

Same graph can also be represented in several ways

Inductive Triple Graphs

Page 11: Inductive Triple Graphs: A purely functional approach to represent RDF

API

In Haskell they are implemented as a type class

Can be seen as an API that hides internal representation

class TGr gr where empty ∷ gr a match ∷ a → gr a → (TContext a,gr a) mkGraph ∷ [(a,a,a)] → gr a nodes ∷ gr a → [a] extend ∷ TContext a → gr a → gr a

─ empty graph─ decompose a graph─ Graph from triples─ nodes of a graph─ extend a graph (:&)

Inductive Triple Graphs

Page 12: Inductive Triple Graphs: A purely functional approach to represent RDF

Folds

It is possible to define the Fold combinator over inductive triple graphs

foldTGraph ∷ TGr gr ⇒ b → (TContext a → b → b) → gr a → bfoldTGraph e f g = case nodes g of [] → e (n:_) → let (ctx,g') = match n g in f ctx (foldTGraph e f g')

Inductive Triple Graphs

Fold is one of the most general combinators. Captures primitive recursionLots of operations can be defined in terms of folds

Page 13: Inductive Triple Graphs: A purely functional approach to represent RDF

Other operations

Map

Inductive Triple Graphs

rev ∷ (TGr gr) ⇒ gr a → gr a rev = mapTGraph swapCtx where swapCtx (n,pred,succ,rels) = (n,succ,pred,map swap rels)

Reverse the edges in a graph

mapTGraph ∷ (TGr gr) ⇒ (TContext a → TContext b) → gr a → gr b mapTGraph f = foldTGraph empty (λc g → extend (f c) g)

Other examples...Depth First Search, Breadth First Search, topological sort, ...

Page 14: Inductive Triple Graphs: A purely functional approach to represent RDF

Review

Users don't need to be aware of node indexesNot possible to define graphs with errors

ConversionInductive graphs Triple inductive graphs

Algorithm presented in paper

Triple inductive graphs Inductive graphs Triple inductive graphs are implemented using FGL

Inductive Triple Graphs

Page 15: Inductive Triple Graphs: A purely functional approach to represent RDF

Inductive RDF Graphs

Based on Inductive Triple Graphs

2nd Proposal

Page 16: Inductive Triple Graphs: A purely functional approach to represent RDF

RDF Graphs

RDF model = graph made from triples (s,p,o) where: s = subject (URI or blanknode) p = predicate (URI) o = Object (URI, blanknode, literal)

_1:p

:b_2

@prefix : <http://example.org#> .:a :p _:1 .:a :p _:2 ._:1 :q :b ._:2 :r :b .:q :year 2013 .

:a

:p :q

:r

:year 2013

Turtle syntax

Inductive RDF Graphs

Page 17: Inductive Triple Graphs: A purely functional approach to represent RDF

RDF Graphs

3 aspects:Predicates (URIs) can be subjects or objectsEach node has a unique label (URI, literal, BNode Id)Blank nodes (BNodes) are locally scoped

BNodes can be seen as existential values

x:p

:by

∃x y∃

:a

:p :q

:r

:year 2013

Inductive RDF Graphs

Page 18: Inductive Triple Graphs: A purely functional approach to represent RDF

Definition

RDF Graphs can be:Ground: Inductive Triple Graphs over Resources Blank nodes: Encode bNodes with logical variables

data Resource = IRI String | Literal String | BNode BNodeId

type BNodeId = Int

data RDFGraph = Ground (TGraph Resource) | Exists (BNodeId → RDFGraph)

Inductive RDF Graphs

Page 19: Inductive Triple Graphs: A purely functional approach to represent RDF

Example with bNodes

x:p

:by

∃x

:a

:p :q

:r

:year 2013

Exists (λx →Exists (λy →

Ground (

(IRI "a",[],[(IRI "p",BNode x),(IRI "p",BNode y)],[]) :& (IRI "b",[(BNode x,IRI "q"),(BNode y,IRI "r")],[],[]) :&

(IRI "q", [(IRI "year",Literal "2013")], [], []) :& Empty)))

∃y

Inductive RDF Graphs

Page 20: Inductive Triple Graphs: A purely functional approach to represent RDF

Some operations

Some operations on RDF GraphsFold RDF graphs

Inductive RDF Graphs

mergeRDF ∷ RDFGraph → RDFGraph → RDFGraph mergeRDF g (Exists f) = Exists (λx → mergeRDF g (f x)) mergeRDF g (Basic g1) = foldTGraph g (λc g' → compRDF c g') g1

Merge 2 graphs

foldRDFGraph ∷ a → (TContext Resource → a → a) → RDFGraph → a foldRDFGraph e h = foldRDFGraph' e h 0 where foldRDFGraph' e h s (Basic g) = foldTGraph e h g foldRDFGraph' e h s (Exists f) = foldRDFGrap' e h (s + 1) (f s)

Page 21: Inductive Triple Graphs: A purely functional approach to represent RDF

Implementation

HaskellScala

Page 22: Inductive Triple Graphs: A purely functional approach to represent RDF

Haskell Implementation

Haskell implementationAvailable at GitHub:

https://github.com/labra/haws

2 ImplementationsUsing Church like encodingBased on the FGL library

Page 23: Inductive Triple Graphs: A purely functional approach to represent RDF

Scala Implementation

Based on Graph for Scala (Peter Empen)Available in GitHub

https://github.com/labra/wesin

Triple graphs are implemented as Hypergraph with 3-hyperedges

a b

r

p

q

a b

r

p

q

e1

e2

Page 24: Inductive Triple Graphs: A purely functional approach to represent RDF

Conclusions

RDF graphs can be encoded using Inductive Triple GraphsPossible applications:

Higher-order combinators: Folds, maps, etc.Program transformation and reasoningConcurrency

Purely FunctionalProgramming

RDF Graphs

Page 25: Inductive Triple Graphs: A purely functional approach to represent RDF

Future Work

Inductive Triple GraphsOther domains?

Inductive RDF GraphsAlgebra of RDF GraphsRDF Graph Library

Datatype Literals, Named graphs

Implement Common RDF algorithmsNormalization and comparisonRDF Querying and traversalReal applications and performance comparisons

Page 26: Inductive Triple Graphs: A purely functional approach to represent RDF

End of presentation