SlideShare una empresa de Scribd logo
1 de 123
Descargar para leer sin conexión
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 difficult 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 specific 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 specification 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.
• Difficult to implement an efficient 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 configuration 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 difficult to preserve.
• Difficult 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.
• Reification 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 refines 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-defined 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-defined 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-defined 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-defined 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-defined 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-defined 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 defined
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
first 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
first 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)
(specified 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)
(specified 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 specification 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 specification 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 specification 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 specification 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 specification 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

Más contenido relacionado

Similar a Java-Prolog Integration Ecosystem

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 a Java-Prolog Integration Ecosystem (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)
 

Más de 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
 

Más de 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
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 

Último (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 

Java-Prolog Integration Ecosystem

  • 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 difficult 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 specific 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 specification 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. • Difficult to implement an efficient 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 configuration 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 difficult to preserve. • Difficult 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. • Reification 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 refines 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-defined 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-defined 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-defined 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-defined 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-defined 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-defined 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 defined 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 first 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 first 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) (specified 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) (specified 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 specification 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 specification 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 specification 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 specification 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 specification 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