Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Successfully reported this slideshow.

1,336 views

Published on

License: CC Attribution License

No Downloads

Total views

1,336

On SlideShare

0

From Embeds

0

Number of Embeds

3

Shares

0

Downloads

13

Comments

0

Likes

2

No embeds

No notes for slide

- 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. 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. 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. 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. 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. 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. Inductive Triple Graphs Simplified representation of Inductive Graphs 1st Proposal
- 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. 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. 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. 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. 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. 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. 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. Inductive RDF Graphs Based on Inductive Triple Graphs 2nd Proposal
- 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. 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. 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. 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. 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)
- 21. Implementation Haskell Scala
- 22. Haskell Implementation Haskell implementation Available at GitHub: https://github.com/labra/haws 2 Implementations Using Church like encoding Based on the FGL library
- 23. 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
- 24. Conclusions RDF graphs can be encoded using Inductive Triple Graphs Possible applications: Higher-order combinators: Folds, maps, etc. Program transformation and reasoning Concurrency Purely Functional Programming RDF Graphs
- 25. Future Work Inductive Triple Graphs Other domains? Inductive RDF Graphs Algebra of RDF Graphs RDF Graph Library Datatype Literals, Named graphs Implement Common RDF algorithms Normalization and comparison RDF Querying and traversal Real applications and performance comparisons
- 26. End of presentation

No public clipboards found for this slide

Be the first to comment