SlideShare a Scribd company logo
1 of 123
Download to read offline
Towards a Software Ecosystem
for Java-Prolog Interoperability
Sergio Castro Kim Mens
RELEASeD LAB
UniversitƩ catholique de Louvain
Belgium
Paulo Moura
Center for Research in Advanced Computing Systems
INESC TEC
Portugal
1
Tuesday 9 July 13
2
LogicObjects
Future work/
Conclusions
Content
JPC
Hydra
(or how to build reusable hybrid components)
Tuesday 9 July 13
2
LogicObjects
Future work/
Conclusions
Content
JPC
Hydra
(or how to build reusable hybrid components)
Tuesday 9 July 13
2
LogicObjects
Future work/
Conclusions
Content
JPC
Hydra
(or how to build reusable hybrid components)
Tuesday 9 July 13
2
LogicObjects
Future work/
Conclusions
Content
JPC
Hydra
(or how to build reusable hybrid components)
Tuesday 9 July 13
3
OO
programming
Logic
programming
Appropriate for modelling
real-world concepts
Often enjoy rich software
ecosystems
Declarative reasoning
Tuesday 9 July 13
3
OO
programming
Logic
programming
Appropriate for modelling
real-world concepts
Often enjoy rich software
ecosystems
Declarative reasoning
Tuesday 9 July 13
3
OO
programming
Logic
programming
Appropriate for modelling
real-world concepts
Often enjoy rich software
ecosystems
Declarative reasoning
Tuesday 9 July 13
3
OO
programming
Logic
programming
Appropriate for modelling
real-world concepts
Often enjoy rich software
ecosystems
Declarative reasoning
Tuesday 9 July 13
Integration difļ¬cult to achieve
ā€¢ The Prolog community is fragmented.
ā€¢ Existing Java-Prolog libraries also suffer the symptoms of such
fragmentation.
4
Tuesday 9 July 13
An ecosystem for Java-Prolog
development
ā€¢ Providing a portable general-purpose library for building Java-
Prolog systems (JPC).
ā€¢ Providing a framework for linguistic symbiosis between Java &
Prolog (LogicObjects).
ā€¢ Providing a set of reusable hybrid components.
5
Tuesday 9 July 13
Why Java ?
ā€¢ None of the authors is a big fan of the Java language itself.
ā€¢ But we recognise the advantages of the huge Java ecosystem.
ā€¢ And the emerging languages running on the JVM
ā€¢ (e.g., Scala, Clojure, JRuby, etc...).
6
Tuesday 9 July 13
ā€¢ Facilitates the creation of hybrid Java-Prolog applications and
frameworks.
ā€¢ Not constrained to a speciļ¬c execution environment (e.g. an
Eclipse plugin).
ā€¢ Compatible with some of the most 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.
7
1https://github.com/sergio-castro/
JPC: Java-Prolog Connectivity
Tuesday 9 July 13
Lessons learned when building
libraries without JPC
ā€¢ Applications are strongly coupled to a concrete Java-Prolog
library.
ā€¢ Conversion concerns tangled with other concerns.
ā€¢ Complex routines dealing with conversion heuristics (high
cyclomatic complexity).
ā€¢ Ugly ad-hoc implementation of context-dependent
conversions.
8
Tuesday 9 July 13
JPC features
ā€¢ A portable abstraction of a Prolog virtual machine.
ā€¢ A set of utilities for dealing with Java-Prolog inter-language
conversions.
9
Tuesday 9 July 13
JPC as a portable layer
10
Prolog engines
Bridge libraries
JPC drivers
JPC library
Java-Prolog
applications
Java-Prolog
frameworks
(layer coupling denoted by the
direction of the arrows)
Tuesday 9 July 13
11
A Prolog query
browser based on
JPC
Tuesday 9 July 13
12
Tuesday 9 July 13
JPC as a tool for inter-language
conversions
ā€¢ JPC implements a ā€œnewā€ mechanism for passing artefacts
between Java and Prolog.
ā€¢ Mechanism based on the speciļ¬cation of mappings of such
artefacts.
13
Tuesday 9 July 13
Common integration techniques
ā€¢ Shared memory approach (e.g. SOUL).
ā€¢ Passing object references to Prolog (e.g. JPL).
ā€¢ Serializing objects (e.g. InterProlog).
ā€¢ Mapping objects to terms (e.g. JPC, LogicObjects).
14
Tuesday 9 July 13
Shared memory approach
ā€¢ Tight integration/control between Java and Prolog.
ā€¢ Difļ¬cult to implement an efļ¬cient Prolog embedded in Java.
ā€¢ Often no access to well-proven Prolog libraries.
ā€¢ But easy access to libraries in the host language.
15
Tuesday 9 July 13
Passing object references
ā€¢ The original object reference is preserved.
ā€¢ Garbage collection may be an issue.
ā€¢ No control on the term representation of an object on the
Prolog side.
16
Tuesday 9 July 13
Serializing objects
ā€¢ Object reference is not preserved.
ā€¢ No conļ¬guration required.
ā€¢ Only works with serializable objects.
ā€¢ Support for circular relations.
ā€¢ No control on the term representation of an object on the
Prolog side.
17
Tuesday 9 July 13
Mapping objects to terms
ā€¢ Object reference is difļ¬cult to preserve.
ā€¢ Difļ¬cult to support circular relations.
ā€¢ Requires explicit mappings (where they cannot be inferred).
ā€¢ Fine control on the (context dependent) term representation
of an object.
18
Tuesday 9 July 13
JPC mapping features
ā€¢ Helps to modularize context dependent conversions.
ā€¢ Converters can receive hints on the expected conversion to
apply.
ā€¢ Custom conversions can be added at any moment.
ā€¢ Catalog of useful Prolog-Java converters.
19
Tuesday 9 July 13
JPC architecture
ā€¢ Abstraction of a PrologVM.
ā€¢ Reiļ¬cation of Prolog data types (e.g.Atom, Compound, etc).
ā€¢ The conversion context.
20
Tuesday 9 July 13
Conversion context components
ā€¢ The converter manager.
ā€¢ The type solver.
ā€¢ The instantiation manager.
21
Tuesday 9 July 13
The converter manager
ā€¢ Converts between Java-Prolog artefacts.
ā€¢ Composition of specialized converters (primitive types
converters, exception converters, multi-valued converters,
etc).
ā€¢ Interprets and reļ¬nes hints from the user.
22
Tuesday 9 July 13
public class CollectionConverter<E> extends JpcConverter<Collection<E>, Term> {
@Override
public Collection<E> fromTerm(Term listTerm, Type type, Jpc context) {
	 ...
}
...
}
23
A pre-deļ¬ned converter example
Tuesday 9 July 13
public class CollectionConverter<E> extends JpcConverter<Collection<E>, Term> {
@Override
public Collection<E> fromTerm(Term listTerm, Type type, Jpc context) {
	 ...
}
...
}
23
A pre-deļ¬ned converter example
Java type
Tuesday 9 July 13
public class CollectionConverter<E> extends JpcConverter<Collection<E>, Term> {
@Override
public Collection<E> fromTerm(Term listTerm, Type type, Jpc context) {
	 ...
}
...
}
23
A pre-deļ¬ned converter example
Prolog type
Tuesday 9 July 13
public class CollectionConverter<E> extends JpcConverter<Collection<E>, Term> {
@Override
public Collection<E> fromTerm(Term listTerm, Type type, Jpc context) {
	 ...
}
...
}
23
A pre-deļ¬ned converter example
term to convert
Tuesday 9 July 13
public class CollectionConverter<E> extends JpcConverter<Collection<E>, Term> {
@Override
public Collection<E> fromTerm(Term listTerm, Type type, Jpc context) {
	 ...
}
...
}
23
A pre-deļ¬ned converter example
type guiding conversion
Tuesday 9 July 13
public class CollectionConverter<E> extends JpcConverter<Collection<E>, Term> {
@Override
public Collection<E> fromTerm(Term listTerm, Type type, Jpc context) {
	 ...
}
...
}
23
A pre-deļ¬ned converter example
the conversion context
Tuesday 9 July 13
A default conversion example
Jpc jpc = ... //the conversion context
Term listTerm = listTerm(new Atom("1"), new Atom("2")); //[ā€˜1ā€™, ā€˜2ā€™]
List<String> list = jpc.fromTerm(listTerm);
assertEquals("1", list.get(0));
assertEquals("2", list.get(1));
24
Tuesday 9 July 13
A default conversion example
Jpc jpc = ... //the conversion context
Term listTerm = listTerm(new Atom("1"), new Atom("2")); //[ā€˜1ā€™, ā€˜2ā€™]
List<String> list = jpc.fromTerm(listTerm);
assertEquals("1", list.get(0));
assertEquals("2", list.get(1));
24
Prolog list of
atoms
Tuesday 9 July 13
A default conversion example
Jpc jpc = ... //the conversion context
Term listTerm = listTerm(new Atom("1"), new Atom("2")); //[ā€˜1ā€™, ā€˜2ā€™]
List<String> list = jpc.fromTerm(listTerm);
assertEquals("1", list.get(0));
assertEquals("2", list.get(1));
24
Java list of
Strings
Tuesday 9 July 13
A typed conversion example
Term listTerm = listTerm(new Atom("1"), new Atom("2"));
Type type = new TypeToken<ArrayList<Integer>>(){}.getType();
List<Integer> list = jpc.fromTerm(listTerm, type);
assertEquals(1, list.get(0));
assertEquals(2, list.get(1));
25
Tuesday 9 July 13
A typed conversion example
Term listTerm = listTerm(new Atom("1"), new Atom("2"));
Type type = new TypeToken<ArrayList<Integer>>(){}.getType();
List<Integer> list = jpc.fromTerm(listTerm, type);
assertEquals(1, list.get(0));
assertEquals(2, list.get(1));
25
type guiding conversion
Tuesday 9 July 13
A custom converter
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);
	 }
}
26
Tuesday 9 July 13
The type solver
ā€¢ Attempts to infer the best Java type of a Prolog term if no
hint is available.
ā€¢ Question:What does this term look like ?
[A-x,B-y,C-z]
ā€¢ Answer: It may be a map.
27
Tuesday 9 July 13
The instantiation manager
ā€¢ A customizable mechanism for instantiating abstract classes/
interfaces if required.
ā€¢ E.g. a Prolog list term may be mapped to a Java List or a Map.
ā€¢ This manager knows which instance of List and Map to use (if
the given hint does not contain such information).
28
Tuesday 9 July 13
LogicObjects
ā€¢ A portable Java-Prolog linguistic symbiosis framework.
ā€¢ Currently being migrated to JPC.
ā€¢ Based on annotations for specifying mappings between Java-
Prolog artefacts.
ā€¢ Support for context dependent mappings.
29
Tuesday 9 July 13
Symbiosis
30
ā€œThe intimate living together of two dissimilar organisms in a
mutually beneficial relationship.ā€ (Merriam-Webster dictionary)
Tuesday 9 July 13
Linguistic symbiosis
ā€¢ Objects from different worlds must understand each other.
ā€¢ Invoking routines from another language as if they were deļ¬ned
in their own language.
31
ā€¢ Easier to achieve if the
languages belong to the
same paradigm.
Tuesday 9 July 13
A paradigm leak
ā€œThe event of concepts leaking from one programming paradigm
to anotherā€
32
* Gybels, K.
SOUL and Smalltalk - Just Married: Evolution of the Interaction Between
a Logic and an Object-Oriented Language Towards Symbiosis.
In Proceedings of the Workshop on Declarative Programming in the Context
of Object-Oriented Languages. (2003)
*
Tuesday 9 July 13
The inhabitants of our two
worlds
33
The OO
world
The logic
world
Tuesday 9 July 13
The inhabitants of our two
worlds
33
Packages
Classes
Objects
Methods
Method invocations
Return values
The OO
world
The logic
world
Libraries
Modules
Terms
Clauses
Queries
Query solutions
Tuesday 9 July 13
Reducing the gap with Logtalk
34
The OO
world
The logic
world
Tuesday 9 July 13
Reducing the gap with Logtalk
34
The OO
world
The logic
world
Logtalk
An object-oriented layer
Tuesday 9 July 13
Case Study
35
The London underground
from:
Tuesday 9 July 13
Relevant concepts
36
The London underground
Tuesday 9 July 13
Relevant concepts
36
The London underground
stations
Tuesday 9 July 13
Relevant concepts
36
The London underground
stations
lines
Tuesday 9 July 13
Relevant concepts
36
The London underground
stations
linesmetro
Tuesday 9 July 13
Interesting relations
37
line1A C
line2
D
F
B
Tuesday 9 July 13
Interesting relations
37
line1A C
line2
D
F
B
Connected: Directly connected
(e.g., A with B).
connected
Tuesday 9 July 13
Interesting relations
37
line1A C
line2
D
F
B
Connected: Directly connected
(e.g., A with B).
Nearby: At most one intermediate
station, in the same line (e.g., A with C).
nearby
Tuesday 9 July 13
Interesting relations
37
line1A C
line2
D
F
B
Connected: Directly connected
(e.g., A with B).
Nearby: At most one intermediate
station, in the same line (e.g., A with C).
Reachable: Transitively connected
(e.g., A with F).
reachable
Tuesday 9 July 13
Interesting relations
38
Connected: Directly connected
(e.g., A with B).
Nearby: At most one intermediate
station, in the same line (e.g., A with C).
Reachable: Transitively connected
(e.g., A with F).
Easily expressed with
logic facts and rules
Tuesday 9 July 13
Which is the best language for
this problem?
ā€¢ A logic language would let us express our problem using facts
and rules.
ā€¢ But we sill want access to a modern OO language to develop
a user friendly interface.
ā€¢ Then letā€™s do it with both through linguistic symbiosis.
39
Tuesday 9 July 13
Implementation Strategy
ā€¢ Develop the program in Prolog.
ā€¢ Wrap it with an OO layer (Logtalk).
ā€¢ Program the Java side using LogicObjects.
40
Tuesday 9 July 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).
41
Tuesday 9 July 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).
41
FACTS
Tuesday 9 July 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).
41
RULES
Tuesday 9 July 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).
42
:- object(metro).
:- end_object.
Tuesday 9 July 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).
42
:- object(metro).
:- end_object.
Tuesday 9 July 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).
42
:- object(metro).
:- end_object.
:- public([connected/3, nearby/2, reachable/3, line/1]). ACCESS MODIFIERS
Tuesday 9 July 13
Logtalk parametric objects
43
:- 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.
Tuesday 9 July 13
Logtalk parametric objects
43
:- 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.
PARAMETRIC OBJECT
Tuesday 9 July 13
Logtalk parametric objects
43
:- 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.
PARAMETRIC OBJECT
PARAMETRIC OBJECT
Tuesday 9 July 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ā€™
44
Tuesday 9 July 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ā€™
44
Tuesday 9 July 13
The Java world
45
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 {
...
}
Tuesday 9 July 13
The Java world
45
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ā€})
Tuesday 9 July 13
Mapping objects from the two
worlds
46
Tuesday 9 July 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.
47
* Some of them presented a bit differently in:
D'Hondt, Maja and Gybels, Kris and Jonckers, Viviane.
Seamless integration of rule-based knowledge and object-
oriented functionality with linguistic symbiosis.
In Proceedings of the 2004 ACM symposium on Applied computing,
SAC '04, pages 1328{1335, New York, NY, USA, 2004. ACM.
*
Tuesday 9 July 13
48
Translating objects to logic terms
Tuesday 9 July 13
48
Translating objects to logic terms
Tuesday 9 July 13
48
Translating objects to logic terms
Tuesday 9 July 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(l_name)
Translating objects to logic terms
49
Java Logtalk
Tuesday 9 July 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(l_name)
Translating objects to logic terms
49
Java Logtalk
Tuesday 9 July 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(l_name)
Translating objects to logic terms
49
Java Logtalk
Tuesday 9 July 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(l_name)
Translating objects to logic terms
49
Java Logtalk
Tuesday 9 July 13
Mapping Java methods to Logtalk
methods
50
@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();	
}
line(l_name)::connects(
station(s1_name), station(s2_name)).
line(l_name)::connects(_, _).
Java Logtalk
Tuesday 9 July 13
Mapping Java methods to Logtalk
methods
50
@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();	
}
line(l_name)::connects(
station(s1_name), station(s2_name)).
line(l_name)::connects(_, _).
Java Logtalk
Tuesday 9 July 13
Mapping Java methods to Logtalk
methods
50
@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();	
}
line(l_name)::connects(
station(s1_name), station(s2_name)).
line(l_name)::connects(_, _).
Java Logtalk
Tuesday 9 July 13
Mapping Java methods to Logtalk
methods
50
@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();	
}
line(l_name)::connects(
station(s1_name), station(s2_name)).
line(l_name)::connects(_, _).
Java Logtalk
Tuesday 9 July 13
@LObject(args = {"name"})
public abstract class Station {
@LSolution("IntermediateStations")
@LMethod(name = "reachable", args = {"$1", "IntermediateStations"})
public abstract List<Station> intermediateStations(Station station);
...
}
51
Dealing with unbound variables in
method calls
Tuesday 9 July 13
@LObject(args = {"name"})
public abstract class Station {
@LSolution("IntermediateStations")
@LMethod(name = "reachable", args = {"$1", "IntermediateStations"})
public abstract List<Station> intermediateStations(Station station);
...
}
51
ļ¬rst Java method parameter
(as term)
Dealing with unbound variables in
method calls
Tuesday 9 July 13
@LObject(args = {"name"})
public abstract class Station {
@LSolution("IntermediateStations")
@LMethod(name = "reachable", args = {"$1", "IntermediateStations"})
public abstract List<Station> intermediateStations(Station station);
...
}
51
ļ¬rst Java method parameter
(as term)
unbound
logic variable
Dealing with unbound variables in
method calls
Tuesday 9 July 13
@LObject(args = {"name"})
public abstract class Station {
@LSolution("IntermediateStations")
@LMethod(name = "reachable", args = {"$1", "IntermediateStations"})
public abstract List<Station> intermediateStations(Station station);
...
}
51
station(s1_name)::reachable(station(s2_name), IntermediateStations)
Dealing with unbound variables in
method calls
Tuesday 9 July 13
52
Interpreting a query result as a
Java object
The logic solutions
Varx1 x1, Vary1 y1
Varx2 x2, Vary2 y2
Varxn xn, Varyn yn
Tuesday 9 July 13
52
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
Tuesday 9 July 13
53
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)
Tuesday 9 July 13
53
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)
Tuesday 9 July 13
54
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)
Tuesday 9 July 13
54
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)
(speciļ¬ed in a method
with @LSolution)
Tuesday 9 July 13
54
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)
(speciļ¬ed in a method
with @LSolution)
(default solution)
Tuesday 9 July 13
@LObject(args = {"name"})
public abstract class Station {
@LSolution("IntermediateStations")
@LMethod(name = "reachable", args = {"$1", "IntermediateStations"})
public abstract List<Station> intermediateStations(Station station);
...
}
55
Explicitly speciļ¬cation of return
values
Tuesday 9 July 13
@LObject(args = {"name"})
public abstract class Station {
@LSolution("IntermediateStations")
@LMethod(name = "reachable", args = {"$1", "IntermediateStations"})
public abstract List<Station> intermediateStations(Station station);
...
}
55
Explicitly speciļ¬cation of return
values
Tuesday 9 July 13
@LObject(args = {"name"})
public abstract class Station {
@LSolution("IntermediateStations")
@LMethod(name = "reachable", args = {"$1", "IntermediateStations"})
public abstract List<Station> intermediateStations(Station station);
...
}
55
Explicitly speciļ¬cation of return
values
Tuesday 9 July 13
@LObject(args = {"name"})
public abstract class Station {
@LMethod(name = "reachable", args = {"$1", "LSolution"})
public abstract List<Station> intermediateStations(Station station);
...
}
56
Implicit speciļ¬cation of return
values
Tuesday 9 July 13
@LObject(args = {"name"})
public abstract class Station {
@LMethod(name = "reachable", args = {"$1", "LSolution"})
public abstract List<Station> intermediateStations(Station station);
...
}
56
Implicit speciļ¬cation of return
values
Tuesday 9 July 13
Managing multiplicity
57
ā€¢ A logic routine can have many solutions, in Java only one.
ā€¢ Multiple values can be grouped with @LComposition.
ā€¢ The kind of container to return depends on the method
signature.
ā€¢ The kind of object in the container is also extracted from the
method signature.
Tuesday 9 July 13
58
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)
Tuesday 9 July 13
58
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)
Tuesday 9 July 13
@LObject(args = {"name"})
public abstract class Station {
...
@LComposition @LSolution("S")
@LMethod(args = {"S"})
public abstract List<Station> nearby();
}
59
station(aName)::nearby(S).
LogtalkJava
Returning multiple values from
queries
Tuesday 9 July 13
@LObject(args = {"name"})
public abstract class Station {
...
@LComposition @LSolution("S")
@LMethod(args = {"S"})
public abstract List<Station> nearby();
}
59
station(aName)::nearby(S).
LogtalkJava
Returning multiple values from
queries
Tuesday 9 July 13
@LObject(args = {"name"})
public abstract class Station {
...
@LComposition @LSolution("S")
@LMethod(args = {"S"})
public abstract List<Station> nearby();
}
59
station(aName)::nearby(S).
LogtalkJava
Returning multiple values from
queries
Tuesday 9 July 13
@LObject(args = {"name"})
public abstract class Station {
...
@LComposition @LSolution("S")
@LMethod(args = {"S"})
public abstract List<Station> nearby();
}
59
container type
station(aName)::nearby(S).
LogtalkJava
Returning multiple values from
queries
Tuesday 9 July 13
@LObject(args = {"name"})
public abstract class Station {
...
@LComposition @LSolution("S")
@LMethod(args = {"S"})
public abstract List<Station> nearby();
}
59
each solution type
container type
station(aName)::nearby(S).
LogtalkJava
Returning multiple values from
queries
Tuesday 9 July 13
Returning a property of the result
set
60
@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();	
}
Tuesday 9 July 13
Returning a property of the result
set
60
@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
Tuesday 9 July 13
Returning a property of the result
set
60
@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
Tuesday 9 July 13
Instantiating a symbiotic object in
Java
Line line = newLogicObject(Line.class, ā€œcentralā€);
System.out.println("Number of segments of line " + line + ": " + line.segments());
61
Tuesday 9 July 13
Instantiating a symbiotic object in
Java
Line line = newLogicObject(Line.class, ā€œcentralā€);
System.out.println("Number of segments of line " + line + ": " + line.segments());
61
Tuesday 9 July 13
Instantiating a symbiotic object in
Java
Line line = newLogicObject(Line.class, ā€œcentralā€);
System.out.println("Number of segments of line " + line + ": " + line.segments());
61
Tuesday 9 July 13
Other features
ā€¢ Java expressions embedded in logic terms (symbiosis terms).
ā€¢ Dependency management.
ā€¢ Integration with plain Prolog (without Logtalk).
62
Tuesday 9 July 13
Future work
ā€¢ Finishing a full two-ways linguistic symbiosis framework.
ā€¢ Supporting more Prolog engines.
ā€¢ Adding support to other kinds of integration techniques (e.g.
serialization and objects references).
ā€¢ Continue the development of reusable hybrid components.
63
Tuesday 9 July 13
Inspiration from other domains
ā€¢ Interoperability layer: JDBC.
ā€¢ Mapping of artefacts using annotations: JAXB.
ā€¢ Context dependent conversions: GSON.
ā€¢ Linguistic symbiosis concepts: SOUL.
64
Tuesday 9 July 13
Conclusions
ā€¢ We have provided portable and simple solutions for many
issues concerning Java-Prolog interoperability.
ā€¢ We are actively exploring how far we can get in automation/
transparency regarding Java-Prolog linguistic symbiosis.
ā€¢ We are targeting complex heterogeneous realistic scenarios.
ā€¢ We are attempting to provide reusable hybrid components
and frameworks that may be helpful to the community.
65
Tuesday 9 July 13
Thanks
66
Tuesday 9 July 13

More Related Content

Similar to Towards a software ecosystem for java prolog interoperabilty

Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Martijn Verburg
Ā 
Clojure for Java developers
Clojure for Java developersClojure for Java developers
Clojure for Java developersJohn Stevenson
Ā 
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
Ā 
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in ClojurescriptProgscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in ClojurescriptJohn Stevenson
Ā 
Reactor grails realtime web devoxx 2013
Reactor grails realtime web   devoxx 2013Reactor grails realtime web   devoxx 2013
Reactor grails realtime web devoxx 2013StƩphane Maldini
Ā 
Using Elasticsearch as the Primary Data Store
Using Elasticsearch as the Primary Data StoreUsing Elasticsearch as the Primary Data Store
Using Elasticsearch as the Primary Data StoreVolkan Yazıcı
Ā 
Whatā€™s expected in Java 9
Whatā€™s expected in Java 9Whatā€™s expected in Java 9
Whatā€™s expected in Java 9Gal Marder
Ā 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevMattias Karlsson
Ā 
Concurrent talk
Concurrent talkConcurrent talk
Concurrent talkrahulrevo
Ā 
20100730 phpstudy
20100730 phpstudy20100730 phpstudy
20100730 phpstudyYusuke Ando
Ā 
How I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with AirflowHow I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with AirflowLaura Lorenz
Ā 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7Deniz Oguz
Ā 
Softshake 2013: Introduction to NoSQL with Couchbase
Softshake 2013: Introduction to NoSQL with CouchbaseSoftshake 2013: Introduction to NoSQL with Couchbase
Softshake 2013: Introduction to NoSQL with CouchbaseTugdual Grall
Ā 
DevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern JavaDevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern JavaHenri Tremblay
Ā 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John StevensonJAX London
Ā 
Modeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based GamesModeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based GamesRay Toal
Ā 
Research @ RELEASeD (presented at SATTOSE2013)
Research @ RELEASeD (presented at SATTOSE2013)Research @ RELEASeD (presented at SATTOSE2013)
Research @ RELEASeD (presented at SATTOSE2013)kim.mens
Ā 

Similar to Towards a software ecosystem for java prolog interoperabilty (20)

Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)
Ā 
Clojure for Java developers
Clojure for Java developersClojure for Java developers
Clojure for Java developers
Ā 
Java 7: Quo vadis?
Java 7: Quo vadis?Java 7: Quo vadis?
Java 7: Quo vadis?
Ā 
Reactor spring one2gx_2013_0902-final
Reactor spring one2gx_2013_0902-finalReactor spring one2gx_2013_0902-final
Reactor spring one2gx_2013_0902-final
Ā 
Project Coin
Project CoinProject Coin
Project Coin
Ā 
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in ClojurescriptProgscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Ā 
Reactor grails realtime web devoxx 2013
Reactor grails realtime web   devoxx 2013Reactor grails realtime web   devoxx 2013
Reactor grails realtime web devoxx 2013
Ā 
Using Elasticsearch as the Primary Data Store
Using Elasticsearch as the Primary Data StoreUsing Elasticsearch as the Primary Data Store
Using Elasticsearch as the Primary Data Store
Ā 
Whatā€™s expected in Java 9
Whatā€™s expected in Java 9Whatā€™s expected in Java 9
Whatā€™s expected in Java 9
Ā 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
Ā 
Concurrent talk
Concurrent talkConcurrent talk
Concurrent talk
Ā 
2 P Seminar
2 P Seminar2 P Seminar
2 P Seminar
Ā 
20100730 phpstudy
20100730 phpstudy20100730 phpstudy
20100730 phpstudy
Ā 
How I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with AirflowHow I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with Airflow
Ā 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7
Ā 
Softshake 2013: Introduction to NoSQL with Couchbase
Softshake 2013: Introduction to NoSQL with CouchbaseSoftshake 2013: Introduction to NoSQL with Couchbase
Softshake 2013: Introduction to NoSQL with Couchbase
Ā 
DevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern JavaDevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern Java
Ā 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
Ā 
Modeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based GamesModeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based Games
Ā 
Research @ RELEASeD (presented at SATTOSE2013)
Research @ RELEASeD (presented at SATTOSE2013)Research @ RELEASeD (presented at SATTOSE2013)
Research @ RELEASeD (presented at SATTOSE2013)
Ā 

More from kim.mens

Software Maintenance and Evolution
Software Maintenance and EvolutionSoftware Maintenance and Evolution
Software Maintenance and Evolutionkim.mens
Ā 
Context-Oriented Programming
Context-Oriented ProgrammingContext-Oriented Programming
Context-Oriented Programmingkim.mens
Ā 
Software Reuse and Object-Oriented Programming
Software Reuse and Object-Oriented ProgrammingSoftware Reuse and Object-Oriented Programming
Software Reuse and Object-Oriented Programmingkim.mens
Ā 
Bad Code Smells
Bad Code SmellsBad Code Smells
Bad Code Smellskim.mens
Ā 
Object-Oriented Design Heuristics
Object-Oriented Design HeuristicsObject-Oriented Design Heuristics
Object-Oriented Design Heuristicskim.mens
Ā 
Software Patterns
Software PatternsSoftware Patterns
Software Patternskim.mens
Ā 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoringkim.mens
Ā 
Domain Modelling
Domain ModellingDomain Modelling
Domain Modellingkim.mens
Ā 
Object-Oriented Application Frameworks
Object-Oriented Application FrameworksObject-Oriented Application Frameworks
Object-Oriented Application Frameworkskim.mens
Ā 
Towards a Context-Oriented Software Implementation Framework
Towards a Context-Oriented Software Implementation FrameworkTowards a Context-Oriented Software Implementation Framework
Towards a Context-Oriented Software Implementation Frameworkkim.mens
Ā 
Towards a Taxonomy of Context-Aware Software Variabilty Approaches
Towards a Taxonomy of Context-Aware Software Variabilty ApproachesTowards a Taxonomy of Context-Aware Software Variabilty Approaches
Towards a Taxonomy of Context-Aware Software Variabilty Approacheskim.mens
Ā 
Breaking the Walls: A Unified Vision on Context-Oriented Software Engineering
Breaking the Walls: A Unified Vision on Context-Oriented Software EngineeringBreaking the Walls: A Unified Vision on Context-Oriented Software Engineering
Breaking the Walls: A Unified Vision on Context-Oriented Software Engineeringkim.mens
Ā 
Context-oriented programming
Context-oriented programmingContext-oriented programming
Context-oriented programmingkim.mens
Ā 
Basics of reflection
Basics of reflectionBasics of reflection
Basics of reflectionkim.mens
Ā 
Advanced Reflection in Java
Advanced Reflection in JavaAdvanced Reflection in Java
Advanced Reflection in Javakim.mens
Ā 
Basics of reflection in java
Basics of reflection in javaBasics of reflection in java
Basics of reflection in javakim.mens
Ā 
Reflection in Ruby
Reflection in RubyReflection in Ruby
Reflection in Rubykim.mens
Ā 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Rubykim.mens
Ā 
Introduction to Smalltalk
Introduction to SmalltalkIntroduction to Smalltalk
Introduction to Smalltalkkim.mens
Ā 
A gentle introduction to reflection
A gentle introduction to reflectionA gentle introduction to reflection
A gentle introduction to reflectionkim.mens
Ā 

More from kim.mens (20)

Software Maintenance and Evolution
Software Maintenance and EvolutionSoftware Maintenance and Evolution
Software Maintenance and Evolution
Ā 
Context-Oriented Programming
Context-Oriented ProgrammingContext-Oriented Programming
Context-Oriented Programming
Ā 
Software Reuse and Object-Oriented Programming
Software Reuse and Object-Oriented ProgrammingSoftware Reuse and Object-Oriented Programming
Software Reuse and Object-Oriented Programming
Ā 
Bad Code Smells
Bad Code SmellsBad Code Smells
Bad Code Smells
Ā 
Object-Oriented Design Heuristics
Object-Oriented Design HeuristicsObject-Oriented Design Heuristics
Object-Oriented Design Heuristics
Ā 
Software Patterns
Software PatternsSoftware Patterns
Software Patterns
Ā 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
Ā 
Domain Modelling
Domain ModellingDomain Modelling
Domain Modelling
Ā 
Object-Oriented Application Frameworks
Object-Oriented Application FrameworksObject-Oriented Application Frameworks
Object-Oriented Application Frameworks
Ā 
Towards a Context-Oriented Software Implementation Framework
Towards a Context-Oriented Software Implementation FrameworkTowards a Context-Oriented Software Implementation Framework
Towards a Context-Oriented Software Implementation Framework
Ā 
Towards a Taxonomy of Context-Aware Software Variabilty Approaches
Towards a Taxonomy of Context-Aware Software Variabilty ApproachesTowards a Taxonomy of Context-Aware Software Variabilty Approaches
Towards a Taxonomy of Context-Aware Software Variabilty Approaches
Ā 
Breaking the Walls: A Unified Vision on Context-Oriented Software Engineering
Breaking the Walls: A Unified Vision on Context-Oriented Software EngineeringBreaking the Walls: A Unified Vision on Context-Oriented Software Engineering
Breaking the Walls: A Unified Vision on Context-Oriented Software Engineering
Ā 
Context-oriented programming
Context-oriented programmingContext-oriented programming
Context-oriented programming
Ā 
Basics of reflection
Basics of reflectionBasics of reflection
Basics of reflection
Ā 
Advanced Reflection in Java
Advanced Reflection in JavaAdvanced Reflection in Java
Advanced Reflection in Java
Ā 
Basics of reflection in java
Basics of reflection in javaBasics of reflection in java
Basics of reflection in java
Ā 
Reflection in Ruby
Reflection in RubyReflection in Ruby
Reflection in Ruby
Ā 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
Ā 
Introduction to Smalltalk
Introduction to SmalltalkIntroduction to Smalltalk
Introduction to Smalltalk
Ā 
A gentle introduction to reflection
A gentle introduction to reflectionA gentle introduction to reflection
A gentle introduction to reflection
Ā 

Recently uploaded

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
Ā 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
Ā 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
Ā 
Navi Mumbai Call Girls šŸ„° 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls šŸ„° 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls šŸ„° 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls šŸ„° 8617370543 Service Offer VIP Hot ModelDeepika Singh
Ā 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
Ā 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
Ā 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
Ā 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
Ā 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
Ā 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
Ā 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
Ā 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
Ā 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vƔzquez
Ā 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
Ā 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
Ā 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
Ā 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
Ā 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
Ā 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
Ā 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
Ā 

Recently uploaded (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
Ā 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
Ā 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
Ā 
Navi Mumbai Call Girls šŸ„° 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls šŸ„° 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls šŸ„° 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls šŸ„° 8617370543 Service Offer VIP Hot Model
Ā 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Ā 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Ā 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
Ā 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
Ā 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
Ā 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
Ā 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
Ā 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
Ā 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Ā 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Ā 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
Ā 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Ā 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
Ā 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
Ā 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
Ā 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
Ā 

Towards a software ecosystem for java prolog interoperabilty

  • 1. Towards a Software Ecosystem for Java-Prolog Interoperability Sergio Castro Kim Mens RELEASeD LAB UniversitĆ© catholique de Louvain Belgium Paulo Moura Center for Research in Advanced Computing Systems INESC TEC Portugal 1 Tuesday 9 July 13
  • 2. 2 LogicObjects Future work/ Conclusions Content JPC Hydra (or how to build reusable hybrid components) Tuesday 9 July 13
  • 3. 2 LogicObjects Future work/ Conclusions Content JPC Hydra (or how to build reusable hybrid components) Tuesday 9 July 13
  • 4. 2 LogicObjects Future work/ Conclusions Content JPC Hydra (or how to build reusable hybrid components) Tuesday 9 July 13
  • 5. 2 LogicObjects Future work/ Conclusions Content JPC Hydra (or how to build reusable hybrid components) Tuesday 9 July 13
  • 6. 3 OO programming Logic programming Appropriate for modelling real-world concepts Often enjoy rich software ecosystems Declarative reasoning Tuesday 9 July 13
  • 7. 3 OO programming Logic programming Appropriate for modelling real-world concepts Often enjoy rich software ecosystems Declarative reasoning Tuesday 9 July 13
  • 8. 3 OO programming Logic programming Appropriate for modelling real-world concepts Often enjoy rich software ecosystems Declarative reasoning Tuesday 9 July 13
  • 9. 3 OO programming Logic programming Appropriate for modelling real-world concepts Often enjoy rich software ecosystems Declarative reasoning Tuesday 9 July 13
  • 10. Integration difļ¬cult to achieve ā€¢ The Prolog community is fragmented. ā€¢ Existing Java-Prolog libraries also suffer the symptoms of such fragmentation. 4 Tuesday 9 July 13
  • 11. An ecosystem for Java-Prolog development ā€¢ Providing a portable general-purpose library for building Java- Prolog systems (JPC). ā€¢ Providing a framework for linguistic symbiosis between Java & Prolog (LogicObjects). ā€¢ Providing a set of reusable hybrid components. 5 Tuesday 9 July 13
  • 12. Why Java ? ā€¢ None of the authors is a big fan of the Java language itself. ā€¢ But we recognise the advantages of the huge Java ecosystem. ā€¢ And the emerging languages running on the JVM ā€¢ (e.g., Scala, Clojure, JRuby, etc...). 6 Tuesday 9 July 13
  • 13. ā€¢ Facilitates the creation of hybrid Java-Prolog applications and frameworks. ā€¢ Not constrained to a speciļ¬c execution environment (e.g. an Eclipse plugin). ā€¢ Compatible with some of the most 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. 7 1https://github.com/sergio-castro/ JPC: Java-Prolog Connectivity Tuesday 9 July 13
  • 14. Lessons learned when building libraries without JPC ā€¢ Applications are strongly coupled to a concrete Java-Prolog library. ā€¢ Conversion concerns tangled with other concerns. ā€¢ Complex routines dealing with conversion heuristics (high cyclomatic complexity). ā€¢ Ugly ad-hoc implementation of context-dependent conversions. 8 Tuesday 9 July 13
  • 15. JPC features ā€¢ A portable abstraction of a Prolog virtual machine. ā€¢ A set of utilities for dealing with Java-Prolog inter-language conversions. 9 Tuesday 9 July 13
  • 16. JPC as a portable layer 10 Prolog engines Bridge libraries JPC drivers JPC library Java-Prolog applications Java-Prolog frameworks (layer coupling denoted by the direction of the arrows) Tuesday 9 July 13
  • 17. 11 A Prolog query browser based on JPC Tuesday 9 July 13
  • 19. JPC as a tool for inter-language conversions ā€¢ JPC implements a ā€œnewā€ mechanism for passing artefacts between Java and Prolog. ā€¢ Mechanism based on the speciļ¬cation of mappings of such artefacts. 13 Tuesday 9 July 13
  • 20. Common integration techniques ā€¢ Shared memory approach (e.g. SOUL). ā€¢ Passing object references to Prolog (e.g. JPL). ā€¢ Serializing objects (e.g. InterProlog). ā€¢ Mapping objects to terms (e.g. JPC, LogicObjects). 14 Tuesday 9 July 13
  • 21. Shared memory approach ā€¢ Tight integration/control between Java and Prolog. ā€¢ Difļ¬cult to implement an efļ¬cient Prolog embedded in Java. ā€¢ Often no access to well-proven Prolog libraries. ā€¢ But easy access to libraries in the host language. 15 Tuesday 9 July 13
  • 22. Passing object references ā€¢ The original object reference is preserved. ā€¢ Garbage collection may be an issue. ā€¢ No control on the term representation of an object on the Prolog side. 16 Tuesday 9 July 13
  • 23. Serializing objects ā€¢ Object reference is not preserved. ā€¢ No conļ¬guration required. ā€¢ Only works with serializable objects. ā€¢ Support for circular relations. ā€¢ No control on the term representation of an object on the Prolog side. 17 Tuesday 9 July 13
  • 24. Mapping objects to terms ā€¢ Object reference is difļ¬cult to preserve. ā€¢ Difļ¬cult to support circular relations. ā€¢ Requires explicit mappings (where they cannot be inferred). ā€¢ Fine control on the (context dependent) term representation of an object. 18 Tuesday 9 July 13
  • 25. JPC mapping features ā€¢ Helps to modularize context dependent conversions. ā€¢ Converters can receive hints on the expected conversion to apply. ā€¢ Custom conversions can be added at any moment. ā€¢ Catalog of useful Prolog-Java converters. 19 Tuesday 9 July 13
  • 26. JPC architecture ā€¢ Abstraction of a PrologVM. ā€¢ Reiļ¬cation of Prolog data types (e.g.Atom, Compound, etc). ā€¢ The conversion context. 20 Tuesday 9 July 13
  • 27. Conversion context components ā€¢ The converter manager. ā€¢ The type solver. ā€¢ The instantiation manager. 21 Tuesday 9 July 13
  • 28. The converter manager ā€¢ Converts between Java-Prolog artefacts. ā€¢ Composition of specialized converters (primitive types converters, exception converters, multi-valued converters, etc). ā€¢ Interprets and reļ¬nes hints from the user. 22 Tuesday 9 July 13
  • 29. public class CollectionConverter<E> extends JpcConverter<Collection<E>, Term> { @Override public Collection<E> fromTerm(Term listTerm, Type type, Jpc context) { ... } ... } 23 A pre-deļ¬ned converter example Tuesday 9 July 13
  • 30. public class CollectionConverter<E> extends JpcConverter<Collection<E>, Term> { @Override public Collection<E> fromTerm(Term listTerm, Type type, Jpc context) { ... } ... } 23 A pre-deļ¬ned converter example Java type Tuesday 9 July 13
  • 31. public class CollectionConverter<E> extends JpcConverter<Collection<E>, Term> { @Override public Collection<E> fromTerm(Term listTerm, Type type, Jpc context) { ... } ... } 23 A pre-deļ¬ned converter example Prolog type Tuesday 9 July 13
  • 32. public class CollectionConverter<E> extends JpcConverter<Collection<E>, Term> { @Override public Collection<E> fromTerm(Term listTerm, Type type, Jpc context) { ... } ... } 23 A pre-deļ¬ned converter example term to convert Tuesday 9 July 13
  • 33. public class CollectionConverter<E> extends JpcConverter<Collection<E>, Term> { @Override public Collection<E> fromTerm(Term listTerm, Type type, Jpc context) { ... } ... } 23 A pre-deļ¬ned converter example type guiding conversion Tuesday 9 July 13
  • 34. public class CollectionConverter<E> extends JpcConverter<Collection<E>, Term> { @Override public Collection<E> fromTerm(Term listTerm, Type type, Jpc context) { ... } ... } 23 A pre-deļ¬ned converter example the conversion context Tuesday 9 July 13
  • 35. A default conversion example Jpc jpc = ... //the conversion context Term listTerm = listTerm(new Atom("1"), new Atom("2")); //[ā€˜1ā€™, ā€˜2ā€™] List<String> list = jpc.fromTerm(listTerm); assertEquals("1", list.get(0)); assertEquals("2", list.get(1)); 24 Tuesday 9 July 13
  • 36. A default conversion example Jpc jpc = ... //the conversion context Term listTerm = listTerm(new Atom("1"), new Atom("2")); //[ā€˜1ā€™, ā€˜2ā€™] List<String> list = jpc.fromTerm(listTerm); assertEquals("1", list.get(0)); assertEquals("2", list.get(1)); 24 Prolog list of atoms Tuesday 9 July 13
  • 37. A default conversion example Jpc jpc = ... //the conversion context Term listTerm = listTerm(new Atom("1"), new Atom("2")); //[ā€˜1ā€™, ā€˜2ā€™] List<String> list = jpc.fromTerm(listTerm); assertEquals("1", list.get(0)); assertEquals("2", list.get(1)); 24 Java list of Strings Tuesday 9 July 13
  • 38. A typed conversion example Term listTerm = listTerm(new Atom("1"), new Atom("2")); Type type = new TypeToken<ArrayList<Integer>>(){}.getType(); List<Integer> list = jpc.fromTerm(listTerm, type); assertEquals(1, list.get(0)); assertEquals(2, list.get(1)); 25 Tuesday 9 July 13
  • 39. A typed conversion example Term listTerm = listTerm(new Atom("1"), new Atom("2")); Type type = new TypeToken<ArrayList<Integer>>(){}.getType(); List<Integer> list = jpc.fromTerm(listTerm, type); assertEquals(1, list.get(0)); assertEquals(2, list.get(1)); 25 type guiding conversion Tuesday 9 July 13
  • 40. A custom converter 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); } } 26 Tuesday 9 July 13
  • 41. The type solver ā€¢ Attempts to infer the best Java type of a Prolog term if no hint is available. ā€¢ Question:What does this term look like ? [A-x,B-y,C-z] ā€¢ Answer: It may be a map. 27 Tuesday 9 July 13
  • 42. The instantiation manager ā€¢ A customizable mechanism for instantiating abstract classes/ interfaces if required. ā€¢ E.g. a Prolog list term may be mapped to a Java List or a Map. ā€¢ This manager knows which instance of List and Map to use (if the given hint does not contain such information). 28 Tuesday 9 July 13
  • 43. LogicObjects ā€¢ A portable Java-Prolog linguistic symbiosis framework. ā€¢ Currently being migrated to JPC. ā€¢ Based on annotations for specifying mappings between Java- Prolog artefacts. ā€¢ Support for context dependent mappings. 29 Tuesday 9 July 13
  • 44. Symbiosis 30 ā€œThe intimate living together of two dissimilar organisms in a mutually beneficial relationship.ā€ (Merriam-Webster dictionary) Tuesday 9 July 13
  • 45. Linguistic symbiosis ā€¢ Objects from different worlds must understand each other. ā€¢ Invoking routines from another language as if they were deļ¬ned in their own language. 31 ā€¢ Easier to achieve if the languages belong to the same paradigm. Tuesday 9 July 13
  • 46. A paradigm leak ā€œThe event of concepts leaking from one programming paradigm to anotherā€ 32 * Gybels, K. SOUL and Smalltalk - Just Married: Evolution of the Interaction Between a Logic and an Object-Oriented Language Towards Symbiosis. In Proceedings of the Workshop on Declarative Programming in the Context of Object-Oriented Languages. (2003) * Tuesday 9 July 13
  • 47. The inhabitants of our two worlds 33 The OO world The logic world Tuesday 9 July 13
  • 48. The inhabitants of our two worlds 33 Packages Classes Objects Methods Method invocations Return values The OO world The logic world Libraries Modules Terms Clauses Queries Query solutions Tuesday 9 July 13
  • 49. Reducing the gap with Logtalk 34 The OO world The logic world Tuesday 9 July 13
  • 50. Reducing the gap with Logtalk 34 The OO world The logic world Logtalk An object-oriented layer Tuesday 9 July 13
  • 51. Case Study 35 The London underground from: Tuesday 9 July 13
  • 52. Relevant concepts 36 The London underground Tuesday 9 July 13
  • 53. Relevant concepts 36 The London underground stations Tuesday 9 July 13
  • 54. Relevant concepts 36 The London underground stations lines Tuesday 9 July 13
  • 55. Relevant concepts 36 The London underground stations linesmetro Tuesday 9 July 13
  • 57. Interesting relations 37 line1A C line2 D F B Connected: Directly connected (e.g., A with B). connected Tuesday 9 July 13
  • 58. Interesting relations 37 line1A C line2 D F B Connected: Directly connected (e.g., A with B). Nearby: At most one intermediate station, in the same line (e.g., A with C). nearby Tuesday 9 July 13
  • 59. Interesting relations 37 line1A C line2 D F B Connected: Directly connected (e.g., A with B). Nearby: At most one intermediate station, in the same line (e.g., A with C). Reachable: Transitively connected (e.g., A with F). reachable Tuesday 9 July 13
  • 60. Interesting relations 38 Connected: Directly connected (e.g., A with B). Nearby: At most one intermediate station, in the same line (e.g., A with C). Reachable: Transitively connected (e.g., A with F). Easily expressed with logic facts and rules Tuesday 9 July 13
  • 61. Which is the best language for this problem? ā€¢ A logic language would let us express our problem using facts and rules. ā€¢ But we sill want access to a modern OO language to develop a user friendly interface. ā€¢ Then letā€™s do it with both through linguistic symbiosis. 39 Tuesday 9 July 13
  • 62. Implementation Strategy ā€¢ Develop the program in Prolog. ā€¢ Wrap it with an OO layer (Logtalk). ā€¢ Program the Java side using LogicObjects. 40 Tuesday 9 July 13
  • 63. 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). 41 Tuesday 9 July 13
  • 64. 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). 41 FACTS Tuesday 9 July 13
  • 65. 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). 41 RULES Tuesday 9 July 13
  • 66. 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). 42 :- object(metro). :- end_object. Tuesday 9 July 13
  • 67. 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). 42 :- object(metro). :- end_object. Tuesday 9 July 13
  • 68. 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). 42 :- object(metro). :- end_object. :- public([connected/3, nearby/2, reachable/3, line/1]). ACCESS MODIFIERS Tuesday 9 July 13
  • 69. Logtalk parametric objects 43 :- 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. Tuesday 9 July 13
  • 70. Logtalk parametric objects 43 :- 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. PARAMETRIC OBJECT Tuesday 9 July 13
  • 71. Logtalk parametric objects 43 :- 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. PARAMETRIC OBJECT PARAMETRIC OBJECT Tuesday 9 July 13
  • 72. 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ā€™ 44 Tuesday 9 July 13
  • 73. 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ā€™ 44 Tuesday 9 July 13
  • 74. The Java world 45 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 { ... } Tuesday 9 July 13
  • 75. The Java world 45 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ā€}) Tuesday 9 July 13
  • 76. Mapping objects from the two worlds 46 Tuesday 9 July 13
  • 77. 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. 47 * Some of them presented a bit differently in: D'Hondt, Maja and Gybels, Kris and Jonckers, Viviane. Seamless integration of rule-based knowledge and object- oriented functionality with linguistic symbiosis. In Proceedings of the 2004 ACM symposium on Applied computing, SAC '04, pages 1328{1335, New York, NY, USA, 2004. ACM. * Tuesday 9 July 13
  • 78. 48 Translating objects to logic terms Tuesday 9 July 13
  • 79. 48 Translating objects to logic terms Tuesday 9 July 13
  • 80. 48 Translating objects to logic terms Tuesday 9 July 13
  • 81. 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(l_name) Translating objects to logic terms 49 Java Logtalk Tuesday 9 July 13
  • 82. 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(l_name) Translating objects to logic terms 49 Java Logtalk Tuesday 9 July 13
  • 83. 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(l_name) Translating objects to logic terms 49 Java Logtalk Tuesday 9 July 13
  • 84. 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(l_name) Translating objects to logic terms 49 Java Logtalk Tuesday 9 July 13
  • 85. Mapping Java methods to Logtalk methods 50 @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(); } line(l_name)::connects( station(s1_name), station(s2_name)). line(l_name)::connects(_, _). Java Logtalk Tuesday 9 July 13
  • 86. Mapping Java methods to Logtalk methods 50 @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(); } line(l_name)::connects( station(s1_name), station(s2_name)). line(l_name)::connects(_, _). Java Logtalk Tuesday 9 July 13
  • 87. Mapping Java methods to Logtalk methods 50 @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(); } line(l_name)::connects( station(s1_name), station(s2_name)). line(l_name)::connects(_, _). Java Logtalk Tuesday 9 July 13
  • 88. Mapping Java methods to Logtalk methods 50 @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(); } line(l_name)::connects( station(s1_name), station(s2_name)). line(l_name)::connects(_, _). Java Logtalk Tuesday 9 July 13
  • 89. @LObject(args = {"name"}) public abstract class Station { @LSolution("IntermediateStations") @LMethod(name = "reachable", args = {"$1", "IntermediateStations"}) public abstract List<Station> intermediateStations(Station station); ... } 51 Dealing with unbound variables in method calls Tuesday 9 July 13
  • 90. @LObject(args = {"name"}) public abstract class Station { @LSolution("IntermediateStations") @LMethod(name = "reachable", args = {"$1", "IntermediateStations"}) public abstract List<Station> intermediateStations(Station station); ... } 51 ļ¬rst Java method parameter (as term) Dealing with unbound variables in method calls Tuesday 9 July 13
  • 91. @LObject(args = {"name"}) public abstract class Station { @LSolution("IntermediateStations") @LMethod(name = "reachable", args = {"$1", "IntermediateStations"}) public abstract List<Station> intermediateStations(Station station); ... } 51 ļ¬rst Java method parameter (as term) unbound logic variable Dealing with unbound variables in method calls Tuesday 9 July 13
  • 92. @LObject(args = {"name"}) public abstract class Station { @LSolution("IntermediateStations") @LMethod(name = "reachable", args = {"$1", "IntermediateStations"}) public abstract List<Station> intermediateStations(Station station); ... } 51 station(s1_name)::reachable(station(s2_name), IntermediateStations) Dealing with unbound variables in method calls Tuesday 9 July 13
  • 93. 52 Interpreting a query result as a Java object The logic solutions Varx1 x1, Vary1 y1 Varx2 x2, Vary2 y2 Varxn xn, Varyn yn Tuesday 9 July 13
  • 94. 52 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 Tuesday 9 July 13
  • 95. 53 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) Tuesday 9 July 13
  • 96. 53 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) Tuesday 9 July 13
  • 97. 54 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) Tuesday 9 July 13
  • 98. 54 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) (speciļ¬ed in a method with @LSolution) Tuesday 9 July 13
  • 99. 54 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) (speciļ¬ed in a method with @LSolution) (default solution) Tuesday 9 July 13
  • 100. @LObject(args = {"name"}) public abstract class Station { @LSolution("IntermediateStations") @LMethod(name = "reachable", args = {"$1", "IntermediateStations"}) public abstract List<Station> intermediateStations(Station station); ... } 55 Explicitly speciļ¬cation of return values Tuesday 9 July 13
  • 101. @LObject(args = {"name"}) public abstract class Station { @LSolution("IntermediateStations") @LMethod(name = "reachable", args = {"$1", "IntermediateStations"}) public abstract List<Station> intermediateStations(Station station); ... } 55 Explicitly speciļ¬cation of return values Tuesday 9 July 13
  • 102. @LObject(args = {"name"}) public abstract class Station { @LSolution("IntermediateStations") @LMethod(name = "reachable", args = {"$1", "IntermediateStations"}) public abstract List<Station> intermediateStations(Station station); ... } 55 Explicitly speciļ¬cation of return values Tuesday 9 July 13
  • 103. @LObject(args = {"name"}) public abstract class Station { @LMethod(name = "reachable", args = {"$1", "LSolution"}) public abstract List<Station> intermediateStations(Station station); ... } 56 Implicit speciļ¬cation of return values Tuesday 9 July 13
  • 104. @LObject(args = {"name"}) public abstract class Station { @LMethod(name = "reachable", args = {"$1", "LSolution"}) public abstract List<Station> intermediateStations(Station station); ... } 56 Implicit speciļ¬cation of return values Tuesday 9 July 13
  • 105. Managing multiplicity 57 ā€¢ A logic routine can have many solutions, in Java only one. ā€¢ Multiple values can be grouped with @LComposition. ā€¢ The kind of container to return depends on the method signature. ā€¢ The kind of object in the container is also extracted from the method signature. Tuesday 9 July 13
  • 106. 58 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) Tuesday 9 July 13
  • 107. 58 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) Tuesday 9 July 13
  • 108. @LObject(args = {"name"}) public abstract class Station { ... @LComposition @LSolution("S") @LMethod(args = {"S"}) public abstract List<Station> nearby(); } 59 station(aName)::nearby(S). LogtalkJava Returning multiple values from queries Tuesday 9 July 13
  • 109. @LObject(args = {"name"}) public abstract class Station { ... @LComposition @LSolution("S") @LMethod(args = {"S"}) public abstract List<Station> nearby(); } 59 station(aName)::nearby(S). LogtalkJava Returning multiple values from queries Tuesday 9 July 13
  • 110. @LObject(args = {"name"}) public abstract class Station { ... @LComposition @LSolution("S") @LMethod(args = {"S"}) public abstract List<Station> nearby(); } 59 station(aName)::nearby(S). LogtalkJava Returning multiple values from queries Tuesday 9 July 13
  • 111. @LObject(args = {"name"}) public abstract class Station { ... @LComposition @LSolution("S") @LMethod(args = {"S"}) public abstract List<Station> nearby(); } 59 container type station(aName)::nearby(S). LogtalkJava Returning multiple values from queries Tuesday 9 July 13
  • 112. @LObject(args = {"name"}) public abstract class Station { ... @LComposition @LSolution("S") @LMethod(args = {"S"}) public abstract List<Station> nearby(); } 59 each solution type container type station(aName)::nearby(S). LogtalkJava Returning multiple values from queries Tuesday 9 July 13
  • 113. Returning a property of the result set 60 @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(); } Tuesday 9 July 13
  • 114. Returning a property of the result set 60 @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 Tuesday 9 July 13
  • 115. Returning a property of the result set 60 @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 Tuesday 9 July 13
  • 116. Instantiating a symbiotic object in Java Line line = newLogicObject(Line.class, ā€œcentralā€); System.out.println("Number of segments of line " + line + ": " + line.segments()); 61 Tuesday 9 July 13
  • 117. Instantiating a symbiotic object in Java Line line = newLogicObject(Line.class, ā€œcentralā€); System.out.println("Number of segments of line " + line + ": " + line.segments()); 61 Tuesday 9 July 13
  • 118. Instantiating a symbiotic object in Java Line line = newLogicObject(Line.class, ā€œcentralā€); System.out.println("Number of segments of line " + line + ": " + line.segments()); 61 Tuesday 9 July 13
  • 119. Other features ā€¢ Java expressions embedded in logic terms (symbiosis terms). ā€¢ Dependency management. ā€¢ Integration with plain Prolog (without Logtalk). 62 Tuesday 9 July 13
  • 120. Future work ā€¢ Finishing a full two-ways linguistic symbiosis framework. ā€¢ Supporting more Prolog engines. ā€¢ Adding support to other kinds of integration techniques (e.g. serialization and objects references). ā€¢ Continue the development of reusable hybrid components. 63 Tuesday 9 July 13
  • 121. Inspiration from other domains ā€¢ Interoperability layer: JDBC. ā€¢ Mapping of artefacts using annotations: JAXB. ā€¢ Context dependent conversions: GSON. ā€¢ Linguistic symbiosis concepts: SOUL. 64 Tuesday 9 July 13
  • 122. Conclusions ā€¢ We have provided portable and simple solutions for many issues concerning Java-Prolog interoperability. ā€¢ We are actively exploring how far we can get in automation/ transparency regarding Java-Prolog linguistic symbiosis. ā€¢ We are targeting complex heterogeneous realistic scenarios. ā€¢ We are attempting to provide reusable hybrid components and frameworks that may be helpful to the community. 65 Tuesday 9 July 13