Successfully reported this slideshow.                          Upcoming SlideShare
×

# Inductive Triple Graphs: A purely functional approach to represent RDF

1,336 views

Published on

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

Published in: Technology, Education
• Full Name
Comment goes here.

Are you sure you want to Yes No • Be the first to comment

### Inductive Triple Graphs: A purely functional approach to represent RDF

1. 1. Inductive Triple Graphs: A purely functional approach to represent RDF Johan Jeuring Utrecht University Open University of the Netherlands The Netherlands j.t.jeuring@uu.nl Jose María Álvarez Rodríguez South East European Research Center The Netherlands jmalvarez@seerc.org Jose Emilio Labra Gayo University of Oviedo Spain labra@uniovi.es
2. 2. Motivation Combine Purely Functional Programming and Semantic Web? Purely Functional Programming Referential transparency Immutable datastructures Scalability Concurrency, parallelism Higher-order functions Combinators Program transformation . . . Semantic Web RDF Graphs URIs as properties Blank nodes Graph manipulation SPARQL Inference Big Data . . . 2 separate communities
3. 3. 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
4. 4. Inductive Graphs Define the context of a node Nodes 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 r s 1 2 3
5. 5. 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 r s 1 2 3 a c b p q r s 1 2 3
6. 6. Inductive graphs FGL library Widely used in Haskell since 2001 Users 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
7. 7. Inductive Triple Graphs Simplified representation of Inductive Graphs 1st Proposal
8. 8. Assumptions Each node/edge hava a label Labels are unique Label of an edge can also be the label of a node Motivation No need for node indexes Edges that can also be nodes a b r p q
9. 9. 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 r s Context of b = ('b', [('a','p')], [('q','a'),('r','c')], [] ) Context of r = ('r',[],[],[('b','c')])
10. 10. Inductive definition data 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
11. 11. 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 (:&)
12. 12. Folds It is possible to define the Fold combinator over inductive triple graphs foldTGraph ∷ TGr gr ⇒ b → (TContext a → b → b) → gr a → b foldTGraph e f g = case nodes g of [] → e (n:_) → let (ctx,g') = match n g in f ctx (foldTGraph e f g') Fold is one of the most general combinators. Captures primitive recursion Lots of operations can be defined in terms of folds
13. 13. Other operations Map 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, ...
14. 14. Review Users don't need to be aware of node indexes Not possible to define graphs with errors Conversion Inductive graphs Triple inductive graphs Algorithm presented in paper Triple inductive graphs Inductive graphs Triple inductive graphs are implemented using FGL
15. 15. Inductive RDF Graphs Based on Inductive Triple Graphs 2nd Proposal
16. 16. 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
17. 17. RDF Graphs 3 aspects: Predicates (URIs) can be subjects or objects Each 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
18. 18. 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)
19. 19. 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
20. 20. Some operations Some operations on RDF Graphs Fold 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)