Download presentation

Presentation is loading. Please wait.

Published byAlec Gartrell Modified over 2 years ago

1
PathLP – Path-based Logic Programming Mira Balaban, Igal Khitron Computer Science Department Ben-Gurion University Mini-project-course Fall 20131

2
PathLP compact logic programming A compact logic programming language Inspired from – Object-Oriented Logic Programming languages: F-Logic (Kifer, Lausen, Wu 1995) FLORA-2 (http://flora.sourceforge.net/, 2009)http://flora.sourceforge.net/ – Object-Oriented database and web query languages : XSQL (Kifer, Kim, Sagiv 1992) XPATH – a query language over XML documents (http://www.w3schools.com/xpath/). (http://www.w3schools.com/xpath/) guarded path expressions Supports reasoning over guarded path expressions typing notions: Supports typing notions: – Hierarchy – Membership Mini-project-course Fall 20132

3
PathLP status PathLP is still under development by Mira Balaban, Igal Khitron, Michael Kifer (alphabetical order). Intended for: – Formal support for Model-Level Integrated Development Environments : Simultaneous reasoning over multiple models – Reasoning over applications that support hierarchical structures, like Access policy in Network Management Publications: – Mira Balaban and Michael Kifer: "An Overview of F-OML: An F-Logic Based Object Modeling Language", ECEASST'11 36."An Overview of F-OML: An F-Logic Based Object Modeling Language" – Mira Balaban and Michael Kifer: "Logic Based Model-Level Software Development with F- OML", MoDELS'2011."Logic Based Model-Level Software Development with F- OML" – Igal Khitron, Michael Kifer, Mira Balaban: “PathLP: A Logic Programming Language of Path Expressions”, PLDE 2012. Application: Version 1.4 PathLP1.4 PathLP1.4 Mini-project-course Fall 20133

4
Model-level IDE – Needed modeling services modeling Provide a modeling constraint language for extending UML diagrams: – Object Constraint Language (OCL) – PathLP Verification Verification of UML diagrams design patterns Specification of design patterns. Reasoning Reasoning about UML diagrams Testing Testing UML diagrams Model Model refactoring Meta-modeling Meta-modeling : – DSML specification – Formalize UML specification Mini-project-course Fall 20134

5
Model-level IDE – Integration with a modeling platform Diagrammatic models Diagrammatic models – concrete external syntax. Mini-project-course Fall 20135 Modeling services model 1 model n … UML development platform model 1 -module … model n -module Underlying formal modeling language transformations

6
Model-level IDE – Integration with a modeling platform Diagrammatic models Diagrammatic models – concrete external syntax. Mini-project-course Fall 20136 model 1 -module … model n -module F-OM L PathLP Modeling services model 1 model n … UML development platform transformations

7
PathLP constructs Path expressions Facts Rules Constraints Queries Mini-project-course Fall 20137

8
PathLP: Object path expressions constants, variables,., guards Consist of constants, variables,., guards objects Denote objects ?C.friend.student[?S].name The names of a student s of a friend of c, for some bindings s and c to variables ?S and ?C Mini-project-course Fall 2013 constant variable guard 8 denotation c friend student s name student … … …

9
PathLP: Object path expressions & Query formulas Query formula: John.childWith(Mary)[?C].name[?N], ?C:Student,?C.ageAt(2010)<20 The name ?N of ?C, who is a child with Mary of John, is a student and whose age at 2010 is less than 20 Mini-project-course Fall 2013 elementary formula 9 denotation John ?C Student childWith(Mary) name … … ageAt(2010) n<20 elementary formula ?N

10
PathLP: Type path expressions Person!spouse[Person]{0..1} The type of spouse s of nodes of type Person (nodes pointed by spouse edges) is Person (or a subtype of Person ), and there is at most 1 such edge Assume – ?n1.spouse[?n2] – Mini-project-course Fall 201310 ?n1 spouse ?n2 Cardinality constraint

11
PathLP: Type path expressions Person!spouse[Person]{0..1} The type of spouse s of nodes of type Person is Person (or a subtype of Person ), and there is at most 1 such edge Assume – ?n1.spouse[?n2] – ?n1:Person Mini-project-course Fall 201311 Person ?n1 spouse ?n2

12
PathLP: Type path expressions Person!spouse[Person]{0..1} The type of spouse s of nodes of type Person is Person (or a subtype of Person ), and there is at most 1 such edge Assume – ?n1.spouse[?n2] – ?n1:Person Mini-project-course Fall 201312 and Person ?n1 IF at most 1 spouse edge spouse ?n2 THEN ?n2:Person

13
PathLP: Type path expressions Person!spouse[Person]{0..1} The type of spouse s of nodes of type Person is Person (or a subtype of Person ), and there is at most 1 such edge Assume – ?n1.spouse[?n2] – ?n1:Person Mini-project-course Fall 201313 and Person ?n1 spouse IF at most 1 spouse edge spouse ?n2 THEN Type edge spouse … ?n2:Person

14
PathLP: Facts – specify assertions John.spouse[Mary]; John.child[Bob]; John.child[Bill]; – John has a spouse Mary and children Bob and Bill (and possibly others) Type hierarchy and membership assertions: : Bob:CS_teaching_committee; :: CS_teaching_committee::Teaching_committee; : Teaching_committee:Committee; :: Committee::Group; – Bob CS_teaching_committee Teaching_committee Committee Group ! A type assertion: Person!spouse[Person]{0..1}; – The type of spous es of Person is Person, or one of its subtypes, and the cardinality constraint is {0..1} Mini-project-course Fall 201314

15
PathLP: Rules, Constraints, Queries Rules Rules – specify implications: – ?A:advisor :- ?T:Thesis, ?T.author.advisor[?A].read[?T],?A:Professor; ?A is an advisor if ?A has read a thesis ?T of an author that ?A advises Constraints Constraints – restrict legal states: – !- ?P:Professor, not ?P.degree[PhD]; forbid states with a professor ?P that does not have a PhD degree Queries Queries – trigger computation – ?- ?A:Professor, ?A.review[?Thesis], ?A.supervise.thesis-of[?Thesis]; Find a professor that reviews a thesis of somebody s/he supervises. A more compact expression: ?- ?A:Professor,?A.review.author.advisor[?A]; Mini-project-course Fall 201315

16
PathLP – as a basis for Object-Oriented modeling Defines entities: paths – Inter-related by paths typed – Possibly typed inclusion inclusion “::” membership membership “:” Multi-level Multi-level modeling: – Unrestricted “ :: “ and “ : “ Polymorphism: Polymorphism: – Parameterized – Parameterized path expressions – Type hierarchy Mini-project-course Fall 201316 Object navigation Class Class hierarchy Object creation; Testing Reflection Patterns Model query Static analysis

17
PathLP – implementation Beta version 1.4: – pathlp.sf.net (Igal Khitron) pathlp.sf.net – Compiler and interpreter – In XSB prolog open source tabling prolog supports well-founded negation – Windows, Linux, Unix – Large test cases: 200,000 facts Mini-project-course Fall 201317

18
Mini-Project subject – Develop a Graph Services library in PathLP An example library: JGraphTJGraphT From the JGraphT home page: – JGraphT is a free Java graph library that provides mathematical graph-theory objects and algorithms. JGraphT supports various types of graphs including: directed and undirected graphs. graphs with weighted / unweighted / labeled or any user-defined edges. various edge multiplicity options, including: simple-graphs, multigraphs, pseudographs. unmodifiable graphs - allow modules to provide "read-only" access to internal graphs. listenable graphs - allow external listeners to track modification events. subgraphs graphs that are auto-updating subgraph views on other graphs. all compositions of above graphs. – Although powerful, JGraphT is designed to be simple and type-safe (via Java generics). For example, graph vertices can be of any objects. You can create graphs based on: Strings, URLs, XML documents, etc; you can even create graphs of graphs! This code example shows how.code example Mini-project-course Fall 201318

19
Mini-Project subject – Develop a Graph Services library in PathLP Why having “yet another JGraphT” in PathLP?JGraphT Mini-project-course Fall 201319

20
Mini-Project subject – Develop a Graph Service library in PathLP Why having “yet another JGraphT” in PathLP?JGraphT What are the special features of Logic Programming languages? – Reasoning! – Answer queries! – Analysis! Mini-project-course Fall 201320

21
Graph representation in PathLP Directed graph: – Facts: n1.edge[n2]; n1.edge[n3]; n1.edge[n4]; n2.edge[n3]; n2.edge[n5]; n4.edge[n2]; n4.edge[n4]; n5.edge[n2]; n5.edge[n4]; Mini-project-course Fall 201321 n1 n2 n4n3 n5

22
Querying the directed graph Directed graph: – Facts: n1.edge[n2]; n1.edge[n3]; n1.edge[n4]; n2.edge[n3]; n2.edge[n5]; n4.edge[n2]; n4.edge[n4]; n5.edge[n2]; n5.edge[n4]; – Queries: ?- n1.edge[?N]; ?- ?N1.edge[?N2]; ?- ?N1.edge[?_N2],?_N2.edge[?N1]; ?- ?n.edge[?n]; ?- not n1.edge[n2]; ?- ?N._size(edge)[?edge_number],?edge_number<2 ; Mini-project-course Fall 201322 n1 n2 n4n3 n5

23
Reasoning about the directed graph Paths in the directed graph: – Rules: ?n1.path[?n2]:- ?n1.edge[?n2]; ?n1.path[?n2]:- ?n1.path[?n3],?n3.edge[?n2]; – Facts: n1.edge[n3];n4.edge[n2]; n1.edge[n4];n4.edge[n4]; n2.edge[n3];n5.edge[n2]; n2.edge[n5];n5.edge[n4]; – Queries: ?- n5.path[n5]; ?- ?N.path[n5]; ?- ?N.path[n5],?N != n5; ?- ?n.path[?n]; ?- not(n1.path[n1]); ?- n1.path[?N],not(?N.path[?N]); – Rule: ?n.selfPath[true]:- ?n.path[?n]; – Query: ?- ?N._size(selfpath)[?path_num],?path_num>1; Mini-project-course Fall 201323 n1 n2 n4n3 n5

24
Reasoning about the directed graph Adding path details and node typing: – Rules: ?N1.path([?N1,?N2])[?N2]:- ?N1.edge[?N2]; ?N1.path([?N1|?P])[?N3]:- ?N1.edge[?N2],?N2.path(?P)[?N3]; ?N1.loop[?N2]:- ?N1.edge[?N2],?N2.edge[?N1]; ?N.origin[true]:- ?N:Node,not ?N.enter_edge[true]; ?N.enter_edge[true]:- ?N1.edge[?N]; ?N.sink[true]:- ?N:Node,not ?N.leaving_edge[true]; ?N.leaving_edge[true]:- ?N.edge[?N1]; isolated(?N)[true] :- origin(?N)[true],sink(?N)[true]; – Facts: n1:Node; n2:Node; n3:Node; n4:Node; n5:Node; n6:Node; n1.edge[n3];n4.edge[n2]; n1.edge[n4];n4.edge[n4]; n2.edge[n3];n5.edge[n2]; n2.edge[n5];n5.edge[n4]; – Queries: ?- n5.path(?P)[n5]; ?- ?N.path(?P)[n5]; ?- ?N.path(?_P)[n5]; is the same as ?- ?N.path[n5]; ?- ?N.path(?_P)[n5],not ?_P.member[n4]; ?- ?N.loop[n5]; ?- ?N1.origin[true],?N2.origin[true],?N1!=?N2; ?- ?_N.isolated[true]); Mini-project-course Fall 201324 n1 n2 n4n3 n5 n6

25
Reasoning about the directed graph Adding labeled edges, edge typing, path typing: – Rules: ?P:Path :-?N1.path(?P)[?N2]; % Bad modeling! Why? ?P.nodes[?P] :- ?P:Path,?N1.path(?P)[?N2]; ?P.node[?N] :- ?P.nodes[?Node_list],?Node_list.member[?N]; ?E:Edge :- ?N1.edge(?E)[?N2]; ?E.source[?N] :- ?E:Edge,?N.edge(?E)[?N1]; – Facts: n1:Node; n2:Node; n3:Node; n4:Node; n5:Node; n6:Node; n1.edge[n3];n4.edge[n2]; n1.edge[n4];n4.edge[n4]; n2.edge[n3];n5.edge[n2]; n2.edge[n5];n5.edge(e54)[n4]; – Note the different design decision about the status of nodes and edges: Node typing is mandatory Edge typing is inferred Mini-project-course Fall 201325 n1 n2 n4n3 n5 n6 e54

26
Reasoning about the directed graph Improved path modeling: – Rules: path(?node_list):Path :-?N1.path(?node_list)[?N2]; path(?node_list).nodes[?node_list] :-?N1.path(?node_list)[?N2]; ?P.node[?N] :- ?P.nodes[?Node_list], ?Node_list.member[?N]; ?P.first[?N] :- ?P:Path, ?P.nodes[ [?N|?rest_nodes] ]; ?P.last[?N] :- ?P:Path, ?P.nodes[?node_list], ?node_list.reverse[[?N|?rest_nodes]]; – Constraints: !- ?P:Path, ?P.first[?N1], ?P.last[?N2], ?P.nodes[?node_list], not ?N1.path(?node_list)[?N2]; – Facts: n1:Node; n2:Node; n3:Node; n4:Node; n5:Node; n6:Node; n1.edge[n3];n4.edge[n2]; n1.edge[n4];n4.edge[n4]; n2.edge[n3];n5.edge[n2]; n2.edge[n5];n5.edge(e54)[n4]; Mini-project-course Fall 201326 n1 n2 n4n3 n5 n6 e54

27
Reasoning about the directed graph Adding more constraints: – Rules: path(?node_list):Path :-?N1.path(?node_list)[?N2]; path(?node_list).nodes[?node_list] :-?N1.path(?node_list)[?N2]; ?E:Edge :- ?N1.edge(?E)[?N2]; ?E.source[?N] :- ?E:Edge,?N.edge(?E)[?N1]; – Constraint: !- ?E.source[?N1],?E.source[?N2], ?N1!=?N2; !- ?N1.path(?P)[?N2], ?P.member[?N],not ?N:Node; A single labeled edge between nodes: !- ?N1.edge(?L1)[?N2], ?N1.edge(?L2)[?N2], ?L1 != ?L2; A single labeled edge leaving a node: !- Node!edge(?L)[Node]{0..1}; Mini-project-course Fall 201327 n1 n2 n4n3 n5 n6 e54

28
Reasoning about the directed graph Adding path properties and sub-typing: – Rules: path(?node_list):Compact_Path :- path(?node_list):Path, ?node_list.compactList[true]; ?List.compactList[true] :- not ?L1.append([?N],?L2,[?N],?L3)[?List]; ?P:Cycle :- ?P:Path,?P.first[?N],?P.last[?N]; path(?node_list).length[?number] :- ?node_list.length[?number]; Compact_Path :: Path; Cycle :: Path; – Constraints: !- path(?node_list):Compact_Path, not ?node_list.compactList[true]; !- ?P:Cycle, ?P.first[?N1], ?P.last[?N2], ?N1 != ?N2; Mini-project-course Fall 201328 n1 n2 n4n3 n5 n6 e54

29
Reasoning about the directed graph Adding multiple graphs: – Rules: ?G.node[?N] :-?G.nodes[?Node_list],?Node_list.member[?N]; ?N.graph[?G] :-?G.node[?N]; ?G1.intersection(?G2)[?G] :- ?G1.nodes[?Ns1],?G2.nodes[?Ns2], ?G1.edges[?Es1],?G2.edges[?Es2], ?Ns1.intersection(?Ns2)[?Ns], ?Es1.intersection(?Es2)[?Es], ?G:Directed_graph,?G.nodes[?Ns],?G.edges[?Es]; ?G.is_empty[true] :- ?G:Directed_graph,?G.nodes[ [] ]; ?G1.disjoint[?G2] :- ?G1.intersection(?G2)[?G], ?G.is_empty[true]; ?G.path[?P]:- ?P.nodes[?Nodes_P],?G.nodes[?Nodes_G], ?Nodes_G.contains[?Nodes_P]; ?G:Cyclic_directed_graph :- ?G.path[?P],?P:Cycle; ?G:DAG :- not ?G:Cyclic_directed_graph; – A different modeling approach – using functional constructors: intersection(?G1,?G2):Directed_graph :- ?G1:Directed_graph,?G2:Directed_graph; intersection(?G1,?G2).nodes[intersection(?Ns1,?Ns2)] :- ?G1.nodes[?Ns1],?G2.nodes[?Ns2]; – A type Constraint: Directed_graph!nodes[List]{1..1}; – Facts: g1:Directed_graph; g1.nodes[[n1,n2,n3,n4,n5,n6]]; g1.edges[[e12,e13,e14,e25,e52,e23,e42,e44]]; Mini-project-course Fall 201329

30
30Mini-project-course Fall 2013

Similar presentations

Presentation is loading. Please wait....

OK

4/20/2017.

4/20/2017.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on field study definition Ppt on shell structures analysis Ppt on phonetic transcription examples Ppt on area related to circles for class 10 Ppt on time response analysis control Cardiopulmonary anatomy and physiology ppt on cells Export pdf to ppt online convert Ppt on national education day india Ppt on dispersal of seeds by animals pictures Economics for kids ppt on batteries