SlideShare ist ein Scribd-Unternehmen logo
1 von 104
Downloaden Sie, um offline zu lesen
A Portable and Extensible Approach for Linguistic
Symbiosis between an Object-Oriented and a Logic
Programming Language
Sergio Castro
Sergio.Castro@uclouvain.be
RELEASeD LAB
Université catholique de Louvain
Belgium
1
LogicObjects
Monday 26 August 13
2
OO
programming
Logic
programming
Useful for modelling
non-declarative concepts
Often enjoy rich software
ecosystems
Declarative reasoning &
Knowledge representation
Monday 26 August 13
2
OO
programming
Logic
programming
Useful for modelling
non-declarative concepts
Often enjoy rich software
ecosystems
Declarative reasoning &
Knowledge representation
Monday 26 August 13
2
OO
programming
Logic
programming
Useful for modelling
non-declarative concepts
Often enjoy rich software
ecosystems
Declarative reasoning &
Knowledge representation
Monday 26 August 13
2
OO
programming
Logic
programming
Useful for modelling
non-declarative concepts
Often enjoy rich software
ecosystems
Declarative reasoning &
Knowledge representation
Monday 26 August 13
3
Monday 26 August 13
Considerable amount of
integration tools and techniques
4
Monday 26 August 13
Considerable amount of
integration tools and techniques
4
SOUL
TyRuBa
JPL
InterProlog
PDT Connector
TuProlog
LogicJava Jiprolog
Kernel-Prolog
CIAO Prolog
Jasper
Jekejeke Prolog
Kiev
PrologBeans
PrologCafeJavaLog
MINERVA
jProlog
ProvaK-Prolog
CommonRules Styla
Jinni Prolog
Yajxb
Monday 26 August 13
Research scope
5
“Bidirectional linguistic integration between Prolog and a
statically typed, class based OO language (Java)”
Monday 26 August 13
But... why Java ?
• A huge Java ecosystem.
• Emerging languages running on the JVM (e.g. Scala, Clojure, etc.).
• A large user base.
6
We recognize the
advantages of:
Monday 26 August 13
Outline
• JPC: a portable Java-Prolog interoperability layer.
• LogicObjects: a linguistic integration framework.
• Research status.
• Future work.
• Conclusions.
7
Monday 26 August 13
8
Prolog engines
Bridge libraries
JPC drivers
JPC library
Java-Prolog
applications
Java-Prolog
frameworks
(layer coupling denoted by the
direction of the arrows)
High level architectural overview
Monday 26 August 13
• Attempts to facilitate the creation of hybrid Java-Prolog
applications and frameworks.
• Inspired by JPL, InterProlog and Google’s Gson libraries.
• Compatible with some popular open source Prolog engines
(XSB,YAP, SWI) and more coming soon.
• Available at the Maven central snapshot repository and
GitHub1 (currently) under the LGPL license.
9
1https://github.com/sergio-castro/
JPC: Java-Prolog connectivity
Monday 26 August 13
JPC features
• A portable abstraction of a Prolog virtual machine.
• A set of utilities for dealing with common Java-Prolog
interoperability problems.
• High level support for:
• Mapping between Java objects and Prolog terms.
• Dealing with object references and object serialization in
Prolog.
10
Monday 26 August 13
11
Converter
manager
Instantiation
manager
Type solver
JPC Context
A conversion context as a first
order entity
Monday 26 August 13
12
Converter1 Converter2 Converter3
Dispatcher
Converter manager
The converter manager
Monday 26 August 13
12
Converter1 Converter2 Converter3
Dispatcher
(chain of responsibility pattern)
Converter manager
The converter manager
Monday 26 August 13
12
Converter1 Converter2 Converter3
Dispatcher
(chain of responsibility pattern)
Converter manager
The converter manager
primitive types converters,
exception converters,
multi-valued converters,
etc.
Monday 26 August 13
Modularising mappings between
Java objects and Prolog terms
public class StationConverter extends JpcConverter<Station, Compound> {
	 public static final String STATION_FUNCTOR = "station";
	
	 @Override public Compound toTerm(Station station, Jpc context) {
	 	 return new Compound(STATION_FUNCTOR, asList(new Atom(station.getName())));
	 }
	
	 @Override public Station fromTerm(Compound term, Jpc context) {
	 	 String stationName = ((Atom)term.arg(1)).getName();
	 	 return new StationJpc(stationName);
	 }
}
13
Monday 26 August 13
Modularising mappings between
Java objects and Prolog terms
public class StationConverter extends JpcConverter<Station, Compound> {
	 public static final String STATION_FUNCTOR = "station";
	
	 @Override public Compound toTerm(Station station, Jpc context) {
	 	 return new Compound(STATION_FUNCTOR, asList(new Atom(station.getName())));
	 }
	
	 @Override public Station fromTerm(Compound term, Jpc context) {
	 	 String stationName = ((Atom)term.arg(1)).getName();
	 	 return new StationJpc(stationName);
	 }
}
13
Java type
Monday 26 August 13
Modularising mappings between
Java objects and Prolog terms
public class StationConverter extends JpcConverter<Station, Compound> {
	 public static final String STATION_FUNCTOR = "station";
	
	 @Override public Compound toTerm(Station station, Jpc context) {
	 	 return new Compound(STATION_FUNCTOR, asList(new Atom(station.getName())));
	 }
	
	 @Override public Station fromTerm(Compound term, Jpc context) {
	 	 String stationName = ((Atom)term.arg(1)).getName();
	 	 return new StationJpc(stationName);
	 }
}
13
Prolog type
Monday 26 August 13
Modularising mappings between
Java objects and Prolog terms
public class StationConverter extends JpcConverter<Station, Compound> {
	 public static final String STATION_FUNCTOR = "station";
	
	 @Override public Compound toTerm(Station station, Jpc context) {
	 	 return new Compound(STATION_FUNCTOR, asList(new Atom(station.getName())));
	 }
	
	 @Override public Station fromTerm(Compound term, Jpc context) {
	 	 String stationName = ((Atom)term.arg(1)).getName();
	 	 return new StationJpc(stationName);
	 }
}
13
Monday 26 August 13
Modularising mappings between
Java objects and Prolog terms
public class StationConverter extends JpcConverter<Station, Compound> {
	 public static final String STATION_FUNCTOR = "station";
	
	 @Override public Compound toTerm(Station station, Jpc context) {
	 	 return new Compound(STATION_FUNCTOR, asList(new Atom(station.getName())));
	 }
	
	 @Override public Station fromTerm(Compound term, Jpc context) {
	 	 String stationName = ((Atom)term.arg(1)).getName();
	 	 return new StationJpc(stationName);
	 }
}
13
Monday 26 August 13
Configuring a JPC context with a
custom converter
Jpc jpcContext = JpcBuilder.create()
.registerConverter(new StationConverter()).build();
14
Monday 26 August 13
Configuring a JPC context with a
custom converter
Jpc jpcContext = JpcBuilder.create()
.registerConverter(new StationConverter()).build();
14
Default builder
(includes pre-defined
converters)
Monday 26 August 13
Configuring a JPC context with a
custom converter
Jpc jpcContext = JpcBuilder.create()
.registerConverter(new StationConverter()).build();
14
Default builder
(includes pre-defined
converters)
Extending JPC with
new conversions
Monday 26 August 13
Querying Prolog with JPC
15
public class StationManager {
public static final Jpc jpcContext = ... //context includes StationConverter
...
public Station mainStation() {
	 String stationVarName = "Station";
	 Term goal = new Compound("main_station", asList(new Variable(stationVarName)));
	 Query query = getPrologEngine().query(goal, jpcContext);
	 return query.<Station>selectObject(stationVarName).oneSolutionOrThrow();
}
}
Monday 26 August 13
Querying Prolog with JPC
15
public class StationManager {
public static final Jpc jpcContext = ... //context includes StationConverter
...
public Station mainStation() {
	 String stationVarName = "Station";
	 Term goal = new Compound("main_station", asList(new Variable(stationVarName)));
	 Query query = getPrologEngine().query(goal, jpcContext);
	 return query.<Station>selectObject(stationVarName).oneSolutionOrThrow();
}
}
main_station(Station)
Monday 26 August 13
Querying Prolog with JPC
15
public class StationManager {
public static final Jpc jpcContext = ... //context includes StationConverter
...
public Station mainStation() {
	 String stationVarName = "Station";
	 Term goal = new Compound("main_station", asList(new Variable(stationVarName)));
	 Query query = getPrologEngine().query(goal, jpcContext);
	 return query.<Station>selectObject(stationVarName).oneSolutionOrThrow();
}
}
Monday 26 August 13
Querying Prolog with JPC
15
public class StationManager {
public static final Jpc jpcContext = ... //context includes StationConverter
...
public Station mainStation() {
	 String stationVarName = "Station";
	 Term goal = new Compound("main_station", asList(new Variable(stationVarName)));
	 Query query = getPrologEngine().query(goal, jpcContext);
	 return query.<Station>selectObject(stationVarName).oneSolutionOrThrow();
}
}
binding of Station as a Java object
Monday 26 August 13
Dealing with object references
@Test
public void testJRef() {
Object o = new Object();
Term jRef = RefManager.jRefTerm(o);
assertTrue(o == jpc.fromTerm(jRef));
o = null;
System.gc();
try {
	 jpc.fromTerm(jRef);
	 fail();
} catch(RuntimeException e) {}
}
16
Monday 26 August 13
Dealing with serialized objects
@Test
public void testSerializedTerm() {
	 String s = "hello";
	 Term term = SerializedObject.serializedObjectTerm(s);
	 String s2 = jpc.fromTerm(term);
	 assertFalse(s == s2);
	 assertEquals(s, s2);
}
17
Monday 26 August 13
18
A Prolog query
browser based on
JPC
Monday 26 August 13
19
Monday 26 August 13
JPC as a library for implementing
Java-Prolog frameworks
20
Prolog engines
Bridge libraries
JPC drivers
JPC library
Java-Prolog
applications
Java-Prolog
frameworks
(layer coupling denoted by the
direction of the arrows)
Monday 26 August 13
JPC as a library for implementing
Java-Prolog frameworks
20
Prolog engines
Bridge libraries
JPC drivers
JPC library
Java-Prolog
applications
Java-Prolog
frameworks
(layer coupling denoted by the
direction of the arrows)
e.g. LogicObjects
Monday 26 August 13
LogicObjects
• A portable Java-Prolog linguistic symbiosis framework.
• Implemented on top of the JPC library.
• Provides obliviousness concerning integration (in common
scenarios).
• Based on annotations for customising the integration and
minimising programming effort.
21
Monday 26 August 13
Symbiosis
22
“The intimate living together of two dissimilar organisms in a
mutually beneficial relationship.” (Merriam-Webster dictionary)
Monday 26 August 13
Linguistic symbiosis
• Objects from different worlds must understand each other.
• Invoking routines from another language as if they were defined
in their own language.
23
• Easier to achieve if the
languages belong to the
same paradigm.
Monday 26 August 13
A paradigm leak
“The event of concepts leaking from one programming paradigm
to another”
24
* Brichau, J. et al.
Towards linguistic symbiosis of an object-oriented and a logic
programming language.
In Proceedings of the Workshop on Multiparadigm Programming with Object-
Oriented Languages. (2002)
*
Monday 26 August 13
The inhabitants of our two
worlds
25
The OO
world
The logic
world
Monday 26 August 13
The inhabitants of our two
worlds
25
Classes
Objects
Messages
Methods
Return values
Packages The OO
world
The logic
world
Facts
Rules
Terms
Queries
Query solutions
Modules
Monday 26 August 13
Reducing the gap with Logtalk
26
The OO
world
The logic
world
Monday 26 August 13
Reducing the gap with Logtalk
26
The OO
world
The logic
world
Logtalk
An object-oriented layer
Monday 26 August 13
Case study
27
The London underground
from:
Monday 26 August 13
Relevant concepts
28
The London underground
Monday 26 August 13
Relevant concepts
28
The London underground
stations
linesmetro
Monday 26 August 13
A rule based system using Prolog
connected(station(bond_street), station(oxford_circus), line(central)).
connected(station(oxford_circus), station(tottenham_court_road), line(central)).
...
nearby(S1,S2) :- connected(S1,S2,_).
nearby(S1,S2) :- connected(S1,S3,L), connected(S3,S2,L).
reachable(S1,S2,[]) :- connected(S1,S2,_).
reachable(S1,S2,[S3|Ss]) :- connected(S1,S3,_), reachable(S3,S2,Ss).
line(Name) :- setof(L, S1^S2^connected(S1,S2,L), Ls), list::member(line(Name), Ls).
29
Monday 26 August 13
A rule based system using Prolog
connected(station(bond_street), station(oxford_circus), line(central)).
connected(station(oxford_circus), station(tottenham_court_road), line(central)).
...
nearby(S1,S2) :- connected(S1,S2,_).
nearby(S1,S2) :- connected(S1,S3,L), connected(S3,S2,L).
reachable(S1,S2,[]) :- connected(S1,S2,_).
reachable(S1,S2,[S3|Ss]) :- connected(S1,S3,_), reachable(S3,S2,Ss).
line(Name) :- setof(L, S1^S2^connected(S1,S2,L), Ls), list::member(line(Name), Ls).
29
FACTS
Monday 26 August 13
A rule based system using Prolog
connected(station(bond_street), station(oxford_circus), line(central)).
connected(station(oxford_circus), station(tottenham_court_road), line(central)).
...
nearby(S1,S2) :- connected(S1,S2,_).
nearby(S1,S2) :- connected(S1,S3,L), connected(S3,S2,L).
reachable(S1,S2,[]) :- connected(S1,S2,_).
reachable(S1,S2,[S3|Ss]) :- connected(S1,S3,_), reachable(S3,S2,Ss).
line(Name) :- setof(L, S1^S2^connected(S1,S2,L), Ls), list::member(line(Name), Ls).
29
RULES
Monday 26 August 13
Adding an object-oriented layer
with Logtalk
connected(station(bond_street), station(oxford_circus), line(central)).
connected(station(oxford_circus), station(tottenham_court_road), line(central)).
...
nearby(S1,S2) :- connected(S1,S2,_).
nearby(S1,S2) :- connected(S1,S3,L), connected(S3,S2,L).
reachable(S1,S2,[]) :- connected(S1,S2,_).
reachable(S1,S2,[S3|Ss]) :- connected(S1,S3,_), reachable(S3,S2,Ss).
line(Name) :- setof(L, S1^S2^connected(S1,S2,L), Ls), list::member(line(Name), Ls).
30
:- object(metro).
:- end_object.
Monday 26 August 13
Adding an object-oriented layer
with Logtalk
connected(station(bond_street), station(oxford_circus), line(central)).
connected(station(oxford_circus), station(tottenham_court_road), line(central)).
...
nearby(S1,S2) :- connected(S1,S2,_).
nearby(S1,S2) :- connected(S1,S3,L), connected(S3,S2,L).
reachable(S1,S2,[]) :- connected(S1,S2,_).
reachable(S1,S2,[S3|Ss]) :- connected(S1,S3,_), reachable(S3,S2,Ss).
line(Name) :- setof(L, S1^S2^connected(S1,S2,L), Ls), list::member(line(Name), Ls).
30
:- object(metro).
:- end_object.
Monday 26 August 13
Adding an object-oriented layer
with Logtalk
connected(station(bond_street), station(oxford_circus), line(central)).
connected(station(oxford_circus), station(tottenham_court_road), line(central)).
...
nearby(S1,S2) :- connected(S1,S2,_).
nearby(S1,S2) :- connected(S1,S3,L), connected(S3,S2,L).
reachable(S1,S2,[]) :- connected(S1,S2,_).
reachable(S1,S2,[S3|Ss]) :- connected(S1,S3,_), reachable(S3,S2,Ss).
line(Name) :- setof(L, S1^S2^connected(S1,S2,L), Ls), list::member(line(Name), Ls).
30
:- object(metro).
:- end_object.
:- public([connected/3, nearby/2, reachable/3, line/1]). ACCESS MODIFIERS
Monday 26 August 13
Logtalk parametric objects
31
:- object(line(_Name)).
:- public([name/1, connects/2]).
name(Name) :- parameter(1, Name).
...	
:- end_object.
:- object(station(_Name)).
:- public([name/1, connected/2, nearby/1, reachable/2]).
name(Name) :- parameter(1, Name).
...	
:- end_object.
Monday 26 August 13
PARAMETRIC OBJECT
Logtalk parametric objects
31
:- object(line(_Name)).
:- public([name/1, connects/2]).
name(Name) :- parameter(1, Name).
...	
:- end_object.
:- object(station(_Name)).
:- public([name/1, connected/2, nearby/1, reachable/2]).
name(Name) :- parameter(1, Name).
...	
:- end_object.
Monday 26 August 13
PARAMETRIC OBJECT
PARAMETRIC OBJECT
Logtalk parametric objects
31
:- object(line(_Name)).
:- public([name/1, connects/2]).
name(Name) :- parameter(1, Name).
...	
:- end_object.
:- object(station(_Name)).
:- public([name/1, connected/2, nearby/1, reachable/2]).
name(Name) :- parameter(1, Name).
...	
:- end_object.
Monday 26 August 13
Invoking a Logtak method
Messages in Logtalk are expressed with the :: operator.
For example:
line(central)::connects(Station1, Station2)
Answers all the stations connected by the line ‘central’
32
Monday 26 August 13
Invoking a Logtak method
Messages in Logtalk are expressed with the :: operator.
For example:
line(central)::connects(Station1, Station2)
Answers all the stations connected by the line ‘central’
32
Monday 26 August 13
Meta-level artefacts from the two
worlds
33
Monday 26 August 13
The Java world
34
public abstract class Line {
	 String name;
public Line(String name) {this.name = name;}
	
	 public abstract boolean connects(Station s1, Station s2);
	
	
	 public abstract int segments();	
}
public abstract class Station {
...
}
public abstract class Metro {
...
}
Monday 26 August 13
The Java world
34
public abstract class Line {
	 String name;
public Line(String name) {this.name = name;}
	
	 public abstract boolean connects(Station s1, Station s2);
	
	
	 public abstract int segments();	
}
public abstract class Station {
...
}
public abstract class Metro {
...
}
@LObject(args={“name”})
@LMethod(name={“connects”}, args={“_”, “_”})
@LObject(args={“name”})
Monday 26 August 13
Linguistic symbiosis challenges
• Translating objects to logic terms (and back).
• Mapping OO methods to logic queries.
• Dealing with unbound variables.
• Returning values from queries.
• Managing multiplicity.
35
* Some of them presented a bit differently in:
D'Hondt, M. et al.
Seamless integration of rule-based knowledge and object-
oriented functionality with linguistic symbiosis.
In Proceedings of the 2004 ACM symposium on Applied computing.
(2004)
*
Monday 26 August 13
public abstract class Metro {...}
@LObject(name = "my_metro")
public abstract class Metro {...}
@LObject(args = {"name"})
public abstract class Line {
	 private String name;
...	
}
metro
my_metro
line(lineName)
Translating objects to logic terms
36
Java Prolog
Monday 26 August 13
public abstract class Metro {...}
@LObject(name = "my_metro")
public abstract class Metro {...}
@LObject(args = {"name"})
public abstract class Line {
	 private String name;
...	
}
metro
my_metro
line(lineName)
Translating objects to logic terms
36
Java Prolog
Monday 26 August 13
public abstract class Metro {...}
@LObject(name = "my_metro")
public abstract class Metro {...}
@LObject(args = {"name"})
public abstract class Line {
	 private String name;
...	
}
metro
my_metro
line(lineName)
Translating objects to logic terms
36
Java Prolog
Monday 26 August 13
public abstract class Metro {...}
@LObject(name = "my_metro")
public abstract class Metro {...}
@LObject(args = {"name"})
public abstract class Line {
	 private String name;
...	
}
metro
my_metro
line(lineName)
Translating objects to logic terms
36
Java Prolog
Monday 26 August 13
line(lName)::connects(
station(s1Name), station(s2Name)).
line(lName)::connects(_, _).
Mapping Java methods to Logtalk
methods
37
@LObject(args = {"name"})
public abstract class Line {
private String name;
public abstract
boolean connects(Station s1, Station s2);
	
	
@LMethod(name = "connects", args = {"_", "_"})	
public abstract
int segments();	
}
Java Prolog
Monday 26 August 13
line(lName)::connects(
station(s1Name), station(s2Name)).
line(lName)::connects(_, _).
Mapping Java methods to Logtalk
methods
37
@LObject(args = {"name"})
public abstract class Line {
private String name;
public abstract
boolean connects(Station s1, Station s2);
	
	
@LMethod(name = "connects", args = {"_", "_"})	
public abstract
int segments();	
}
Java Prolog
Monday 26 August 13
line(lName)::connects(
station(s1Name), station(s2Name)).
line(lName)::connects(_, _).
Mapping Java methods to Logtalk
methods
37
@LObject(args = {"name"})
public abstract class Line {
private String name;
public abstract
boolean connects(Station s1, Station s2);
	
	
@LMethod(name = "connects", args = {"_", "_"})	
public abstract
int segments();	
}
Java Prolog
Monday 26 August 13
line(lName)::connects(
station(s1Name), station(s2Name)).
line(lName)::connects(_, _).
Mapping Java methods to Logtalk
methods
37
@LObject(args = {"name"})
public abstract class Line {
private String name;
public abstract
boolean connects(Station s1, Station s2);
	
	
@LMethod(name = "connects", args = {"_", "_"})	
public abstract
int segments();	
}
Java Prolog
anonymous variables
Monday 26 August 13
38
Interpreting a query result as a
Java object
The logic solutions
Varx1 x1, Vary1 y1
Varx2 x2, Vary2 y2
Varxn xn, Varyn yn
Monday 26 August 13
38
Interpreting a query result as a
Java object
The logic solutions
Varx1 x1, Vary1 y1
Varx2 x2, Vary2 y2
Varxn xn, Varyn yn
(set of frames binding logic
variables to terms)
frame 1
frame 2
frame n
Monday 26 August 13
39
Interpreting a query result as a
Java object
The logic solutions
Varx1 x1, Vary1 y1
Varx2 x2, Vary2 y2
Varxn xn, Varyn yn
(set of frames binding logic
variables to terms)
Monday 26 August 13
39
Interpreting a query result as a
Java object
The logic solutions The method return value
Varx1 x1, Vary1 y1
Varx2 x2, Vary2 y2
aJavaObject
Varxn xn, Varyn yn
(set of frames binding logic
variables to terms)
Monday 26 August 13
40
The logic solutions
Varx1 x1, Vary1 y1
Varx2 x2, Vary2 y2
Varxn xn, Varyn yn
(set of frames binding logic
variables to terms)
Returning values from one
solution
Monday 26 August 13
40
The logic solutions The method return value
Varx1 x1, Vary1 y1
Varx2 x2, Vary2 y2
aJavaObject
Varxn xn, Varyn yn
(set of frames binding logic
variables to terms)
Returning values from one
solution
Monday 26 August 13
41
Returning values from one
solution
The logic solutions The method return value
term(Varx1, Vary1)
Varx1 x1, Vary1 y1
Varx2 x2, Vary2 y2
Varxn xn, Varyn yn
(set of frames binding logic
variables to terms)
Monday 26 August 13
41
Returning values from one
solution
The logic solutions The method return value
term(Varx1, Vary1)
Varx1 x1, Vary1 y1
Varx2 x2, Vary2 y2
Varxn xn, Varyn yn
(set of frames binding logic
variables to terms)
(specified in a method
with @LSolution)
Monday 26 August 13
41
Returning values from one
solution
The logic solutions The method return value
term(Varx1, Vary1)
Varx1 x1, Vary1 y1 term(x1, y1)
Varx2 x2, Vary2 y2 term(x2, y2)
Varxn xn, Varyn yn term(xn, yn)
(set of frames binding logic
variables to terms)
(specified in a method
with @LSolution)
(default solution)
Monday 26 August 13
42
Explicit specification of return
values
@LObject(args = {"name"})
public abstract class Station {
@LSolution("IStations")
@LMethod(name = "reachable", args = {"$1", "IStations"})
public abstract List<Station> intermediateStations(Station station);
...
Monday 26 August 13
42
Explicit specification of return
values
@LObject(args = {"name"})
public abstract class Station {
@LSolution("IStations")
@LMethod(name = "reachable", args = {"$1", "IStations"})
public abstract List<Station> intermediateStations(Station station);
...
Monday 26 August 13
• Preprocessing macros and Java exp.
• Convert arguments to terms.
• Convert method to a predicate.
• Convert receiver object to a term.
• Build a query.
• Determine solution heuristic.
• Convert solution terms back to objects.
43
• $1 => station (method parameter).
• (station(a), IStations)
• intermediateStations => reachable/2.
• station(b)
• station(b)::reachable(station(a), IStations)
• Binding of IStations (first solution).
• [station(x), station(y)] => List<Station>
Processing Steps Outcome
@LObject(args = {"name"})
public abstract class Station {
@LSolution("IStations")
@LMethod(name = "reachable", args = {"$1", "IStations"})
public abstract List<Station> intermediateStations(Station station);
...
}
Monday 26 August 13
first Java method parameter
• Preprocessing macros and Java exp.
• Convert arguments to terms.
• Convert method to a predicate.
• Convert receiver object to a term.
• Build a query.
• Determine solution heuristic.
• Convert solution terms back to objects.
43
• $1 => station (method parameter).
• (station(a), IStations)
• intermediateStations => reachable/2.
• station(b)
• station(b)::reachable(station(a), IStations)
• Binding of IStations (first solution).
• [station(x), station(y)] => List<Station>
Processing Steps Outcome
@LObject(args = {"name"})
public abstract class Station {
@LSolution("IStations")
@LMethod(name = "reachable", args = {"$1", "IStations"})
public abstract List<Station> intermediateStations(Station station);
...
}
Monday 26 August 13
first Java method parameter
• Preprocessing macros and Java exp.
• Convert arguments to terms.
• Convert method to a predicate.
• Convert receiver object to a term.
• Build a query.
• Determine solution heuristic.
• Convert solution terms back to objects.
43
• $1 => station (method parameter).
• (station(a), IStations)
• intermediateStations => reachable/2.
• station(b)
• station(b)::reachable(station(a), IStations)
• Binding of IStations (first solution).
• [station(x), station(y)] => List<Station>
Processing Steps Outcome
@LObject(args = {"name"})
public abstract class Station {
@LSolution("IStations")
@LMethod(name = "reachable", args = {"$1", "IStations"})
public abstract List<Station> intermediateStations(Station station);
...
}
unbound
Prolog variable
(as term)
Monday 26 August 13
• Preprocessing macros and Java exp.
• Convert arguments to terms.
• Convert method to a predicate.
• Convert receiver object to a term.
• Build a query.
• Determine solution heuristic.
• Convert solution terms back to objects.
43
• $1 => station (method parameter).
• (station(a), IStations)
• intermediateStations => reachable/2.
• station(b)
• station(b)::reachable(station(a), IStations)
• Binding of IStations (first solution).
• [station(x), station(y)] => List<Station>
Processing Steps Outcome
@LObject(args = {"name"})
public abstract class Station {
@LSolution("IStations")
@LMethod(name = "reachable", args = {"$1", "IStations"})
public abstract List<Station> intermediateStations(Station station);
...
}
Monday 26 August 13
• Preprocessing macros and Java exp.
• Convert arguments to terms.
• Convert method to a predicate.
• Convert receiver object to a term.
• Build a query.
• Determine solution heuristic.
• Convert solution terms back to objects.
43
• $1 => station (method parameter).
• (station(a), IStations)
• intermediateStations => reachable/2.
• station(b)
• station(b)::reachable(station(a), IStations)
• Binding of IStations (first solution).
• [station(x), station(y)] => List<Station>
Processing Steps Outcome
@LObject(args = {"name"})
public abstract class Station {
@LSolution("IStations")
@LMethod(name = "reachable", args = {"$1", "IStations"})
public abstract List<Station> intermediateStations(Station station);
...
}
(instance of)
Monday 26 August 13
station(b)::reachable(station(a), IStations)
• Preprocessing macros and Java exp.
• Convert arguments to terms.
• Convert method to a predicate.
• Convert receiver object to a term.
• Build a query.
• Determine solution heuristic.
• Convert solution terms back to objects.
43
• $1 => station (method parameter).
• (station(a), IStations)
• intermediateStations => reachable/2.
• station(b)
• station(b)::reachable(station(a), IStations)
• Binding of IStations (first solution).
• [station(x), station(y)] => List<Station>
Processing Steps Outcome
@LObject(args = {"name"})
public abstract class Station {
@LSolution("IStations")
@LMethod(name = "reachable", args = {"$1", "IStations"})
public abstract List<Station> intermediateStations(Station station);
...
}
Monday 26 August 13
station(b)::reachable(station(a), IStations)
• Preprocessing macros and Java exp.
• Convert arguments to terms.
• Convert method to a predicate.
• Convert receiver object to a term.
• Build a query.
• Determine solution heuristic.
• Convert solution terms back to objects.
43
• $1 => station (method parameter).
• (station(a), IStations)
• intermediateStations => reachable/2.
• station(b)
• station(b)::reachable(station(a), IStations)
• Binding of IStations (first solution).
• [station(x), station(y)] => List<Station>
Processing Steps Outcome
@LObject(args = {"name"})
public abstract class Station {
@LSolution("IStations")
@LMethod(name = "reachable", args = {"$1", "IStations"})
public abstract List<Station> intermediateStations(Station station);
...
}
Monday 26 August 13
station(b)::reachable(station(a), IStations)
• Preprocessing macros and Java exp.
• Convert arguments to terms.
• Convert method to a predicate.
• Convert receiver object to a term.
• Build a query.
• Determine solution heuristic.
• Convert solution terms back to objects.
43
• $1 => station (method parameter).
• (station(a), IStations)
• intermediateStations => reachable/2.
• station(b)
• station(b)::reachable(station(a), IStations)
• Binding of IStations (first solution).
• [station(x), station(y)] => List<Station>
Processing Steps Outcome
@LObject(args = {"name"})
public abstract class Station {
@LSolution("IStations")
@LMethod(name = "reachable", args = {"$1", "IStations"})
public abstract List<Station> intermediateStations(Station station);
...
}
Monday 26 August 13
44
Returning multiple values from
queries
The logic solutions The method return value
term(Varx1, Vary1)
Varx1 x1, Vary1 y1 term(x1, y1)
Varx2 x2, Vary2 y2 term(x2, y2)
Varxn xn, Varyn yn term(xn, yn)
Monday 26 August 13
44
Returning multiple values from
queries
The logic solutions The method return value
term(Varx1, Vary1)
Varx1 x1, Vary1 y1 term(x1, y1)
Varx2 x2, Vary2 y2 term(x2, y2)
Varxn xn, Varyn yn term(xn, yn)
a composed solution
(specified in a method
with @LComposition)
Monday 26 August 13
45
The logic solutions The method return value
(a property of the result set)
Varx1 x1, Vary1 y1
Varx2 x2, Vary2 y2
Varxn xn, Varyn yn
Returning a property of the result
set
}
Monday 26 August 13
45
The logic solutions The method return value
(a property of the result set)
Varx1 x1, Vary1 y1
Varx2 x2, Vary2 y2
Varxn xn, Varyn yn
is there a solution ?
Returning a property of the result
set
how many solutions ?
}
Monday 26 August 13
Returning a property of the result
set
46
@LObject(args = {"name"})
public abstract class Line {
private String name;
	
public abstract
boolean connects(Station s1, Station s2);
	
	
@LMethod(name = "connects", args = {"_", "_"})	
public abstract
int segments();	
}
Monday 26 August 13
Returning a property of the result
set
46
@LObject(args = {"name"})
public abstract class Line {
private String name;
	
public abstract
boolean connects(Station s1, Station s2);
	
	
@LMethod(name = "connects", args = {"_", "_"})	
public abstract
int segments();	
}
should return if logic method succeeds or not
Monday 26 August 13
Returning a property of the result
set
46
@LObject(args = {"name"})
public abstract class Line {
private String name;
	
public abstract
boolean connects(Station s1, Station s2);
	
	
@LMethod(name = "connects", args = {"_", "_"})	
public abstract
int segments();	
}
should return if logic method succeeds or not
should return the number of solutions
Monday 26 August 13
Instantiating a symbiotic object in
Java
Line line = newLogicObject(Line.class, “central”);
System.out.println("Number of segments of line " + line + ": " + line.segments());
47
Monday 26 August 13
Instantiating a symbiotic object in
Java
Line line = newLogicObject(Line.class, “central”);
System.out.println("Number of segments of line " + line + ": " + line.segments());
47
Monday 26 August 13
Instantiating a symbiotic object in
Java
Line line = newLogicObject(Line.class, “central”);
System.out.println("Number of segments of line " + line + ": " + line.segments());
47
Monday 26 August 13
Other features
• Java expressions embedded in logic terms (symbiosis terms).
• Dependency management support.
• Integration with plain Prolog (without Logtalk).
• Not constrained to a specific execution environment (e.g. an
Eclipse plugin).
48
Monday 26 August 13
Inspiration from other domains
• Common interoperability layer: JDBC.
• Mapping artefacts using annotations: JAXB.
• Context dependent conversions: GSON.
• Linguistic symbiosis concepts: SOUL.
49
1http://www.oracle.com/technetwork/java/javase/jdbc/
2https://jaxb.java.net/
3http://code.google.com/p/google-gson/
4http://soft.vub.ac.be/SOUL/
1
2
3
4
Monday 26 August 13
implemented
pending
if time allows it
• Integration direction
• OO to Prolog
• Prolog to OO
• Linguistic symbiosis
• Automation
• Transparency
• Customisation
• Preserving causality
• Inter-language reflection
• Code querying
• Code transformation
• Code generation
• Symbiotic inter-language reflection
• Portability
Research status
50
Monday 26 August 13
Future work
• Finishing a full bidirectional linguistic symbiosis framework.
• Exploring the feasibility of our approach for symbiotic inter-
language reflection.
• Adding support for more Prolog engines (e.g. an embedded
one).
• Continue the development of reusable hybrid components.
51
Monday 26 August 13
Conclusions
• We are actively exploring how far we can get in automation/
transparency regarding Java-Prolog linguistic integration.
• We are attempting to provide reusable hybrid components
and frameworks that may be helpful to the community.
• And we are trying to do this in a portable way.
52
Monday 26 August 13

Weitere ähnliche Inhalte

Was ist angesagt?

Java Collections API
Java Collections APIJava Collections API
Java Collections APIAlex Miller
 
Java.util.concurrent.concurrent hashmap
Java.util.concurrent.concurrent hashmapJava.util.concurrent.concurrent hashmap
Java.util.concurrent.concurrent hashmapSrinivasan Raghvan
 
How to Think in RxJava Before Reacting
How to Think in RxJava Before ReactingHow to Think in RxJava Before Reacting
How to Think in RxJava Before ReactingIndicThreads
 
JDK1.7 features
JDK1.7 featuresJDK1.7 features
JDK1.7 featuresindia_mani
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for AndroidTomáš Kypta
 
Reactive programming with RxAndroid
Reactive programming with RxAndroidReactive programming with RxAndroid
Reactive programming with RxAndroidSavvycom Savvycom
 
Intro to Java 8 Closures (Dainius Mezanskas)
Intro to Java 8 Closures (Dainius Mezanskas)Intro to Java 8 Closures (Dainius Mezanskas)
Intro to Java 8 Closures (Dainius Mezanskas)Kaunas Java User Group
 
Introduction to Retrofit and RxJava
Introduction to Retrofit and RxJavaIntroduction to Retrofit and RxJava
Introduction to Retrofit and RxJavaFabio Collini
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJavaJobaer Chowdhury
 
Codefreeze eng
Codefreeze engCodefreeze eng
Codefreeze engDevexperts
 
Reactive Android: RxJava and beyond
Reactive Android: RxJava and beyondReactive Android: RxJava and beyond
Reactive Android: RxJava and beyondFabio Tiriticco
 
Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams IndicThreads
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present FutureIndicThreads
 
Just Another QSAR Project under OpenTox
Just Another QSAR Project under OpenToxJust Another QSAR Project under OpenTox
Just Another QSAR Project under OpenToxPantelis Sopasakis
 
An Introduction to RxJava
An Introduction to RxJavaAn Introduction to RxJava
An Introduction to RxJavaSanjay Acharya
 

Was ist angesagt? (20)

Java Collections API
Java Collections APIJava Collections API
Java Collections API
 
Java after 8
Java after 8Java after 8
Java after 8
 
Java.util.concurrent.concurrent hashmap
Java.util.concurrent.concurrent hashmapJava.util.concurrent.concurrent hashmap
Java.util.concurrent.concurrent hashmap
 
How to Think in RxJava Before Reacting
How to Think in RxJava Before ReactingHow to Think in RxJava Before Reacting
How to Think in RxJava Before Reacting
 
Java 8 streams
Java 8 streams Java 8 streams
Java 8 streams
 
JDK1.7 features
JDK1.7 featuresJDK1.7 features
JDK1.7 features
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
 
Collections forceawakens
Collections forceawakensCollections forceawakens
Collections forceawakens
 
Reactive programming with RxAndroid
Reactive programming with RxAndroidReactive programming with RxAndroid
Reactive programming with RxAndroid
 
Intro to Java 8 Closures (Dainius Mezanskas)
Intro to Java 8 Closures (Dainius Mezanskas)Intro to Java 8 Closures (Dainius Mezanskas)
Intro to Java 8 Closures (Dainius Mezanskas)
 
Introduction to Retrofit and RxJava
Introduction to Retrofit and RxJavaIntroduction to Retrofit and RxJava
Introduction to Retrofit and RxJava
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJava
 
Codefreeze eng
Codefreeze engCodefreeze eng
Codefreeze eng
 
Reactive Android: RxJava and beyond
Reactive Android: RxJava and beyondReactive Android: RxJava and beyond
Reactive Android: RxJava and beyond
 
Functional java 8
Functional java 8Functional java 8
Functional java 8
 
Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present Future
 
Parallel streams in java 8
Parallel streams in java 8Parallel streams in java 8
Parallel streams in java 8
 
Just Another QSAR Project under OpenTox
Just Another QSAR Project under OpenToxJust Another QSAR Project under OpenTox
Just Another QSAR Project under OpenTox
 
An Introduction to RxJava
An Introduction to RxJavaAn Introduction to RxJava
An Introduction to RxJava
 

Ähnlich wie LogicObjects

Concurrent talk
Concurrent talkConcurrent talk
Concurrent talkrahulrevo
 
PigSPARQL: A SPARQL Query Processing Baseline for Big Data
PigSPARQL: A SPARQL Query Processing Baseline for Big DataPigSPARQL: A SPARQL Query Processing Baseline for Big Data
PigSPARQL: A SPARQL Query Processing Baseline for Big DataAlexander Schätzle
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8Raffi Khatchadourian
 
Reactor spring one2gx_2013_0902-final
Reactor spring one2gx_2013_0902-finalReactor spring one2gx_2013_0902-final
Reactor spring one2gx_2013_0902-finalStéphane Maldini
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaRick Warren
 
Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()daewon jeong
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android InfrastructureAlexey Buzdin
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android InfrastructureC.T.Co
 
Lambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeLambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeIan Robertson
 
Highlights from Java 10-13 and Future of Java at JCON 2019 by Alukhanov and K...
Highlights from Java 10-13 and Future of Java at JCON 2019 by Alukhanov and K...Highlights from Java 10-13 and Future of Java at JCON 2019 by Alukhanov and K...
Highlights from Java 10-13 and Future of Java at JCON 2019 by Alukhanov and K...Vadym Kazulkin
 
Java PRESENTATION(PACKAGES,CLASSES,VARIABLES,FLOW CONTROL,EXCEPTION)
Java PRESENTATION(PACKAGES,CLASSES,VARIABLES,FLOW CONTROL,EXCEPTION)Java PRESENTATION(PACKAGES,CLASSES,VARIABLES,FLOW CONTROL,EXCEPTION)
Java PRESENTATION(PACKAGES,CLASSES,VARIABLES,FLOW CONTROL,EXCEPTION)quantumiq448
 
What is new in java 8 concurrency
What is new in java 8 concurrencyWhat is new in java 8 concurrency
What is new in java 8 concurrencykshanth2101
 
Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive ProgrammingAndres Almiray
 
Matlab and Python: Basic Operations
Matlab and Python: Basic OperationsMatlab and Python: Basic Operations
Matlab and Python: Basic OperationsWai Nwe Tun
 
Petro Gordiievych "From Java 9 to Java 12"
Petro Gordiievych "From Java 9 to Java 12"Petro Gordiievych "From Java 9 to Java 12"
Petro Gordiievych "From Java 9 to Java 12"LogeekNightUkraine
 

Ähnlich wie LogicObjects (20)

Concurrent talk
Concurrent talkConcurrent talk
Concurrent talk
 
Project Coin
Project CoinProject Coin
Project Coin
 
PigSPARQL: A SPARQL Query Processing Baseline for Big Data
PigSPARQL: A SPARQL Query Processing Baseline for Big DataPigSPARQL: A SPARQL Query Processing Baseline for Big Data
PigSPARQL: A SPARQL Query Processing Baseline for Big Data
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8
 
Reactor spring one2gx_2013_0902-final
Reactor spring one2gx_2013_0902-finalReactor spring one2gx_2013_0902-final
Reactor spring one2gx_2013_0902-final
 
Java 7: Quo vadis?
Java 7: Quo vadis?Java 7: Quo vadis?
Java 7: Quo vadis?
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
 
Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Lambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeLambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive Code
 
Advance Java
Advance JavaAdvance Java
Advance Java
 
Java 7 & 8 New Features
Java 7 & 8 New FeaturesJava 7 & 8 New Features
Java 7 & 8 New Features
 
Highlights from Java 10-13 and Future of Java at JCON 2019 by Alukhanov and K...
Highlights from Java 10-13 and Future of Java at JCON 2019 by Alukhanov and K...Highlights from Java 10-13 and Future of Java at JCON 2019 by Alukhanov and K...
Highlights from Java 10-13 and Future of Java at JCON 2019 by Alukhanov and K...
 
Java PRESENTATION(PACKAGES,CLASSES,VARIABLES,FLOW CONTROL,EXCEPTION)
Java PRESENTATION(PACKAGES,CLASSES,VARIABLES,FLOW CONTROL,EXCEPTION)Java PRESENTATION(PACKAGES,CLASSES,VARIABLES,FLOW CONTROL,EXCEPTION)
Java PRESENTATION(PACKAGES,CLASSES,VARIABLES,FLOW CONTROL,EXCEPTION)
 
What is new in java 8 concurrency
What is new in java 8 concurrencyWhat is new in java 8 concurrency
What is new in java 8 concurrency
 
Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive Programming
 
Matlab and Python: Basic Operations
Matlab and Python: Basic OperationsMatlab and Python: Basic Operations
Matlab and Python: Basic Operations
 
Petro Gordiievych "From Java 9 to Java 12"
Petro Gordiievych "From Java 9 to Java 12"Petro Gordiievych "From Java 9 to Java 12"
Petro Gordiievych "From Java 9 to Java 12"
 

Kürzlich hochgeladen

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 

Kürzlich hochgeladen (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 

LogicObjects

  • 1. A Portable and Extensible Approach for Linguistic Symbiosis between an Object-Oriented and a Logic Programming Language Sergio Castro Sergio.Castro@uclouvain.be RELEASeD LAB Université catholique de Louvain Belgium 1 LogicObjects Monday 26 August 13
  • 2. 2 OO programming Logic programming Useful for modelling non-declarative concepts Often enjoy rich software ecosystems Declarative reasoning & Knowledge representation Monday 26 August 13
  • 3. 2 OO programming Logic programming Useful for modelling non-declarative concepts Often enjoy rich software ecosystems Declarative reasoning & Knowledge representation Monday 26 August 13
  • 4. 2 OO programming Logic programming Useful for modelling non-declarative concepts Often enjoy rich software ecosystems Declarative reasoning & Knowledge representation Monday 26 August 13
  • 5. 2 OO programming Logic programming Useful for modelling non-declarative concepts Often enjoy rich software ecosystems Declarative reasoning & Knowledge representation Monday 26 August 13
  • 7. Considerable amount of integration tools and techniques 4 Monday 26 August 13
  • 8. Considerable amount of integration tools and techniques 4 SOUL TyRuBa JPL InterProlog PDT Connector TuProlog LogicJava Jiprolog Kernel-Prolog CIAO Prolog Jasper Jekejeke Prolog Kiev PrologBeans PrologCafeJavaLog MINERVA jProlog ProvaK-Prolog CommonRules Styla Jinni Prolog Yajxb Monday 26 August 13
  • 9. Research scope 5 “Bidirectional linguistic integration between Prolog and a statically typed, class based OO language (Java)” Monday 26 August 13
  • 10. But... why Java ? • A huge Java ecosystem. • Emerging languages running on the JVM (e.g. Scala, Clojure, etc.). • A large user base. 6 We recognize the advantages of: Monday 26 August 13
  • 11. Outline • JPC: a portable Java-Prolog interoperability layer. • LogicObjects: a linguistic integration framework. • Research status. • Future work. • Conclusions. 7 Monday 26 August 13
  • 12. 8 Prolog engines Bridge libraries JPC drivers JPC library Java-Prolog applications Java-Prolog frameworks (layer coupling denoted by the direction of the arrows) High level architectural overview Monday 26 August 13
  • 13. • Attempts to facilitate the creation of hybrid Java-Prolog applications and frameworks. • Inspired by JPL, InterProlog and Google’s Gson libraries. • Compatible with some popular open source Prolog engines (XSB,YAP, SWI) and more coming soon. • Available at the Maven central snapshot repository and GitHub1 (currently) under the LGPL license. 9 1https://github.com/sergio-castro/ JPC: Java-Prolog connectivity Monday 26 August 13
  • 14. JPC features • A portable abstraction of a Prolog virtual machine. • A set of utilities for dealing with common Java-Prolog interoperability problems. • High level support for: • Mapping between Java objects and Prolog terms. • Dealing with object references and object serialization in Prolog. 10 Monday 26 August 13
  • 15. 11 Converter manager Instantiation manager Type solver JPC Context A conversion context as a first order entity Monday 26 August 13
  • 16. 12 Converter1 Converter2 Converter3 Dispatcher Converter manager The converter manager Monday 26 August 13
  • 17. 12 Converter1 Converter2 Converter3 Dispatcher (chain of responsibility pattern) Converter manager The converter manager Monday 26 August 13
  • 18. 12 Converter1 Converter2 Converter3 Dispatcher (chain of responsibility pattern) Converter manager The converter manager primitive types converters, exception converters, multi-valued converters, etc. Monday 26 August 13
  • 19. Modularising mappings between Java objects and Prolog terms public class StationConverter extends JpcConverter<Station, Compound> { public static final String STATION_FUNCTOR = "station"; @Override public Compound toTerm(Station station, Jpc context) { return new Compound(STATION_FUNCTOR, asList(new Atom(station.getName()))); } @Override public Station fromTerm(Compound term, Jpc context) { String stationName = ((Atom)term.arg(1)).getName(); return new StationJpc(stationName); } } 13 Monday 26 August 13
  • 20. Modularising mappings between Java objects and Prolog terms public class StationConverter extends JpcConverter<Station, Compound> { public static final String STATION_FUNCTOR = "station"; @Override public Compound toTerm(Station station, Jpc context) { return new Compound(STATION_FUNCTOR, asList(new Atom(station.getName()))); } @Override public Station fromTerm(Compound term, Jpc context) { String stationName = ((Atom)term.arg(1)).getName(); return new StationJpc(stationName); } } 13 Java type Monday 26 August 13
  • 21. Modularising mappings between Java objects and Prolog terms public class StationConverter extends JpcConverter<Station, Compound> { public static final String STATION_FUNCTOR = "station"; @Override public Compound toTerm(Station station, Jpc context) { return new Compound(STATION_FUNCTOR, asList(new Atom(station.getName()))); } @Override public Station fromTerm(Compound term, Jpc context) { String stationName = ((Atom)term.arg(1)).getName(); return new StationJpc(stationName); } } 13 Prolog type Monday 26 August 13
  • 22. Modularising mappings between Java objects and Prolog terms public class StationConverter extends JpcConverter<Station, Compound> { public static final String STATION_FUNCTOR = "station"; @Override public Compound toTerm(Station station, Jpc context) { return new Compound(STATION_FUNCTOR, asList(new Atom(station.getName()))); } @Override public Station fromTerm(Compound term, Jpc context) { String stationName = ((Atom)term.arg(1)).getName(); return new StationJpc(stationName); } } 13 Monday 26 August 13
  • 23. Modularising mappings between Java objects and Prolog terms public class StationConverter extends JpcConverter<Station, Compound> { public static final String STATION_FUNCTOR = "station"; @Override public Compound toTerm(Station station, Jpc context) { return new Compound(STATION_FUNCTOR, asList(new Atom(station.getName()))); } @Override public Station fromTerm(Compound term, Jpc context) { String stationName = ((Atom)term.arg(1)).getName(); return new StationJpc(stationName); } } 13 Monday 26 August 13
  • 24. Configuring a JPC context with a custom converter Jpc jpcContext = JpcBuilder.create() .registerConverter(new StationConverter()).build(); 14 Monday 26 August 13
  • 25. Configuring a JPC context with a custom converter Jpc jpcContext = JpcBuilder.create() .registerConverter(new StationConverter()).build(); 14 Default builder (includes pre-defined converters) Monday 26 August 13
  • 26. Configuring a JPC context with a custom converter Jpc jpcContext = JpcBuilder.create() .registerConverter(new StationConverter()).build(); 14 Default builder (includes pre-defined converters) Extending JPC with new conversions Monday 26 August 13
  • 27. Querying Prolog with JPC 15 public class StationManager { public static final Jpc jpcContext = ... //context includes StationConverter ... public Station mainStation() { String stationVarName = "Station"; Term goal = new Compound("main_station", asList(new Variable(stationVarName))); Query query = getPrologEngine().query(goal, jpcContext); return query.<Station>selectObject(stationVarName).oneSolutionOrThrow(); } } Monday 26 August 13
  • 28. Querying Prolog with JPC 15 public class StationManager { public static final Jpc jpcContext = ... //context includes StationConverter ... public Station mainStation() { String stationVarName = "Station"; Term goal = new Compound("main_station", asList(new Variable(stationVarName))); Query query = getPrologEngine().query(goal, jpcContext); return query.<Station>selectObject(stationVarName).oneSolutionOrThrow(); } } main_station(Station) Monday 26 August 13
  • 29. Querying Prolog with JPC 15 public class StationManager { public static final Jpc jpcContext = ... //context includes StationConverter ... public Station mainStation() { String stationVarName = "Station"; Term goal = new Compound("main_station", asList(new Variable(stationVarName))); Query query = getPrologEngine().query(goal, jpcContext); return query.<Station>selectObject(stationVarName).oneSolutionOrThrow(); } } Monday 26 August 13
  • 30. Querying Prolog with JPC 15 public class StationManager { public static final Jpc jpcContext = ... //context includes StationConverter ... public Station mainStation() { String stationVarName = "Station"; Term goal = new Compound("main_station", asList(new Variable(stationVarName))); Query query = getPrologEngine().query(goal, jpcContext); return query.<Station>selectObject(stationVarName).oneSolutionOrThrow(); } } binding of Station as a Java object Monday 26 August 13
  • 31. Dealing with object references @Test public void testJRef() { Object o = new Object(); Term jRef = RefManager.jRefTerm(o); assertTrue(o == jpc.fromTerm(jRef)); o = null; System.gc(); try { jpc.fromTerm(jRef); fail(); } catch(RuntimeException e) {} } 16 Monday 26 August 13
  • 32. Dealing with serialized objects @Test public void testSerializedTerm() { String s = "hello"; Term term = SerializedObject.serializedObjectTerm(s); String s2 = jpc.fromTerm(term); assertFalse(s == s2); assertEquals(s, s2); } 17 Monday 26 August 13
  • 33. 18 A Prolog query browser based on JPC Monday 26 August 13
  • 35. JPC as a library for implementing Java-Prolog frameworks 20 Prolog engines Bridge libraries JPC drivers JPC library Java-Prolog applications Java-Prolog frameworks (layer coupling denoted by the direction of the arrows) Monday 26 August 13
  • 36. JPC as a library for implementing Java-Prolog frameworks 20 Prolog engines Bridge libraries JPC drivers JPC library Java-Prolog applications Java-Prolog frameworks (layer coupling denoted by the direction of the arrows) e.g. LogicObjects Monday 26 August 13
  • 37. LogicObjects • A portable Java-Prolog linguistic symbiosis framework. • Implemented on top of the JPC library. • Provides obliviousness concerning integration (in common scenarios). • Based on annotations for customising the integration and minimising programming effort. 21 Monday 26 August 13
  • 38. Symbiosis 22 “The intimate living together of two dissimilar organisms in a mutually beneficial relationship.” (Merriam-Webster dictionary) Monday 26 August 13
  • 39. Linguistic symbiosis • Objects from different worlds must understand each other. • Invoking routines from another language as if they were defined in their own language. 23 • Easier to achieve if the languages belong to the same paradigm. Monday 26 August 13
  • 40. A paradigm leak “The event of concepts leaking from one programming paradigm to another” 24 * Brichau, J. et al. Towards linguistic symbiosis of an object-oriented and a logic programming language. In Proceedings of the Workshop on Multiparadigm Programming with Object- Oriented Languages. (2002) * Monday 26 August 13
  • 41. The inhabitants of our two worlds 25 The OO world The logic world Monday 26 August 13
  • 42. The inhabitants of our two worlds 25 Classes Objects Messages Methods Return values Packages The OO world The logic world Facts Rules Terms Queries Query solutions Modules Monday 26 August 13
  • 43. Reducing the gap with Logtalk 26 The OO world The logic world Monday 26 August 13
  • 44. Reducing the gap with Logtalk 26 The OO world The logic world Logtalk An object-oriented layer Monday 26 August 13
  • 45. Case study 27 The London underground from: Monday 26 August 13
  • 46. Relevant concepts 28 The London underground Monday 26 August 13
  • 47. Relevant concepts 28 The London underground stations linesmetro Monday 26 August 13
  • 48. A rule based system using Prolog connected(station(bond_street), station(oxford_circus), line(central)). connected(station(oxford_circus), station(tottenham_court_road), line(central)). ... nearby(S1,S2) :- connected(S1,S2,_). nearby(S1,S2) :- connected(S1,S3,L), connected(S3,S2,L). reachable(S1,S2,[]) :- connected(S1,S2,_). reachable(S1,S2,[S3|Ss]) :- connected(S1,S3,_), reachable(S3,S2,Ss). line(Name) :- setof(L, S1^S2^connected(S1,S2,L), Ls), list::member(line(Name), Ls). 29 Monday 26 August 13
  • 49. A rule based system using Prolog connected(station(bond_street), station(oxford_circus), line(central)). connected(station(oxford_circus), station(tottenham_court_road), line(central)). ... nearby(S1,S2) :- connected(S1,S2,_). nearby(S1,S2) :- connected(S1,S3,L), connected(S3,S2,L). reachable(S1,S2,[]) :- connected(S1,S2,_). reachable(S1,S2,[S3|Ss]) :- connected(S1,S3,_), reachable(S3,S2,Ss). line(Name) :- setof(L, S1^S2^connected(S1,S2,L), Ls), list::member(line(Name), Ls). 29 FACTS Monday 26 August 13
  • 50. A rule based system using Prolog connected(station(bond_street), station(oxford_circus), line(central)). connected(station(oxford_circus), station(tottenham_court_road), line(central)). ... nearby(S1,S2) :- connected(S1,S2,_). nearby(S1,S2) :- connected(S1,S3,L), connected(S3,S2,L). reachable(S1,S2,[]) :- connected(S1,S2,_). reachable(S1,S2,[S3|Ss]) :- connected(S1,S3,_), reachable(S3,S2,Ss). line(Name) :- setof(L, S1^S2^connected(S1,S2,L), Ls), list::member(line(Name), Ls). 29 RULES Monday 26 August 13
  • 51. Adding an object-oriented layer with Logtalk connected(station(bond_street), station(oxford_circus), line(central)). connected(station(oxford_circus), station(tottenham_court_road), line(central)). ... nearby(S1,S2) :- connected(S1,S2,_). nearby(S1,S2) :- connected(S1,S3,L), connected(S3,S2,L). reachable(S1,S2,[]) :- connected(S1,S2,_). reachable(S1,S2,[S3|Ss]) :- connected(S1,S3,_), reachable(S3,S2,Ss). line(Name) :- setof(L, S1^S2^connected(S1,S2,L), Ls), list::member(line(Name), Ls). 30 :- object(metro). :- end_object. Monday 26 August 13
  • 52. Adding an object-oriented layer with Logtalk connected(station(bond_street), station(oxford_circus), line(central)). connected(station(oxford_circus), station(tottenham_court_road), line(central)). ... nearby(S1,S2) :- connected(S1,S2,_). nearby(S1,S2) :- connected(S1,S3,L), connected(S3,S2,L). reachable(S1,S2,[]) :- connected(S1,S2,_). reachable(S1,S2,[S3|Ss]) :- connected(S1,S3,_), reachable(S3,S2,Ss). line(Name) :- setof(L, S1^S2^connected(S1,S2,L), Ls), list::member(line(Name), Ls). 30 :- object(metro). :- end_object. Monday 26 August 13
  • 53. Adding an object-oriented layer with Logtalk connected(station(bond_street), station(oxford_circus), line(central)). connected(station(oxford_circus), station(tottenham_court_road), line(central)). ... nearby(S1,S2) :- connected(S1,S2,_). nearby(S1,S2) :- connected(S1,S3,L), connected(S3,S2,L). reachable(S1,S2,[]) :- connected(S1,S2,_). reachable(S1,S2,[S3|Ss]) :- connected(S1,S3,_), reachable(S3,S2,Ss). line(Name) :- setof(L, S1^S2^connected(S1,S2,L), Ls), list::member(line(Name), Ls). 30 :- object(metro). :- end_object. :- public([connected/3, nearby/2, reachable/3, line/1]). ACCESS MODIFIERS Monday 26 August 13
  • 54. Logtalk parametric objects 31 :- object(line(_Name)). :- public([name/1, connects/2]). name(Name) :- parameter(1, Name). ... :- end_object. :- object(station(_Name)). :- public([name/1, connected/2, nearby/1, reachable/2]). name(Name) :- parameter(1, Name). ... :- end_object. Monday 26 August 13
  • 55. PARAMETRIC OBJECT Logtalk parametric objects 31 :- object(line(_Name)). :- public([name/1, connects/2]). name(Name) :- parameter(1, Name). ... :- end_object. :- object(station(_Name)). :- public([name/1, connected/2, nearby/1, reachable/2]). name(Name) :- parameter(1, Name). ... :- end_object. Monday 26 August 13
  • 56. PARAMETRIC OBJECT PARAMETRIC OBJECT Logtalk parametric objects 31 :- object(line(_Name)). :- public([name/1, connects/2]). name(Name) :- parameter(1, Name). ... :- end_object. :- object(station(_Name)). :- public([name/1, connected/2, nearby/1, reachable/2]). name(Name) :- parameter(1, Name). ... :- end_object. Monday 26 August 13
  • 57. Invoking a Logtak method Messages in Logtalk are expressed with the :: operator. For example: line(central)::connects(Station1, Station2) Answers all the stations connected by the line ‘central’ 32 Monday 26 August 13
  • 58. Invoking a Logtak method Messages in Logtalk are expressed with the :: operator. For example: line(central)::connects(Station1, Station2) Answers all the stations connected by the line ‘central’ 32 Monday 26 August 13
  • 59. Meta-level artefacts from the two worlds 33 Monday 26 August 13
  • 60. The Java world 34 public abstract class Line { String name; public Line(String name) {this.name = name;} public abstract boolean connects(Station s1, Station s2); public abstract int segments(); } public abstract class Station { ... } public abstract class Metro { ... } Monday 26 August 13
  • 61. The Java world 34 public abstract class Line { String name; public Line(String name) {this.name = name;} public abstract boolean connects(Station s1, Station s2); public abstract int segments(); } public abstract class Station { ... } public abstract class Metro { ... } @LObject(args={“name”}) @LMethod(name={“connects”}, args={“_”, “_”}) @LObject(args={“name”}) Monday 26 August 13
  • 62. Linguistic symbiosis challenges • Translating objects to logic terms (and back). • Mapping OO methods to logic queries. • Dealing with unbound variables. • Returning values from queries. • Managing multiplicity. 35 * Some of them presented a bit differently in: D'Hondt, M. et al. Seamless integration of rule-based knowledge and object- oriented functionality with linguistic symbiosis. In Proceedings of the 2004 ACM symposium on Applied computing. (2004) * Monday 26 August 13
  • 63. public abstract class Metro {...} @LObject(name = "my_metro") public abstract class Metro {...} @LObject(args = {"name"}) public abstract class Line { private String name; ... } metro my_metro line(lineName) Translating objects to logic terms 36 Java Prolog Monday 26 August 13
  • 64. public abstract class Metro {...} @LObject(name = "my_metro") public abstract class Metro {...} @LObject(args = {"name"}) public abstract class Line { private String name; ... } metro my_metro line(lineName) Translating objects to logic terms 36 Java Prolog Monday 26 August 13
  • 65. public abstract class Metro {...} @LObject(name = "my_metro") public abstract class Metro {...} @LObject(args = {"name"}) public abstract class Line { private String name; ... } metro my_metro line(lineName) Translating objects to logic terms 36 Java Prolog Monday 26 August 13
  • 66. public abstract class Metro {...} @LObject(name = "my_metro") public abstract class Metro {...} @LObject(args = {"name"}) public abstract class Line { private String name; ... } metro my_metro line(lineName) Translating objects to logic terms 36 Java Prolog Monday 26 August 13
  • 67. line(lName)::connects( station(s1Name), station(s2Name)). line(lName)::connects(_, _). Mapping Java methods to Logtalk methods 37 @LObject(args = {"name"}) public abstract class Line { private String name; public abstract boolean connects(Station s1, Station s2); @LMethod(name = "connects", args = {"_", "_"}) public abstract int segments(); } Java Prolog Monday 26 August 13
  • 68. line(lName)::connects( station(s1Name), station(s2Name)). line(lName)::connects(_, _). Mapping Java methods to Logtalk methods 37 @LObject(args = {"name"}) public abstract class Line { private String name; public abstract boolean connects(Station s1, Station s2); @LMethod(name = "connects", args = {"_", "_"}) public abstract int segments(); } Java Prolog Monday 26 August 13
  • 69. line(lName)::connects( station(s1Name), station(s2Name)). line(lName)::connects(_, _). Mapping Java methods to Logtalk methods 37 @LObject(args = {"name"}) public abstract class Line { private String name; public abstract boolean connects(Station s1, Station s2); @LMethod(name = "connects", args = {"_", "_"}) public abstract int segments(); } Java Prolog Monday 26 August 13
  • 70. line(lName)::connects( station(s1Name), station(s2Name)). line(lName)::connects(_, _). Mapping Java methods to Logtalk methods 37 @LObject(args = {"name"}) public abstract class Line { private String name; public abstract boolean connects(Station s1, Station s2); @LMethod(name = "connects", args = {"_", "_"}) public abstract int segments(); } Java Prolog anonymous variables Monday 26 August 13
  • 71. 38 Interpreting a query result as a Java object The logic solutions Varx1 x1, Vary1 y1 Varx2 x2, Vary2 y2 Varxn xn, Varyn yn Monday 26 August 13
  • 72. 38 Interpreting a query result as a Java object The logic solutions Varx1 x1, Vary1 y1 Varx2 x2, Vary2 y2 Varxn xn, Varyn yn (set of frames binding logic variables to terms) frame 1 frame 2 frame n Monday 26 August 13
  • 73. 39 Interpreting a query result as a Java object The logic solutions Varx1 x1, Vary1 y1 Varx2 x2, Vary2 y2 Varxn xn, Varyn yn (set of frames binding logic variables to terms) Monday 26 August 13
  • 74. 39 Interpreting a query result as a Java object The logic solutions The method return value Varx1 x1, Vary1 y1 Varx2 x2, Vary2 y2 aJavaObject Varxn xn, Varyn yn (set of frames binding logic variables to terms) Monday 26 August 13
  • 75. 40 The logic solutions Varx1 x1, Vary1 y1 Varx2 x2, Vary2 y2 Varxn xn, Varyn yn (set of frames binding logic variables to terms) Returning values from one solution Monday 26 August 13
  • 76. 40 The logic solutions The method return value Varx1 x1, Vary1 y1 Varx2 x2, Vary2 y2 aJavaObject Varxn xn, Varyn yn (set of frames binding logic variables to terms) Returning values from one solution Monday 26 August 13
  • 77. 41 Returning values from one solution The logic solutions The method return value term(Varx1, Vary1) Varx1 x1, Vary1 y1 Varx2 x2, Vary2 y2 Varxn xn, Varyn yn (set of frames binding logic variables to terms) Monday 26 August 13
  • 78. 41 Returning values from one solution The logic solutions The method return value term(Varx1, Vary1) Varx1 x1, Vary1 y1 Varx2 x2, Vary2 y2 Varxn xn, Varyn yn (set of frames binding logic variables to terms) (specified in a method with @LSolution) Monday 26 August 13
  • 79. 41 Returning values from one solution The logic solutions The method return value term(Varx1, Vary1) Varx1 x1, Vary1 y1 term(x1, y1) Varx2 x2, Vary2 y2 term(x2, y2) Varxn xn, Varyn yn term(xn, yn) (set of frames binding logic variables to terms) (specified in a method with @LSolution) (default solution) Monday 26 August 13
  • 80. 42 Explicit specification of return values @LObject(args = {"name"}) public abstract class Station { @LSolution("IStations") @LMethod(name = "reachable", args = {"$1", "IStations"}) public abstract List<Station> intermediateStations(Station station); ... Monday 26 August 13
  • 81. 42 Explicit specification of return values @LObject(args = {"name"}) public abstract class Station { @LSolution("IStations") @LMethod(name = "reachable", args = {"$1", "IStations"}) public abstract List<Station> intermediateStations(Station station); ... Monday 26 August 13
  • 82. • Preprocessing macros and Java exp. • Convert arguments to terms. • Convert method to a predicate. • Convert receiver object to a term. • Build a query. • Determine solution heuristic. • Convert solution terms back to objects. 43 • $1 => station (method parameter). • (station(a), IStations) • intermediateStations => reachable/2. • station(b) • station(b)::reachable(station(a), IStations) • Binding of IStations (first solution). • [station(x), station(y)] => List<Station> Processing Steps Outcome @LObject(args = {"name"}) public abstract class Station { @LSolution("IStations") @LMethod(name = "reachable", args = {"$1", "IStations"}) public abstract List<Station> intermediateStations(Station station); ... } Monday 26 August 13
  • 83. first Java method parameter • Preprocessing macros and Java exp. • Convert arguments to terms. • Convert method to a predicate. • Convert receiver object to a term. • Build a query. • Determine solution heuristic. • Convert solution terms back to objects. 43 • $1 => station (method parameter). • (station(a), IStations) • intermediateStations => reachable/2. • station(b) • station(b)::reachable(station(a), IStations) • Binding of IStations (first solution). • [station(x), station(y)] => List<Station> Processing Steps Outcome @LObject(args = {"name"}) public abstract class Station { @LSolution("IStations") @LMethod(name = "reachable", args = {"$1", "IStations"}) public abstract List<Station> intermediateStations(Station station); ... } Monday 26 August 13
  • 84. first Java method parameter • Preprocessing macros and Java exp. • Convert arguments to terms. • Convert method to a predicate. • Convert receiver object to a term. • Build a query. • Determine solution heuristic. • Convert solution terms back to objects. 43 • $1 => station (method parameter). • (station(a), IStations) • intermediateStations => reachable/2. • station(b) • station(b)::reachable(station(a), IStations) • Binding of IStations (first solution). • [station(x), station(y)] => List<Station> Processing Steps Outcome @LObject(args = {"name"}) public abstract class Station { @LSolution("IStations") @LMethod(name = "reachable", args = {"$1", "IStations"}) public abstract List<Station> intermediateStations(Station station); ... } unbound Prolog variable (as term) Monday 26 August 13
  • 85. • Preprocessing macros and Java exp. • Convert arguments to terms. • Convert method to a predicate. • Convert receiver object to a term. • Build a query. • Determine solution heuristic. • Convert solution terms back to objects. 43 • $1 => station (method parameter). • (station(a), IStations) • intermediateStations => reachable/2. • station(b) • station(b)::reachable(station(a), IStations) • Binding of IStations (first solution). • [station(x), station(y)] => List<Station> Processing Steps Outcome @LObject(args = {"name"}) public abstract class Station { @LSolution("IStations") @LMethod(name = "reachable", args = {"$1", "IStations"}) public abstract List<Station> intermediateStations(Station station); ... } Monday 26 August 13
  • 86. • Preprocessing macros and Java exp. • Convert arguments to terms. • Convert method to a predicate. • Convert receiver object to a term. • Build a query. • Determine solution heuristic. • Convert solution terms back to objects. 43 • $1 => station (method parameter). • (station(a), IStations) • intermediateStations => reachable/2. • station(b) • station(b)::reachable(station(a), IStations) • Binding of IStations (first solution). • [station(x), station(y)] => List<Station> Processing Steps Outcome @LObject(args = {"name"}) public abstract class Station { @LSolution("IStations") @LMethod(name = "reachable", args = {"$1", "IStations"}) public abstract List<Station> intermediateStations(Station station); ... } (instance of) Monday 26 August 13
  • 87. station(b)::reachable(station(a), IStations) • Preprocessing macros and Java exp. • Convert arguments to terms. • Convert method to a predicate. • Convert receiver object to a term. • Build a query. • Determine solution heuristic. • Convert solution terms back to objects. 43 • $1 => station (method parameter). • (station(a), IStations) • intermediateStations => reachable/2. • station(b) • station(b)::reachable(station(a), IStations) • Binding of IStations (first solution). • [station(x), station(y)] => List<Station> Processing Steps Outcome @LObject(args = {"name"}) public abstract class Station { @LSolution("IStations") @LMethod(name = "reachable", args = {"$1", "IStations"}) public abstract List<Station> intermediateStations(Station station); ... } Monday 26 August 13
  • 88. station(b)::reachable(station(a), IStations) • Preprocessing macros and Java exp. • Convert arguments to terms. • Convert method to a predicate. • Convert receiver object to a term. • Build a query. • Determine solution heuristic. • Convert solution terms back to objects. 43 • $1 => station (method parameter). • (station(a), IStations) • intermediateStations => reachable/2. • station(b) • station(b)::reachable(station(a), IStations) • Binding of IStations (first solution). • [station(x), station(y)] => List<Station> Processing Steps Outcome @LObject(args = {"name"}) public abstract class Station { @LSolution("IStations") @LMethod(name = "reachable", args = {"$1", "IStations"}) public abstract List<Station> intermediateStations(Station station); ... } Monday 26 August 13
  • 89. station(b)::reachable(station(a), IStations) • Preprocessing macros and Java exp. • Convert arguments to terms. • Convert method to a predicate. • Convert receiver object to a term. • Build a query. • Determine solution heuristic. • Convert solution terms back to objects. 43 • $1 => station (method parameter). • (station(a), IStations) • intermediateStations => reachable/2. • station(b) • station(b)::reachable(station(a), IStations) • Binding of IStations (first solution). • [station(x), station(y)] => List<Station> Processing Steps Outcome @LObject(args = {"name"}) public abstract class Station { @LSolution("IStations") @LMethod(name = "reachable", args = {"$1", "IStations"}) public abstract List<Station> intermediateStations(Station station); ... } Monday 26 August 13
  • 90. 44 Returning multiple values from queries The logic solutions The method return value term(Varx1, Vary1) Varx1 x1, Vary1 y1 term(x1, y1) Varx2 x2, Vary2 y2 term(x2, y2) Varxn xn, Varyn yn term(xn, yn) Monday 26 August 13
  • 91. 44 Returning multiple values from queries The logic solutions The method return value term(Varx1, Vary1) Varx1 x1, Vary1 y1 term(x1, y1) Varx2 x2, Vary2 y2 term(x2, y2) Varxn xn, Varyn yn term(xn, yn) a composed solution (specified in a method with @LComposition) Monday 26 August 13
  • 92. 45 The logic solutions The method return value (a property of the result set) Varx1 x1, Vary1 y1 Varx2 x2, Vary2 y2 Varxn xn, Varyn yn Returning a property of the result set } Monday 26 August 13
  • 93. 45 The logic solutions The method return value (a property of the result set) Varx1 x1, Vary1 y1 Varx2 x2, Vary2 y2 Varxn xn, Varyn yn is there a solution ? Returning a property of the result set how many solutions ? } Monday 26 August 13
  • 94. Returning a property of the result set 46 @LObject(args = {"name"}) public abstract class Line { private String name; public abstract boolean connects(Station s1, Station s2); @LMethod(name = "connects", args = {"_", "_"}) public abstract int segments(); } Monday 26 August 13
  • 95. Returning a property of the result set 46 @LObject(args = {"name"}) public abstract class Line { private String name; public abstract boolean connects(Station s1, Station s2); @LMethod(name = "connects", args = {"_", "_"}) public abstract int segments(); } should return if logic method succeeds or not Monday 26 August 13
  • 96. Returning a property of the result set 46 @LObject(args = {"name"}) public abstract class Line { private String name; public abstract boolean connects(Station s1, Station s2); @LMethod(name = "connects", args = {"_", "_"}) public abstract int segments(); } should return if logic method succeeds or not should return the number of solutions Monday 26 August 13
  • 97. Instantiating a symbiotic object in Java Line line = newLogicObject(Line.class, “central”); System.out.println("Number of segments of line " + line + ": " + line.segments()); 47 Monday 26 August 13
  • 98. Instantiating a symbiotic object in Java Line line = newLogicObject(Line.class, “central”); System.out.println("Number of segments of line " + line + ": " + line.segments()); 47 Monday 26 August 13
  • 99. Instantiating a symbiotic object in Java Line line = newLogicObject(Line.class, “central”); System.out.println("Number of segments of line " + line + ": " + line.segments()); 47 Monday 26 August 13
  • 100. Other features • Java expressions embedded in logic terms (symbiosis terms). • Dependency management support. • Integration with plain Prolog (without Logtalk). • Not constrained to a specific execution environment (e.g. an Eclipse plugin). 48 Monday 26 August 13
  • 101. Inspiration from other domains • Common interoperability layer: JDBC. • Mapping artefacts using annotations: JAXB. • Context dependent conversions: GSON. • Linguistic symbiosis concepts: SOUL. 49 1http://www.oracle.com/technetwork/java/javase/jdbc/ 2https://jaxb.java.net/ 3http://code.google.com/p/google-gson/ 4http://soft.vub.ac.be/SOUL/ 1 2 3 4 Monday 26 August 13
  • 102. implemented pending if time allows it • Integration direction • OO to Prolog • Prolog to OO • Linguistic symbiosis • Automation • Transparency • Customisation • Preserving causality • Inter-language reflection • Code querying • Code transformation • Code generation • Symbiotic inter-language reflection • Portability Research status 50 Monday 26 August 13
  • 103. Future work • Finishing a full bidirectional linguistic symbiosis framework. • Exploring the feasibility of our approach for symbiotic inter- language reflection. • Adding support for more Prolog engines (e.g. an embedded one). • Continue the development of reusable hybrid components. 51 Monday 26 August 13
  • 104. Conclusions • We are actively exploring how far we can get in automation/ transparency regarding Java-Prolog linguistic integration. • We are attempting to provide reusable hybrid components and frameworks that may be helpful to the community. • And we are trying to do this in a portable way. 52 Monday 26 August 13