|
From: <tom...@us...> - 2008-03-18 03:01:29
|
Revision: 1161
http://jason.svn.sourceforge.net/jason/?rev=1161&view=rev
Author: tomklapiscak
Date: 2008-03-17 20:01:18 -0700 (Mon, 17 Mar 2008)
Log Message:
-----------
travel_agent example improved and tidied up.
JASDL no longer relies on jasdl_agent_name setting - agent name is (more appropriately) taken from agent architecture.
Modified Paths:
--------------
trunk/applications/jasdl-owlapi/examples/travel_agent/config.mas2j
trunk/applications/jasdl-owlapi/examples/travel_agent/customer.asl
trunk/applications/jasdl-owlapi/examples/travel_agent/travel_agent.asl
trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java
trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlConfigurator.java
Modified: trunk/applications/jasdl-owlapi/examples/travel_agent/config.mas2j
===================================================================
--- trunk/applications/jasdl-owlapi/examples/travel_agent/config.mas2j 2008-03-18 02:05:59 UTC (rev 1160)
+++ trunk/applications/jasdl-owlapi/examples/travel_agent/config.mas2j 2008-03-18 03:01:18 UTC (rev 1161)
@@ -21,9 +21,7 @@
/* Jason Project */
-/* Note: Uses c-build.xml for two reasons:
- * 1) to prevent need for large classpath specification in this file
- * 2) to automatically run ant jar task for jasdl and jmca so up-to-date versions are used
+/* Note: Uses c-build.xml to automatically run ant jar task for jasdl and jmca so up-to-date versions are used
*/
MAS dalt08 {
@@ -32,23 +30,13 @@
agents:
travel_agent
travel_agent.asl
- [
- jasdl_agent_name = "travelagent",
- // implication, "default" is a reserved ontology name
- // also, "self"
+ [
jasdl_default_mapping_strategies="jasdl.bridge.alias.DecapitaliseMappingStrategy", // applied to incoming ontologies and those given no automapping
- //TODO: what about when automapping causes a conflict?! anonymous aliasing?
-
+
jasdl_ontologies="travel",
jasdl_travel_uri="http://www.dur.ac.uk/t.g.klapiscak/onts/travel.owl",
- //jasdl_travel_mapping_strategies="jasdl.bridge.alias.DecapitaliseMappingStrategy",
- jasdl_travel_mapping_manual="small_beach=beach",
-
- jasdl_places_uri="http://www.dur.ac.uk/t.g.klapiscak/onts/places.owl",
- jasdl_places_mapping_strategies="jasdl.bridge.alias.DecapitaliseMappingStrategy"
-
- //,jasdl_aktors_uri="http://www.aktors.org/ontology/portal.owl",
- //jasdl_aktors_mapping_strategies="jasdl.bridge.alias.DecapitaliseMappingStrategy"
+ /*jasdl_travel_mapping_strategies="jasdl.bridge.alias.DecapitaliseMappingStrategy",*/ // defaults can be overriden per-ontology here
+ jasdl_travel_mapping_manual="small_beach=beach" // these manual mappings will override any automatic mappings made by strategies
]
agentArchClass jasdl.architecture.JasdlAgArch
agentClass jasdl.asSemantics.JasdlAgent
@@ -57,30 +45,23 @@
customer
customer.asl
- [
- jasdl_agent_name = "customer",
+ [
+ /* jasdl_default_mapping_strategies="jasdl.bridge.alias.DecapitaliseMappingStrategy", */ // defaults to this
jasdl_ontologies="holidays,places",
- //jasdl_holidays_uri="file:///home/tom/Desktop/Project/workspace/jason/applications/jasdl-owlapi/examples/travel_agent/ontologies/travel.owl",
+ /*jasdl_holidays_uri="file:///home/tom/Desktop/Project/workspace/jason/applications/jasdl-owlapi/examples/travel_agent/ontologies/travel.owl", */
jasdl_holidays_uri="http://www.dur.ac.uk/t.g.klapiscak/onts/travel.owl",
jasdl_holidays_mapping_strategies="jasdl.bridge.alias.DecapitaliseMappingStrategy",
- jasdl_holidays_mapping_manual="small_beach=beach, luxuriousHotel=LuxuryHotel", // arbitrary primitive mappings handled correctly
+ jasdl_holidays_mapping_manual="small_beach=beach, luxuriousHotel=LuxuryHotel", // for demonstration of arbitrary primitive mappings being handled correctly
jasdl_places_uri="http://www.dur.ac.uk/t.g.klapiscak/onts/places.owl",
jasdl_places_mapping_strategies="jasdl.bridge.alias.DecapitaliseMappingStrategy"
-
- /* Example per-agent proxy settings used for ontology instantiation */
- //jasdl_http_proxy="127.0.0.1:3128"
- //jasdl_https_proxy="127.0.0.1:8080"
- //jasdl_ftp_proxy="127.0.0.1:8080"
- //jasdl_socks_proxy="127.0.0.1:1080"
]
agentArchClass jasdl.architecture.JasdlAgArch
agentClass jasdl.asSemantics.JasdlAgent
beliefBaseClass jasdl.bb.JasdlBeliefBase
#1;
-
classpath: "../../lib/**/*.jar";"../../../jmca/lib/jmca.jar";
}
Modified: trunk/applications/jasdl-owlapi/examples/travel_agent/customer.asl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/travel_agent/customer.asl 2008-03-18 02:05:59 UTC (rev 1160)
+++ trunk/applications/jasdl-owlapi/examples/travel_agent/customer.asl 2008-03-18 03:01:18 UTC (rev 1161)
@@ -18,41 +18,44 @@
*
*/
-//+luxuriousHotel(L)[o(holidays), source(Source)]
+luxuriousHotel(L)[o(holidays), source(Source)]
- <-
+ <-
+ .print("The ", L, " luxurious hotel is available");
- ?hotel(L)[o(holidays)];
- .print("The ", L, " luxurious hotel is available");
- jasdl.ia.define_class(query, "holidays:city and holidays:hasAccommodation value self:", L);
- .send(Source, askOne, query(City)[o(self)], query(City)[o(self)]);
+ // construct a class containing all cities in which L is located
+ jasdl.ia.define_class(cityOfL, "holidays:city and holidays:hasAccommodation value self:", L);
+ .send(Source, askOne, cityOfL(City)[o(self)], cityOfL(City)[o(self)]); // use to "query" to sender of this luxuriousHotel (travel_agent)
.print(L, " is located in the city ", City);
// check given hotel is located in a destination that has some museums
jasdl.ia.define_class(hotelNearMuseums, "holidays:isLocatedAt some (holidays:hasActivity some holidays:museums)");
- .send(Source, askOne, hotelNearMuseums(HotelNearMuseums)[o(self)], hotelNearMuseums(HotelNearMuseums)[o(self)]);
+ .send(Source, askOne, hotelNearMuseums(HotelNearMuseums)[o(self)], hotelNearMuseums(HotelNearMuseums)[o(self)]); // use to "query" to sender of this luxuriousHotel (travel_agent)
.print(HotelNearMuseums, " is a hotel located in a city with some museums");
+ // Shows a class definition in part composed of other run-time class definitions
jasdl.ia.define_class(luxuriousHotelNearMuseums, "self:hotelNearMuseums AND holidays:luxuriousHotel");
- .send(Source, askOne, luxuriousHotelNearMuseums(LuxuriousHotelNearMuseums)[o(self)], luxuriousHotelNearMuseums(LuxuriousHotelNearMuseums)[o(self)]);
+ .send(Source, askOne, luxuriousHotelNearMuseums(LuxuriousHotelNearMuseums)[o(self)], luxuriousHotelNearMuseums(LuxuriousHotelNearMuseums)[o(self)]); // use to "query" to sender of this luxuriousHotel (travel_agent)
.print(LuxuriousHotelNearMuseums, " is a luxurious hotel located in a city with some museums");
// bundle([h_1...h_n]) demonstrates how JASDL deals with nested se-content
// in particular, this query bundles together an arbitrary number of queries into a single message
- .send(Source, askOne, bundle( [ luxuriousHotel(H1)[o(holidays)], hotel(H2)[o(holidays)], activity(H3)[o(holidays)], hotelNearMuseums(H4)[o(self)] ] ), Response);
+ .send(Source, askOne, bundle( [ luxuriousHotel(H1)[o(holidays)], hotel(H2)[o(holidays)], activity(H3)[o(holidays)], hotelNearMuseums(H4)[o(self)] ] ), Response); // use to "query" to sender of this luxuriousHotel (travel_agent)
.print("Bundled query response: ", Response);
+ // ontology refered to by "places" is not known by travel_agent, but will be instantiated at run-time so it can usefully deal with this message
+ .send(Source, tell, building(travel_lodge)[o(places)]);
+ .send(Source, askOne, building(travel_lodge)[o(places)], _, 1000); // ensure information has been recieved by sender (travel_agent)
+
+ // demonstrates use of class definitions that mix entities from different ontologies
+ jasdl.ia.define_class(buildingAndHotel, "places:building and holidays:hotel");
+ .send(Source, askOne, buildingAndHotel(BuildingAndHotel)[o(self)], buildingAndHotel(BuildingAndHotel)[o(self)]);
+ .print(BuildingAndHotel, " is a building and a hotel");
+
.send(Source, tell, example_KSAA_complete).
-
+// Shows how we can receive all_different assertions that can now be sent (since they are no longer asserted using internal actions)
+all_different(XS)[o(holidays), source(Source)]
<-
- .print(XS, " are mutually distinct individuals, according to ", Source);
- .send(Source, tell, building(travel_lodge)[o(places)]);
- .wait(1000); // wait to ensure travel_agent has had a chance to add this information to its belief base
+ .print(XS, " are mutually distinct individuals, according to ", Source).
- jasdl.ia.define_class(q3, "(places:place and places:building) and holidays:hotel");
- .send(Source, askOne, q3(Hotel)[o(self)], q3(Hotel)[o(self)]);
- .print(Hotel, " is a building and a hotel").
-
Modified: trunk/applications/jasdl-owlapi/examples/travel_agent/travel_agent.asl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/travel_agent/travel_agent.asl 2008-03-18 02:05:59 UTC (rev 1160)
+++ trunk/applications/jasdl-owlapi/examples/travel_agent/travel_agent.asl 2008-03-18 03:01:18 UTC (rev 1161)
@@ -39,16 +39,12 @@
+urbanArea(windsor)[o(travel)]; // windsor is an urban area
+isPartOf(windsor, london)[o(travel)]; // windsor is a part of london
+isPartOf(london, england)[o(travel)]; // london is a part of england
- +hasPricePerNight(hilton, 22.0)[o(travel)]; // hilton costs £22 a night
-
+ +hasPricePerNight(hilton, 22.0)[o(travel)]; // hilton costs £22 a night
+museums(scienceMuseum)[o(travel)];
+hasActivity(london, scienceMuseum)[o(travel)];
+hotel(travel_lodge)[o(travel)];
-
.print("Completed: Updating Belief Base 1").
-
-
@example_ubb_2[atomic]
+!example_UBB_2
<-
@@ -88,8 +84,10 @@
<-
.print("Example: Knowledge Sharing Among Agents");
.send(customer, tell, luxuryHotel(hilton)[o(travel)]);
- .send(customer, tell, all_different([hilton, fourSeasons])[o(travel)]). // since all_different assertions are treated as SE-literals, we can now send them between agents
-
+ // since all_different assertions are treated as SE-literals, we can now send them between agents
+ .send(customer, tell, all_different([hilton, fourSeasons])[o(travel)]).
+
+
// for dealing with bundled queries - see customer.asl
@bundle_1[atomic]
+?bundle([]).
@@ -144,9 +142,11 @@
+urbanArea(x)[o(travel), source(tom)];
+ruralArea(y)[o(travel), source(ben)];
- ?all_different([x,y])[o(travel), source(tom), source(ben)]; // because knowledge from tom and ben contributed to the inference that x and y are distinct
+ // because knowledge from tom and ben contributed to the inference that x and y are distinct
+ ?all_different([x,y])[o(travel), source(tom), source(ben)];
- ?familyDestination(butlins)[o(travel), something]; // notice "something" annotation is gathered here since it all_different assertion contributes to this inference
+ // notice "something" annotation is gathered (added in !example_all_different) here since it all_different assertion contributes to this inference
+ ?familyDestination(butlins)[o(travel), something];
.print("Complete: annotation gathering").
Modified: trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java 2008-03-18 02:05:59 UTC (rev 1160)
+++ trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java 2008-03-18 03:01:18 UTC (rev 1161)
@@ -5,6 +5,7 @@
import jasdl.asSemantics.parsing.URIEntityChecker;
import jasdl.asSyntax.JasdlPlanLibrary;
import jasdl.bb.JasdlBeliefBase;
+import jasdl.bridge.AllDifferentPlaceholder;
import jasdl.bridge.ToAxiomConverter;
import jasdl.bridge.ToSELiteralConverter;
import jasdl.bridge.alias.Alias;
@@ -132,7 +133,20 @@
// load .mas2j JASDL configuration
JasdlConfigurator config = new JasdlConfigurator(this);
config.configure(stts);
- return super.initAg(arch, bb, src, stts);
+
+ TransitionSystem ts = super.initAg(arch, bb, src, stts);
+
+ // *** The following must be performed after super.initAg since we require an agent name to be set ***
+
+ // create a personal ontology for (axioms that reference) run-time defined class
+ createOntology(getPersonalOntologyLabel(), getPersonalOntologyURI(), true);
+
+ // create a "placeholder" ontology so we can safely map thing and nothing without actually loading the ontology
+ createOntology(AliasFactory.OWL_THING.getLabel(), URI.create("http://www.w3.org/2002/07/owl"), false);
+ getAliasManager().put( AliasFactory.OWL_THING, getOntologyManager().getOWLDataFactory().getOWLThing());
+ getAliasManager().put( AliasFactory.OWL_NOTHING, getOntologyManager().getOWLDataFactory().getOWLNothing());
+
+ return ts;
}
@@ -237,12 +251,10 @@
OWLOntology ontology = ontologyManager.loadOntologyFromPhysicalURI(uri);
Set<OWLOntology> imports = ontologyManager.getImportsClosure(ontology);
reasoner.loadOntologies(imports);
- reasoner.classify();
- labelManager.put(label, ontology, false); // (successfully) loaded ontologies never personal
- physicalURIManager.put(ontology, uri);
- logicalURIManager.put(ontology, ontology.getURI());
+ reasoner.classify();
+ initOntology(ontology, label, uri, ontology.getURI(), false); // (successfully) loaded ontologies never personal
+ applyMappingStrategies(ontology, strategies);
getLogger().fine("Loaded ontology from "+uri+" and assigned label "+label);
- applyMappingStrategies(ontology, strategies);
return ontology;
}catch(OWLOntologyCreationException e){
getLogger().warning("Placeholder personal ontology substituted for unreachable "+uri);
@@ -252,6 +264,8 @@
}
}
+
+
/**
* Creates and fully maps a blank ontology. Used for example for "owl" ontology, containing
* axioms referencing "owl:thing" and "owl:nothing", and for personal ontologies containing
@@ -263,10 +277,8 @@
public OWLOntology createOntology(Atom label, URI uri, boolean isPersonal) throws JasdlException{
try{
OWLOntology ontology = getOntologyManager().createOntology( uri );
- getLabelManager().put(label, ontology, isPersonal);
- getPhysicalURIManager().put(ontology, uri);
- getLogicalURIManager().put(ontology, uri);
getReasoner().loadOntology(ontology);
+ initOntology(ontology, label, uri, uri, isPersonal);
return ontology;
} catch (OWLOntologyCreationException e) {
throw new JasdlException("Error instantiating OWL ontology. Reason: "+e);
@@ -274,6 +286,23 @@
}
/**
+ * Common ontology initialisation functionality, sets up various mappings.
+ * @param ontology
+ * @param label
+ * @param physicalURI
+ * @param logicalURI
+ * @param isPersonal
+ * @throws JasdlException
+ */
+ private void initOntology(OWLOntology ontology, Atom label, URI physicalURI, URI logicalURI, boolean isPersonal) throws JasdlException{
+ labelManager.put(label, ontology, isPersonal);
+ physicalURIManager.put(ontology, physicalURI);
+ logicalURIManager.put(ontology, logicalURI);
+ // create the AllDifferent placeholder entity for this ontology
+ getAliasManager().put( AliasFactory.INSTANCE.all_different(label), new AllDifferentPlaceholder(label)); // must be new instance to avoid duplicate mapping exceptions
+ }
+
+ /**
* When a duplicate mapping is encountered, an anonymous alias is created for the offending resource
* @param ontology
* @param strategies
@@ -364,14 +393,8 @@
* @return
*/
public String getAgentName(){
- return agentName;
+ return getTS().getUserAgArch().getAgName();
}
-
- public void setAgentName(String agentName){
- this.agentName = agentName;
- }
-
-
public List<MappingStrategy> getDefaultMappingStrategies() {
Modified: trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlConfigurator.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlConfigurator.java 2008-03-18 02:05:59 UTC (rev 1160)
+++ trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlConfigurator.java 2008-03-18 03:01:18 UTC (rev 1161)
@@ -27,6 +27,14 @@
private static String MAS2J_MAPPING_MANUAL = "_mapping_manual";
private static String MAS2J_AGENT_NAME = "_agent_name";
+ /**
+ * List of reserved ontology labels. Currently:
+ * <ul>
+ * <li> "default" - allows jasdl_default_mapping_strategies to be conveniently used to define the default mapping strategies performed
+ * by this agent on unknown incoming ontologies and predefined ontologies lacking mapping strategy definition</li>
+ * <li> "self" - refers to the "personal" ontology used by this agent to store axioms referencing run-time defined classes and individuals </li>
+ * </ul>
+ */
public static List<Atom> reservedOntologyLabels = Arrays.asList( new Atom[] {new Atom("default"), new Atom("self")});
@@ -38,15 +46,11 @@
public void configure(Settings stts) throws JasdlException{
try{
- // load agent name
- agent.setAgentName(prepareUserParameter( stts, MAS2J_PREFIX + MAS2J_AGENT_NAME ));
-
// load default mapping strategies
agent.setDefaultMappingStrategies(getMappingStrategies(stts, new Atom("default"))); //implication "default" is a reserved ontology label
loadOntologies(stts);
- applyManualMappings(stts);
- applyMiscMappings();
+ applyManualMappings(stts);
}catch(JasdlException e){
@@ -134,34 +138,12 @@
return strategies;
}
- /**
- * Maps thing and nothing. Must use "owl" label to refer to these, e.g. thing(x)[o(owl)]
- *
- * @throws JasdlException
- */
- private void applyMiscMappings() throws JasdlException{
-
- // create a "placeholder" ontology so we can safely map thing and nothing without actually loading the ontology
- agent.createOntology(AliasFactory.OWL_THING.getLabel(), URI.create("http://www.w3.org/2002/07/owl"), false);
-
- // create a personal ontology for (axioms that reference) run-time defined class
- agent.createOntology(agent.getPersonalOntologyLabel(), agent.getPersonalOntologyURI(), true);
-
- agent.getAliasManager().put( AliasFactory.OWL_THING, agent.getOntologyManager().getOWLDataFactory().getOWLThing());
- agent.getAliasManager().put( AliasFactory.OWL_NOTHING, agent.getOntologyManager().getOWLDataFactory().getOWLNothing());
-
- for(Atom label : agent.getLabelManager().getLefts()){
- agent.getAliasManager().put( AliasFactory.INSTANCE.all_different(label), new AllDifferentPlaceholder(label)); // must be new instance to avoid duplicate mapping exceptions
- }
- }
-
-
/**
* Convenience method to strip quotes and trim a .mas2j setting
* @param stts .mas2j settings
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|