Upload
jose-emilio-labra-gayo
View
576
Download
1
Embed Size (px)
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
Citation preview
Inductive Triple Graphs: A purely functional approach to represent RDF
Johan JeuringUtrecht University
Open University of the Netherlands
Jose María Álvarez RodríguezSouth East European Research
CenterThe Netherlands
Jose Emilio Labra GayoUniversity of Oviedo
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
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
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
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
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
Inductive Triple Graphs
Simplified representation of Inductive Graphs
1st Proposal
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
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
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
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
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
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, ...
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
Inductive RDF Graphs
Based on Inductive Triple Graphs
2nd Proposal
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
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
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
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
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)
Implementation
HaskellScala
Haskell Implementation
Haskell implementationAvailable at GitHub:
https://github.com/labra/haws
2 ImplementationsUsing Church like encodingBased on the FGL library
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
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
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
End of presentation