You can subscribe to this list here.
| 2008 |
Jan
|
Feb
|
Mar
(35) |
Apr
(96) |
May
(39) |
Jun
(25) |
Jul
(7) |
Aug
(7) |
Sep
(44) |
Oct
(17) |
Nov
(14) |
Dec
(9) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2009 |
Jan
(5) |
Feb
(28) |
Mar
(26) |
Apr
(14) |
May
(3) |
Jun
(3) |
Jul
(13) |
Aug
(41) |
Sep
(12) |
Oct
|
Nov
(2) |
Dec
(17) |
| 2010 |
Jan
(9) |
Feb
(5) |
Mar
(11) |
Apr
(3) |
May
(4) |
Jun
(2) |
Jul
(3) |
Aug
(8) |
Sep
(2) |
Oct
(11) |
Nov
(3) |
Dec
(1) |
| 2011 |
Jan
|
Feb
(1) |
Mar
(8) |
Apr
(4) |
May
(4) |
Jun
(5) |
Jul
(3) |
Aug
(2) |
Sep
(7) |
Oct
(4) |
Nov
(4) |
Dec
(2) |
| 2012 |
Jan
|
Feb
|
Mar
(4) |
Apr
(11) |
May
(8) |
Jun
(2) |
Jul
(7) |
Aug
(6) |
Sep
(2) |
Oct
(2) |
Nov
|
Dec
(3) |
| 2013 |
Jan
|
Feb
(1) |
Mar
(7) |
Apr
(3) |
May
(1) |
Jun
(4) |
Jul
(8) |
Aug
(4) |
Sep
(4) |
Oct
(6) |
Nov
(8) |
Dec
(6) |
| 2014 |
Jan
|
Feb
|
Mar
(2) |
Apr
(4) |
May
(6) |
Jun
(10) |
Jul
|
Aug
(7) |
Sep
(15) |
Oct
(4) |
Nov
(1) |
Dec
(1) |
| 2015 |
Jan
|
Feb
(1) |
Mar
(10) |
Apr
(4) |
May
(6) |
Jun
(1) |
Jul
|
Aug
(2) |
Sep
(2) |
Oct
(5) |
Nov
(6) |
Dec
(12) |
| 2016 |
Jan
(1) |
Feb
(4) |
Mar
(7) |
Apr
(30) |
May
(5) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <tom...@us...> - 2008-04-20 16:49:12
|
Revision: 1231
http://jason.svn.sourceforge.net/jason/?rev=1231&view=rev
Author: tomklapiscak
Date: 2008-04-20 09:48:43 -0700 (Sun, 20 Apr 2008)
Log Message:
-----------
Removed shop1.asl
Removed Paths:
-------------
trunk/applications/jasdl-owlapi/examples/commerce/src/asl/shop1.asl
Deleted: trunk/applications/jasdl-owlapi/examples/commerce/src/asl/shop1.asl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/src/asl/shop1.asl 2008-04-20 16:47:30 UTC (rev 1230)
+++ trunk/applications/jasdl-owlapi/examples/commerce/src/asl/shop1.asl 2008-04-20 16:48:43 UTC (rev 1231)
@@ -1,183 +0,0 @@
-{include("common/society.asl")}
-
-/* Product catalogue could be specified in a file and imported at run-time */
-
-
-
-+!add_to_order(Order, Brand, Qty)[source(PA)] :
- product(Brand)[o(c)] & // check known product brand
- hasCustomer(Order, Customer)[o(c)] & employs(Customer, PA)[o(s)] & // check PA is authorised to speak on behalf of customer whose order it is
- hasInStock(Brand, StockLevel)[o(c)] & StockLevel>=Qty // check we have enough stock
- <-
-
- // get a unique purchase identifier
- jasdl.ia.get_anonymous_individual(PID);
-
- // add purchase
- +purchase(PID)[o(c)];
- +includes(Order, PID)[o(c)];
- +hasBrand(PID, Brand)[o(c)];
- +hasQuantity(PID, Qty)[o(c)];
- .send(PA, tell, confirmed(Order, Brand, Qty)).
-
-@available[atomic]
-+!allocate_available(Van)
- <-
- ?available(Van)[source(_)];
- -available(Van)[source(_)].
-
-+?available(Van)
- <-
- .concat("+",available(Van)[source(_)], WaitFor);
- .wait(WaitFor);
- ?available(Van)[source(_)].
-
-+!confirm_order(Order)[source(PA)] :
- hasCustomer(Order, Customer)[o(c)] &
- employs(Customer, PA)[o(s)]
- <-
- !deploy(Order);
- !allocate_available(Van);
- !recall(Van);
- !load(Order, Van);
- !dispatch(Order, Van);
- !unload(Order, Van);
- +available(Van);
- -includes(Order, _)[o(c)];
- .send(Customer, tell, order_complete(Order)).
-
-+!load(Order, Van) : .my_name(Me) & inVicinityOf(Van)
- <-
- -hasPosition(Van, X, Y)[source(Van)];
- .findall(PID, includes(Order, PID)[o(c)], PIDs);
- .send(Van, achieve, load(PIDs));
- L=loading_complete[source(Van)];
- .concat("+", L, WaitFor);
- .wait(WaitFor);
- -L.
-
-+!unload(Order, Van)
- <-
- .findall(PID, includes(Order, PID)[o(c)], PIDs);
- .send(Van, achieve, unload(PIDs));
- L=unloading_complete[source(Van)];
- .concat("+", L, WaitFor);
- .wait(WaitFor);
- -L.
-
-+!recall(Van)
- <-
- .my_name(Me);
- ?hasPosition(Me, MX, MY);
- !hasPosition(Van, MX, MY).
-
-+!dispatch(Order, Van)
- <-
- ?hasCustomer(Order, Customer)[o(c)];
- .send(Customer, askOne, hasPosition(Customer, X, Y), hasPosition(Customer, X, Y));
- !hasPosition(Van, X, Y).
-
-
-+!hasPosition(Van, X, Y) : L=hasPosition(Van, X, Y) & not L
- <-
- .send(Van, achieve, hasPosition(Van, X, Y));
- .concat("+", L[source(Van)], WaitFor);
- .wait(WaitFor);
- -L.
-
-+!hasPosition(Van, X, Y) : L=hasPosition(Van, X, Y) & L.
-
-
-
-
-+!deploy([]).
-+!deploy([Purchase|Purchases])
- <-
- ?hasBrand(Purchase, Brand)[o(c)];
- ?hasQuantity(Purchase, Qty)[o(c)];
- deploy(Purchase, Brand, Qty);
- .print("Deploying crate", Purchase);
- !deploy(Purchases).
-+!deploy(Order)
- <-
- .findall(PID, includes(Order, PID)[o(c)], PIDs);
- !deploy(PIDs).
-
-
-
-
-+?details(Brand, Details) : product(PID)[o(c)]
- <-
- ?hasPrice(Brand, Price)[o(c)];
- ?hasInStock(Brand, StockLevel)[o(c)];
- jasdl.ia.get_types(Brand, self, true, Types);
- .concat("Brand Name=", Brand, ", Stock level=", StockLevel, ", Price=", ", Classifications=", Types, Price, Details).
-
-/* Failed to get details. Reason: No price listed for product type */
--?details(Brand, Details) : product(Brand)[o(c)] & not hasPrice(Brand, Price)
- <-
- .concat("No price listed for product ", Brand, Details).
-
-+!print_details(Brand) : product(Brand)[o(c)]
- <-
- ?details(Brand, Details);
- .print(Details).
-
-/* Opening a new order */
-+?hasOrder(Customer, Order)[o(c)] // check customer is known?
- <-
- // do something else here?
- // instantiate order
- +hasOrder(Customer, Order)[o(c)].
-
-
-/* Local Prices */
-
-
-
-/* We trust the delivery_agent when it informs of a product removal */
-/*
--hovis(PID)[o(c)]
- <-
- -product(PID)[o(c), source(self)];
- ?details(PID, Details);
- .print("Sold ", Details).
-*/
-
-
-/* Gets this shop's price for a class of individuals */
-// TODO: jasdl.ia.seliteral(Literal)
-/* SAFELY allowing classes to be subjects of properties*/
-/*
-Deprecated, prices are obtained statically
-+?hasPrice(PID, Price) : .atom(PID)
- <-
- .print("Get price of ", PID);
- ?hasPrice(product(PID)[o(c)], Price). // <- why doesn't this work?
-
-
-
-
-+!hasPrice(product(PID)[o(c)], Price) // <- note: not semantically-enriched
- <-
- .findall(product(PID)[o(c)], product(PID)[o(c)], Groundings);
- .print("Setting price to ",Price," for ", Groundings);
- !hasPrice(Groundings, Price).
-
-+!hasPrice([Grounding | Groundings], Price)
- <-
- jasdl.ia.get_individual(Grounding, PID);
- +hasPrice(PID, Price)[o(c)]; // <- note: semantically-enriched
- !hasPrice(Groundings, Price).
-
-+!hasPrice([], _).
-
-*/
-
-
-/*
- Doesn't work, since concat creates string term and so includes quotation marks which are not valid URI characters
- .findall(ID, includes(Order, ID)[o(c)], IDs);
- .length(IDs, MaxID);
- .concat("purchase_", Order, "_", MaxID, PID);
- */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tom...@us...> - 2008-04-20 16:47:45
|
Revision: 1230
http://jason.svn.sourceforge.net/jason/?rev=1230&view=rev
Author: tomklapiscak
Date: 2008-04-20 09:47:30 -0700 (Sun, 20 Apr 2008)
Log Message:
-----------
Given an incoming trigger, t, suppose we generalise to an SE-Plan, p, when looking for a relevant plan to deal with t.
The special variables JASDL_TG_CAUSE_RETAIN_ANNOTS and JASDL_TG_CAUSE are unified within the unifier of the intention that p is pushed onto
with t (including all annotations) and t with all annotations but "o" dropped. Has already proved to be a useful mechanism in the commerce example.
SE-Plans are now "inserted into" the plan library (in fact just the list of candidate SE-Plans returned) in order of generality (most specific first).
The algorithm to determine whether the trigger of one SE-Plan is more specific than another also supports arbitrarily nested SE-Literals.
Individuals are only instantiated under the enclosing SE-Literal's ontology if no reference to the individual (i.e. it's functor only) can be found across all ontologies known to the agent. In this sense, individuals are global across ontologies. TODO: is this safe? what if we want to reference two individuals by the same functor, but different label (i.e. ontology)? Qualify individuals with the [o(...)] annotation perhaps?
Fixed bug in jasdl.define_class. Abolishes defined class AFTER expression has been parsed in case the class definition uses a previously defined class by the same name within it.
Manchester OWL syntax renderers now renders class expressions in "normal form" (NsPrefix and URI short form providers extend Normalising short form provider that detects run-time defined classes and substitutes them for their renderings in terms of schema-defined classes). Both "anon" outgoing message annotations and classes renderings produced by jasdl.ia.get_class_definition are now inherently in normal form (the latter solves the thorny issue of run-time defined classes being defined in terms of themselves). Common#normaliseExpression deprecated since it is no longer needed.
Problem with Jason + JASDL - annotations of selected events added to triggers of intended means plan clones. Sometimes results in SE-Literals with multiple "o" annotations - hacked for now (last "o" removed).
jasdl.ia.define_class now removes assertions involving abolished definitions.
Continuing work on commerce example.
jasdl.ia.get_unique_individual now produces an individual name guaranteed to be unique across entire agent society (by prefixing identifier with agent name).
Modified Paths:
--------------
trunk/applications/jasdl-owlapi/README
trunk/applications/jasdl-owlapi/examples/commerce/bin/build.xml
trunk/applications/jasdl-owlapi/examples/commerce/commerce.mas2j
trunk/applications/jasdl-owlapi/examples/commerce/onts/commerce.owl
trunk/applications/jasdl-owlapi/examples/commerce/onts/society.owl
trunk/applications/jasdl-owlapi/examples/commerce/src/asl/customer.asl
trunk/applications/jasdl-owlapi/examples/commerce/src/asl/pa.asl
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/CommerceEnvironment.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/CommerceModel.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelCustomer.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelShop.java
trunk/applications/jasdl-owlapi/src/jasdl/JASDLParams.java
trunk/applications/jasdl-owlapi/src/jasdl/architecture/JASDLAgArch.java
trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JASDLAgent.java
trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JASDLAgentConfigurator.java
trunk/applications/jasdl-owlapi/src/jasdl/asSyntax/JASDLPlanLibrary.java
trunk/applications/jasdl-owlapi/src/jasdl/asSyntax/SEPlan.java
trunk/applications/jasdl-owlapi/src/jasdl/bb/JASDLBeliefBase.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/DLUnifier.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/JASDLOntologyManager.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/AxiomToSELiteralConverter.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/SELiteralToAxiomConverter.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/IncomingProtocolProcessingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/OutgoingProtocolProcessingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/ProtocolProcessor.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteral.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralDataPropertyAssertion.java
trunk/applications/jasdl-owlapi/src/jasdl/env/JASDLEnvironment.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/define_class.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/get_anonymous_individual.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/get_class_definition.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/get_individual.java
trunk/applications/jasdl-owlapi/src/jasdl/util/owlapi/rendering/NsPrefixOWLObjectShortFormProvider.java
trunk/applications/jasdl-owlapi/src/jasdl/util/owlapi/rendering/URIOWLObjectShortFormProvider.java
Added Paths:
-----------
trunk/applications/jasdl-owlapi/examples/commerce/src/asl/shop.asl
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelCustomerListener.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/ui/
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/ui/customer/
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/ui/customer/CustomerUIFrame.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/ui/customer/CustomerUIPanel.java
trunk/applications/jasdl-owlapi/src/jasdl/test/JASDLBeliefBaseTest.java
trunk/applications/jasdl-owlapi/src/jasdl/util/JASDLCommon.java
trunk/applications/jasdl-owlapi/src/jasdl/util/owlapi/parsing/NsPrefixOWLEntityChecker.java
trunk/applications/jasdl-owlapi/src/jasdl/util/owlapi/rendering/NormalisingOWLObjectShortFormProvider.java
Removed Paths:
-------------
trunk/applications/jasdl-owlapi/src/jasdl/test/JasdlBeliefBaseTest.java
trunk/applications/jasdl-owlapi/src/jasdl/util/Common.java
trunk/applications/jasdl-owlapi/src/jasdl/util/owlapi/parsing/NSPrefixOWLEntityChecker.java
Modified: trunk/applications/jasdl-owlapi/README
===================================================================
--- trunk/applications/jasdl-owlapi/README 2008-04-18 18:55:08 UTC (rev 1229)
+++ trunk/applications/jasdl-owlapi/README 2008-04-20 16:47:30 UTC (rev 1230)
@@ -20,4 +20,18 @@
Please refer to /trunk/jason/applications/jasdl-owlapi/examples/travel_agent/config.mas2j for an example of how to configure JASDL agents.
-Thank you for your interest in JASDL!
\ No newline at end of file
+*** Known issues ***
+
+The -+ operator does not function properly. Until this problem is fixed the operation must be performed in two steps as shown here:
+-+a;
+becomes:
+-a;
++a;
+
+When TG is applied to complex test goals, unifications do not propagate correctly
+
+Trigger generalisation is not properly applied when searching for an suitable failure event for intended means that are not in the top level of an intention.
+
+
+
+Thank you for your interest in JASDL!
Modified: trunk/applications/jasdl-owlapi/examples/commerce/bin/build.xml
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/bin/build.xml 2008-04-18 18:55:08 UTC (rev 1229)
+++ trunk/applications/jasdl-owlapi/examples/commerce/bin/build.xml 2008-04-20 16:47:30 UTC (rev 1230)
@@ -5,7 +5,7 @@
This file was generated by Jason ?
http://jason.sf.net
- April 18, 2008 - 18:12:11
+ April 20, 2008 - 17:28:53
-->
<project name ="commerce"
Modified: trunk/applications/jasdl-owlapi/examples/commerce/commerce.mas2j
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/commerce.mas2j 2008-04-18 18:55:08 UTC (rev 1229)
+++ trunk/applications/jasdl-owlapi/examples/commerce/commerce.mas2j 2008-04-20 16:47:30 UTC (rev 1230)
@@ -7,13 +7,13 @@
environment: commerce.env.CommerceEnvironment
agents:
- shop1
+ shop
[
jasdl_ontologies="c,s",
jasdl_c_uri="/onts/commerce.owl",
jasdl_s_uri="/onts/society.owl"
]
- #1
+ #2
agentArchClass jasdl.architecture.JASDLAgArch
agentClass jasdl.asSemantics.JASDLAgent
beliefBaseClass jasdl.bb.JASDLBeliefBase;
Modified: trunk/applications/jasdl-owlapi/examples/commerce/onts/commerce.owl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/onts/commerce.owl 2008-04-18 18:55:08 UTC (rev 1229)
+++ trunk/applications/jasdl-owlapi/examples/commerce/onts/commerce.owl 2008-04-20 16:47:30 UTC (rev 1230)
@@ -75,10 +75,17 @@
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#includedIn -->
+
+ <owl:ObjectProperty rdf:about="#includedIn">
+ <owl:inverseOf rdf:resource="#includes"/>
+ </owl:ObjectProperty>
+
+
+
<!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#includes -->
<owl:ObjectProperty rdf:about="#includes">
- <rdf:type rdf:resource="&owl;TransitiveProperty"/>
<rdfs:domain rdf:resource="#Order"/>
<rdfs:range rdf:resource="#Purchase"/>
</owl:ObjectProperty>
@@ -116,6 +123,16 @@
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#hasProductDescription -->
+
+ <owl:DatatypeProperty rdf:about="#hasProductDescription">
+ <rdf:type rdf:resource="&owl;FunctionalProperty"/>
+ <rdfs:domain rdf:resource="#Purchase"/>
+ <rdfs:range rdf:resource="&xsd;string"/>
+ </owl:DatatypeProperty>
+
+
+
<!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#hasQuantity -->
<owl:DatatypeProperty rdf:about="#hasQuantity">
@@ -126,6 +143,15 @@
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#hasShopDescription -->
+
+ <owl:DatatypeProperty rdf:about="#hasShopDescription">
+ <rdfs:domain rdf:resource="#Purchase"/>
+ <rdfs:range rdf:resource="&xsd;string"/>
+ </owl:DatatypeProperty>
+
+
+
<!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#hasVolume -->
<owl:DatatypeProperty rdf:about="#hasVolume">
@@ -339,31 +365,6 @@
- <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#InStock -->
-
- <owl:Class rdf:about="#InStock">
- <owl:equivalentClass>
- <owl:Class>
- <owl:intersectionOf rdf:parseType="Collection">
- <rdf:Description rdf:about="#Product"/>
- <owl:Restriction>
- <owl:onProperty rdf:resource="#hasInStock"/>
- <owl:someValuesFrom>
- <rdf:Description>
- <rdf:type rdf:resource="&owl;DataRange"/>
- <owl11:minInclusive rdf:datatype="&xsd;int">1</owl11:minInclusive>
- <owl11:onDataRange rdf:resource="&xsd;int"/>
- </rdf:Description>
- </owl:someValuesFrom>
- </owl:Restriction>
- </owl:intersectionOf>
- </owl:Class>
- </owl:equivalentClass>
- <rdfs:subClassOf rdf:resource="#Product"/>
- </owl:Class>
-
-
-
<!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Ingredient -->
<owl:Class rdf:about="#Ingredient">
Modified: trunk/applications/jasdl-owlapi/examples/commerce/onts/society.owl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/onts/society.owl 2008-04-18 18:55:08 UTC (rev 1229)
+++ trunk/applications/jasdl-owlapi/examples/commerce/onts/society.owl 2008-04-20 16:47:30 UTC (rev 1230)
@@ -57,23 +57,20 @@
- <!--
- ///////////////////////////////////////////////////////////////////////////////////////
- //
- // Data properties
- //
- ///////////////////////////////////////////////////////////////////////////////////////
- -->
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#ownedBy -->
+ <owl:ObjectProperty rdf:about="#ownedBy">
+ <rdf:type rdf:resource="&owl;FunctionalProperty"/>
+ </owl:ObjectProperty>
- <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#isBusy -->
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#owns -->
- <owl:DatatypeProperty rdf:about="#isBusy">
- <rdf:type rdf:resource="&owl;FunctionalProperty"/>
- <rdfs:range rdf:resource="&xsd;int"/>
- </owl:DatatypeProperty>
+ <owl:ObjectProperty rdf:about="#owns">
+ <rdf:type rdf:resource="&owl;InverseFunctionalProperty"/>
+ <owl:inverseOf rdf:resource="#ownedBy"/>
+ </owl:ObjectProperty>
@@ -96,6 +93,22 @@
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#Butchers -->
+
+ <owl:Class rdf:about="#Butchers">
+ <rdfs:subClassOf rdf:resource="#Shop"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#Company -->
+
+ <owl:Class rdf:about="#Company">
+ <rdfs:subClassOf rdf:resource="&owl;Thing"/>
+ </owl:Class>
+
+
+
<!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#Customer -->
<owl:Class rdf:about="#Customer">
@@ -114,6 +127,14 @@
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#GreenGrocers -->
+
+ <owl:Class rdf:about="#GreenGrocers">
+ <rdfs:subClassOf rdf:resource="#Shop"/>
+ </owl:Class>
+
+
+
<!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#PA -->
<owl:Class rdf:about="#PA">
@@ -134,9 +155,9 @@
- <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#Tesco -->
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#Supermarket -->
- <owl:Class rdf:about="#Tesco">
+ <owl:Class rdf:about="#Supermarket">
<rdfs:subClassOf rdf:resource="#Shop"/>
</owl:Class>
@@ -185,18 +206,13 @@
<!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#delivery_van1 -->
- <DeliveryVan rdf:about="#delivery_van1">
- <isBusy rdf:datatype="&xsd;int">0</isBusy>
- </DeliveryVan>
+ <DeliveryVan rdf:about="#delivery_van1"/>
<!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#delivery_van2 -->
- <DeliveryVan rdf:about="#delivery_van2">
- <isBusy rdf:datatype="&xsd;int">0</isBusy>
- <isEmployedBy rdf:resource="#shop1"/>
- </DeliveryVan>
+ <DeliveryVan rdf:about="#delivery_van2"/>
@@ -220,12 +236,28 @@
<!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#shop1 -->
- <Tesco rdf:about="#shop1">
+ <Supermarket rdf:about="#shop1">
<employs rdf:resource="#delivery_van1"/>
- </Tesco>
+ <ownedBy rdf:resource="#tescos_inc"/>
+ </Supermarket>
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#shop2 -->
+
+ <Butchers rdf:about="#shop2">
+ <employs rdf:resource="#delivery_van2"/>
+ <ownedBy rdf:resource="#tescos_inc"/>
+ </Butchers>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#tescos_inc -->
+
+ <Company rdf:about="#tescos_inc"/>
+
+
+
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
@@ -237,15 +269,17 @@
<rdf:Description>
<rdf:type rdf:resource="&owl;AllDifferent"/>
<owl:distinctMembers rdf:parseType="Collection">
+ <rdf:Description rdf:about="#pa3"/>
+ <rdf:Description rdf:about="#customer3"/>
+ <rdf:Description rdf:about="#delivery_van1"/>
<rdf:Description rdf:about="#pa2"/>
<rdf:Description rdf:about="#shop1"/>
<rdf:Description rdf:about="#pa1"/>
+ <rdf:Description rdf:about="#customer1"/>
<rdf:Description rdf:about="#customer2"/>
- <rdf:Description rdf:about="#customer1"/>
+ <rdf:Description rdf:about="#tescos_inc"/>
<rdf:Description rdf:about="#delivery_van2"/>
- <rdf:Description rdf:about="#delivery_van1"/>
- <rdf:Description rdf:about="#customer3"/>
- <rdf:Description rdf:about="#pa3"/>
+ <rdf:Description rdf:about="#shop2"/>
</owl:distinctMembers>
</rdf:Description>
</rdf:RDF>
Modified: trunk/applications/jasdl-owlapi/examples/commerce/src/asl/customer.asl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/src/asl/customer.asl 2008-04-18 18:55:08 UTC (rev 1229)
+++ trunk/applications/jasdl-owlapi/examples/commerce/src/asl/customer.asl 2008-04-20 16:47:30 UTC (rev 1230)
@@ -6,36 +6,44 @@
* - the structural information in the ontology gives us a richer palette for semantic matching over and above that available through
* e.g. synonym matching.
* Assuming central repository of agents and their types (society.owl schema)
+ * IDs are propagated through annotations to match product request brands with quantities
*/
-!behave.
-
- // need to use SE-Literals to take advantage of syntactic translation
-+!behave
- <-
- .random(Rand);
- .wait(Rand*2000);
- .my_name(Me);
- jasdl.ia.define_class(employedPA, "s:pA and s:isEmployedBy value s:", Me);
- ?employedPA(PA)[o(self)];
- !order(PA, Me, bread(_)[o(c)], 1);
- !order(PA, Me, milk(_)[o(c)], 1);
- !order(PA, Me, bread(hovis)[o(c)], 1);
- .send(PA, achieve, confirm_order(Me)).
+
++ui_product_request(ProductDescription, ShopDescription, Qty)[source(percept)]
+ <-
+ .print("UI recieved request");
+ // Get a PA employed by me
+ ?employs(PA);
-+!order(PA, Order, Product, Qty)
+ // Explicitly discard the percept - in case an identical request comes in next perception cycle (we still want to catch it)
+ -ui_product_request(ProductDescription, ShopDescription, Qty)[source(percept)];
+
+ // Must be defined locally in order to take advantage of syntactic translation.
+ // If these were simply sent as string to PA and this agent had different entity aliases / ontology labels
+ // then the PA would not be able to understand the request.
+
+ jasdl.ia.define_class(suitableProduct, ProductDescription);
+ jasdl.ia.define_class(suitableShop, ShopDescription);
+
+
+ // Request a suitable brand from the PA
+ jasdl.ia.send(PA, achieve, suitable(suitableProduct(_)[o(self)], suitableShop(_)[o(self)], Qty)).
+
+
++!product(Brand)[o(c), source(PA), approve, id(ID)] :
+ employs(PA)
<-
- .send(PA, achieve, order(Order, Product, Qty));
- Confirmed = confirmed(Order, Brand, Qty)[source(PA)];
- .concat("+", Confirmed, WaitConfirmed); .wait(WaitConfirmed);
- -Confirmed.
+ approve(Brand);
+ .send(PA, tell, approved(product(Brand)[o(c), id(ID)])).
-+order_complete(Order)[source(Shop)]
+-!product(Brand)[o(c), source(PA), approve, id(ID)] :
+ employs(PA)
<-
- -order_complete(Order)[source(Shop)];
- !behave.
+ .send(PA, tell, rejected(product(Brand)[o(c), id(ID)])).
+
Modified: trunk/applications/jasdl-owlapi/examples/commerce/src/asl/pa.asl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/src/asl/pa.asl 2008-04-18 18:55:08 UTC (rev 1229)
+++ trunk/applications/jasdl-owlapi/examples/commerce/src/asl/pa.asl 2008-04-20 16:47:30 UTC (rev 1230)
@@ -2,30 +2,130 @@
-+!order(Order, Product, Qty)[source(Employer)] : isEmployedBy(Employer)
++!suitable(ProductClass, ShopClass, Qty)[source(Customer)] :
+ isEmployedBy(Customer)
+ <-
+ ?hasOrder(Customer, Order)[o(c)];
+ .print(Order);
+
+ ?ShopClass;
+ jasdl.ia.get_individual(ShopClass, Shop);
+
+
+ // Generate a unique (guaranteed across entire agent society) request identifier (individual)
+ jasdl.ia.get_anonymous_individual(ID);
+
+ jasdl.ia.get_class_definition(ShopClass, ShopDescription);
+ jasdl.ia.get_class_definition(ProductClass, ProductDescription);
+
+ // Add the condition that the product must be in stock (this is not something the customer should be concerned with)
+ .concat("(",ProductDescription,") and c:hasInStock some integer [ >= ",Qty,"]",ProductDescriptionInStock);
+
+ // Parse the product description into a class
+ jasdl.ia.define_class(productInStock, ProductDescriptionInStock);
+
+ .print("Asking ",Shop,":", ProductDescriptionInStock);
+
+ // Ask for all brands that match these criteria
+ //jasdl.ia.send(Shop, achieve, suitable(description(Brand)[o(self)])[id(ID)]).
+ jasdl.ia.send(Shop, askOne, productInStock(Brand)[o(self), id(ID)]);
+
+ +purchase(ID)[o(c)];
+ +includes(Order, ID)[o(c)];
+ +hasQuantity(ID, Qty)[o(c)];
+ +hasProductDescription(ID, ProductDescription)[o(c)];
+ +hasShopDescription(ID, ShopDescription)[o(c)].
+
+
++product(Brand)[o(c), id(ID), source(Shop)] :
+ shop(Shop)[o(s)] // from a known shop
<-
- ?shop(Shop)[o(s)];
- jasdl.ia.send(Shop, askOne, hasOrder(Employer, Order)[o(c)], hasOrder(Employer, Order)[o(c)]);
- // get me a brand that is in stock
- jasdl.ia.get_class_definition(Product, ProductDefinition);
- jasdl.ia.define_class(productInStock, ProductDefinition);//, " and (c:hasInStock some integer [>= ",Qty ," ])");
- jasdl.ia.send(Shop, askOne, productInStock(Brand)[o(self)], product(Brand)[o(c)]);
- .print("Brand name: ", Brand);
- /* Check against medical requirements of customer */
- .send(Shop, achieve, add_to_order(Order, Brand, Qty));
- Confirmed = confirmed(Order, Brand, Qty)[source(Shop)];
- .concat("+", Confirmed, WaitConfirmed); .wait(WaitConfirmed);
- -Confirmed;
- .send(Employer, tell, Confirmed).
+ !approve(product(Brand)[o(c), id(ID)]).
++referral(Referred)[id(ID), source(Shop)] :
+ shop(Referred)[o(s)] &
+ shop(Shop)[o(s)]
+ <-
+ -referral(Referred)[id(ID), source(Shop)];
+ .print("referred to ", Referred).
-+!confirm_order(Order)[source(Employer)] : isEmployedBy(Employer)
++failed[id(ID), source(Shop)] :
+ shop(Shop)[o(s)]
<-
- ?shop(Shop)[o(s)];
- .send(Shop, achieve, confirm_order(Order)).
+ !abolish_purchase(ID);
+ .print("Failed!").
++!approve(A)
+ <-
+
+ // get my employer (rule expressed in terms of SE-Literals, see common/society.asl)
+ ?isEmployedBy(Employer);
+
+ .my_name(Me);
+ .add_annot(A, source(Me), B);
+
+ // ask customer for approval
+ // We add the approve annotation to isolate this
+ // type of query from others
+ .add_annot(B, approve, C);
+ .send(Employer, achieve, C).
+
++approved(product(Brand)[o(c), id(ID)])[source(Employer)] :
+ isEmployedBy(Employer)
+ <-
+ +hasBrand(ID, Brand)[o(c)];
+ .print("Approved ", Brand, " (id: ", ID, ")").
+
+@sdfdsf[breakpoint]
++rejected(product(Brand)[o(c), id(ID)])[source(Employer)] :
+ isEmployedBy(Employer)
+ <-
+ ?includedIn(ID, Order)[o(c)];
+ ?hasQuantity(ID, Qty)[o(c)];
+ ?hasProductDescription(ID, ProductDescription)[o(c)];
+ ?hasShopDescription(ID, ShopDescription)[o(c)];
+
+ !abolish_purchase(ID);
+
+ .concat("(",ProductDescription,") and not {c:",Brand,"}", AmmendedProductDescription);
+ .print("Rejected ", Brand, " (id: ", ID, ")");
+
+ // We need this individual to be instantiated in our own commerce ontology
+ // to allow us to safely refer to it in class expressions
+ //+product(Brand)[o(c)];
+
+ // Get the class describing the type of product, adding the additional requirement that it
+ // also not be the individual rejected by the customer
+ jasdl.ia.define_class(ammendedProductClass, AmmendedProductDescription);
+
+ // Get the class describing the desired type of shop, without changing any requirements
+ jasdl.ia.define_class(shopClass, ShopDescription);
+
+ .print("Rejected ", Brand, ". Retry with shop=", ShopDescription, " and product=", AmmendedProductDescription);
+
+ // We use the same achieve goal used by a customer here, effectively emulating a customer request, but with the ammended product
+ // description, given the customer's rejection
+ !suitable(ammendedProductClass(_)[o(self)], shopClass(_)[o(self)], Qty)[source(Employer)].
++!abolish_purchase(ID) :
+ purchase(ID)[o(c)]
+ <-
+ -hasProductDescription(ID, _)[o(c), source(self)];
+ -hasShopDescription(ID, _)[o(c), source(self)];
+ -includedIn(ID, _)[o(c), source(self)];
+ -hasQuantity(ID, _)[o(c), source(self)];
+ -purchase(ID)[o(c), source(self)].
+
+
+/* Opening a new order.
+ * Will only be generated with no order can be found (or at least none by this name)
+ */
++?hasOrder(Customer, Order)[o(c)] :
+ isEmployedBy(Customer)
+ <-
+ jasdl.ia.get_anonymous_individual(Order);
+ +hasOrder(Customer, Order)[o(c)].
Added: trunk/applications/jasdl-owlapi/examples/commerce/src/asl/shop.asl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/src/asl/shop.asl (rev 0)
+++ trunk/applications/jasdl-owlapi/examples/commerce/src/asl/shop.asl 2008-04-20 16:47:30 UTC (rev 1230)
@@ -0,0 +1,240 @@
+{include("common/society.asl")}
+
++!kqml_received(Sender, askOne, Content[o(O), id(ID)], MsgId) :
+ pA(PA)[o(s)]
+ <-
+ .add_annot(Content, source(Sender), X);
+ .add_annot(X, o(O), Y);
+ .add_annot(Y, id(ID), Z);
+ ?Z.
+
+
+
+
+
+
+
+
++?product(Brand)[o(c), id(ID), source(PA)] : JASDL_TG_CAUSE
+ <-
+ //.add_annot(JASDL_TG_CAUSE, id(ID), Response);
+ //.send(PA, tell, Response).
+ jasdl.ia.get_individual(JASDL_TG_CAUSE, Brand);
+ .print("Sending ", JASDL_TG_CAUSE);
+ .send(PA, tell, product(Brand)[o(c), id(ID)]).
+
+/** Plans dealing with a failure to find a suitable product within the belief-base of this agent */
+
++?thing(Brand)[o(owl), id(ID), source(PA)] :
+ not JASDL_TG_CAUSE
+ <-
+ .print("Requested unknown product, moreover, no other shops in this company can be identified to potentially service this request");
+ .send(PA, tell, failure[id(ID)]).
+
++?product(Brand)[o(c), id(ID), source(PA)] :
+ not JASDL_TG_CAUSE &
+ .my_name(Me) &
+ ownedBy(Me, Owner)[o(s)] &
+ jasdl.ia.define_class(mightStock, "s:shop and s:ownedBy value s:",Owner," and (not {s:",Me,"})") &
+ mightStock(Shop)[o(self)]
+ <-
+ .print("Requested unknown product, attempting to refer to any other shop owned by this company");
+ .send(PA, tell, referral(Shop)[id(ID)]).
+
+/**
+ * No suitable product has been found in this agent's belief base. However,
+ * because it is a type of meat product, it might be worth looking for butchers
+ * owned by this company and referring to PA to them (if any are known).
+ */
++?meat(Brand)[o(c), id(ID), source(PA)] :
+ not JASDL_TG_CAUSE &
+ .my_name(Me) &
+ ownedBy(Me, Owner)[o(s)] &
+ jasdl.ia.define_class(mightStock, "s:butchers and s:ownedBy value s:",Owner," and (not {s:",Me,"})") &
+ mightStock(Butchers)[o(self)]
+ <-
+ .print("Requested unknown meat product, attempting to refer to a butchers owned by this company");
+ .send(PA, tell, referral(Butchers)[id(ID)]).
+
+/****************************************************************/
+
+
+
+
+
++!add_to_order(Order, Brand, Qty)[source(PA)] :
+ product(Brand)[o(c)] & // check known product brand
+ hasCustomer(Order, Customer)[o(c)] & employs(Customer, PA)[o(s)] & // check PA is authorised to speak on behalf of customer whose order it is
+ hasInStock(Brand, StockLevel)[o(c)] & StockLevel>=Qty // check we have enough stock
+ <-
+
+ // get a unique purchase identifier
+ jasdl.ia.get_anonymous_individual(PID);
+
+ // add purchase
+ +purchase(PID)[o(c)];
+ +includes(Order, PID)[o(c)];
+ +hasBrand(PID, Brand)[o(c)];
+ +hasQuantity(PID, Qty)[o(c)];
+ .send(PA, tell, confirmed(Order, Brand, Qty)).
+
+
+
++!confirm_order(Order)[source(PA)] :
+ hasCustomer(Order, Customer)[o(c)] &
+ employs(Customer, PA)[o(s)]
+ <-
+ !deploy(Order);
+ !allocate_available(Van);
+ !recall(Van);
+ !load(Order, Van);
+ !dispatch(Order, Van);
+ !unload(Order, Van);
+ +available(Van);
+ .abolish(includes(Order, _)[o(c)]);
+ .send(Customer, tell, order_complete(Order)).
+
+
+
+@available[atomic]
++!allocate_available(Van)
+ <-
+ ?available(Van)[source(_)];
+ -available(Van)[source(_)].
+
++?available(Van)
+ <-
+ .concat("+",available(Van)[source(_)], WaitFor);
+ .wait(WaitFor);
+ ?available(Van)[source(_)].
+
++!load(Order, Van) : .my_name(Me) & inVicinityOf(Van)
+ <-
+ -hasPosition(Van, X, Y)[source(Van)];
+ .findall(PID, includes(Order, PID)[o(c)], PIDs);
+ .send(Van, achieve, load(PIDs));
+ L=loading_complete[source(Van)];
+ .concat("+", L, WaitFor);
+ .wait(WaitFor);
+ -L.
+
++!unload(Order, Van)
+ <-
+ .findall(PID, includes(Order, PID)[o(c)], PIDs);
+ .send(Van, achieve, unload(PIDs));
+ L=unloading_complete[source(Van)];
+ .concat("+", L, WaitFor);
+ .wait(WaitFor);
+ -L.
+
++!recall(Van)
+ <-
+ .my_name(Me);
+ ?hasPosition(Me, MX, MY);
+ !hasPosition(Van, MX, MY).
+
++!dispatch(Order, Van)
+ <-
+ ?hasCustomer(Order, Customer)[o(c)];
+ .send(Customer, askOne, hasPosition(Customer, X, Y), hasPosition(Customer, X, Y));
+ !hasPosition(Van, X, Y).
+
+
++!hasPosition(Van, X, Y) : L=hasPosition(Van, X, Y) & not L
+ <-
+ .send(Van, achieve, hasPosition(Van, X, Y));
+ .concat("+", L[source(Van)], WaitFor);
+ .wait(WaitFor);
+ -L.
+
++!hasPosition(Van, X, Y) : L=hasPosition(Van, X, Y) & L.
+
+
+
+
++!deploy([]).
++!deploy([Purchase|Purchases])
+ <-
+ ?hasBrand(Purchase, Brand)[o(c)];
+ ?hasQuantity(Purchase, Qty)[o(c)];
+ deploy(Purchase, Brand, Qty);
+ .print("Deploying crate", Purchase);
+ !deploy(Purchases).
++!deploy(Order)
+ <-
+ .findall(PID, includes(Order, PID)[o(c)], PIDs);
+ !deploy(PIDs).
+
+
+
+
++?details(Brand, Details) : product(PID)[o(c)]
+ <-
+ ?hasPrice(Brand, Price)[o(c)];
+ ?hasInStock(Brand, StockLevel)[o(c)];
+ jasdl.ia.get_types(Brand, self, true, Types);
+ .concat("Brand Name=", Brand, ", Stock level=", StockLevel, ", Price=", ", Classifications=", Types, Price, Details).
+
+/* Failed to get details. Reason: No price listed for product type */
+-?details(Brand, Details) : product(Brand)[o(c)] & not hasPrice(Brand, Price)
+ <-
+ .concat("No price listed for product ", Brand, Details).
+
++!print_details(Brand) : product(Brand)[o(c)]
+ <-
+ ?details(Brand, Details);
+ .print(Details).
+
+
+
+
+/* Local Prices */
+
+
+
+/* We trust the delivery_agent when it informs of a product removal */
+/*
+-hovis(PID)[o(c)]
+ <-
+ -product(PID)[o(c), source(self)];
+ ?details(PID, Details);
+ .print("Sold ", Details).
+*/
+
+
+/* Gets this shop's price for a class of individuals */
+// TODO: jasdl.ia.seliteral(Literal)
+/* SAFELY allowing classes to be subjects of properties*/
+/*
+Deprecated, prices are obtained statically
++?hasPrice(PID, Price) : .atom(PID)
+ <-
+ .print("Get price of ", PID);
+ ?hasPrice(product(PID)[o(c)], Price). // <- why doesn't this work?
+
+
+
+
++!hasPrice(product(PID)[o(c)], Price) // <- note: not semantically-enriched
+ <-
+ .findall(product(PID)[o(c)], product(PID)[o(c)], Groundings);
+ .print("Setting price to ",Price," for ", Groundings);
+ !hasPrice(Groundings, Price).
+
++!hasPrice([Grounding | Groundings], Price)
+ <-
+ jasdl.ia.get_individual(Grounding, PID);
+ +hasPrice(PID, Price)[o(c)]; // <- note: semantically-enriched
+ !hasPrice(Groundings, Price).
+
++!hasPrice([], _).
+
+*/
+
+
+/*
+ Doesn't work, since concat creates string term and so includes quotation marks which are not valid URI characters
+ .findall(ID, includes(Order, ID)[o(c)], IDs);
+ .length(IDs, MaxID);
+ .concat("purchase_", Order, "_", MaxID, PID);
+ */
Modified: trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/CommerceEnvironment.java
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/CommerceEnvironment.java 2008-04-18 18:55:08 UTC (rev 1229)
+++ trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/CommerceEnvironment.java 2008-04-20 16:47:30 UTC (rev 1230)
@@ -1,7 +1,7 @@
package commerce.env;
// Environment code for project commerce.mas2j
-import static jasdl.util.Common.getCurrentDir;
+import static jasdl.util.JASDLCommon.getCurrentDir;
import jasdl.bridge.factory.AliasFactory;
import jasdl.bridge.mapping.aliasing.Alias;
import jasdl.bridge.mapping.aliasing.DecapitaliseMappingStrategy;
@@ -21,14 +21,17 @@
import java.net.URI;
import java.util.Arrays;
import java.util.List;
+import java.util.Vector;
import java.util.logging.Logger;
import commerce.env.model.CommerceModel;
import commerce.env.model.ModelAgent;
+import commerce.env.model.ModelCustomer;
import commerce.env.model.ModelDeliveryVan;
import commerce.env.model.ModelObject;
import commerce.env.model.ModelShop;
import commerce.exception.ModelAgentException;
+import commerce.ui.customer.CustomerUIFrame;
@@ -38,7 +41,7 @@
* @author tom
*
*/
-public class CommerceEnvironment extends JASDLEnvironment {
+public class CommerceEnvironment extends JASDLEnvironment{
public Atom s = new Atom("s");
@@ -57,11 +60,20 @@
super.init(args);
model = new CommerceModel(new Dimension(20, 20), this);
+
view = new CommerceView(model);
+
+ CustomerUIFrame customerUIFrame = new CustomerUIFrame(this);
+ // for each customer set-up a UI Panel
+ for(ModelObject o : model.getObjects()){
+ if(o instanceof ModelCustomer){
+ customerUIFrame.addCustomer((ModelCustomer)o);
+ }
+ }
try {
- getJasdlOntologyManager().loadOntology(c, URI.create("file://"+getCurrentDir()+"/onts/commerce.owl"), mappingStrategies);
- getJasdlOntologyManager().loadOntology(s, URI.create("file://"+getCurrentDir()+"/onts/society.owl"), mappingStrategies);
+ getJom().loadOntology(c, URI.create("file://"+getCurrentDir()+"/onts/commerce.owl"), mappingStrategies);
+ getJom().loadOntology(s, URI.create("file://"+getCurrentDir()+"/onts/society.owl"), mappingStrategies);
} catch (JASDLException e) {
e.printStackTrace();
@@ -69,9 +81,10 @@
updatePercepts();
+
}
-
+
private void updatePercepts(){
synchronized(model.getObjects()){
try{
@@ -116,7 +129,6 @@
@Override
public boolean executeAction(String agName, Structure action) {
Logger agentLogger = Logger.getLogger(agName);
-
try{
Term[] terms = new Term[action.getTerms().size()];
int i=0;
@@ -155,8 +167,18 @@
}
}
+ if(agent instanceof ModelCustomer){
+ ModelCustomer customer = (ModelCustomer)agent;
+ if(action.getFunctor().equals("request_product")){
+ customer.request(terms[0].toString(), terms[1].toString(), (int)((NumberTerm)terms[2]).solve());
+ }
+ if(action.getFunctor().equals("approve")){
+ return customer.approve(terms[0].toString());
+ }
+ }
+
}catch(ModelAgentException e){
agentLogger.info("Unable to complete action "+action+". Reason: ");
e.printStackTrace();
@@ -164,7 +186,7 @@
}finally{
updatePercepts();
}
- agentLogger.fine("Completed action "+action);
+ agentLogger.info("Completed action "+action);
return true;
}
Modified: trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/CommerceModel.java
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/CommerceModel.java 2008-04-18 18:55:08 UTC (rev 1229)
+++ trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/CommerceModel.java 2008-04-20 16:47:30 UTC (rev 1230)
@@ -51,7 +51,11 @@
shop1.addProductToCatalogue(new Product("bread", "kingsmill", 1.6, 750), 58);
shop1.addProductToCatalogue(new Product("milk", "cravendale", 0.9, 500), 33);
+ ModelShop shop2 = new ModelShop(new Atom("shop2"), new Point(5, 3), this, env);
+ shop2.addProductToCatalogue(new Product("beef", "farmer_jims_rump_steak", 1.4, 800), 22);
+
addObject(shop1);
+ addObject(shop2);
addObject(new ModelCustomer(new Atom("customer1"), new Point(10, 10), this, env));
addObject(new ModelCustomer(new Atom("customer2"), new Point(15, 8), this, env));
addObject(new ModelCustomer(new Atom("customer3"), new Point(19, 3), this, env));
@@ -60,6 +64,8 @@
addObject(new ModelPA(new Atom("pa1"), new Point(0, 0), this, env));
addObject(new ModelPA(new Atom("pa2"), new Point(0, 0), this, env));
+ updateObjects();
+
}
public void setView(CommerceView view){
Modified: trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelCustomer.java
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelCustomer.java 2008-04-18 18:55:08 UTC (rev 1229)
+++ trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelCustomer.java 2008-04-20 16:47:30 UTC (rev 1230)
@@ -13,9 +13,14 @@
import commerce.env.CommerceEnvironment;
public class ModelCustomer extends ModelMobileAgent {
+
+ private List<ModelCustomerListener> listeners;
+ private List<Request> requests;
public ModelCustomer(Atom id, Point position, CommerceModel model, CommerceEnvironment env) {
super(id, position, model, env);
+ requests = new Vector<Request>();
+ listeners = new Vector<ModelCustomerListener>();
}
public List<Literal> getPercepts() throws JASDLException{
@@ -37,6 +42,40 @@
return percepts;
}
+
+ public void addListener(ModelCustomerListener listener){
+ listeners.add(listener);
+ }
+
+ @Override
+ public void addPercepts() throws JASDLException {
+ super.addPercepts();
+ for(Request request : requests){
+ env.addPercept(getId().toString(), Literal.parseLiteral("ui_product_request("+request.productDescription+","+request.shopDescription+","+request.qty+")"));
+ }
+ requests.clear();
+ }
+
+
+ public void request(String productDescription, String shopDescription, int qty){
+ Request request = new Request(productDescription, shopDescription, qty);
+ System.out.println("Requested "+request);
+ requests.add(request);
+ }
+
+ /**
+ * Returns true if all listeners approve of this choice as a purchase
+ * @param brand
+ * @return
+ */
+ public boolean approve(String brand){
+ boolean result = true;
+ for(ModelCustomerListener listener : listeners){
+ result&=listener.approve(brand); // do all listeners approve of this choice?
+ }
+ return result;
+ }
+
protected float getOffset(){
return 0.6f;
}
@@ -45,4 +84,26 @@
return new Color(0, 100, 0);
}
+ /**
+ * Associates a product description with a quantity
+ * @author tom
+ *
+ */
+ class Request{
+ public String shopDescription;
+ public String productDescription;
+ public int qty;
+ public Request(String productDescription, String shopDescription, int qty) {
+ super();
+ this.shopDescription = shopDescription;
+ this.productDescription = productDescription;
+ this.qty = qty;
+ }
+
+ public String toString(){
+ return productDescription+" ("+qty+")";
+ }
+
+ }
+
}
Added: trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelCustomerListener.java
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelCustomerListener.java (rev 0)
+++ trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelCustomerListener.java 2008-04-20 16:47:30 UTC (rev 1230)
@@ -0,0 +1,17 @@
+package commerce.env.model;
+
+/**
+ * Classes interested in events from a ModelCustomer should implement this class and add themselves as a listener to ModelCustomer
+ * @author tom
+ *
+ */
+public interface ModelCustomerListener {
+
+ /**
+ * Listener implementations should return true iff they approve of this brand as a purchase.
+ * All listeners must approve for the choice to be accepted
+ * @param brand
+ * @return
+ */
+ public boolean approve(String brand);
+}
Modified: trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelShop.java
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelShop.java 2008-04-18 18:55:08 UTC (rev 1229)
+++ trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelShop.java 2008-04-20 16:47:30 UTC (rev 1230)
@@ -9,7 +9,9 @@
import java.awt.Point;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
+import java.util.Vector;
import commerce.env.CommerceEnvironment;
import commerce.exception.ModelShopException;
@@ -75,7 +77,10 @@
*/
@Override
public void addPercepts() throws JASDLException {
- super.addPercepts();
+ super.addPercepts();
+
+ List<Atom> differentIndividuals = new Vector<Atom>();
+
for(Product product : catalogue){
// add product
@@ -123,10 +128,22 @@
new NumberTermImpl(product.RRP),
new Term[0],
env.c)
- .getLiteral());
-
-
+ .getLiteral());
+
+ differentIndividuals.add(new Atom(product.brand));
}
+
+ // enter all products into an all_different assertion
+ Atom[] is = (Atom[]) differentIndividuals.toArray(new Atom[differentIndividuals.size()]);
+ env.addPercept(
+ getId().toString(),
+ env.getSELiteralFactory().construct(
+ true,
+ is,
+ new Atom[0],
+ env.c)
+ .getLiteral());
+
}
protected float getOffset(){
Added: trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/ui/customer/CustomerUIFrame.java
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/ui/customer/CustomerUIFrame.java (rev 0)
+++ trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/ui/customer/CustomerUIFrame.java 2008-04-20 16:47:30 UTC (rev 1230)
@@ -0,0 +1,36 @@
+package commerce.ui.customer;
+
+import java.awt.Dimension;
+
+import javax.swing.JFrame;
+import javax.swing.JTabbedPane;
+
+import commerce.env.CommerceEnvironment;
+import commerce.env.model.ModelCustomer;
+
+public class CustomerUIFrame extends JFrame{
+
+ private JTabbedPane tabs;
+ private CommerceEnvironment env;
+
+ public CustomerUIFrame(CommerceEnvironment env){
+ super("Commerce: Customer UI");
+ this.env = env;
+
+ setPreferredSize(new Dimension(220, 320));
+
+ tabs = new JTabbedPane();
+ add(tabs);
+ tabs.setVisible(true);
+
+ pack();
+ setVisible(true);
+ }
+
+ public void addCustomer(ModelCustomer customer){
+ CustomerUIPanel panel = new CustomerUIPanel(env, customer);
+ tabs.addTab(customer.getLabel(), panel);
+ }
+
+
+}
Added: trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/ui/customer/CustomerUIPanel.java
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/ui/customer/CustomerUIPanel.java (rev 0)
+++ trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/ui/customer/CustomerUIPanel.java 2008-04-20 16:47:30 UTC (rev 1230)
@@ -0,0 +1,88 @@
+package commerce.ui.customer;
+
+import jason.asSyntax.Literal;
+
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JSpinner;
+import javax.swing.JTextArea;
+import javax.swing.SpinnerNumberModel;
+
+import commerce.env.CommerceEnvironment;
+import commerce.env.model.ModelCustomer;
+import commerce.env.model.ModelCustomerListener;
+
+public class CustomerUIPanel extends JPanel implements ModelCustomerListener{
+ private JTextArea productDescriptionField;
+ private JButton submitButton;
+ private ModelCustomer customer;
+ private CommerceEnvironment env;
+ private JSpinner qty;
+ private JTextArea shopDescriptionField;
+
+ public CustomerUIPanel(CommerceEnvironment env, ModelCustomer customer){
+ super();
+ this.customer = customer;
+
+ customer.addListener(this);
+
+ this.env = env;
+ setupUI();
+ }
+
+ private void setupUI(){
+ JPanel productRequestPane = new JPanel();
+ add(productRequestPane);
+ productRequestPane.setPreferredSize(new Dimension(200, 200));
+ productRequestPane.setLayout(new BoxLayout(productRequestPane, BoxLayout.Y_AXIS));
+
+ productDescriptionField = new JTextArea(20, 8);
+ productRequestPane.add(productDescriptionField);
+
+ shopDescriptionField = new JTextArea(20, 8);
+ productRequestPane.add(shopDescriptionField);
+
+ JPanel buttonPane = new JPanel();
+ buttonPane.setPreferredSize(new Dimension(200, 100));
+ buttonPane.setLayout(new FlowLayout());
+ productRequestPane.add(buttonPane);
+
+ submitButton = new JButton("Submit");
+ buttonPane.add(submitButton);
+ submitButton.addActionListener(new ProductRequestSubmitButtonActionListener());
+
+ qty = new JSpinner(new SpinnerNumberModel(1, 0, 200, 1));
+ buttonPane.add(qty);
+
+ }
+
+ class ProductRequestSubmitButtonActionListener implements ActionListener{
+ public void actionPerformed(ActionEvent event) {
+ String productDescription = productDescriptionField.getText();
+ String shopDescription = shopDescriptionField.getText();
+
+ // strip new lines
+ productDescription = productDescription.replace("\n", " ");
+ shopDescription = shopDescription.replace("\n", " ");
+ env.executeAction(customer.getId().toString(), Literal.parseLiteral(
+ "request_product(\""+productDescription+"\","+"\""+shopDescription+"\","+qty.getValue()+")"));
+ }
+ }
+
+ public boolean approve(String brand) {
+ int n = JOptionPane.showConfirmDialog(
+ this,
+ "Does the following product meet your requirements?\n"+brand,
+ "Your personal agent seeks your approval",
+ JOptionPane.YES_NO_OPTION);
+
+ return n == JOptionPane.YES_OPTION;
+ }
+}
Modified: trunk/applications/jasdl-owlapi/src/jasdl/JASDLParams.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/JASDLParams.java 2008-04-18 18:55:08 UTC (rev 1229)
+++ trunk/applications/jasdl-owlapi/src/jasdl/JASDLParams.java 2008-04-20 16:47:30 UTC (rev 1230)
@@ -10,6 +10,10 @@
import jason.asSyntax.Atom;
public class JASDLParams {
+ public static String JASDL_TG_CAUSE_RETAIN_ANNOTS = "JASDL_TG_CAUSE_RETAIN_ANNOTS";
+
+ public static String JASDL_TG_CAUSE = "JASDL_TG_CAUSE";
+
/**
* Functor of the structure containing the ontology label which maps to the ontology a SE-Literal refers to
*/
Modified: trunk/applications/jasdl-owlapi/src/jasdl/architecture/JASDLAgArch.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/architecture/JASDLAgArch.java 2008-04-18 18:55:08 UTC (rev 1229)
+++ trunk/applications/jasdl-owlapi/src/jasdl/architecture/JASDLAgArch.java 2008-04-20 16:47:30 UTC (rev 1230)
@@ -47,7 +47,7 @@
public void initAg(String agClass, ClassParameters bbPars, String asSrc, Settings stts) throws JasonException {
super.initAg(agClass, bbPars, asSrc, stts);
- processor = new ProtocolProcessor(getAgent().getJom(), getAgent().getDefaultMappingStrategies(), getAgent().getSELiteralFactory());
+ processor = new ProtocolProcessor(getAgent().getJom(), getAgent().getDefaultMappingStrategies());
}
@Override
Modified: trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JASDLAgent.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JASDLAgent.java 2008-04-18 18:55:08 UTC (rev 1229)
+++ trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JASDLAgent.java 2008-04-20 16:47:30 UTC (rev 1230)
@@ -22,6 +22,7 @@
import jasdl.JASDLParams;
import jasdl.asSyntax.JASDLPlanLibrary;
+import jasdl.asSyntax.SEPlan;
import jasdl.bb.JASDLBeliefBase;
import jasdl.bb.bebops.JASDLIncisionFunction;
import jasdl.bb.bebops.JASDLKernelsetFilter;
@@ -35,7 +36,6 @@
import jasdl.bridge.mapping.label.LabelManager;
import jasdl.bridge.mapping.label.OntologyURIManager;
import jasdl.bridge.seliteral.SELiteral;
-import jasdl.util.exception.JASDLConfigurationException;
import jasdl.util.exception.JASDLException;
import jasdl.util.exception.JASDLNotEnrichedException;
import jason.JasonException;
@@ -61,7 +61,6 @@
import org.semanticweb.owl.model.OWLAxiom;
import org.semanticweb.owl.model.OWLDataFactory;
import org.semanticweb.owl.model.OWLDescription;
-import org.semanticweb.owl.model.OWLIndividualAxiom;
import org.semanticweb.owl.model.OWLOntology;
import org.semanticweb.owl.model.OWLOntologyManager;
import org.semanticweb.owl.model.RemoveAxiom;
@@ -88,11 +87,8 @@
private JASDLOntologyManager jom;
- private SELiteralFactory seLiteralFactory;
- public AxiomToSELiteralConverter axiomToSELiteralConverter;
- private SELiteralToAxiomConverter SELiteralToAxiomConverter;
private JASDLAgentConfigurator config;
@@ -102,12 +98,12 @@
// instantiate utility classes
jom = new JASDLOntologyManager(getLogger());
config = new JASDLAgentConfigurator(this);
- seLiteralFactory = new SELiteralFactory(getJom());
- SELiteralToAxiomConverter = new SELiteralToAxiomConverter(this);
- axiomToSELiteralConverter = new AxiomToSELiteralConverter(this);
+
// override plan library
setPL(new JASDLPlanLibrary(this));
+
+
}
@@ -122,7 +118,12 @@
config.preInitConfigure(stts);
TransitionSystem ts = super.initAg(arch, bb, src, stts);
config.postInitConfigure(stts);
+
+ for(SEPlan se : ((JASDLPlanLibrary)getPL()).getSEPlans()){
+ getLogger().finest(se.getTrigger().toString());
+ }
+
return ts;
}
@@ -275,6 +276,10 @@
return getTS().getUserAgArch().getAgName();
}
+ public SELiteralFactory getSELiteralFactory(){
+ return getJom().getSELiteralFactory();
+ }
+
public List<MappingStrategy> getDefaultMappingStrategies() {
return config.getDefaultMappingStrategies();
}
@@ -307,16 +312,12 @@
return getJom().getReasoner();
}
- public SELiteralFactory getSELiteralFactory() {
- return seLiteralFactory;
- }
-
public SELiteralToAxiomConverter getSELiteralToAxiomConverter() {
- return SELiteralToAxiomConverter;
+ return getJom().getSELiteralToAxiomConverter();
}
public AxiomToSELiteralConverter getAxiomToSELiteralConverter() {
- return axiomToSELiteralConverter;
+ return getJom().getAxiomToSELiteralConverter();
}
public OWLDataFactory getOWLDataFactory() {
Modified: trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JASDLAgentConfigurator.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JASDLAgentConfigurator.java 2008-04-18 18:55:08 UTC (rev 1229)
+++ trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JASDLAgentConfigurator.java 2008-04-20 16:47:30 UTC (rev 1230)
@@ -19,8 +19,8 @@
*/
package jasdl.asSemantics;
-import static jasdl.util.Common.getCurrentDir;
-import static jasdl.util.Common.strip;
+import static jasdl.util.JASDLCommon.getCurrentDir;
+import static jasdl.util.JASDLCommon.strip;
import jasdl.JASDLParams;
import jasdl.bridge.factory.AliasFactory;
import jasdl.bridge.mapping.aliasing.Alias;
@@ -52,8 +52,6 @@
private HashMap<Atom, Float> trustMap;
private boolean beliefRevisionEnabled;
-
- private boolean annotationGatheringEnabled;
private boolean contractionEnabled;
@@ -200,7 +198,7 @@
}
public void setAnnotationGatheringEnabled(boolean b) {
- this.annotationGatheringEnabled = b;
+ agent.getJom().setAnnotationGatheringEnabled(b);
}
/**
@@ -364,7 +362,7 @@
}
public boolean isAnnotationGatheringEnabled() {
- return annotationGatheringEnabled;
+ return agent.getJom().isAnnotationGatheringEnabled();
}
public boolean isBeliefRevisionEnabled() {
Modified: trunk/applications/jasdl-owlapi/src/jasdl/asSyntax/JASDLPlanLibrary.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/asSyntax/JASDLPlanLibrary.java 2008-04-18 18:55:08 UTC (rev 1229)
+++ trunk/applications/jasdl-owlapi/src/jasdl/asSyntax/JASDLPlanLibrary.java 2008-04-20 16:47:30 UTC (rev 1230)
@@ -21,24 +21,31 @@
import jasdl.asSemantics.JASDLAgent;
import jasdl.bridge.seliteral.SELiteral;
+import jasdl.util.JASDLCommon;
import jasdl.util.exception.JASDLException;
+import jasdl.util.exception.JASDLInvalidSELiteralException;
import jasdl.util.exception.JASDLNotEnrichedException;
import jason.JasonException;
import jason.asSyntax.Literal;
import jason.asSyntax.Plan;
import jason.asSyntax.PlanLibrary;
+import jason.asSyntax.Structure;
import jason.asSyntax.Term;
import jason.asSyntax.Trigger;
-import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
-import java.util.Set;
import java.util.Vector;
import java.util.logging.Logger;
+import org.semanticweb.owl.model.OWLException;
+
/**
- * TODO: What about lists with nested SE-Literals? Prohibit?
- * @author tom
+ *
+ * SE-Plans are ordered most specific -> most general, ensuring the most specific option is generalised to.
+ * TODO: write tests
+ *
+ * @author Tom Klapiscak
*
*/
public class JASDLPlanLibrary extends PlanLibrary {
@@ -48,24 +55,113 @@
/**
* Keep track of SE Plans for generating candidate relevances for incoming triggers containing SE-Literals
*/
- private Set<SEPlan> sePlans;
+ private LinkedList<SEPlan> sePlans;
public JASDLPlanLibrary(JASDLAgent agent) {
this.agent = agent;
- sePlans = new HashSet<SEPlan>();
+ sePlans = new LinkedList<SEPlan>();
}
+
@Override
public void add(Plan p) throws JasonException {
// All plan who's trigger contains a SE-Literal is added as an SE-Plan so DL-unification can be performed when checking its relevance
if (containsSELiteral(p.getTrigger().getLiteral())) {
SEPlan sePlan = new SEPlan(agent, p);
- sePlans.add(sePlan);
+
+ try {
+ insertSEPlan(sePlan);
+ } catch (OWLException e) {
+ throw new JasonException("Error placing SE-Plan "+p, e);
+ }
+
super.add(sePlan);
} else {
super.add(p);
}
}
+
+ /**
+ * Inserts an SE-Plan according to its specificity (most specific first).
+ * TODO: Is this not better placed within a JMCA option selection strategy?
+ */
+ private void insertSEPlan(SEPlan unplaced) throws JASDLException, OWLException{
+ int i = 0;
+ for(SEPlan placed : sePlans){
+ Literal x = unplaced.getTrigger().getLiteral();
+ Literal y = placed.getTrigger().getLiteral();
+ boolean xIsMoreSpecific = isMoreSpecific(x, y);
+ getLogger().finest("Is "+x+" more specific than "+y+"? "+xIsMoreSpecific);
+ if(xIsMoreSpecific) break;
+ i++;
+ }
+ sePlans.add(i, unplaced);
+ }
+
+
+ public List<SEPlan> getSEPlans(){
+ return sePlans;
+ }
+
+ /**
+ * Semantically naive literals are always considered more specific than semantically enriched.
+ * Do not need to consider incomparable literals (those with different arities or those with different semantic enrichment state)
+ * since one can never generalise to the other.
+ *
+ * Algorithm functions as follows:
+ *
+ * Terminal cases:
+ * if either x or y is not a structure, they are incomparable (different arities (at least one has no terms))
+ * If arity(x)!=arity(y) then they are considered incomparable and we (arbitrarily) return arity(x)<arity(y)
+ * If SN(x) and SE(y) then we return true
+ * if SE(x) and SN(y) then we return false
+ * if SE(x) and SE(y) then we return subsumes(y, x) (i.e. true if x is more specific)
+ *
+ * Recursive case:
+ * score=0
+ * if SN(x) and SN(y) then
+ * for each term of x and y in parallel
+ * if isMoreSpecific(x, y) then score++ else score--
+ *
+ * if score>=0 then we return true (i.e. x has a greater number of more specific terms than y) else false
+ *
+ */
+ private boolean isMoreSpecific(Term _x, Term _y) throws JASDLException, OWLException{
+ if(!_x.isStructure() || !_y.isStructure()) return false;
+ Structure x = (Structure)_x;
+ Structure y = (Structure)_y;
+
+ if(x.getArity() != y.getArity()) return false;
+ SELiteral sx = null;
+ SELiteral sy = null;
+
+ try {
+ if(x.isLiteral()) sx = agent.getSELiteralFactory().construct((Literal)x);
+ } catch (JASDLInvalidSELiteralException e) {
+ }
+
+ try {
+ if(y.isLiteral()) sy = agent.getSELiteralFactory().construct((Literal)y);
+ } catch (JASDLInvalidSELiteralException e) {
+ }
+
+ if((sx == null && sy != null) || (sx != null && sy == null)) return false;
+
+ if(sx != null && sy != null) return JASDLCommon.subsumes(agent.getJom(), sy.toOWLObject(), sx.toOWLObject());
+
+ // both sx and sy are semantically-naive and have equivalent arities
+ int score = 0;
+ for(int i=0; i<x.getArity(); i++){
+ Term xt = x.getTerm(i);
+ Term yt = y.getTerm(i);
+
+ if(isMoreSpecific(xt, yt)) score++; else score--;
+
+ }
+
+ if(score>=0) return true; else return false;
+ }
+
@Override
public List<Plan> getCandidatePlans(Trigger te) {
@@ -77,6 +173,8 @@
candidates = new Vector<Plan>();
}
candidates.addAll(sePlans);
+
+
}
return candidates;
Modified: trunk/applications/jasdl-owlapi/src/jasdl/asSyntax/SEPlan.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/asSyntax/SEPlan.java 2008-04-18 18:55:08 UTC (rev 1229)
+++ trunk/applications/jasdl-owlapi/src/jasdl/asSyntax/SEPlan.java 2008-04-20 16:47:30 UTC (rev 1230)
@@ -19,11 +19,15 @@
*/
package jasdl.asSyntax;
+import jasdl.JASDLParams;
import jasdl.asSemantics.JASDLAgent;
+import jasdl.bridge.DLUnifier;
import jason.asSemantics.Unifier;
+import jason.asSyntax.Literal;
import jason.asSyntax.Plan;
+import jason.asSyntax.Term;
import jason.asSyntax.Trigger;
-import jasdl.bridge.DLUnifier;
+import jason.asSyntax.VarTerm;
/**
* <p>A plan whose trigger is associated with a semantically-enriched literal.</p>
@@ -32,7 +36,7 @@
* @author Tom Klapiscak
*
*/
-public class SEPlan extends Plan {
+public class SEPlan extends Plan{
private static final long serialVersionUID = 1L;
private JASDLAgent agent;
@@ -44,12 +48,23 @@
@Override
public Unifier isRelevant(Trigger te) {
- Unifier un = super.isRelevant(te); // better solution? extend unifier?
+ Unifier un = super.isRelevant(te);
if (un != null) { // plan is specifically relevant to deal with the trigger
return un;
}
DLUnifier dlun = new DLUnifier(agent);
if (dlun.unifiesNoUndo(getTrigger(), te)) { // <- plan's trigger subsumes incoming
+
+ Literal causeWithAnnots = (Literal)te.getLiteral().clone();
+ dlun.unifiesNoUndo(new VarTerm(JASDLParams.JASDL_TG_CAUSE_RETAIN_ANNOTS), causeWithAnnots);
+
+ Literal causeNoAnnots = (Literal)te.getLiteral().clone();
+ Term o = causeNoAnnots.getAnnots(JASDLParams.ONTOLOGY_ANNOTATION_FUNCTOR).get(0);
+ causeNoAnnots.clearAnnots();
+ causeNoAnnots.addAnnot(o);
+ dlun.unifiesNoUndo(new VarTerm(JASDLParams.JASDL_TG_CAUSE), causeNoAnnots);
+
+
return dlun;
} else {
return null;
Modified: trunk/applications/jasdl-owlapi/src/jasdl/bb/JASDLBeliefBase.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bb/JASDLBeliefBase.java 2008-04-18 18:55:08 UTC (rev 1229)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bb/JASDLBeliefBase.java 2008-04-20 16:47:30 UTC (rev 1230)
@@ -146,7 +146,7 @@
BeliefBaseContractor contractor = new BeliefBaseContractor(agent.getOntologyManager(), new JASDLReasonerFactory(), agent.getLogger());
removeList = contractor.contract(axiom, new JASDLKernelsetFil...
[truncated message content] |
|
From: <tom...@us...> - 2008-04-18 18:55:16
|
Revision: 1229
http://jason.svn.sourceforge.net/jason/?rev=1229&view=rev
Author: tomklapiscak
Date: 2008-04-18 11:55:08 -0700 (Fri, 18 Apr 2008)
Log Message:
-----------
Correcting commit errors...
Removed Paths:
-------------
trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tom...@us...> - 2008-04-18 18:53:51
|
Revision: 1228
http://jason.svn.sourceforge.net/jason/?rev=1228&view=rev
Author: tomklapiscak
Date: 2008-04-18 11:53:37 -0700 (Fri, 18 Apr 2008)
Log Message:
-----------
Correcting commit errors...
Added Paths:
-----------
trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/
trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/IncomingProtocolProcessingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/OutgoingProtocolProcessingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/ProtocolProcessingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/ProtocolProcessor.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/package.html
Added: trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/IncomingProtocolProcessingStrategy.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/IncomingProtocolProcessingStrategy.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/IncomingProtocolProcessingStrategy.java 2008-04-18 18:53:37 UTC (rev 1228)
@@ -0,0 +1,304 @@
+/*
+ * Copyright (C) 2008 Thomas Klapiscak (t.g...@du...)
+ *
+ * This file is part of JASDL.
+ *
+ * JASDL is free software: you can redistribute it and/or modify
+ * it under the terms of the Lesser GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * JASDL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Lesser GNU General Public License for more details.
+ *
+ * You should have received a copy of the Lesser GNU General Public License
+ * along with JASDL. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package jasdl.bridge.protocol;
+
+import static jasdl.util.Common.strip;
+import jasdl.JASDLParams;
+import jasdl.bridge.JASDLOntologyManager;
+import jasdl.bridge.mapping.aliasing.Alias;
+import jasdl.bridge.mapping.aliasing.MappingStrategy;
+import jasdl.bridge.seliteral.SELiteral;
+import jasdl.util.exception.JASDLException;
+import jasdl.util.exception.JASDLMessageContentException;
+import jasdl.util.exception.JASDLNotEnrichedException;
+import jasdl.util.exception.JASDLUnknownMappingException;
+import jason.asSyntax.Atom;
+import jason.asSyntax.ListTerm;
+import jason.asSyntax.ListTermImpl;
+import jason.asSyntax.Literal;
+import jason.asSyntax.StringTerm;
+import jason.asSyntax.Structure;
+import jason.asSyntax.Term;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+
+import org.semanticweb.owl.model.OWLEntity;
+import org.semanticweb.owl.model.OWLException;
+import org.semanticweb.owl.model.OWLOntology;
+
+public class IncomingProtocolProcessingStrategy implements ProtocolProcessingStrategy {
+
+ private List<MappingStrategy> mappingStrategies;
+
+ public IncomingProtocolProcessingStrategy(List<MappingStrategy> mappingStrategies) {
+ this.mappingStrategies = mappingStrategies;
+ }
+
+ public Literal process(Literal l, JASDLOntologyManager jasdlOntologyManager) throws JASDLException {
+ try {
+ jasdlOntologyManager.getLogger().fine("Processing incoming " + l);
+
+ SELiteral sl = new SELiteral(l, jasdlOntologyManager); // <- NOTE: might not actually be an SE-Literal!
+ processAllDifferent(sl, jasdlOntologyManager);
+ processNamed(sl, jasdlOntologyManager);
+ processAnon(sl, jasdlOntologyManager);
+ processIndividuals(sl, jasdlOntologyManager); // <- MUST be performed last (since we need o annotation to be added)
+
+ return sl.getLiteral();
+ } catch (JASDLNotEnrichedException e) {
+ // do nothing
+ }
+ return l;
+
+ }
+
+ private void processAllDifferent(SELiteral sl, JASDLOntologyManager jasdlOntologyManager) throws JASDLMessageContentException {
+ List<Term> allDifferentAnnots = sl.getLiteral().getAnnots(JASDLParams.ALL_DIFFERENT_ANNOTATION_FUNCTOR).getAsList();
+ if (allDifferentAnnots.size() > 1) {
+ throw new JASDLMessageContentException("Multiple " + JASDLParams.ALL_DIFFERENT_ANNOTATION_FUNCTOR + " annotations preset");
+ } else if (allDifferentAnnots.size() == 1) {
+ Term _allDifferentAnnot = allDifferentAnnots.get(0);
+ if (!_allDifferentAnnot.isStructure())
+ throw new JASDLMessageContentException(_allDifferentAnnot + " must be a structure");
+ Structure allDifferentAnnot = (Structure) _allDifferentAnnot;
+
+ // get ontology
+ Term ontologyTerm = allDifferentAnnot.getTerm(0);
+ if (!(ontologyTerm instanceof StringTerm))
+ throw new JASDLMessageContentException("second term of " + JASDLParams.NAMED_ANNOTATION_FUNCTOR + " must be a string");
+ String _uri = ontologyTerm.toString();
+
+ // try loading the ontology, if fails create it (we don't know whether this ontology is personal or not here!)
+ OWLOntology ontology;
+ try {
+ ontology = jasdlOntologyManager.loadOntology(_uri, mappingStrategies);
+ } catch (JASDLException e) {
+ try {
+ ontology = jasdlOntologyManager.createOntology(_uri, true);
+ } catch (JASDLException e1) {
+ throw new JASDLMessageContentException("Unable to create ontology", e);
+ }
+ }
+ // add "o" annotation with label (may be anonymous if ontology was novel or personal)
+ Structure o = new Structure(JASDLParams.ONTOLOGY_ANNOTATION_FUNCTOR);
+ try {
+ o.addTerm(jasdlOntologyManager.getLabelManager().getLeft(ontology));
+ } catch (JASDLUnknownMappingException e) {
+ throw new JASDLMessageContentException("Ontology creation failed", e);
+ }
+ sl.getLiteral().addAnnot(o);
+
+ sl.getLiteral().delAnnot(allDifferentAnnot);
+
+ }
+ }
+
+ private void processIndividuals(SELiteral sl, JASDLOntologyManager jasdlOntologyManager) throws JASDLMessageContentException {
+ List<Term> iAnnots = sl.getLiteral().getAnnots(JASDLParams.I_ANNOTATION_FUNCTOR).getAsList();
+ if (iAnnots.size() > 1) {
+ throw new JASDLMessageContentException("Multiple " + JASDLParams.I_ANNOTATION_FUNCTOR + " annotations present");
+ } else if (iAnnots.size() == 1) {
+ try {
+ Term _iAnnot = iAnnots.get(0);
+ if (!_iAnnot.isStructure())
+ throw new JASDLMessageContentException(_iAnnot + " must be a structure");
+ Structure iAnnot = (Structure) _iAnnot;
+
+ if (sl.getLiteral().getFunctor().equals(JASDLParams.OWL_ALL_DIFFERENT_FUNCTOR.toString())) { // for all_different assertions
+ ListTerm uris = (ListTerm) iAnnot.getTerm(0);
+ ListTerm originals = (ListTerm) sl.getLiteral().getTerm(0); // must be a list term
+ ListTerm translations = new ListTermImpl();
+ int i = 0;
+ for (Term uriTerm : uris) {
+ try {
+ translations.add(translateIndividualURIStringTerm(uriTerm, jasdlOntologyManager));
+ } catch (JASDLUnknownMappingException e) {
+ // individual is not known, leave it as it is
+ translations.add(originals.get(i));
+ }
+ i++;
+ }
+ sl.getLiteral().setTerm(0, translations);
+ } else { // for class and property assertions
+ for (int i = 0; i < sl.getLiteral().getArity(); i++) { // for each ground atomic term - handles classes and object properies. terms of i annotation are relative to literal terms
+ Term term = sl.getLiteral().getTerm(i);
+ if (term.isGround() && term.isAtom()) {
+ // get the URI relative to this term
+ if (iAnnot.getArity() - 1 < i)
+ throw new JASDLMessageContentException("Insufficient arity");
+ try {
+ sl.getLiteral().setTerm(i, translateIndividualURIStringTerm(iAnnot.getTerm(i), jasdlOntologyManager));
+ } catch (JASDLUnknownMappingException e) {
+ // individual is not known, leave it as it is
+ }
+ }
+ }
+ }
+ sl.getLiteral().delAnnot(iAnnot); // drop i, no longer needed
+ } catch (JASDLMessageContentException e) {
+ throw new JASDLMessageContentException("Unable to translate individuals for " + sl, e);
+ }
+ }
+ }
+
+ private Atom translateIndividualURIStringTerm(Term _uriTerm, JASDLOntologyManager jasdlOntologyManager) throws JASDLMessageContentException, JASDLUnknownMappingException {
+ if (!_uriTerm.isString())
+ throw new JASDLMessageContentException(_uriTerm + " does not have a single string term");
+ StringTerm uriTerm = (StringTerm) _uriTerm;
+ URI uri;
+ try {
+ uri = new URI(strip(uriTerm.toString(), "\"")); // Quotes stripped
+ } catch (URISyntaxException e) {
+ throw new JASDLMessageContentException("Invalid URI supplied", e);
+ }
+
+ // if this agent is aware of an individual known by this uri, translate atom to local mapping (otherwise UnknownMappingException will be thrown)
+ OWLEntity entity = jasdlOntologyManager.toEntity(uri);
+ if (!entity.isOWLIndividual())
+ throw new JASDLMessageContentException(uri + " is not an individual");
+ Alias alias = jasdlOntologyManager.getAliasManager().getLeft(entity);
+ // replace the atom functor with that of local alias
+ return alias.getFunctor();
+ }
+
+ /**
+ * Applies processing to incoming SE-Literals possessing the "named" annotation, i.e. they refer to a class defined in the ontology schema.
+ * @param sl
+ * @param agent
+ * @return
+ * @throws JASDLException
+ */
+ private void processNamed(SELiteral sl, JASDLOntologyManager jasdlOntologyManager) throws JASDLException {
+ ListTerm nameds = sl.getLiteral().getAnnots(JASDLParams.NAMED_ANNOTATION_FUNCTOR);
+ if (nameds.size() == 1) {
+
+ // get named annotation
+ Term _named = nameds.get(0);
+ if (!(_named instanceof Structure)) {
+ throw new JASDLException("Invalid " + JASDLParams.NAMED_ANNOTATION_FUNCTOR + " annotation: " + _named);
+ }
+ Structure named = (Structure) _named;
+ if (named.getArity() != 2) {
+ throw new JASDLException("Invalid " + JASDLParams.NAMED_ANNOTATION_FUNCTOR + " annotation arity: " + _named);
+ }
+
+ // get ontology
+ Term ontologyTerm = named.getTerm(1);
+ if (!(ontologyTerm instanceof StringTerm))
+ throw new JASDLMessageContentException("second term of " + JASDLParams.NAMED_ANNOTATION_FUNCTOR + " must be a string");
+ String _uri = named.getTerm(1).toString();
+ OWLOntology ontology = jasdlOntologyManager.loadOntology(_uri, mappingStrategies); // may instantiate a new ontology with anonymous label
+
+ // add "o" annotation with label (may be anonymous if ontology was novel)
+ Structure o = new Structure(JASDLParams.ONTOLOGY_ANNOTATION_FUNCTOR);
+ o.addTerm(jasdlOntologyManager.getLabelManager().getLeft(ontology));
+ sl.getLiteral().addAnnot(o);
+
+ // get entity URI
+ Term expressionTerm = named.getTerm(0);
+ if (!(expressionTerm instanceof StringTerm)) {
+ throw new JASDLException("Invalid " + JASDLParams.NAMED_ANNOTATION_FUNCTOR + " annotation term: " + expressionTerm);
+ }
+ String expression = strip(expressionTerm.toString(), "\""); // quotes stripped
+
+ URI uri;
+ try {
+ uri = new URI(expression);
+ } catch (URISyntaxException e) {
+ throw new JASDLException("Invalid entity URI in " + expression);
+ }
+ Alias local = jasdlOntologyManager.getAliasManager().getLeft(jasdlOntologyManager.toEntity(uri)); // will already be present by definition
+
+ // create new (SE) Literal
+ sl.mutateFunctor(local.getFunctor().toString());
+
+ sl.getLiteral().delAnnot(named); // drop named, no longer needed
+ }
+ }
+
+ private void processAnon(SELiteral sl, JASDLOntologyManager jasdlOntologyManager) throws JASDLException {
+ ListTerm anons = sl.getLiteral().getAnnots(JASDLParams.ANON_ANNOTATION_FUNCTOR);
+ if (anons.size() == 1) {
+ // Get Anon annotation
+ Term _anon = anons.get(0);
+ if (!(_anon instanceof Structure)) {
+ throw new JASDLException("Invalid " + JASDLParams.ANON_ANNOTATION_FUNCTOR + " annotation: " + _anon);
+ }
+ Structure anon = (Structure) _anon;
+ if (anon.getArity() != 3) {
+ throw new JASDLException("Invalid " + JASDLParams.ANON_ANNOTATION_FUNCTOR + " annotation arity: " + _anon);
+ }
+
+ // Get expression
+ Term expressionTerm = anon.getTerm(0);
+ if (!(expressionTerm instanceof StringTerm)) {
+ throw new JASDLException("Invalid " + JASDLParams.ANON_ANNOTATION_FUNCTOR + " annotation expression term: " + expressionTerm);
+ }
+ String expression = strip(expressionTerm.toString(), "\""); // quotes stripped
+
+ // Parse prequisite ontology URIs
+ Term prereqsTerm = anon.getTerm(1);
+ if (!(prereqsTerm instanceof ListTerm)) {
+ throw new JASDLException("Invalid " + JASDLParams.ANON_ANNOTATION_FUNCTOR + " annotation prereqs term: " + expressionTerm);
+ }
+ ListTerm prereqs = (ListTerm) prereqsTerm;
+ for (Term _prereqTerm : prereqs) {
+ if (!(_prereqTerm instanceof StringTerm)) {
+ throw new JASDLException("Invalid " + JASDLParams.ANON_ANNOTATION_FUNCTOR + " prereq: " + _prereqTerm);
+ }
+ StringTerm prereqTerm = (StringTerm) _prereqTerm;
+ String prereq = strip(prereqTerm.toString(), "\""); // quotes stripped
+ jasdlOntologyManager.loadOntology(prereq, mappingStrategies); // <- may instantiate a new ontology
+ }
+
+ // Get (possibly instantiate) a personal ontology for this agent
+ Term personalURITerm = anon.getTerm(2);
+ if (!personalURITerm.isString())
+ throw new JASDLMessageContentException("third term of " + JASDLParams.ANON_ANNOTATION_FUNCTOR + " must be a string");
+ OWLOntology ontology;
+ try {
+ ontology = jasdlOntologyManager.getOntology(personalURITerm.toString());
+ } catch (JASDLUnknownMappingException e) {
+ // we have not recieved an anonymous class definition from this agent before, instantiate a personal placeholder ontology for them
+ ontology = jasdlOntologyManager.createOntology(personalURITerm.toString(), true);
+ }
+ // add "o" annotation
+ Structure o = new Structure(JASDLParams.ONTOLOGY_ANNOTATION_FUNCTOR);
+ o.addTerm(jasdlOntologyManager.getLabelManager().getLeft(ontology));
+ sl.getLiteral().addAnnot(o);
+
+ // do we already know this expression?
+ Atom functor = new Atom(sl.getLiteral().getFunctor());
+ try {
+ jasdlOntologyManager.defineClass(functor, sl.getOntologyLabel(), expression, jasdlOntologyManager.getManchesterURIDescriptionParser()); // Instantiate defined expression
+ } catch (OWLException e) {
+ // do nothing
+ throw new JASDLException("Error defining new class " + functor, e);
+ }
+
+ // drop anon annotation, no longer needed
+ sl.getLiteral().delAnnot(anon);
+ }
+
+ }
+
+}
Added: trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/OutgoingProtocolProcessingStrategy.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/OutgoingProtocolProcessingStrategy.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/OutgoingProtocolProcessingStrategy.java 2008-04-18 18:53:37 UTC (rev 1228)
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2008 Thomas Klapiscak (t.g...@du...)
+ *
+ * This file is part of JASDL.
+ *
+ * JASDL is free software: you can redistribute it and/or modify
+ * it under the terms of the Lesser GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * JASDL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Lesser GNU General Public License for more details.
+ *
+ * You should have received a copy of the Lesser GNU General Public License
+ * along with JASDL. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package jasdl.bridge.protocol;
+
+import jasdl.JASDLParams;
+import jasdl.bridge.JASDLOntologyManager;
+import jasdl.bridge.factory.SELiteralFactory;
+import jasdl.bridge.seliteral.SELiteral;
+import jasdl.bridge.seliteral.SELiteralAllDifferentAssertion;
+import jasdl.util.exception.JASDLException;
+import jasdl.util.exception.JASDLNotEnrichedException;
+import jasdl.util.exception.JASDLUnknownMappingException;
+import jason.asSyntax.ListTerm;
+import jason.asSyntax.ListTermImpl;
+import jason.asSyntax.Literal;
+import jason.asSyntax.StringTerm;
+import jason.asSyntax.StringTermImpl;
+import jason.asSyntax.Structure;
+import jason.asSyntax.Term;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.semanticweb.owl.model.OWLDescription;
+import org.semanticweb.owl.model.OWLEntity;
+import org.semanticweb.owl.model.OWLIndividual;
+import org.semanticweb.owl.model.OWLOntology;
+
+public class OutgoingProtocolProcessingStrategy implements ProtocolProcessingStrategy {
+
+ private SELiteralFactory SELiteralFactory;
+
+ public OutgoingProtocolProcessingStrategy(SELiteralFactory SELiteralFactory) {
+ this.SELiteralFactory = SELiteralFactory;
+ }
+
+ /**
+ * Only applies processing if l is SE-Literal, otherwise l is returned as is
+ * Replaces ontology label with physical uri
+ * Adds expr annotation unambiguously describing what is meant by alias
+ * Adds origin annotation if literal refers to defined class
+ * @param l
+ * @throws JASDLException
+ */
+ public Literal process(Literal l, JASDLOntologyManager jom) throws JASDLException {
+ jom.getLogger().fine("Processing outgoing " + l);
+
+ Literal result = l;
+ try {
+ SELiteral sl = SELiteralFactory.construct(l);
+
+ OWLEntity entity = (OWLEntity) sl.toOWLObject();
+ String expression = normaliseExpression(jom.getManchesterURIOWLObjectRenderer().render(entity), jom);
+
+ StringTerm expressionTerm = new StringTermImpl(expression);
+
+ if (entity.isOWLClass() && jom.getDefinitionManager().isKnownLeft(entity.asOWLClass())) { // we have an anonymous run-time defined class
+
+ // construct anon annotation
+ Structure anon = new Structure(JASDLParams.ANON_ANNOTATION_FUNCTOR);
+
+ // add the class expression
+ anon.addTerm(expressionTerm);
+
+ // add set of prerequisite ontologies
+ Set<OWLOntology> prereqs = new HashSet<OWLOntology>();
+ String[] tokens = expression.toString().split("[ |\n]");
+ for (String token : tokens) {
+ try {
+ URI entityURI = new URI(token);
+ URI ontologyURI = new URI(entityURI.getScheme(), entityURI.getSchemeSpecificPart(), null);
+ prereqs.add(jom.getLogicalURIManager().getLeft(ontologyURI));
+ } catch (URISyntaxException e) {
+ // do nothing, probably a keyword
+ } catch (JASDLUnknownMappingException e) {
+ // do nothing, probably a keyword
+ }
+ }
+ ListTerm list = new ListTermImpl();
+ for (OWLOntology prereq : prereqs) {
+ list.add(new StringTermImpl(jom.getPhysicalURIManager().getRight(prereq).toString()));
+ }
+ anon.addTerm(list);
+
+ // add the (personal) ontology this is from
+ StringTerm personalURI = new StringTermImpl(jom.getPhysicalURIManager().getRight(sl.getOntology()).toString());
+ anon.addTerm(personalURI);
+
+ sl.getLiteral().addAnnot(anon);
+
+ jom.getLogger().fine("Sending anonymous "+sl);
+
+ } else {
+
+ // unambiguously refer to named entity
+ StringTerm ontologyURITerm = new StringTermImpl(jom.getPhysicalURIManager().getRight(sl.getOntology()).toString());
+ if ((sl instanceof SELiteralAllDifferentAssertion)) {// special case for all_different
+ Structure all_different = new Structure(JASDLParams.ALL_DIFFERENT_ANNOTATION_FUNCTOR);
+ all_different.addTerm(ontologyURITerm);
+ sl.getLiteral().addAnnot(all_different);
+ } else {
+ Structure named = new Structure(JASDLParams.NAMED_ANNOTATION_FUNCTOR);
+ named.addTerm(expressionTerm);
+ // add ontology this naming is from
+ named.addTerm(ontologyURITerm);
+ sl.getLiteral().addAnnot(named);
+ }
+
+ }
+
+ // unambiguously refer to any nested individuals ("i" annotation). terms of "i" are relative to terms of literal
+ Structure iAnnot = new Structure(JASDLParams.I_ANNOTATION_FUNCTOR);
+ if (sl instanceof SELiteralAllDifferentAssertion) { // for all_different assertions
+ ListTerm translations = new ListTermImpl();
+ SELiteralAllDifferentAssertion ad = sl.asAllDifferentAssertion();
+ //Set<OWLIndividual> is = ad.getOWLIndividuals(); <- can't use this! We need to impose an ordering
+ ListTerm originals = (ListTerm) ad.getLiteral().getTerm(0);
+ for (Term original : originals) {
+ OWLIndividual i = sl.getOWLIndividual(original);
+ URI uri = i.getURI();
+ translations.add(new StringTermImpl(uri.toString()));
+ }
+ iAnnot.addTerm(translations);
+ } else { // for class and property assertions
+ for (int i = 0; i < sl.getLiteral().getArity(); i++) { // for each ground atomic term of literal
+ Term term = sl.getLiteral().getTerm(i);
+ if (term.isGround() && term.isAtom()) {
+ URI uri = sl.getOWLIndividual(i).getURI();
+ iAnnot.addTerm(new StringTermImpl(uri.toString()));
+ } else {
+ iAnnot.addTerm(JASDLParams.NO_INDIVIDUAL_MAPPING); // <- added so subject / objects mappings can be easily distinguished by maintenance of relative positions for object properties
+ }
+ }
+ }
+ sl.getLiteral().addAnnot(iAnnot);
+
+ sl.getLiteral().delAnnot(sl.getOntologyAnnotation()); // drop "o" before sending
+
+ result = sl.getLiteral();
+ } catch (JASDLNotEnrichedException e) {
+ // do nothing
+ //e.printStackTrace();
+ }
+ return result;
+ }
+
+ /**
+ * Returns an expression in which all references to run-time defined classes have been (recursuvely) replaced
+ * with the rendering of their anonymous descriptions, thus ensuring this rendering only refers to predefined classes.
+ * @param expression expression to normalise
+ * @param agent
+ * @return normalised form of expression
+ * @throws JASDLException
+ */
+ private String normaliseExpression(String expression, JASDLOntologyManager jasdlOntologyManager) throws JASDLException {
+ String[] tokens = expression.toString().split("[ |\n]");
+ String newExpression = "";
+ for (String token : tokens) {
+ try {
+ URI entityURI = new URI(token);
+ OWLEntity entity = jasdlOntologyManager.toEntity(entityURI);
+ if (entity.isOWLClass()) {
+ try {
+ OWLDescription desc = jasdlOntologyManager.getDefinitionManager().getRight(entity.asOWLClass());
+ String rendering = jasdlOntologyManager.getManchesterURIOWLObjectRenderer().render(desc);
+ newExpression += "(" + normaliseExpression(rendering, jasdlOntologyManager) + ")";
+ } catch (JASDLUnknownMappingException e1) {
+ // this is a predefined class
+ newExpression += token;
+ }
+ } else {
+ // this is a predefined non-class entity (property, individual, etc)
+ newExpression += token;
+ }
+ } catch (URISyntaxException e) {
+ // this is (probably) a keyword
+ newExpression += " " + token + " ";
+ } catch (JASDLUnknownMappingException e2) {
+ // this is (probably) a keyword
+ newExpression += " " + token + " ";
+ }
+
+ }
+ return newExpression;
+ }
+
+}
Added: trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/ProtocolProcessingStrategy.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/ProtocolProcessingStrategy.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/ProtocolProcessingStrategy.java 2008-04-18 18:53:37 UTC (rev 1228)
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2008 Thomas Klapiscak (t.g...@du...)
+ *
+ * This file is part of JASDL.
+ *
+ * JASDL is free software: you can redistribute it and/or modify
+ * it under the terms of the Lesser GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * JASDL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Lesser GNU General Public License for more details.
+ *
+ * You should have received a copy of the Lesser GNU General Public License
+ * along with JASDL. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package jasdl.bridge.protocol;
+
+import jasdl.bridge.JASDLOntologyManager;
+import jasdl.util.exception.JASDLException;
+import jason.asSyntax.Literal;
+
+public interface ProtocolProcessingStrategy {
+ public Literal process(Literal propcont, JASDLOntologyManager jasdlOntologyManager) throws JASDLException;
+}
Added: trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/ProtocolProcessor.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/ProtocolProcessor.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/ProtocolProcessor.java 2008-04-18 18:53:37 UTC (rev 1228)
@@ -0,0 +1,92 @@
+package jasdl.bridge.protocol;
+
+import jasdl.bridge.JASDLOntologyManager;
+import jasdl.bridge.factory.SELiteralFactory;
+import jasdl.bridge.mapping.aliasing.MappingStrategy;
+import jasdl.util.exception.JASDLException;
+import jasdl.util.exception.JASDLMessageContentException;
+import jason.asSyntax.ListTerm;
+import jason.asSyntax.ListTermImpl;
+import jason.asSyntax.Literal;
+import jason.asSyntax.Structure;
+import jason.asSyntax.Term;
+import jason.asSyntax.VarTerm;
+
+import java.util.List;
+
+public class ProtocolProcessor {
+ private JASDLOntologyManager jom;
+
+ private ProtocolProcessingStrategy incomingStrategy;
+
+ private ProtocolProcessingStrategy outgoingStrategy;
+
+ /**
+ * Sets up using default processing strategies
+ *
+ */
+ public ProtocolProcessor(JASDLOntologyManager jom, List<MappingStrategy> mappingStrategies, SELiteralFactory seLiteralFactory) {
+ this.jom = jom;
+ this.incomingStrategy = new IncomingProtocolProcessingStrategy(mappingStrategies);
+ this.outgoingStrategy = new OutgoingProtocolProcessingStrategy(seLiteralFactory);
+ }
+
+ public ProtocolProcessor(JASDLOntologyManager jom, ProtocolProcessingStrategy incomingStrategy, ProtocolProcessingStrategy outgoingStrategy) {
+ super();
+ this.jom = jom;
+ this.incomingStrategy = incomingStrategy;
+ this.outgoingStrategy = outgoingStrategy;
+ }
+
+ public Structure processIncomingStructure(Structure struct) throws JASDLMessageContentException {
+ return processStructure(struct, incomingStrategy);
+ }
+
+ public Structure processOutgoingStructure(Structure struct) throws JASDLMessageContentException {
+ return processStructure(struct, outgoingStrategy);
+ }
+
+ private Structure processStructure(Structure struct, ProtocolProcessingStrategy strategy) throws JASDLMessageContentException {
+
+ // recurse down terms and lists (for "bundled" SE-enriched content)
+ if (struct.getArity() > 0) { // if we have any terms to process!
+ // Process outer SE-enriched content
+ if (struct.isLiteral()) { // processing strategies only apply to Literals
+ Literal l = (Literal) struct;
+ try {
+ struct = strategy.process(l, jom);
+ } catch (JASDLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ //int i=0;
+ //for(Term _term : struct.getTerms()){ - mustn't use in case struct is a list
+ if (struct.isVar()) {
+ struct = (Structure) ((VarTerm) struct).getValue(); // resolve struct if var
+ }
+ if (struct.isList()) { // special processing for lists (since we can't (or rather shouldn't)) use getTerm or setTerm)
+ ListTermImpl newList = new ListTermImpl(); // a "clone"
+ for (Term e : ((ListTerm) struct).getAsList()) {
+ jom.getLogger().finest("Processing " + e);
+ if (e instanceof Structure) {
+ Structure alteredTerm = (Structure) processStructure((Structure) e, strategy);
+ newList.append(alteredTerm);
+ }
+ }
+ return newList;
+ } else { // all other structures
+ for (int i = 0; i < struct.getArity(); i++) {
+ Term _term = struct.getTerm(i);
+ if (_term instanceof Structure) {
+ Structure term = (Structure) _term;
+ Structure alteredTerm = (Structure) processStructure(term, strategy);
+ struct.setTerm(i, alteredTerm); // modifies original struct
+ }
+ }
+ }
+ }
+
+ return struct;
+ }
+}
Added: trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/package.html
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/package.html (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/protocol/package.html 2008-04-18 18:53:37 UTC (rev 1228)
@@ -0,0 +1,5 @@
+<html>
+ <body>
+ Contains classes concerned with implementing JASDL's syntactic translation protocol. Currently used for SE-Message and SE-Percept translation.
+ </body>
+</html>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tom...@us...> - 2008-04-18 18:39:45
|
Revision: 1227
http://jason.svn.sourceforge.net/jason/?rev=1227&view=rev
Author: tomklapiscak
Date: 2008-04-18 11:39:28 -0700 (Fri, 18 Apr 2008)
Log Message:
-----------
Correcting commit errors...
Added Paths:
-----------
trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/
trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/IncomingProtocolProcessingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/OutgoingProtocolProcessingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/ProtocolProcessingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/ProtocolProcessor.java
trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/package.html
Added: trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/IncomingProtocolProcessingStrategy.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/IncomingProtocolProcessingStrategy.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/IncomingProtocolProcessingStrategy.java 2008-04-18 18:39:28 UTC (rev 1227)
@@ -0,0 +1,304 @@
+/*
+ * Copyright (C) 2008 Thomas Klapiscak (t.g...@du...)
+ *
+ * This file is part of JASDL.
+ *
+ * JASDL is free software: you can redistribute it and/or modify
+ * it under the terms of the Lesser GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * JASDL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Lesser GNU General Public License for more details.
+ *
+ * You should have received a copy of the Lesser GNU General Public License
+ * along with JASDL. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package jasdl.bridge.protocol;
+
+import static jasdl.util.Common.strip;
+import jasdl.JASDLParams;
+import jasdl.bridge.JASDLOntologyManager;
+import jasdl.bridge.mapping.aliasing.Alias;
+import jasdl.bridge.mapping.aliasing.MappingStrategy;
+import jasdl.bridge.seliteral.SELiteral;
+import jasdl.util.exception.JASDLException;
+import jasdl.util.exception.JASDLMessageContentException;
+import jasdl.util.exception.JASDLNotEnrichedException;
+import jasdl.util.exception.JASDLUnknownMappingException;
+import jason.asSyntax.Atom;
+import jason.asSyntax.ListTerm;
+import jason.asSyntax.ListTermImpl;
+import jason.asSyntax.Literal;
+import jason.asSyntax.StringTerm;
+import jason.asSyntax.Structure;
+import jason.asSyntax.Term;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+
+import org.semanticweb.owl.model.OWLEntity;
+import org.semanticweb.owl.model.OWLException;
+import org.semanticweb.owl.model.OWLOntology;
+
+public class IncomingProtocolProcessingStrategy implements ProtocolProcessingStrategy {
+
+ private List<MappingStrategy> mappingStrategies;
+
+ public IncomingProtocolProcessingStrategy(List<MappingStrategy> mappingStrategies) {
+ this.mappingStrategies = mappingStrategies;
+ }
+
+ public Literal process(Literal l, JASDLOntologyManager jasdlOntologyManager) throws JASDLException {
+ try {
+ jasdlOntologyManager.getLogger().fine("Processing incoming " + l);
+
+ SELiteral sl = new SELiteral(l, jasdlOntologyManager); // <- NOTE: might not actually be an SE-Literal!
+ processAllDifferent(sl, jasdlOntologyManager);
+ processNamed(sl, jasdlOntologyManager);
+ processAnon(sl, jasdlOntologyManager);
+ processIndividuals(sl, jasdlOntologyManager); // <- MUST be performed last (since we need o annotation to be added)
+
+ return sl.getLiteral();
+ } catch (JASDLNotEnrichedException e) {
+ // do nothing
+ }
+ return l;
+
+ }
+
+ private void processAllDifferent(SELiteral sl, JASDLOntologyManager jasdlOntologyManager) throws JASDLMessageContentException {
+ List<Term> allDifferentAnnots = sl.getLiteral().getAnnots(JASDLParams.ALL_DIFFERENT_ANNOTATION_FUNCTOR).getAsList();
+ if (allDifferentAnnots.size() > 1) {
+ throw new JASDLMessageContentException("Multiple " + JASDLParams.ALL_DIFFERENT_ANNOTATION_FUNCTOR + " annotations preset");
+ } else if (allDifferentAnnots.size() == 1) {
+ Term _allDifferentAnnot = allDifferentAnnots.get(0);
+ if (!_allDifferentAnnot.isStructure())
+ throw new JASDLMessageContentException(_allDifferentAnnot + " must be a structure");
+ Structure allDifferentAnnot = (Structure) _allDifferentAnnot;
+
+ // get ontology
+ Term ontologyTerm = allDifferentAnnot.getTerm(0);
+ if (!(ontologyTerm instanceof StringTerm))
+ throw new JASDLMessageContentException("second term of " + JASDLParams.NAMED_ANNOTATION_FUNCTOR + " must be a string");
+ String _uri = ontologyTerm.toString();
+
+ // try loading the ontology, if fails create it (we don't know whether this ontology is personal or not here!)
+ OWLOntology ontology;
+ try {
+ ontology = jasdlOntologyManager.loadOntology(_uri, mappingStrategies);
+ } catch (JASDLException e) {
+ try {
+ ontology = jasdlOntologyManager.createOntology(_uri, true);
+ } catch (JASDLException e1) {
+ throw new JASDLMessageContentException("Unable to create ontology", e);
+ }
+ }
+ // add "o" annotation with label (may be anonymous if ontology was novel or personal)
+ Structure o = new Structure(JASDLParams.ONTOLOGY_ANNOTATION_FUNCTOR);
+ try {
+ o.addTerm(jasdlOntologyManager.getLabelManager().getLeft(ontology));
+ } catch (JASDLUnknownMappingException e) {
+ throw new JASDLMessageContentException("Ontology creation failed", e);
+ }
+ sl.getLiteral().addAnnot(o);
+
+ sl.getLiteral().delAnnot(allDifferentAnnot);
+
+ }
+ }
+
+ private void processIndividuals(SELiteral sl, JASDLOntologyManager jasdlOntologyManager) throws JASDLMessageContentException {
+ List<Term> iAnnots = sl.getLiteral().getAnnots(JASDLParams.I_ANNOTATION_FUNCTOR).getAsList();
+ if (iAnnots.size() > 1) {
+ throw new JASDLMessageContentException("Multiple " + JASDLParams.I_ANNOTATION_FUNCTOR + " annotations present");
+ } else if (iAnnots.size() == 1) {
+ try {
+ Term _iAnnot = iAnnots.get(0);
+ if (!_iAnnot.isStructure())
+ throw new JASDLMessageContentException(_iAnnot + " must be a structure");
+ Structure iAnnot = (Structure) _iAnnot;
+
+ if (sl.getLiteral().getFunctor().equals(JASDLParams.OWL_ALL_DIFFERENT_FUNCTOR.toString())) { // for all_different assertions
+ ListTerm uris = (ListTerm) iAnnot.getTerm(0);
+ ListTerm originals = (ListTerm) sl.getLiteral().getTerm(0); // must be a list term
+ ListTerm translations = new ListTermImpl();
+ int i = 0;
+ for (Term uriTerm : uris) {
+ try {
+ translations.add(translateIndividualURIStringTerm(uriTerm, jasdlOntologyManager));
+ } catch (JASDLUnknownMappingException e) {
+ // individual is not known, leave it as it is
+ translations.add(originals.get(i));
+ }
+ i++;
+ }
+ sl.getLiteral().setTerm(0, translations);
+ } else { // for class and property assertions
+ for (int i = 0; i < sl.getLiteral().getArity(); i++) { // for each ground atomic term - handles classes and object properies. terms of i annotation are relative to literal terms
+ Term term = sl.getLiteral().getTerm(i);
+ if (term.isGround() && term.isAtom()) {
+ // get the URI relative to this term
+ if (iAnnot.getArity() - 1 < i)
+ throw new JASDLMessageContentException("Insufficient arity");
+ try {
+ sl.getLiteral().setTerm(i, translateIndividualURIStringTerm(iAnnot.getTerm(i), jasdlOntologyManager));
+ } catch (JASDLUnknownMappingException e) {
+ // individual is not known, leave it as it is
+ }
+ }
+ }
+ }
+ sl.getLiteral().delAnnot(iAnnot); // drop i, no longer needed
+ } catch (JASDLMessageContentException e) {
+ throw new JASDLMessageContentException("Unable to translate individuals for " + sl, e);
+ }
+ }
+ }
+
+ private Atom translateIndividualURIStringTerm(Term _uriTerm, JASDLOntologyManager jasdlOntologyManager) throws JASDLMessageContentException, JASDLUnknownMappingException {
+ if (!_uriTerm.isString())
+ throw new JASDLMessageContentException(_uriTerm + " does not have a single string term");
+ StringTerm uriTerm = (StringTerm) _uriTerm;
+ URI uri;
+ try {
+ uri = new URI(strip(uriTerm.toString(), "\"")); // Quotes stripped
+ } catch (URISyntaxException e) {
+ throw new JASDLMessageContentException("Invalid URI supplied", e);
+ }
+
+ // if this agent is aware of an individual known by this uri, translate atom to local mapping (otherwise UnknownMappingException will be thrown)
+ OWLEntity entity = jasdlOntologyManager.toEntity(uri);
+ if (!entity.isOWLIndividual())
+ throw new JASDLMessageContentException(uri + " is not an individual");
+ Alias alias = jasdlOntologyManager.getAliasManager().getLeft(entity);
+ // replace the atom functor with that of local alias
+ return alias.getFunctor();
+ }
+
+ /**
+ * Applies processing to incoming SE-Literals possessing the "named" annotation, i.e. they refer to a class defined in the ontology schema.
+ * @param sl
+ * @param agent
+ * @return
+ * @throws JASDLException
+ */
+ private void processNamed(SELiteral sl, JASDLOntologyManager jasdlOntologyManager) throws JASDLException {
+ ListTerm nameds = sl.getLiteral().getAnnots(JASDLParams.NAMED_ANNOTATION_FUNCTOR);
+ if (nameds.size() == 1) {
+
+ // get named annotation
+ Term _named = nameds.get(0);
+ if (!(_named instanceof Structure)) {
+ throw new JASDLException("Invalid " + JASDLParams.NAMED_ANNOTATION_FUNCTOR + " annotation: " + _named);
+ }
+ Structure named = (Structure) _named;
+ if (named.getArity() != 2) {
+ throw new JASDLException("Invalid " + JASDLParams.NAMED_ANNOTATION_FUNCTOR + " annotation arity: " + _named);
+ }
+
+ // get ontology
+ Term ontologyTerm = named.getTerm(1);
+ if (!(ontologyTerm instanceof StringTerm))
+ throw new JASDLMessageContentException("second term of " + JASDLParams.NAMED_ANNOTATION_FUNCTOR + " must be a string");
+ String _uri = named.getTerm(1).toString();
+ OWLOntology ontology = jasdlOntologyManager.loadOntology(_uri, mappingStrategies); // may instantiate a new ontology with anonymous label
+
+ // add "o" annotation with label (may be anonymous if ontology was novel)
+ Structure o = new Structure(JASDLParams.ONTOLOGY_ANNOTATION_FUNCTOR);
+ o.addTerm(jasdlOntologyManager.getLabelManager().getLeft(ontology));
+ sl.getLiteral().addAnnot(o);
+
+ // get entity URI
+ Term expressionTerm = named.getTerm(0);
+ if (!(expressionTerm instanceof StringTerm)) {
+ throw new JASDLException("Invalid " + JASDLParams.NAMED_ANNOTATION_FUNCTOR + " annotation term: " + expressionTerm);
+ }
+ String expression = strip(expressionTerm.toString(), "\""); // quotes stripped
+
+ URI uri;
+ try {
+ uri = new URI(expression);
+ } catch (URISyntaxException e) {
+ throw new JASDLException("Invalid entity URI in " + expression);
+ }
+ Alias local = jasdlOntologyManager.getAliasManager().getLeft(jasdlOntologyManager.toEntity(uri)); // will already be present by definition
+
+ // create new (SE) Literal
+ sl.mutateFunctor(local.getFunctor().toString());
+
+ sl.getLiteral().delAnnot(named); // drop named, no longer needed
+ }
+ }
+
+ private void processAnon(SELiteral sl, JASDLOntologyManager jasdlOntologyManager) throws JASDLException {
+ ListTerm anons = sl.getLiteral().getAnnots(JASDLParams.ANON_ANNOTATION_FUNCTOR);
+ if (anons.size() == 1) {
+ // Get Anon annotation
+ Term _anon = anons.get(0);
+ if (!(_anon instanceof Structure)) {
+ throw new JASDLException("Invalid " + JASDLParams.ANON_ANNOTATION_FUNCTOR + " annotation: " + _anon);
+ }
+ Structure anon = (Structure) _anon;
+ if (anon.getArity() != 3) {
+ throw new JASDLException("Invalid " + JASDLParams.ANON_ANNOTATION_FUNCTOR + " annotation arity: " + _anon);
+ }
+
+ // Get expression
+ Term expressionTerm = anon.getTerm(0);
+ if (!(expressionTerm instanceof StringTerm)) {
+ throw new JASDLException("Invalid " + JASDLParams.ANON_ANNOTATION_FUNCTOR + " annotation expression term: " + expressionTerm);
+ }
+ String expression = strip(expressionTerm.toString(), "\""); // quotes stripped
+
+ // Parse prequisite ontology URIs
+ Term prereqsTerm = anon.getTerm(1);
+ if (!(prereqsTerm instanceof ListTerm)) {
+ throw new JASDLException("Invalid " + JASDLParams.ANON_ANNOTATION_FUNCTOR + " annotation prereqs term: " + expressionTerm);
+ }
+ ListTerm prereqs = (ListTerm) prereqsTerm;
+ for (Term _prereqTerm : prereqs) {
+ if (!(_prereqTerm instanceof StringTerm)) {
+ throw new JASDLException("Invalid " + JASDLParams.ANON_ANNOTATION_FUNCTOR + " prereq: " + _prereqTerm);
+ }
+ StringTerm prereqTerm = (StringTerm) _prereqTerm;
+ String prereq = strip(prereqTerm.toString(), "\""); // quotes stripped
+ jasdlOntologyManager.loadOntology(prereq, mappingStrategies); // <- may instantiate a new ontology
+ }
+
+ // Get (possibly instantiate) a personal ontology for this agent
+ Term personalURITerm = anon.getTerm(2);
+ if (!personalURITerm.isString())
+ throw new JASDLMessageContentException("third term of " + JASDLParams.ANON_ANNOTATION_FUNCTOR + " must be a string");
+ OWLOntology ontology;
+ try {
+ ontology = jasdlOntologyManager.getOntology(personalURITerm.toString());
+ } catch (JASDLUnknownMappingException e) {
+ // we have not recieved an anonymous class definition from this agent before, instantiate a personal placeholder ontology for them
+ ontology = jasdlOntologyManager.createOntology(personalURITerm.toString(), true);
+ }
+ // add "o" annotation
+ Structure o = new Structure(JASDLParams.ONTOLOGY_ANNOTATION_FUNCTOR);
+ o.addTerm(jasdlOntologyManager.getLabelManager().getLeft(ontology));
+ sl.getLiteral().addAnnot(o);
+
+ // do we already know this expression?
+ Atom functor = new Atom(sl.getLiteral().getFunctor());
+ try {
+ jasdlOntologyManager.defineClass(functor, sl.getOntologyLabel(), expression, jasdlOntologyManager.getManchesterURIDescriptionParser()); // Instantiate defined expression
+ } catch (OWLException e) {
+ // do nothing
+ throw new JASDLException("Error defining new class " + functor, e);
+ }
+
+ // drop anon annotation, no longer needed
+ sl.getLiteral().delAnnot(anon);
+ }
+
+ }
+
+}
Added: trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/OutgoingProtocolProcessingStrategy.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/OutgoingProtocolProcessingStrategy.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/OutgoingProtocolProcessingStrategy.java 2008-04-18 18:39:28 UTC (rev 1227)
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2008 Thomas Klapiscak (t.g...@du...)
+ *
+ * This file is part of JASDL.
+ *
+ * JASDL is free software: you can redistribute it and/or modify
+ * it under the terms of the Lesser GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * JASDL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Lesser GNU General Public License for more details.
+ *
+ * You should have received a copy of the Lesser GNU General Public License
+ * along with JASDL. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package jasdl.bridge.protocol;
+
+import jasdl.JASDLParams;
+import jasdl.bridge.JASDLOntologyManager;
+import jasdl.bridge.factory.SELiteralFactory;
+import jasdl.bridge.seliteral.SELiteral;
+import jasdl.bridge.seliteral.SELiteralAllDifferentAssertion;
+import jasdl.util.exception.JASDLException;
+import jasdl.util.exception.JASDLNotEnrichedException;
+import jasdl.util.exception.JASDLUnknownMappingException;
+import jason.asSyntax.ListTerm;
+import jason.asSyntax.ListTermImpl;
+import jason.asSyntax.Literal;
+import jason.asSyntax.StringTerm;
+import jason.asSyntax.StringTermImpl;
+import jason.asSyntax.Structure;
+import jason.asSyntax.Term;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.semanticweb.owl.model.OWLDescription;
+import org.semanticweb.owl.model.OWLEntity;
+import org.semanticweb.owl.model.OWLIndividual;
+import org.semanticweb.owl.model.OWLOntology;
+
+public class OutgoingProtocolProcessingStrategy implements ProtocolProcessingStrategy {
+
+ private SELiteralFactory SELiteralFactory;
+
+ public OutgoingProtocolProcessingStrategy(SELiteralFactory SELiteralFactory) {
+ this.SELiteralFactory = SELiteralFactory;
+ }
+
+ /**
+ * Only applies processing if l is SE-Literal, otherwise l is returned as is
+ * Replaces ontology label with physical uri
+ * Adds expr annotation unambiguously describing what is meant by alias
+ * Adds origin annotation if literal refers to defined class
+ * @param l
+ * @throws JASDLException
+ */
+ public Literal process(Literal l, JASDLOntologyManager jom) throws JASDLException {
+ jom.getLogger().fine("Processing outgoing " + l);
+
+ Literal result = l;
+ try {
+ SELiteral sl = SELiteralFactory.construct(l);
+
+ OWLEntity entity = (OWLEntity) sl.toOWLObject();
+ String expression = normaliseExpression(jom.getManchesterURIOWLObjectRenderer().render(entity), jom);
+
+ StringTerm expressionTerm = new StringTermImpl(expression);
+
+ if (entity.isOWLClass() && jom.getDefinitionManager().isKnownLeft(entity.asOWLClass())) { // we have an anonymous run-time defined class
+
+ // construct anon annotation
+ Structure anon = new Structure(JASDLParams.ANON_ANNOTATION_FUNCTOR);
+
+ // add the class expression
+ anon.addTerm(expressionTerm);
+
+ // add set of prerequisite ontologies
+ Set<OWLOntology> prereqs = new HashSet<OWLOntology>();
+ String[] tokens = expression.toString().split("[ |\n]");
+ for (String token : tokens) {
+ try {
+ URI entityURI = new URI(token);
+ URI ontologyURI = new URI(entityURI.getScheme(), entityURI.getSchemeSpecificPart(), null);
+ prereqs.add(jom.getLogicalURIManager().getLeft(ontologyURI));
+ } catch (URISyntaxException e) {
+ // do nothing, probably a keyword
+ } catch (JASDLUnknownMappingException e) {
+ // do nothing, probably a keyword
+ }
+ }
+ ListTerm list = new ListTermImpl();
+ for (OWLOntology prereq : prereqs) {
+ list.add(new StringTermImpl(jom.getPhysicalURIManager().getRight(prereq).toString()));
+ }
+ anon.addTerm(list);
+
+ // add the (personal) ontology this is from
+ StringTerm personalURI = new StringTermImpl(jom.getPhysicalURIManager().getRight(sl.getOntology()).toString());
+ anon.addTerm(personalURI);
+
+ sl.getLiteral().addAnnot(anon);
+
+ jom.getLogger().fine("Sending anonymous "+sl);
+
+ } else {
+
+ // unambiguously refer to named entity
+ StringTerm ontologyURITerm = new StringTermImpl(jom.getPhysicalURIManager().getRight(sl.getOntology()).toString());
+ if ((sl instanceof SELiteralAllDifferentAssertion)) {// special case for all_different
+ Structure all_different = new Structure(JASDLParams.ALL_DIFFERENT_ANNOTATION_FUNCTOR);
+ all_different.addTerm(ontologyURITerm);
+ sl.getLiteral().addAnnot(all_different);
+ } else {
+ Structure named = new Structure(JASDLParams.NAMED_ANNOTATION_FUNCTOR);
+ named.addTerm(expressionTerm);
+ // add ontology this naming is from
+ named.addTerm(ontologyURITerm);
+ sl.getLiteral().addAnnot(named);
+ }
+
+ }
+
+ // unambiguously refer to any nested individuals ("i" annotation). terms of "i" are relative to terms of literal
+ Structure iAnnot = new Structure(JASDLParams.I_ANNOTATION_FUNCTOR);
+ if (sl instanceof SELiteralAllDifferentAssertion) { // for all_different assertions
+ ListTerm translations = new ListTermImpl();
+ SELiteralAllDifferentAssertion ad = sl.asAllDifferentAssertion();
+ //Set<OWLIndividual> is = ad.getOWLIndividuals(); <- can't use this! We need to impose an ordering
+ ListTerm originals = (ListTerm) ad.getLiteral().getTerm(0);
+ for (Term original : originals) {
+ OWLIndividual i = sl.getOWLIndividual(original);
+ URI uri = i.getURI();
+ translations.add(new StringTermImpl(uri.toString()));
+ }
+ iAnnot.addTerm(translations);
+ } else { // for class and property assertions
+ for (int i = 0; i < sl.getLiteral().getArity(); i++) { // for each ground atomic term of literal
+ Term term = sl.getLiteral().getTerm(i);
+ if (term.isGround() && term.isAtom()) {
+ URI uri = sl.getOWLIndividual(i).getURI();
+ iAnnot.addTerm(new StringTermImpl(uri.toString()));
+ } else {
+ iAnnot.addTerm(JASDLParams.NO_INDIVIDUAL_MAPPING); // <- added so subject / objects mappings can be easily distinguished by maintenance of relative positions for object properties
+ }
+ }
+ }
+ sl.getLiteral().addAnnot(iAnnot);
+
+ sl.getLiteral().delAnnot(sl.getOntologyAnnotation()); // drop "o" before sending
+
+ result = sl.getLiteral();
+ } catch (JASDLNotEnrichedException e) {
+ // do nothing
+ //e.printStackTrace();
+ }
+ return result;
+ }
+
+ /**
+ * Returns an expression in which all references to run-time defined classes have been (recursuvely) replaced
+ * with the rendering of their anonymous descriptions, thus ensuring this rendering only refers to predefined classes.
+ * @param expression expression to normalise
+ * @param agent
+ * @return normalised form of expression
+ * @throws JASDLException
+ */
+ private String normaliseExpression(String expression, JASDLOntologyManager jasdlOntologyManager) throws JASDLException {
+ String[] tokens = expression.toString().split("[ |\n]");
+ String newExpression = "";
+ for (String token : tokens) {
+ try {
+ URI entityURI = new URI(token);
+ OWLEntity entity = jasdlOntologyManager.toEntity(entityURI);
+ if (entity.isOWLClass()) {
+ try {
+ OWLDescription desc = jasdlOntologyManager.getDefinitionManager().getRight(entity.asOWLClass());
+ String rendering = jasdlOntologyManager.getManchesterURIOWLObjectRenderer().render(desc);
+ newExpression += "(" + normaliseExpression(rendering, jasdlOntologyManager) + ")";
+ } catch (JASDLUnknownMappingException e1) {
+ // this is a predefined class
+ newExpression += token;
+ }
+ } else {
+ // this is a predefined non-class entity (property, individual, etc)
+ newExpression += token;
+ }
+ } catch (URISyntaxException e) {
+ // this is (probably) a keyword
+ newExpression += " " + token + " ";
+ } catch (JASDLUnknownMappingException e2) {
+ // this is (probably) a keyword
+ newExpression += " " + token + " ";
+ }
+
+ }
+ return newExpression;
+ }
+
+}
Added: trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/ProtocolProcessingStrategy.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/ProtocolProcessingStrategy.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/ProtocolProcessingStrategy.java 2008-04-18 18:39:28 UTC (rev 1227)
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2008 Thomas Klapiscak (t.g...@du...)
+ *
+ * This file is part of JASDL.
+ *
+ * JASDL is free software: you can redistribute it and/or modify
+ * it under the terms of the Lesser GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * JASDL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Lesser GNU General Public License for more details.
+ *
+ * You should have received a copy of the Lesser GNU General Public License
+ * along with JASDL. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package jasdl.bridge.protocol;
+
+import jasdl.bridge.JASDLOntologyManager;
+import jasdl.util.exception.JASDLException;
+import jason.asSyntax.Literal;
+
+public interface ProtocolProcessingStrategy {
+ public Literal process(Literal propcont, JASDLOntologyManager jasdlOntologyManager) throws JASDLException;
+}
Added: trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/ProtocolProcessor.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/ProtocolProcessor.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/ProtocolProcessor.java 2008-04-18 18:39:28 UTC (rev 1227)
@@ -0,0 +1,92 @@
+package jasdl.bridge.protocol;
+
+import jasdl.bridge.JASDLOntologyManager;
+import jasdl.bridge.factory.SELiteralFactory;
+import jasdl.bridge.mapping.aliasing.MappingStrategy;
+import jasdl.util.exception.JASDLException;
+import jasdl.util.exception.JASDLMessageContentException;
+import jason.asSyntax.ListTerm;
+import jason.asSyntax.ListTermImpl;
+import jason.asSyntax.Literal;
+import jason.asSyntax.Structure;
+import jason.asSyntax.Term;
+import jason.asSyntax.VarTerm;
+
+import java.util.List;
+
+public class ProtocolProcessor {
+ private JASDLOntologyManager jom;
+
+ private ProtocolProcessingStrategy incomingStrategy;
+
+ private ProtocolProcessingStrategy outgoingStrategy;
+
+ /**
+ * Sets up using default processing strategies
+ *
+ */
+ public ProtocolProcessor(JASDLOntologyManager jom, List<MappingStrategy> mappingStrategies, SELiteralFactory seLiteralFactory) {
+ this.jom = jom;
+ this.incomingStrategy = new IncomingProtocolProcessingStrategy(mappingStrategies);
+ this.outgoingStrategy = new OutgoingProtocolProcessingStrategy(seLiteralFactory);
+ }
+
+ public ProtocolProcessor(JASDLOntologyManager jom, ProtocolProcessingStrategy incomingStrategy, ProtocolProcessingStrategy outgoingStrategy) {
+ super();
+ this.jom = jom;
+ this.incomingStrategy = incomingStrategy;
+ this.outgoingStrategy = outgoingStrategy;
+ }
+
+ public Structure processIncomingStructure(Structure struct) throws JASDLMessageContentException {
+ return processStructure(struct, incomingStrategy);
+ }
+
+ public Structure processOutgoingStructure(Structure struct) throws JASDLMessageContentException {
+ return processStructure(struct, outgoingStrategy);
+ }
+
+ private Structure processStructure(Structure struct, ProtocolProcessingStrategy strategy) throws JASDLMessageContentException {
+
+ // recurse down terms and lists (for "bundled" SE-enriched content)
+ if (struct.getArity() > 0) { // if we have any terms to process!
+ // Process outer SE-enriched content
+ if (struct.isLiteral()) { // processing strategies only apply to Literals
+ Literal l = (Literal) struct;
+ try {
+ struct = strategy.process(l, jom);
+ } catch (JASDLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ //int i=0;
+ //for(Term _term : struct.getTerms()){ - mustn't use in case struct is a list
+ if (struct.isVar()) {
+ struct = (Structure) ((VarTerm) struct).getValue(); // resolve struct if var
+ }
+ if (struct.isList()) { // special processing for lists (since we can't (or rather shouldn't)) use getTerm or setTerm)
+ ListTermImpl newList = new ListTermImpl(); // a "clone"
+ for (Term e : ((ListTerm) struct).getAsList()) {
+ jom.getLogger().finest("Processing " + e);
+ if (e instanceof Structure) {
+ Structure alteredTerm = (Structure) processStructure((Structure) e, strategy);
+ newList.append(alteredTerm);
+ }
+ }
+ return newList;
+ } else { // all other structures
+ for (int i = 0; i < struct.getArity(); i++) {
+ Term _term = struct.getTerm(i);
+ if (_term instanceof Structure) {
+ Structure term = (Structure) _term;
+ Structure alteredTerm = (Structure) processStructure(term, strategy);
+ struct.setTerm(i, alteredTerm); // modifies original struct
+ }
+ }
+ }
+ }
+
+ return struct;
+ }
+}
Added: trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/package.html
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/package.html (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/package.html 2008-04-18 18:39:28 UTC (rev 1227)
@@ -0,0 +1,5 @@
+<html>
+ <body>
+ Contains classes concerned with implementing JASDL's syntactic translation protocol. Currently used for SE-Message and SE-Percept translation.
+ </body>
+</html>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tom...@us...> - 2008-04-18 18:36:23
|
Revision: 1226
http://jason.svn.sourceforge.net/jason/?rev=1226&view=rev
Author: tomklapiscak
Date: 2008-04-18 11:36:16 -0700 (Fri, 18 Apr 2008)
Log Message:
-----------
Correcting commit errors...
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tom...@us...> - 2008-04-18 18:32:29
|
Revision: 1225
http://jason.svn.sourceforge.net/jason/?rev=1225&view=rev
Author: tomklapiscak
Date: 2008-04-18 11:32:05 -0700 (Fri, 18 Apr 2008)
Log Message:
-----------
Correcting commit errors...
Removed Paths:
-------------
trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tom...@us...> - 2008-04-18 18:28:16
|
Revision: 1224
http://jason.svn.sourceforge.net/jason/?rev=1224&view=rev
Author: tomklapiscak
Date: 2008-04-18 11:28:03 -0700 (Fri, 18 Apr 2008)
Log Message:
-----------
Added protocol package (missed in last commit)
Added Paths:
-----------
trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/
trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/IncomingProtocolProcessingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/OutgoingProtocolProcessingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/ProtocolProcessingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/ProtocolProcessor.java
trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/package.html
Added: trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/IncomingProtocolProcessingStrategy.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/IncomingProtocolProcessingStrategy.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/IncomingProtocolProcessingStrategy.java 2008-04-18 18:28:03 UTC (rev 1224)
@@ -0,0 +1,304 @@
+/*
+ * Copyright (C) 2008 Thomas Klapiscak (t.g...@du...)
+ *
+ * This file is part of JASDL.
+ *
+ * JASDL is free software: you can redistribute it and/or modify
+ * it under the terms of the Lesser GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * JASDL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Lesser GNU General Public License for more details.
+ *
+ * You should have received a copy of the Lesser GNU General Public License
+ * along with JASDL. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package jasdl.bridge.protocol;
+
+import static jasdl.util.Common.strip;
+import jasdl.JASDLParams;
+import jasdl.bridge.JASDLOntologyManager;
+import jasdl.bridge.mapping.aliasing.Alias;
+import jasdl.bridge.mapping.aliasing.MappingStrategy;
+import jasdl.bridge.seliteral.SELiteral;
+import jasdl.util.exception.JASDLException;
+import jasdl.util.exception.JASDLMessageContentException;
+import jasdl.util.exception.JASDLNotEnrichedException;
+import jasdl.util.exception.JASDLUnknownMappingException;
+import jason.asSyntax.Atom;
+import jason.asSyntax.ListTerm;
+import jason.asSyntax.ListTermImpl;
+import jason.asSyntax.Literal;
+import jason.asSyntax.StringTerm;
+import jason.asSyntax.Structure;
+import jason.asSyntax.Term;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+
+import org.semanticweb.owl.model.OWLEntity;
+import org.semanticweb.owl.model.OWLException;
+import org.semanticweb.owl.model.OWLOntology;
+
+public class IncomingProtocolProcessingStrategy implements ProtocolProcessingStrategy {
+
+ private List<MappingStrategy> mappingStrategies;
+
+ public IncomingProtocolProcessingStrategy(List<MappingStrategy> mappingStrategies) {
+ this.mappingStrategies = mappingStrategies;
+ }
+
+ public Literal process(Literal l, JASDLOntologyManager jasdlOntologyManager) throws JASDLException {
+ try {
+ jasdlOntologyManager.getLogger().fine("Processing incoming " + l);
+
+ SELiteral sl = new SELiteral(l, jasdlOntologyManager); // <- NOTE: might not actually be an SE-Literal!
+ processAllDifferent(sl, jasdlOntologyManager);
+ processNamed(sl, jasdlOntologyManager);
+ processAnon(sl, jasdlOntologyManager);
+ processIndividuals(sl, jasdlOntologyManager); // <- MUST be performed last (since we need o annotation to be added)
+
+ return sl.getLiteral();
+ } catch (JASDLNotEnrichedException e) {
+ // do nothing
+ }
+ return l;
+
+ }
+
+ private void processAllDifferent(SELiteral sl, JASDLOntologyManager jasdlOntologyManager) throws JASDLMessageContentException {
+ List<Term> allDifferentAnnots = sl.getLiteral().getAnnots(JASDLParams.ALL_DIFFERENT_ANNOTATION_FUNCTOR).getAsList();
+ if (allDifferentAnnots.size() > 1) {
+ throw new JASDLMessageContentException("Multiple " + JASDLParams.ALL_DIFFERENT_ANNOTATION_FUNCTOR + " annotations preset");
+ } else if (allDifferentAnnots.size() == 1) {
+ Term _allDifferentAnnot = allDifferentAnnots.get(0);
+ if (!_allDifferentAnnot.isStructure())
+ throw new JASDLMessageContentException(_allDifferentAnnot + " must be a structure");
+ Structure allDifferentAnnot = (Structure) _allDifferentAnnot;
+
+ // get ontology
+ Term ontologyTerm = allDifferentAnnot.getTerm(0);
+ if (!(ontologyTerm instanceof StringTerm))
+ throw new JASDLMessageContentException("second term of " + JASDLParams.NAMED_ANNOTATION_FUNCTOR + " must be a string");
+ String _uri = ontologyTerm.toString();
+
+ // try loading the ontology, if fails create it (we don't know whether this ontology is personal or not here!)
+ OWLOntology ontology;
+ try {
+ ontology = jasdlOntologyManager.loadOntology(_uri, mappingStrategies);
+ } catch (JASDLException e) {
+ try {
+ ontology = jasdlOntologyManager.createOntology(_uri, true);
+ } catch (JASDLException e1) {
+ throw new JASDLMessageContentException("Unable to create ontology", e);
+ }
+ }
+ // add "o" annotation with label (may be anonymous if ontology was novel or personal)
+ Structure o = new Structure(JASDLParams.ONTOLOGY_ANNOTATION_FUNCTOR);
+ try {
+ o.addTerm(jasdlOntologyManager.getLabelManager().getLeft(ontology));
+ } catch (JASDLUnknownMappingException e) {
+ throw new JASDLMessageContentException("Ontology creation failed", e);
+ }
+ sl.getLiteral().addAnnot(o);
+
+ sl.getLiteral().delAnnot(allDifferentAnnot);
+
+ }
+ }
+
+ private void processIndividuals(SELiteral sl, JASDLOntologyManager jasdlOntologyManager) throws JASDLMessageContentException {
+ List<Term> iAnnots = sl.getLiteral().getAnnots(JASDLParams.I_ANNOTATION_FUNCTOR).getAsList();
+ if (iAnnots.size() > 1) {
+ throw new JASDLMessageContentException("Multiple " + JASDLParams.I_ANNOTATION_FUNCTOR + " annotations present");
+ } else if (iAnnots.size() == 1) {
+ try {
+ Term _iAnnot = iAnnots.get(0);
+ if (!_iAnnot.isStructure())
+ throw new JASDLMessageContentException(_iAnnot + " must be a structure");
+ Structure iAnnot = (Structure) _iAnnot;
+
+ if (sl.getLiteral().getFunctor().equals(JASDLParams.OWL_ALL_DIFFERENT_FUNCTOR.toString())) { // for all_different assertions
+ ListTerm uris = (ListTerm) iAnnot.getTerm(0);
+ ListTerm originals = (ListTerm) sl.getLiteral().getTerm(0); // must be a list term
+ ListTerm translations = new ListTermImpl();
+ int i = 0;
+ for (Term uriTerm : uris) {
+ try {
+ translations.add(translateIndividualURIStringTerm(uriTerm, jasdlOntologyManager));
+ } catch (JASDLUnknownMappingException e) {
+ // individual is not known, leave it as it is
+ translations.add(originals.get(i));
+ }
+ i++;
+ }
+ sl.getLiteral().setTerm(0, translations);
+ } else { // for class and property assertions
+ for (int i = 0; i < sl.getLiteral().getArity(); i++) { // for each ground atomic term - handles classes and object properies. terms of i annotation are relative to literal terms
+ Term term = sl.getLiteral().getTerm(i);
+ if (term.isGround() && term.isAtom()) {
+ // get the URI relative to this term
+ if (iAnnot.getArity() - 1 < i)
+ throw new JASDLMessageContentException("Insufficient arity");
+ try {
+ sl.getLiteral().setTerm(i, translateIndividualURIStringTerm(iAnnot.getTerm(i), jasdlOntologyManager));
+ } catch (JASDLUnknownMappingException e) {
+ // individual is not known, leave it as it is
+ }
+ }
+ }
+ }
+ sl.getLiteral().delAnnot(iAnnot); // drop i, no longer needed
+ } catch (JASDLMessageContentException e) {
+ throw new JASDLMessageContentException("Unable to translate individuals for " + sl, e);
+ }
+ }
+ }
+
+ private Atom translateIndividualURIStringTerm(Term _uriTerm, JASDLOntologyManager jasdlOntologyManager) throws JASDLMessageContentException, JASDLUnknownMappingException {
+ if (!_uriTerm.isString())
+ throw new JASDLMessageContentException(_uriTerm + " does not have a single string term");
+ StringTerm uriTerm = (StringTerm) _uriTerm;
+ URI uri;
+ try {
+ uri = new URI(strip(uriTerm.toString(), "\"")); // Quotes stripped
+ } catch (URISyntaxException e) {
+ throw new JASDLMessageContentException("Invalid URI supplied", e);
+ }
+
+ // if this agent is aware of an individual known by this uri, translate atom to local mapping (otherwise UnknownMappingException will be thrown)
+ OWLEntity entity = jasdlOntologyManager.toEntity(uri);
+ if (!entity.isOWLIndividual())
+ throw new JASDLMessageContentException(uri + " is not an individual");
+ Alias alias = jasdlOntologyManager.getAliasManager().getLeft(entity);
+ // replace the atom functor with that of local alias
+ return alias.getFunctor();
+ }
+
+ /**
+ * Applies processing to incoming SE-Literals possessing the "named" annotation, i.e. they refer to a class defined in the ontology schema.
+ * @param sl
+ * @param agent
+ * @return
+ * @throws JASDLException
+ */
+ private void processNamed(SELiteral sl, JASDLOntologyManager jasdlOntologyManager) throws JASDLException {
+ ListTerm nameds = sl.getLiteral().getAnnots(JASDLParams.NAMED_ANNOTATION_FUNCTOR);
+ if (nameds.size() == 1) {
+
+ // get named annotation
+ Term _named = nameds.get(0);
+ if (!(_named instanceof Structure)) {
+ throw new JASDLException("Invalid " + JASDLParams.NAMED_ANNOTATION_FUNCTOR + " annotation: " + _named);
+ }
+ Structure named = (Structure) _named;
+ if (named.getArity() != 2) {
+ throw new JASDLException("Invalid " + JASDLParams.NAMED_ANNOTATION_FUNCTOR + " annotation arity: " + _named);
+ }
+
+ // get ontology
+ Term ontologyTerm = named.getTerm(1);
+ if (!(ontologyTerm instanceof StringTerm))
+ throw new JASDLMessageContentException("second term of " + JASDLParams.NAMED_ANNOTATION_FUNCTOR + " must be a string");
+ String _uri = named.getTerm(1).toString();
+ OWLOntology ontology = jasdlOntologyManager.loadOntology(_uri, mappingStrategies); // may instantiate a new ontology with anonymous label
+
+ // add "o" annotation with label (may be anonymous if ontology was novel)
+ Structure o = new Structure(JASDLParams.ONTOLOGY_ANNOTATION_FUNCTOR);
+ o.addTerm(jasdlOntologyManager.getLabelManager().getLeft(ontology));
+ sl.getLiteral().addAnnot(o);
+
+ // get entity URI
+ Term expressionTerm = named.getTerm(0);
+ if (!(expressionTerm instanceof StringTerm)) {
+ throw new JASDLException("Invalid " + JASDLParams.NAMED_ANNOTATION_FUNCTOR + " annotation term: " + expressionTerm);
+ }
+ String expression = strip(expressionTerm.toString(), "\""); // quotes stripped
+
+ URI uri;
+ try {
+ uri = new URI(expression);
+ } catch (URISyntaxException e) {
+ throw new JASDLException("Invalid entity URI in " + expression);
+ }
+ Alias local = jasdlOntologyManager.getAliasManager().getLeft(jasdlOntologyManager.toEntity(uri)); // will already be present by definition
+
+ // create new (SE) Literal
+ sl.mutateFunctor(local.getFunctor().toString());
+
+ sl.getLiteral().delAnnot(named); // drop named, no longer needed
+ }
+ }
+
+ private void processAnon(SELiteral sl, JASDLOntologyManager jasdlOntologyManager) throws JASDLException {
+ ListTerm anons = sl.getLiteral().getAnnots(JASDLParams.ANON_ANNOTATION_FUNCTOR);
+ if (anons.size() == 1) {
+ // Get Anon annotation
+ Term _anon = anons.get(0);
+ if (!(_anon instanceof Structure)) {
+ throw new JASDLException("Invalid " + JASDLParams.ANON_ANNOTATION_FUNCTOR + " annotation: " + _anon);
+ }
+ Structure anon = (Structure) _anon;
+ if (anon.getArity() != 3) {
+ throw new JASDLException("Invalid " + JASDLParams.ANON_ANNOTATION_FUNCTOR + " annotation arity: " + _anon);
+ }
+
+ // Get expression
+ Term expressionTerm = anon.getTerm(0);
+ if (!(expressionTerm instanceof StringTerm)) {
+ throw new JASDLException("Invalid " + JASDLParams.ANON_ANNOTATION_FUNCTOR + " annotation expression term: " + expressionTerm);
+ }
+ String expression = strip(expressionTerm.toString(), "\""); // quotes stripped
+
+ // Parse prequisite ontology URIs
+ Term prereqsTerm = anon.getTerm(1);
+ if (!(prereqsTerm instanceof ListTerm)) {
+ throw new JASDLException("Invalid " + JASDLParams.ANON_ANNOTATION_FUNCTOR + " annotation prereqs term: " + expressionTerm);
+ }
+ ListTerm prereqs = (ListTerm) prereqsTerm;
+ for (Term _prereqTerm : prereqs) {
+ if (!(_prereqTerm instanceof StringTerm)) {
+ throw new JASDLException("Invalid " + JASDLParams.ANON_ANNOTATION_FUNCTOR + " prereq: " + _prereqTerm);
+ }
+ StringTerm prereqTerm = (StringTerm) _prereqTerm;
+ String prereq = strip(prereqTerm.toString(), "\""); // quotes stripped
+ jasdlOntologyManager.loadOntology(prereq, mappingStrategies); // <- may instantiate a new ontology
+ }
+
+ // Get (possibly instantiate) a personal ontology for this agent
+ Term personalURITerm = anon.getTerm(2);
+ if (!personalURITerm.isString())
+ throw new JASDLMessageContentException("third term of " + JASDLParams.ANON_ANNOTATION_FUNCTOR + " must be a string");
+ OWLOntology ontology;
+ try {
+ ontology = jasdlOntologyManager.getOntology(personalURITerm.toString());
+ } catch (JASDLUnknownMappingException e) {
+ // we have not recieved an anonymous class definition from this agent before, instantiate a personal placeholder ontology for them
+ ontology = jasdlOntologyManager.createOntology(personalURITerm.toString(), true);
+ }
+ // add "o" annotation
+ Structure o = new Structure(JASDLParams.ONTOLOGY_ANNOTATION_FUNCTOR);
+ o.addTerm(jasdlOntologyManager.getLabelManager().getLeft(ontology));
+ sl.getLiteral().addAnnot(o);
+
+ // do we already know this expression?
+ Atom functor = new Atom(sl.getLiteral().getFunctor());
+ try {
+ jasdlOntologyManager.defineClass(functor, sl.getOntologyLabel(), expression, jasdlOntologyManager.getManchesterURIDescriptionParser()); // Instantiate defined expression
+ } catch (OWLException e) {
+ // do nothing
+ throw new JASDLException("Error defining new class " + functor, e);
+ }
+
+ // drop anon annotation, no longer needed
+ sl.getLiteral().delAnnot(anon);
+ }
+
+ }
+
+}
Added: trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/OutgoingProtocolProcessingStrategy.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/OutgoingProtocolProcessingStrategy.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/OutgoingProtocolProcessingStrategy.java 2008-04-18 18:28:03 UTC (rev 1224)
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2008 Thomas Klapiscak (t.g...@du...)
+ *
+ * This file is part of JASDL.
+ *
+ * JASDL is free software: you can redistribute it and/or modify
+ * it under the terms of the Lesser GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * JASDL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Lesser GNU General Public License for more details.
+ *
+ * You should have received a copy of the Lesser GNU General Public License
+ * along with JASDL. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package jasdl.bridge.protocol;
+
+import jasdl.JASDLParams;
+import jasdl.bridge.JASDLOntologyManager;
+import jasdl.bridge.factory.SELiteralFactory;
+import jasdl.bridge.seliteral.SELiteral;
+import jasdl.bridge.seliteral.SELiteralAllDifferentAssertion;
+import jasdl.util.exception.JASDLException;
+import jasdl.util.exception.JASDLNotEnrichedException;
+import jasdl.util.exception.JASDLUnknownMappingException;
+import jason.asSyntax.ListTerm;
+import jason.asSyntax.ListTermImpl;
+import jason.asSyntax.Literal;
+import jason.asSyntax.StringTerm;
+import jason.asSyntax.StringTermImpl;
+import jason.asSyntax.Structure;
+import jason.asSyntax.Term;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.semanticweb.owl.model.OWLDescription;
+import org.semanticweb.owl.model.OWLEntity;
+import org.semanticweb.owl.model.OWLIndividual;
+import org.semanticweb.owl.model.OWLOntology;
+
+public class OutgoingProtocolProcessingStrategy implements ProtocolProcessingStrategy {
+
+ private SELiteralFactory SELiteralFactory;
+
+ public OutgoingProtocolProcessingStrategy(SELiteralFactory SELiteralFactory) {
+ this.SELiteralFactory = SELiteralFactory;
+ }
+
+ /**
+ * Only applies processing if l is SE-Literal, otherwise l is returned as is
+ * Replaces ontology label with physical uri
+ * Adds expr annotation unambiguously describing what is meant by alias
+ * Adds origin annotation if literal refers to defined class
+ * @param l
+ * @throws JASDLException
+ */
+ public Literal process(Literal l, JASDLOntologyManager jom) throws JASDLException {
+ jom.getLogger().fine("Processing outgoing " + l);
+
+ Literal result = l;
+ try {
+ SELiteral sl = SELiteralFactory.construct(l);
+
+ OWLEntity entity = (OWLEntity) sl.toOWLObject();
+ String expression = normaliseExpression(jom.getManchesterURIOWLObjectRenderer().render(entity), jom);
+
+ StringTerm expressionTerm = new StringTermImpl(expression);
+
+ if (entity.isOWLClass() && jom.getDefinitionManager().isKnownLeft(entity.asOWLClass())) { // we have an anonymous run-time defined class
+
+ // construct anon annotation
+ Structure anon = new Structure(JASDLParams.ANON_ANNOTATION_FUNCTOR);
+
+ // add the class expression
+ anon.addTerm(expressionTerm);
+
+ // add set of prerequisite ontologies
+ Set<OWLOntology> prereqs = new HashSet<OWLOntology>();
+ String[] tokens = expression.toString().split("[ |\n]");
+ for (String token : tokens) {
+ try {
+ URI entityURI = new URI(token);
+ URI ontologyURI = new URI(entityURI.getScheme(), entityURI.getSchemeSpecificPart(), null);
+ prereqs.add(jom.getLogicalURIManager().getLeft(ontologyURI));
+ } catch (URISyntaxException e) {
+ // do nothing, probably a keyword
+ } catch (JASDLUnknownMappingException e) {
+ // do nothing, probably a keyword
+ }
+ }
+ ListTerm list = new ListTermImpl();
+ for (OWLOntology prereq : prereqs) {
+ list.add(new StringTermImpl(jom.getPhysicalURIManager().getRight(prereq).toString()));
+ }
+ anon.addTerm(list);
+
+ // add the (personal) ontology this is from
+ StringTerm personalURI = new StringTermImpl(jom.getPhysicalURIManager().getRight(sl.getOntology()).toString());
+ anon.addTerm(personalURI);
+
+ sl.getLiteral().addAnnot(anon);
+
+ jom.getLogger().fine("Sending anonymous "+sl);
+
+ } else {
+
+ // unambiguously refer to named entity
+ StringTerm ontologyURITerm = new StringTermImpl(jom.getPhysicalURIManager().getRight(sl.getOntology()).toString());
+ if ((sl instanceof SELiteralAllDifferentAssertion)) {// special case for all_different
+ Structure all_different = new Structure(JASDLParams.ALL_DIFFERENT_ANNOTATION_FUNCTOR);
+ all_different.addTerm(ontologyURITerm);
+ sl.getLiteral().addAnnot(all_different);
+ } else {
+ Structure named = new Structure(JASDLParams.NAMED_ANNOTATION_FUNCTOR);
+ named.addTerm(expressionTerm);
+ // add ontology this naming is from
+ named.addTerm(ontologyURITerm);
+ sl.getLiteral().addAnnot(named);
+ }
+
+ }
+
+ // unambiguously refer to any nested individuals ("i" annotation). terms of "i" are relative to terms of literal
+ Structure iAnnot = new Structure(JASDLParams.I_ANNOTATION_FUNCTOR);
+ if (sl instanceof SELiteralAllDifferentAssertion) { // for all_different assertions
+ ListTerm translations = new ListTermImpl();
+ SELiteralAllDifferentAssertion ad = sl.asAllDifferentAssertion();
+ //Set<OWLIndividual> is = ad.getOWLIndividuals(); <- can't use this! We need to impose an ordering
+ ListTerm originals = (ListTerm) ad.getLiteral().getTerm(0);
+ for (Term original : originals) {
+ OWLIndividual i = sl.getOWLIndividual(original);
+ URI uri = i.getURI();
+ translations.add(new StringTermImpl(uri.toString()));
+ }
+ iAnnot.addTerm(translations);
+ } else { // for class and property assertions
+ for (int i = 0; i < sl.getLiteral().getArity(); i++) { // for each ground atomic term of literal
+ Term term = sl.getLiteral().getTerm(i);
+ if (term.isGround() && term.isAtom()) {
+ URI uri = sl.getOWLIndividual(i).getURI();
+ iAnnot.addTerm(new StringTermImpl(uri.toString()));
+ } else {
+ iAnnot.addTerm(JASDLParams.NO_INDIVIDUAL_MAPPING); // <- added so subject / objects mappings can be easily distinguished by maintenance of relative positions for object properties
+ }
+ }
+ }
+ sl.getLiteral().addAnnot(iAnnot);
+
+ sl.getLiteral().delAnnot(sl.getOntologyAnnotation()); // drop "o" before sending
+
+ result = sl.getLiteral();
+ } catch (JASDLNotEnrichedException e) {
+ // do nothing
+ //e.printStackTrace();
+ }
+ return result;
+ }
+
+ /**
+ * Returns an expression in which all references to run-time defined classes have been (recursuvely) replaced
+ * with the rendering of their anonymous descriptions, thus ensuring this rendering only refers to predefined classes.
+ * @param expression expression to normalise
+ * @param agent
+ * @return normalised form of expression
+ * @throws JASDLException
+ */
+ private String normaliseExpression(String expression, JASDLOntologyManager jasdlOntologyManager) throws JASDLException {
+ String[] tokens = expression.toString().split("[ |\n]");
+ String newExpression = "";
+ for (String token : tokens) {
+ try {
+ URI entityURI = new URI(token);
+ OWLEntity entity = jasdlOntologyManager.toEntity(entityURI);
+ if (entity.isOWLClass()) {
+ try {
+ OWLDescription desc = jasdlOntologyManager.getDefinitionManager().getRight(entity.asOWLClass());
+ String rendering = jasdlOntologyManager.getManchesterURIOWLObjectRenderer().render(desc);
+ newExpression += "(" + normaliseExpression(rendering, jasdlOntologyManager) + ")";
+ } catch (JASDLUnknownMappingException e1) {
+ // this is a predefined class
+ newExpression += token;
+ }
+ } else {
+ // this is a predefined non-class entity (property, individual, etc)
+ newExpression += token;
+ }
+ } catch (URISyntaxException e) {
+ // this is (probably) a keyword
+ newExpression += " " + token + " ";
+ } catch (JASDLUnknownMappingException e2) {
+ // this is (probably) a keyword
+ newExpression += " " + token + " ";
+ }
+
+ }
+ return newExpression;
+ }
+
+}
Added: trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/ProtocolProcessingStrategy.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/ProtocolProcessingStrategy.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/ProtocolProcessingStrategy.java 2008-04-18 18:28:03 UTC (rev 1224)
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2008 Thomas Klapiscak (t.g...@du...)
+ *
+ * This file is part of JASDL.
+ *
+ * JASDL is free software: you can redistribute it and/or modify
+ * it under the terms of the Lesser GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * JASDL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Lesser GNU General Public License for more details.
+ *
+ * You should have received a copy of the Lesser GNU General Public License
+ * along with JASDL. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package jasdl.bridge.protocol;
+
+import jasdl.bridge.JASDLOntologyManager;
+import jasdl.util.exception.JASDLException;
+import jason.asSyntax.Literal;
+
+public interface ProtocolProcessingStrategy {
+ public Literal process(Literal propcont, JASDLOntologyManager jasdlOntologyManager) throws JASDLException;
+}
Added: trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/ProtocolProcessor.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/ProtocolProcessor.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/ProtocolProcessor.java 2008-04-18 18:28:03 UTC (rev 1224)
@@ -0,0 +1,92 @@
+package jasdl.bridge.protocol;
+
+import jasdl.bridge.JASDLOntologyManager;
+import jasdl.bridge.factory.SELiteralFactory;
+import jasdl.bridge.mapping.aliasing.MappingStrategy;
+import jasdl.util.exception.JASDLException;
+import jasdl.util.exception.JASDLMessageContentException;
+import jason.asSyntax.ListTerm;
+import jason.asSyntax.ListTermImpl;
+import jason.asSyntax.Literal;
+import jason.asSyntax.Structure;
+import jason.asSyntax.Term;
+import jason.asSyntax.VarTerm;
+
+import java.util.List;
+
+public class ProtocolProcessor {
+ private JASDLOntologyManager jom;
+
+ private ProtocolProcessingStrategy incomingStrategy;
+
+ private ProtocolProcessingStrategy outgoingStrategy;
+
+ /**
+ * Sets up using default processing strategies
+ *
+ */
+ public ProtocolProcessor(JASDLOntologyManager jom, List<MappingStrategy> mappingStrategies, SELiteralFactory seLiteralFactory) {
+ this.jom = jom;
+ this.incomingStrategy = new IncomingProtocolProcessingStrategy(mappingStrategies);
+ this.outgoingStrategy = new OutgoingProtocolProcessingStrategy(seLiteralFactory);
+ }
+
+ public ProtocolProcessor(JASDLOntologyManager jom, ProtocolProcessingStrategy incomingStrategy, ProtocolProcessingStrategy outgoingStrategy) {
+ super();
+ this.jom = jom;
+ this.incomingStrategy = incomingStrategy;
+ this.outgoingStrategy = outgoingStrategy;
+ }
+
+ public Structure processIncomingStructure(Structure struct) throws JASDLMessageContentException {
+ return processStructure(struct, incomingStrategy);
+ }
+
+ public Structure processOutgoingStructure(Structure struct) throws JASDLMessageContentException {
+ return processStructure(struct, outgoingStrategy);
+ }
+
+ private Structure processStructure(Structure struct, ProtocolProcessingStrategy strategy) throws JASDLMessageContentException {
+
+ // recurse down terms and lists (for "bundled" SE-enriched content)
+ if (struct.getArity() > 0) { // if we have any terms to process!
+ // Process outer SE-enriched content
+ if (struct.isLiteral()) { // processing strategies only apply to Literals
+ Literal l = (Literal) struct;
+ try {
+ struct = strategy.process(l, jom);
+ } catch (JASDLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ //int i=0;
+ //for(Term _term : struct.getTerms()){ - mustn't use in case struct is a list
+ if (struct.isVar()) {
+ struct = (Structure) ((VarTerm) struct).getValue(); // resolve struct if var
+ }
+ if (struct.isList()) { // special processing for lists (since we can't (or rather shouldn't)) use getTerm or setTerm)
+ ListTermImpl newList = new ListTermImpl(); // a "clone"
+ for (Term e : ((ListTerm) struct).getAsList()) {
+ jom.getLogger().finest("Processing " + e);
+ if (e instanceof Structure) {
+ Structure alteredTerm = (Structure) processStructure((Structure) e, strategy);
+ newList.append(alteredTerm);
+ }
+ }
+ return newList;
+ } else { // all other structures
+ for (int i = 0; i < struct.getArity(); i++) {
+ Term _term = struct.getTerm(i);
+ if (_term instanceof Structure) {
+ Structure term = (Structure) _term;
+ Structure alteredTerm = (Structure) processStructure(term, strategy);
+ struct.setTerm(i, alteredTerm); // modifies original struct
+ }
+ }
+ }
+ }
+
+ return struct;
+ }
+}
Added: trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/package.html
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/package.html (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/architecture/protocol/package.html 2008-04-18 18:28:03 UTC (rev 1224)
@@ -0,0 +1,5 @@
+<html>
+ <body>
+ Contains classes concerned with implementing JASDL's syntactic translation protocol. Currently used for SE-Message and SE-Percept translation.
+ </body>
+</html>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tom...@us...> - 2008-04-18 18:19:04
|
Revision: 1223
http://jason.svn.sourceforge.net/jason/?rev=1223&view=rev
Author: tomklapiscak
Date: 2008-04-18 11:18:50 -0700 (Fri, 18 Apr 2008)
Log Message:
-----------
Major JASDL revision. Highlights:
Belief base contraction made more efficient (recursive contraction of first-level support lists unnecessary). Contraction now defaults to off since it is experimental. Added .mas2j settings and internal actions jasdl.ia.is_contraction_enabled and jasdl.ia.set_contraction_enabled.
Added option to use Pellet's incremental explanation generator rather than the Bebops library (which uses OWL-APIs black-box debugging features). Deprecated for now due to apparent bugs.
Trigger generalisation mechanism revamped. Can now deal with arbitrary nestings of SE-Literals within Semantically-naive literals. Implemented using an extension to Jason's standard unifier, DLUnifier, that overrides Jason's standard unifier to generalise unification of SE-Literals to include ontological rules. Specifically, functors need not directly match, but be related by subsumption.
jasdl.ia.define_class now supports complex XSD data ranges. i.e. can express classes of the form "travel:hotel and travel:hasPricePerNight some double [<= 15]" - the class of all hotels that have a nightly price of less than or equal to 15.
Added WIP "commerce" example JASDL application.
Revamped JASDL's syntactic-translation protocol for SE-Messages and SE-Percepts. Clearer semantics and improved efficiency. Aliasing now applied also to individuals nested within SE-Literals. Extracted to general ProtocolProcessor class (i.e. messages / percepts).
JASDL can now support SE-percepts (percepts consisting of SE-Literals):
JASDLBeliefBase now handles SE-percepts correctly
Added JASDLEnvironment - to be extended by any JASDL agent making use of an environment. Maintains own JASDLOntologyManager and ensures syntactic-translation processing is performed on SE-Percepts entering standard percept operations (i.e. adding "named", "anon", "i" annotations, etc). Provides a framework of convenience methods for creating SE-percepts (i.e. SELiteralFactory).
JASDLAgArch ensures incoming SE-Percepts are translated back SE-Literals according to local mappings of perceiving agent.
Miscellanous internal actions added:
jasdl.ia.get_types(Functor, Label, direct, Types): unifies Types with a list of classifications of the individual referenced by (Functor, Label). If direct is set, only asserted types are listed, otherwise all inferred types are.
jasdl.ia.get_anonymous_individual(Functor): unifies Functor with a guaranteed unique (wrt. known individuals in ontologies), anonymous individual name.
jasdl.ia.get_class_definition(SELiteral, Rendering): unifies Rendering with the NS-prefix manchester OWL syntax rendering (same used by jasdl.ia.define_class) of the class describing the assertion made by SELiteral.
jasdl.ia.get_functor(Literal, Functor): unifies Functor with the functor of Literal (useful for extracting the class/property alias used by an SE-Literal)
jasdl.ia.get_individual(ClassAssertion, Individual): Unifies Individual with the individual referenced by the SE-Literal ClassAssertion.
jasdl.ia.send(agent, askOne, hotel(hilton)[o(travel)], thing(X)[o(travel)]): Wraps around Jason's default .send performative to enable generalised unification (by setting the current suspended intended-means to use DLUnifier - see above) on the fourth parameter synchronous askOne messages. This this example, X will unify with hilton since "thing" subsumes "hotel".
Extracted ontology management functionality (ontology loading, anonymous instantiation, aliasing, reasoning, labelling and class definition, etc) from JASDLAgent to JASDLOntologyManager
Tidied up static parameter fields and extracted them to JASDLParams class.
Revamped exception handling.
JASDL now makes proper use of XSDVocabulary enumeration provided with OWL-API (rather than duplicating in custom XSDDatatype enum)
SELiterals can no longer be specified with a String "o" term: doesn't fit in well with new design.
Run-time defined classes with clashing alias mappings now override old ones.
Run-time instantiated individuals are added into a (semantically) meaningless assertion axiom - ensures the toEntity method can find them (needed in particular for run-time class renderings).
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/ontologies/places.owl
trunk/applications/jasdl-owlapi/examples/travel_agent/ontologies/travel.owl
trunk/applications/jasdl-owlapi/examples/travel_agent/travel_agent.asl
trunk/applications/jasdl-owlapi/lib/bebops.jar
trunk/applications/jasdl-owlapi/src/jasdl/asSyntax/SEPlan.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/AliasFactory.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/AxiomToSELiteralConverter.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/SELiteralFactory.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/SELiteralToAxiomConverter.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/mapping/MappingManager.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/mapping/aliasing/Alias.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/mapping/aliasing/AliasManager.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/mapping/aliasing/AllDifferentPlaceholder.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/mapping/aliasing/DecapitaliseMappingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/mapping/aliasing/DefinitionManager.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/mapping/label/LabelManager.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/mapping/label/OntologyURIManager.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteral.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralAllDifferentAssertion.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralClassAssertion.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralDataPropertyAssertion.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralObjectPropertyAssertion.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralPropertyAssertion.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/define_class.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/is_annotation_gathering_enabled.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/is_belief_revision_enabled.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/set_annotation_gathering_enabled.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/set_belief_revision_enabled.java
trunk/applications/jasdl-owlapi/src/jasdl/test/JasdlBeliefBaseTest.java
trunk/applications/jasdl-owlapi/src/jasdl/util/Common.java
trunk/applications/jasdl-owlapi/src/jasdl/util/owlapi/parsing/NSPrefixOWLEntityChecker.java
trunk/applications/jasdl-owlapi/src/jasdl/util/owlapi/parsing/URIOWLEntityChecker.java
Added Paths:
-----------
trunk/applications/jasdl-owlapi/examples/commerce/
trunk/applications/jasdl-owlapi/examples/commerce/.classpath
trunk/applications/jasdl-owlapi/examples/commerce/.project
trunk/applications/jasdl-owlapi/examples/commerce/bin/
trunk/applications/jasdl-owlapi/examples/commerce/bin/build.xml
trunk/applications/jasdl-owlapi/examples/commerce/bin/c-build.xml
trunk/applications/jasdl-owlapi/examples/commerce/commerce.mas2j
trunk/applications/jasdl-owlapi/examples/commerce/logging.properties
trunk/applications/jasdl-owlapi/examples/commerce/onts/
trunk/applications/jasdl-owlapi/examples/commerce/onts/commerce.owl
trunk/applications/jasdl-owlapi/examples/commerce/onts/society.owl
trunk/applications/jasdl-owlapi/examples/commerce/src/
trunk/applications/jasdl-owlapi/examples/commerce/src/asl/
trunk/applications/jasdl-owlapi/examples/commerce/src/asl/common/
trunk/applications/jasdl-owlapi/examples/commerce/src/asl/common/society.asl
trunk/applications/jasdl-owlapi/examples/commerce/src/asl/customer.asl
trunk/applications/jasdl-owlapi/examples/commerce/src/asl/delivery_van.asl
trunk/applications/jasdl-owlapi/examples/commerce/src/asl/pa.asl
trunk/applications/jasdl-owlapi/examples/commerce/src/asl/shop1.asl
trunk/applications/jasdl-owlapi/examples/commerce/src/asl/testing.asl
trunk/applications/jasdl-owlapi/examples/commerce/src/java/
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/CommerceEnvironment.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/CommerceView.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/CommerceModel.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelAgent.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelCrate.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelCustomer.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelDeliveryVan.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelMobileAgent.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelObject.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelPA.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/ModelShop.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/env/model/Product.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/exception/
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/exception/CommerceException.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/exception/ModelAgentException.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/exception/ModelDeliveryVanException.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/exception/ModelMobileAgentException.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/exception/ModelShopException.java
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/util/
trunk/applications/jasdl-owlapi/examples/commerce/src/java/commerce/util/Common.java
trunk/applications/jasdl-owlapi/src/jasdl/JASDLParams.java
trunk/applications/jasdl-owlapi/src/jasdl/architecture/JASDLAgArch.java
trunk/applications/jasdl-owlapi/src/jasdl/architecture/package.html
trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JASDLAgent.java
trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JASDLAgentConfigurator.java
trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/package.html
trunk/applications/jasdl-owlapi/src/jasdl/asSyntax/JASDLPlanLibrary.java
trunk/applications/jasdl-owlapi/src/jasdl/bb/JASDLBeliefBase.java
trunk/applications/jasdl-owlapi/src/jasdl/bb/bebops/
trunk/applications/jasdl-owlapi/src/jasdl/bb/bebops/JASDLIncisionFunction.java
trunk/applications/jasdl-owlapi/src/jasdl/bb/bebops/JASDLKernelsetFilter.java
trunk/applications/jasdl-owlapi/src/jasdl/bb/bebops/JASDLReasonerFactory.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/DLUnifier.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/JASDLOntologyManager.java
trunk/applications/jasdl-owlapi/src/jasdl/env/
trunk/applications/jasdl-owlapi/src/jasdl/env/JASDLEnvironment.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/get_anonymous_individual.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/get_class_definition.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/get_functor.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/get_individual.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/get_types.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/is_contraction_enabled.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/logging/
trunk/applications/jasdl-owlapi/src/jasdl/ia/logging/log.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/send.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/set_contraction_enabled.java
trunk/applications/jasdl-owlapi/src/jasdl/package.html
trunk/applications/jasdl-owlapi/src/jasdl/util/exception/JASDLConfigurationException.java
trunk/applications/jasdl-owlapi/src/jasdl/util/exception/JASDLDuplicateMappingException.java
trunk/applications/jasdl-owlapi/src/jasdl/util/exception/JASDLException.java
trunk/applications/jasdl-owlapi/src/jasdl/util/exception/JASDLInvalidSELiteralException.java
trunk/applications/jasdl-owlapi/src/jasdl/util/exception/JASDLMessageContentException.java
trunk/applications/jasdl-owlapi/src/jasdl/util/exception/JASDLNotEnrichedException.java
trunk/applications/jasdl-owlapi/src/jasdl/util/exception/JASDLUnknownMappingException.java
trunk/applications/jasdl-owlapi/src/jasdl/util/owlapi/IndividualAxiomToDescriptionConverter.java
trunk/applications/jasdl-owlapi/src/jasdl/util/owlapi/parsing/XSDDatatypeChecker.java
trunk/applications/jasdl-owlapi/src/jasdl/util/owlapi/rendering/NsPrefixOWLObjectShortFormProvider.java
trunk/applications/jasdl-owlapi/src/jasdl/util/owlapi/rendering/URIOWLObjectShortFormProvider.java
trunk/applications/jasdl-owlapi/src/jasdl/util/owlapi/xsd/XSDVocabularyUtils.java
Removed Paths:
-------------
trunk/applications/jasdl-owlapi/src/jasdl/architecture/IncomingPropContProcessingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/architecture/JasdlAgArch.java
trunk/applications/jasdl-owlapi/src/jasdl/architecture/OutgoingPropContProcessingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/architecture/PropContProcessingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java
trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlConfigurator.java
trunk/applications/jasdl-owlapi/src/jasdl/asSyntax/JasdlPlanLibrary.java
trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlBeliefBase.java
trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlIncisionFunction.java
trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlReasonerFactory.java
trunk/applications/jasdl-owlapi/src/jasdl/bb/TBoxAxiomKernelsetFilter.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/mapping/aliasing/AliasFactory.java
trunk/applications/jasdl-owlapi/src/jasdl/util/exception/DuplicateMappingException.java
trunk/applications/jasdl-owlapi/src/jasdl/util/exception/InvalidSELiteralException.java
trunk/applications/jasdl-owlapi/src/jasdl/util/exception/JasdlConfigurationException.java
trunk/applications/jasdl-owlapi/src/jasdl/util/exception/JasdlException.java
trunk/applications/jasdl-owlapi/src/jasdl/util/exception/NotEnrichedException.java
trunk/applications/jasdl-owlapi/src/jasdl/util/exception/UnknownMappingException.java
trunk/applications/jasdl-owlapi/src/jasdl/util/owlapi/rendering/URIOWLObjectRenderer.java
trunk/applications/jasdl-owlapi/src/jasdl/util/owlapi/xsd/XSDDataType.java
trunk/applications/jasdl-owlapi/src/jasdl/util/owlapi/xsd/XSDDataTypeUtils.java
Property Changed:
----------------
trunk/applications/jasdl-owlapi/examples/
Property changes on: trunk/applications/jasdl-owlapi/examples
___________________________________________________________________
Name: svn:ignore
- testing
brf_test
+ testing
brf_test
commerce (copy)
commerce (another copy)
Property changes on: trunk/applications/jasdl-owlapi/examples/commerce
___________________________________________________________________
Name: svn:ignore
+ .stop___MAS
Added: trunk/applications/jasdl-owlapi/examples/commerce/.classpath
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/.classpath (rev 0)
+++ trunk/applications/jasdl-owlapi/examples/commerce/.classpath 2008-04-18 18:18:50 UTC (rev 1223)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="/home/tom/workspace/jason/lib/jason.jar" sourcepath="/home/tom/workspace/jason/src">
+ <attributes>
+ <attribute name="javadoc_location" value="file:/home/tom/workspace/jason/doc/api/"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry combineaccessrules="false" kind="src" path="/jasdl-owlapi"/>
+ <classpathentry kind="lib" path="/jasdl-owlapi/lib/owlapi-bin.jar" sourcepath="/home/tom/workspace/owlapi/antbuild/build/owlapi-src.jar">
+ <attributes>
+ <attribute name="javadoc_location" value="file:/home/tom/workspace/owlapi/antbuild/build/javadoc/"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="output" path="bin/classes"/>
+</classpath>
Added: trunk/applications/jasdl-owlapi/examples/commerce/.project
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/.project (rev 0)
+++ trunk/applications/jasdl-owlapi/examples/commerce/.project 2008-04-18 18:18:50 UTC (rev 1223)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>commerce</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Property changes on: trunk/applications/jasdl-owlapi/examples/commerce/bin
___________________________________________________________________
Name: svn:ignore
+ classes
Added: trunk/applications/jasdl-owlapi/examples/commerce/bin/build.xml
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/bin/build.xml (rev 0)
+++ trunk/applications/jasdl-owlapi/examples/commerce/bin/build.xml 2008-04-18 18:18:50 UTC (rev 1223)
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+
+<!--
+
+ This file was generated by Jason ?
+ http://jason.sf.net
+
+ April 18, 2008 - 18:12:11
+-->
+
+<project name ="commerce"
+ basedir=".."
+ default="run">
+
+ <property name="mas2j.project.file" value="commerce.mas2j"/>
+ <property name="debug" value=""/> <!-- use "-debug" to run in debug mode -->
+ <property name="build.dir" value="${basedir}/bin/classes" />
+
+ <property name="jasonJar" value="/home/tom/workspace/jason/lib/jason.jar"/>
+
+ <path id="project.classpath">
+ <pathelement location="${basedir}"/>
+ <pathelement location="${build.dir}"/>
+ <pathelement location="${jasonJar}"/>
+ <fileset dir="../../lib" > <include name="**/*.jar" /> </fileset>
+ <pathelement location="../../../jmca/lib/jmca.jar"/>
+
+ </path>
+
+ <!-- tasks the user can override in his/her c-build.xml script -->
+ <target name="user-init">
+ </target>
+ <target name="user-end">
+ </target>
+
+ <target name="init">
+ <mkdir dir="${build.dir}" />
+ <antcall target="user-init" />
+ </target>
+
+ <target name="compile" depends="init">
+ <condition property="srcdir" value="${basedir}/src/java" else="${basedir}" >
+ <available file="${basedir}/src/java" />
+ </condition>
+ <javac srcdir="${srcdir}" destdir="${build.dir}" debug="true" optimize="true" >
+ <classpath refid="project.classpath"/>
+ </javac>
+ </target>
+
+ <target name="jar" depends="compile">
+ <delete file="${ant.project.name}.jar" />
+ <copy file="${jasonJar}" tofile="${ant.project.name}.jar" />
+ <copy file="${mas2j.project.file}" tofile="default.mas2j" />
+ <jar update="yes" jarfile="${ant.project.name}.jar" >
+ <fileset dir="${basedir}">
+ <include name="**/*.asl" />
+ <include name="**/*.mas2j" />
+ </fileset>
+ <fileset dir="${build.dir}">
+ <include name="**/*.class" />
+ </fileset>
+ </jar>
+ <delete file="default.mas2j" />
+ </target>
+
+
+ <target name="jnlp" depends="jar" >
+ <mkdir dir="${basedir}/${ant.project.name}-jws"/>
+ <java classname="jason.infra.centralised.CreateJNLP"
+ failonerror="true" fork="yes" dir="${basedir}/${ant.project.name}-jws" >
+ <classpath refid="project.classpath"/>
+ <arg line="${ant.project.name} ${mas2j.project.file}"/>
+ </java>
+ <copy todir="${basedir}/${ant.project.name}-jws" failonerror="no">
+ <fileset dir="${basedir}/lib" includes="**/*.jar" />
+ <fileset dir="${basedir}" includes="${ant.project.name}.jar" />
+ <fileset dir="/home/tom/workspace/jason/src/images" includes="Jason-GMoreau-Icon.jpg" />
+ </copy>
+ <signjar jar="${basedir}/${ant.project.name}-jws/${ant.project.name}.jar" alias="jason"
+ storepass="rbjhja" keypass="rbjhja" keystore="/home/tom/workspace/jason/src/jasonKeystore" />
+ <echo message="**" />
+ <echo message="** Java Web Start application created in directory ${ant.project.name}-jws" />
+ <echo message="** Update the codebase (in the second line of the .jnlp file)" />
+ <echo message="** with the URL where you will upload the application." />
+ <echo message="**" />
+ </target>
+
+
+ <target name="run" depends="compile" >
+ <echo message="Running project ${ant.project.name}" />
+ <java classname="jason.infra.centralised.RunCentralisedMAS"
+ failonerror="true" fork="yes" dir="${basedir}" >
+ <classpath refid="project.classpath"/>
+ <arg line="${mas2j.project.file} ${debug} "/>
+ <jvmarg line="-Xmx750M"/>
+ </java>
+ <antcall target="user-end" />
+ </target>
+
+ <target name="clean" >
+ <delete failonerror="no" includeEmptyDirs="true" verbose="true">
+ <fileset dir="${basedir}" includes="**/*.class"/>
+ </delete>
+ </target>
+
+
+
+</project>
Added: trunk/applications/jasdl-owlapi/examples/commerce/bin/c-build.xml
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/bin/c-build.xml (rev 0)
+++ trunk/applications/jasdl-owlapi/examples/commerce/bin/c-build.xml 2008-04-18 18:18:50 UTC (rev 1223)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+
+<project name ="custombuild" basedir="..">
+ <!-- Ensure we are using the latest build of Jason -->
+ <property name="jasonJar" value="../../../../lib/jason.jar"/>
+
+ <import file="build.xml"/>
+
+ <target name="user-init">
+ <ant dir="../../../../" inheritAll="false" target="plugin"/>
+ <ant dir="../../../jmca" inheritAll="false"/>
+ <ant dir="../.." inheritAll="false"/>
+ </target>
+
+ <target name="user-end">
+ </target>
+</project>
Added: trunk/applications/jasdl-owlapi/examples/commerce/commerce.mas2j
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/commerce.mas2j (rev 0)
+++ trunk/applications/jasdl-owlapi/examples/commerce/commerce.mas2j 2008-04-18 18:18:50 UTC (rev 1223)
@@ -0,0 +1,60 @@
+/* Jason Project */
+
+MAS commerce {
+
+ infrastructure: Centralised
+
+ environment: commerce.env.CommerceEnvironment
+
+ agents:
+ shop1
+ [
+ jasdl_ontologies="c,s",
+ jasdl_c_uri="/onts/commerce.owl",
+ jasdl_s_uri="/onts/society.owl"
+ ]
+ #1
+ agentArchClass jasdl.architecture.JASDLAgArch
+ agentClass jasdl.asSemantics.JASDLAgent
+ beliefBaseClass jasdl.bb.JASDLBeliefBase;
+
+ delivery_van
+ [
+ jasdl_ontologies="c,s",
+ jasdl_c_uri="/onts/commerce.owl",
+ jasdl_s_uri="/onts/society.owl"
+ ]
+ #2
+ agentArchClass jasdl.architecture.JASDLAgArch
+ agentClass jasdl.asSemantics.JASDLAgent
+ beliefBaseClass jasdl.bb.JASDLBeliefBase;
+
+ customer
+ [
+ jasdl_ontologies="c,s",
+ jasdl_c_uri="/onts/commerce.owl",
+ jasdl_s_uri="/onts/society.owl"
+ ]
+ #3
+ agentArchClass jasdl.architecture.JASDLAgArch
+ agentClass jasdl.asSemantics.JASDLAgent
+ beliefBaseClass jasdl.bb.JASDLBeliefBase;
+
+ pa
+ [
+ jasdl_ontologies="c,s",
+ jasdl_c_uri="/onts/commerce.owl",
+ jasdl_s_uri="/onts/society.owl"
+ ]
+ #3
+ agentArchClass jasdl.architecture.JASDLAgArch
+ agentClass jasdl.asSemantics.JASDLAgent
+ beliefBaseClass jasdl.bb.JASDLBeliefBase;
+
+
+ classpath: "../../lib/**/*.jar"; // JASDL's libraries
+ "../../../jmca/lib/jmca.jar"; // JMCA
+
+ aslSourcePath: "src/asl";
+}
+
Added: trunk/applications/jasdl-owlapi/examples/commerce/logging.properties
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/logging.properties (rev 0)
+++ trunk/applications/jasdl-owlapi/examples/commerce/logging.properties 2008-04-18 18:18:50 UTC (rev 1223)
@@ -0,0 +1,50 @@
+# Jason Default log configuration
+#
+# Comment/uncomment the following lines to setup your log
+#
+
+# default Jason MAS Console
+handlers = jason.runtime.MASConsoleLogHandler
+
+# To use the ConsoleHandler, use the following line instead.
+#handlers= java.util.logging.ConsoleHandler
+
+# To also add the FileHandler, use the following line instead.
+#handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
+
+# Default logging level. Other values are:
+# SEVERE (only severe messages)
+# WARNING (only warnings and severe messages)
+# INFO (normal output)
+# FINE (debug level of messages)
+.level = INFO
+
+
+############################################################
+# Handler specific properties.
+# Describes specific configuration info for Handlers.
+############################################################
+
+# Jason Handler parameters
+jason.runtime.MASConsoleLogHandler.level = ALL
+jason.runtime.MASConsoleLogHandler.formatter = jason.runtime.MASConsoleLogFormatter
+# set one text area for each agent
+jason.runtime.MASConsoleLogHandler.tabbed = true
+
+# default file output is in project's directory.
+java.util.logging.FileHandler.pattern = mas.log
+#java.util.logging.FileHandler.pattern = mas-%u.log
+java.util.logging.FileHandler.limit = 500000
+java.util.logging.FileHandler.count = 1
+java.util.logging.FileHandler.formatter = jason.runtime.MASConsoleLogFormatter
+#java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
+
+# Limit the message that are printed on the console to FINE and above.
+java.util.logging.ConsoleHandler.level = FINE
+java.util.logging.ConsoleHandler.formatter = jason.runtime.MASConsoleLogFormatter
+
+java.level=OFF
+javax.level=OFF
+sun.level=OFF
+jade.level=OFF
+
Added: trunk/applications/jasdl-owlapi/examples/commerce/onts/commerce.owl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/onts/commerce.owl (rev 0)
+++ trunk/applications/jasdl-owlapi/examples/commerce/onts/commerce.owl 2008-04-18 18:18:50 UTC (rev 1223)
@@ -0,0 +1,583 @@
+<?xml version="1.0"?>
+
+
+<!DOCTYPE rdf:RDF [
+ <!ENTITY owl "http://www.w3.org/2002/07/owl#" >
+ <!ENTITY owl11 "http://www.w3.org/2006/12/owl11#" >
+ <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
+ <!ENTITY owl11xml "http://www.w3.org/2006/12/owl11-xml#" >
+ <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
+ <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
+ <!ENTITY commerce "http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#" >
+]>
+
+
+<rdf:RDF xmlns="http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#"
+ xml:base="http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl"
+ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+ xmlns:owl11="http://www.w3.org/2006/12/owl11#"
+ xmlns:owl11xml="http://www.w3.org/2006/12/owl11-xml#"
+ xmlns:owl="http://www.w3.org/2002/07/owl#"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:commerce="http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#">
+ <owl:Ontology rdf:about=""/>
+
+
+
+ <!--
+ ///////////////////////////////////////////////////////////////////////////////////////
+ //
+ // Object Properties
+ //
+ ///////////////////////////////////////////////////////////////////////////////////////
+ -->
+
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#contains -->
+
+ <owl:ObjectProperty rdf:about="#contains">
+ <rdf:type rdf:resource="&owl;TransitiveProperty"/>
+ <rdfs:range rdf:resource="#Ingredient"/>
+ <rdfs:domain rdf:resource="#Product"/>
+ </owl:ObjectProperty>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#hasBrand -->
+
+ <owl:ObjectProperty rdf:about="#hasBrand">
+ <rdf:type rdf:resource="&owl;FunctionalProperty"/>
+ <rdfs:range rdf:resource="#Product"/>
+ <rdfs:domain rdf:resource="#Purchase"/>
+ </owl:ObjectProperty>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#hasCustomer -->
+
+ <owl:ObjectProperty rdf:about="#hasCustomer">
+ <rdf:type rdf:resource="&owl;InverseFunctionalProperty"/>
+ <rdfs:domain rdf:resource="#Order"/>
+ </owl:ObjectProperty>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#hasOrder -->
+
+ <owl:ObjectProperty rdf:about="#hasOrder">
+ <rdf:type rdf:resource="&owl;FunctionalProperty"/>
+ <rdfs:range rdf:resource="#Order"/>
+ <owl:inverseOf rdf:resource="#hasCustomer"/>
+ </owl:ObjectProperty>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#includes -->
+
+ <owl:ObjectProperty rdf:about="#includes">
+ <rdf:type rdf:resource="&owl;TransitiveProperty"/>
+ <rdfs:domain rdf:resource="#Order"/>
+ <rdfs:range rdf:resource="#Purchase"/>
+ </owl:ObjectProperty>
+
+
+
+ <!--
+ ///////////////////////////////////////////////////////////////////////////////////////
+ //
+ // Data properties
+ //
+ ///////////////////////////////////////////////////////////////////////////////////////
+ -->
+
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#hasInStock -->
+
+ <owl:DatatypeProperty rdf:about="#hasInStock">
+ <rdf:type rdf:resource="&owl;FunctionalProperty"/>
+ <rdfs:domain rdf:resource="#Product"/>
+ <rdfs:range rdf:resource="&xsd;integer"/>
+ </owl:DatatypeProperty>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#hasPrice -->
+
+ <owl:DatatypeProperty rdf:about="#hasPrice">
+ <rdf:type rdf:resource="&owl;FunctionalProperty"/>
+ <rdfs:domain rdf:resource="#Product"/>
+ <rdfs:range rdf:resource="&xsd;double"/>
+ </owl:DatatypeProperty>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#hasQuantity -->
+
+ <owl:DatatypeProperty rdf:about="#hasQuantity">
+ <rdf:type rdf:resource="&owl;FunctionalProperty"/>
+ <rdfs:domain rdf:resource="#Purchase"/>
+ <rdfs:range rdf:resource="&xsd;integer"/>
+ </owl:DatatypeProperty>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#hasVolume -->
+
+ <owl:DatatypeProperty rdf:about="#hasVolume">
+ <rdf:type rdf:resource="&owl;FunctionalProperty"/>
+ <rdfs:domain rdf:resource="#Product"/>
+ <rdfs:range rdf:resource="&xsd;double"/>
+ </owl:DatatypeProperty>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#hasWeight -->
+
+ <owl:DatatypeProperty rdf:about="#hasWeight">
+ <rdf:type rdf:resource="&owl;FunctionalProperty"/>
+ <rdfs:domain rdf:resource="#Product"/>
+ <rdfs:range rdf:resource="&xsd;double"/>
+ </owl:DatatypeProperty>
+
+
+
+ <!--
+ ///////////////////////////////////////////////////////////////////////////////////////
+ //
+ // Classes
+ //
+ ///////////////////////////////////////////////////////////////////////////////////////
+ -->
+
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Allergen -->
+
+ <owl:Class rdf:about="#Allergen">
+ <rdfs:subClassOf rdf:resource="#Ingredient"/>
+ <rdfs:comment
+ >Ingredients that are common allergens</rdfs:comment>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Beef -->
+
+ <owl:Class rdf:about="#Beef">
+ <owl:equivalentClass>
+ <owl:Restriction>
+ <owl:onProperty rdf:resource="#contains"/>
+ <owl:hasValue rdf:resource="#BeefIngredient"/>
+ </owl:Restriction>
+ </owl:equivalentClass>
+ <rdfs:subClassOf rdf:resource="#Meat"/>
+ <owl:disjointWith rdf:resource="#Chicken"/>
+ <owl:disjointWith rdf:resource="#Lamb"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Bread -->
+
+ <owl:Class rdf:about="#Bread">
+ <owl:equivalentClass>
+ <owl:Restriction>
+ <owl:onProperty rdf:resource="#contains"/>
+ <owl:hasValue rdf:resource="#Gluten"/>
+ </owl:Restriction>
+ </owl:equivalentClass>
+ <rdfs:subClassOf rdf:resource="#Grocery"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Butter -->
+
+ <owl:Class rdf:about="#Butter">
+ <rdfs:subClassOf rdf:resource="#Dairy"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Chicken -->
+
+ <owl:Class rdf:about="#Chicken">
+ <owl:equivalentClass>
+ <owl:Restriction>
+ <owl:onProperty rdf:resource="#contains"/>
+ <owl:hasValue rdf:resource="#ChickenIngredient"/>
+ </owl:Restriction>
+ </owl:equivalentClass>
+ <rdfs:subClassOf rdf:resource="#Meat"/>
+ <owl:disjointWith rdf:resource="#Lamb"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#ContainsGluten -->
+
+ <owl:Class rdf:about="#ContainsGluten">
+ <owl:equivalentClass>
+ <owl:Class>
+ <owl:intersectionOf rdf:parseType="Collection">
+ <owl:Restriction>
+ <owl:onProperty rdf:resource="#contains"/>
+ <owl:hasValue rdf:resource="#Gluten"/>
+ </owl:Restriction>
+ <rdf:Description rdf:about="#Grocery"/>
+ </owl:intersectionOf>
+ </owl:Class>
+ </owl:equivalentClass>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#ContainsLactose -->
+
+ <owl:Class rdf:about="#ContainsLactose">
+ <owl:equivalentClass>
+ <owl:Class>
+ <owl:intersectionOf rdf:parseType="Collection">
+ <owl:Restriction>
+ <owl:onProperty rdf:resource="#contains"/>
+ <owl:hasValue rdf:resource="#Lactose"/>
+ </owl:Restriction>
+ <rdf:Description rdf:about="#Grocery"/>
+ </owl:intersectionOf>
+ </owl:Class>
+ </owl:equivalentClass>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#ContainsMeat -->
+
+ <owl:Class rdf:about="#ContainsMeat">
+ <owl:equivalentClass>
+ <owl:Class>
+ <owl:intersectionOf rdf:parseType="Collection">
+ <rdf:Description rdf:about="#Grocery"/>
+ <owl:Restriction>
+ <owl:onProperty rdf:resource="#contains"/>
+ <owl:someValuesFrom rdf:resource="#MeatIngredient"/>
+ </owl:Restriction>
+ </owl:intersectionOf>
+ </owl:Class>
+ </owl:equivalentClass>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#ContainsNuts -->
+
+ <owl:Class rdf:about="#ContainsNuts">
+ <owl:equivalentClass>
+ <owl:Class>
+ <owl:intersectionOf rdf:parseType="Collection">
+ <owl:Restriction>
+ <owl:onProperty rdf:resource="#contains"/>
+ <owl:hasValue rdf:resource="#Nuts"/>
+ </owl:Restriction>
+ <rdf:Description rdf:about="#Grocery"/>
+ </owl:intersectionOf>
+ </owl:Class>
+ </owl:equivalentClass>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Cream -->
+
+ <owl:Class rdf:about="#Cream">
+ <rdfs:subClassOf rdf:resource="#Dairy"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Dairy -->
+
+ <owl:Class rdf:about="#Dairy">
+ <owl:equivalentClass>
+ <owl:Restriction>
+ <owl:onProperty rdf:resource="#contains"/>
+ <owl:hasValue rdf:resource="#Lactose"/>
+ </owl:Restriction>
+ </owl:equivalentClass>
+ <rdfs:subClassOf rdf:resource="#Grocery"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Fish -->
+
+ <owl:Class rdf:about="#Fish">
+ <owl:equivalentClass>
+ <owl:Restriction>
+ <owl:onProperty rdf:resource="#contains"/>
+ <owl:hasValue rdf:resource="#FishIngredient"/>
+ </owl:Restriction>
+ </owl:equivalentClass>
+ <rdfs:subClassOf rdf:resource="#Meat"/>
+ <owl:disjointWith rdf:resource="#Beef"/>
+ <owl:disjointWith rdf:resource="#Chicken"/>
+ <owl:disjointWith rdf:resource="#Lamb"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Grocery -->
+
+ <owl:Class rdf:about="#Grocery">
+ <rdfs:subClassOf rdf:resource="#Product"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#InStock -->
+
+ <owl:Class rdf:about="#InStock">
+ <owl:equivalentClass>
+ <owl:Class>
+ <owl:intersectionOf rdf:parseType="Collection">
+ <rdf:Description rdf:about="#Product"/>
+ <owl:Restriction>
+ <owl:onProperty rdf:resource="#hasInStock"/>
+ <owl:someValuesFrom>
+ <rdf:Description>
+ <rdf:type rdf:resource="&owl;DataRange"/>
+ <owl11:minInclusive rdf:datatype="&xsd;int">1</owl11:minInclusive>
+ <owl11:onDataRange rdf:resource="&xsd;int"/>
+ </rdf:Description>
+ </owl:someValuesFrom>
+ </owl:Restriction>
+ </owl:intersectionOf>
+ </owl:Class>
+ </owl:equivalentClass>
+ <rdfs:subClassOf rdf:resource="#Product"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Ingredient -->
+
+ <owl:Class rdf:about="#Ingredient">
+ <rdfs:subClassOf rdf:resource="#Grocery"/>
+ <rdfs:comment
+ >Ingredients that must be noted since some people cannot eat them</rdfs:comment>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Lamb -->
+
+ <owl:Class rdf:about="#Lamb">
+ <owl:equivalentClass>
+ <owl:Restriction>
+ <owl:onProperty rdf:resource="#contains"/>
+ <owl:hasValue rdf:resource="#LambIngredient"/>
+ </owl:Restriction>
+ </owl:equivalentClass>
+ <rdfs:subClassOf rdf:resource="#Meat"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Meat -->
+
+ <owl:Class rdf:about="#Meat">
+ <rdfs:subClassOf rdf:resource="#Grocery"/>
+ <owl:disjointWith rdf:resource="#Vegetable"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#MeatIngredient -->
+
+ <owl:Class rdf:about="#MeatIngredient">
+ <rdfs:subClassOf rdf:resource="#Ingredient"/>
+ <rdfs:comment
+ >Types of meat that food may contain</rdfs:comment>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Milk -->
+
+ <owl:Class rdf:about="#Milk">
+ <rdfs:subClassOf rdf:resource="#Dairy"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Order -->
+
+ <owl:Class rdf:about="#Order">
+ <rdfs:subClassOf rdf:resource="&owl;Thing"/>
+ <rdfs:comment
+ >A set of purchases</rdfs:comment>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Product -->
+
+ <owl:Class rdf:about="#Product">
+ <rdfs:subClassOf rdf:resource="&owl;Thing"/>
+ <rdfs:subClassOf>
+ <owl:Class>
+ <owl:unionOf rdf:parseType="Collection">
+ <owl:Restriction>
+ <owl:onProperty rdf:resource="#hasVolume"/>
+ <owl:someValuesFrom rdf:resource="&xsd;double"/>
+ </owl:Restriction>
+ <owl:Restriction>
+ <owl:onProperty rdf:resource="#hasWeight"/>
+ <owl:someValuesFrom rdf:resource="&xsd;double"/>
+ </owl:Restriction>
+ </owl:unionOf>
+ </owl:Class>
+ </rdfs:subClassOf>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Purchase -->
+
+ <owl:Class rdf:about="#Purchase">
+ <rdfs:subClassOf rdf:resource="&owl;Thing"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#ReadyMeal -->
+
+ <owl:Class rdf:about="#ReadyMeal">
+ <rdfs:subClassOf rdf:resource="#Grocery"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#ShepherdsPie -->
+
+ <owl:Class rdf:about="#ShepherdsPie">
+ <owl:equivalentClass>
+ <owl:Restriction>
+ <owl:onProperty rdf:resource="#contains"/>
+ <owl:hasValue rdf:resource="#BeefIngredient"/>
+ </owl:Restriction>
+ </owl:equivalentClass>
+ <rdfs:subClassOf rdf:resource="#ReadyMeal"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Vegetable -->
+
+ <owl:Class rdf:about="#Vegetable">
+ <rdfs:subClassOf rdf:resource="#Grocery"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#VegetableCurry -->
+
+ <owl:Class rdf:about="#VegetableCurry">
+ <rdfs:subClassOf rdf:resource="#ReadyMeal"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.w3.org/2002/07/owl#Thing -->
+
+ <owl:Class rdf:about="&owl;Thing"/>
+
+
+
+ <!--
+ ///////////////////////////////////////////////////////////////////////////////////////
+ //
+ // Individuals
+ //
+ ///////////////////////////////////////////////////////////////////////////////////////
+ -->
+
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#BeefIngredient -->
+
+ <MeatIngredient rdf:about="#BeefIngredient"/>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#ChickenIngredient -->
+
+ <MeatIngredient rdf:about="#ChickenIngredient"/>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#FishIngredient -->
+
+ <MeatIngredient rdf:about="#FishIngredient"/>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Gluten -->
+
+ <Allergen rdf:about="#Gluten"/>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Lactose -->
+
+ <Allergen rdf:about="#Lactose"/>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#LambIngredient -->
+
+ <MeatIngredient rdf:about="#LambIngredient"/>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#Nuts -->
+
+ <Allergen rdf:about="#Nuts"/>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/commerce.owl#sdfsdf -->
+
+ <Product rdf:about="#sdfsdf">
+ <hasInStock rdf:datatype="&xsd;int">1</hasInStock>
+ </Product>
+
+
+
+ <!--
+ ///////////////////////////////////////////////////////////////////////////////////////
+ //
+ // General axioms
+ //
+ ///////////////////////////////////////////////////////////////////////////////////////
+ -->
+
+ <rdf:Description>
+ <rdf:type rdf:resource="&owl;AllDifferent"/>
+ <owl:distinctMembers rdf:parseType="Collection">
+ <rdf:Description rdf:about="#BeefIngredient"/>
+ <rdf:Description rdf:about="#LambIngredient"/>
+ <rdf:Description rdf:about="#Gluten"/>
+ <rdf:Description rdf:about="#ChickenIngredient"/>
+ <rdf:Description rdf:about="#FishIngredient"/>
+ <rdf:Description rdf:about="#Nuts"/>
+ <rdf:Description rdf:about="#Lactose"/>
+ </owl:distinctMembers>
+ </rdf:Description>
+</rdf:RDF>
Added: trunk/applications/jasdl-owlapi/examples/commerce/onts/society.owl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/onts/society.owl (rev 0)
+++ trunk/applications/jasdl-owlapi/examples/commerce/onts/society.owl 2008-04-18 18:18:50 UTC (rev 1223)
@@ -0,0 +1,251 @@
+<?xml version="1.0"?>
+
+
+<!DOCTYPE rdf:RDF [
+ <!ENTITY owl "http://www.w3.org/2002/07/owl#" >
+ <!ENTITY owl11 "http://www.w3.org/2006/12/owl11#" >
+ <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
+ <!ENTITY owl11xml "http://www.w3.org/2006/12/owl11-xml#" >
+ <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
+ <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
+ <!ENTITY society "http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#" >
+]>
+
+
+<rdf:RDF xmlns="http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#"
+ xml:base="http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl"
+ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+ xmlns:owl11="http://www.w3.org/2006/12/owl11#"
+ xmlns:owl11xml="http://www.w3.org/2006/12/owl11-xml#"
+ xmlns:society="http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#"
+ xmlns:owl="http://www.w3.org/2002/07/owl#"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <owl:Ontology rdf:about=""/>
+
+
+
+ <!--
+ ///////////////////////////////////////////////////////////////////////////////////////
+ //
+ // Object Properties
+ //
+ ///////////////////////////////////////////////////////////////////////////////////////
+ -->
+
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#employs -->
+
+ <owl:ObjectProperty rdf:about="#employs">
+ <rdf:type rdf:resource="&owl;InverseFunctionalProperty"/>
+ <rdfs:domain rdf:resource="#Agent"/>
+ <rdfs:range rdf:resource="#Agent"/>
+ </owl:ObjectProperty>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#isEmployedBy -->
+
+ <owl:ObjectProperty rdf:about="#isEmployedBy">
+ <rdf:type rdf:resource="&owl;FunctionalProperty"/>
+ <rdfs:domain rdf:resource="#Agent"/>
+ <rdfs:range rdf:resource="#Agent"/>
+ <owl:inverseOf rdf:resource="#employs"/>
+ </owl:ObjectProperty>
+
+
+
+ <!--
+ ///////////////////////////////////////////////////////////////////////////////////////
+ //
+ // Data properties
+ //
+ ///////////////////////////////////////////////////////////////////////////////////////
+ -->
+
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#isBusy -->
+
+ <owl:DatatypeProperty rdf:about="#isBusy">
+ <rdf:type rdf:resource="&owl;FunctionalProperty"/>
+ <rdfs:range rdf:resource="&xsd;int"/>
+ </owl:DatatypeProperty>
+
+
+
+ <!--
+ ///////////////////////////////////////////////////////////////////////////////////////
+ //
+ // Classes
+ //
+ ///////////////////////////////////////////////////////////////////////////////////////
+ -->
+
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#Agent -->
+
+ <owl:Class rdf:about="#Agent">
+ <rdfs:subClassOf rdf:resource="&owl;Thing"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#Customer -->
+
+ <owl:Class rdf:about="#Customer">
+ <rdfs:subClassOf rdf:resource="#Agent"/>
+ <owl:disjointWith rdf:resource="#DeliveryVan"/>
+ <owl:disjointWith rdf:resource="#PA"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#DeliveryVan -->
+
+ <owl:Class rdf:about="#DeliveryVan">
+ <rdfs:subClassOf rdf:resource="#Agent"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#PA -->
+
+ <owl:Class rdf:about="#PA">
+ <rdfs:subClassOf rdf:resource="#Agent"/>
+ <owl:disjointWith rdf:resource="#DeliveryVan"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#Shop -->
+
+ <owl:Class rdf:about="#Shop">
+ <rdfs:subClassOf rdf:resource="#Agent"/>
+ <owl:disjointWith rdf:resource="#Customer"/>
+ <owl:disjointWith rdf:resource="#DeliveryVan"/>
+ <owl:disjointWith rdf:resource="#PA"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#Tesco -->
+
+ <owl:Class rdf:about="#Tesco">
+ <rdfs:subClassOf rdf:resource="#Shop"/>
+ </owl:Class>
+
+
+
+ <!-- http://www.w3.org/2002/07/owl#Thing -->
+
+ <owl:Class rdf:about="&owl;Thing"/>
+
+
+
+ <!--
+ ///////////////////////////////////////////////////////////////////////////////////////
+ //
+ // Individuals
+ //
+ ///////////////////////////////////////////////////////////////////////////////////////
+ -->
+
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#customer1 -->
+
+ <Customer rdf:about="#customer1">
+ <employs rdf:resource="#pa1"/>
+ </Customer>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#customer2 -->
+
+ <Customer rdf:about="#customer2">
+ <employs rdf:resource="#pa2"/>
+ </Customer>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#customer3 -->
+
+ <Customer rdf:about="#customer3">
+ <employs rdf:resource="#pa3"/>
+ </Customer>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#delivery_van1 -->
+
+ <DeliveryVan rdf:about="#delivery_van1">
+ <isBusy rdf:datatype="&xsd;int">0</isBusy>
+ </DeliveryVan>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#delivery_van2 -->
+
+ <DeliveryVan rdf:about="#delivery_van2">
+ <isBusy rdf:datatype="&xsd;int">0</isBusy>
+ <isEmployedBy rdf:resource="#shop1"/>
+ </DeliveryVan>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#pa1 -->
+
+ <PA rdf:about="#pa1"/>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#pa2 -->
+
+ <PA rdf:about="#pa2"/>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#pa3 -->
+
+ <PA rdf:about="#pa3"/>
+
+
+
+ <!-- http://www.dur.ac.uk/t.g.klapiscak/onts/society.owl#shop1 -->
+
+ <Tesco rdf:about="#shop1">
+ <employs rdf:resource="#delivery_van1"/>
+ </Tesco>
+
+
+
+ <!--
+ ///////////////////////////////////////////////////////////////////////////////////////
+ //
+ // General axioms
+ //
+ ///////////////////////////////////////////////////////////////////////////////////////
+ -->
+
+ <rdf:Description>
+ <rdf:type rdf:resource="&owl;AllDifferent"/>
+ <owl:distinctMembers rdf:parseType="Collection">
+ <rdf:Description rdf:about="#pa2"/>
+ <rdf:Description rdf:about="#shop1"/>
+ <rdf:Description rdf:about="#pa1"/>
+ <rdf:Description rdf:about="#customer2"/>
+ <rdf:Description rdf:about="#customer1"/>
+ <rdf:Description rdf:about="#delivery_van2"/>
+ <rdf:Description rdf:about="#delivery_van1"/>
+ <rdf:Description rdf:about="#customer3"/>
+ <rdf:Description rdf:about="#pa3"/>
+ </owl:distinctMembers>
+ </rdf:Description>
+</rdf:RDF>
Property changes on: trunk/applications/jasdl-owlapi/examples/commerce/src/asl/common
___________________________________________________________________
Name: svn:ignore
+ Copy of sync_kqml.asl
Added: trunk/applications/jasdl-owlapi/examples/commerce/src/asl/common/society.asl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/src/asl/common/society.asl (rev 0)
+++ trunk/applications/jasdl-owlapi/examples/commerce/src/asl/common/society.asl 2008-04-18 18:18:50 UTC (rev 1223)
@@ -0,0 +1,9 @@
+/*
+ * PA is employed by a single customer (enforced by the fact that employs is inverse functional - and isEmployedBy is functional)
+ * Unfortunately, since employs has an inverse property, it cannot also be transitive
+ */
+
+ // Using SE-Literals in rules.
+ // In this case essentially grounding the domain of an object property with a commonly used value (i.e. my name)
+isEmployedBy(Employer) :- .my_name(Me) & isEmployedBy(Me, Employer)[o(s)].
+employs(Employee) :- .my_name(Me) & employs(Me, Employee)[o(s)].
Added: trunk/applications/jasdl-owlapi/examples/commerce/src/asl/customer.asl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/src/asl/customer.asl (rev 0)
+++ trunk/applications/jasdl-owlapi/examples/commerce/src/asl/customer.asl 2008-04-18 18:18:50 UTC (rev 1223)
@@ -0,0 +1,41 @@
+{include("common/society.asl")}
+
+/* Orders specified incrementally and tracked by PA. Allows real-time feedback about e.g. product availability
+ * Notice that ontology and syntactic translation is providing a well-defined shared vocabulary between agents.
+ * Note with an accurate ontology alignment our agents could communicate even without prior agreement on terms.
+ * - the structural information in the ontology gives us a richer palette for semantic matching over and above that available through
+ * e.g. synonym matching.
+ * Assuming central repository of agents and their types (society.owl schema)
+ */
+
+!behave.
+
+ // need to use SE-Literals to take advantage of syntactic translation
++!behave
+ <-
+ .random(Rand);
+ .wait(Rand*2000);
+
+ .my_name(Me);
+ jasdl.ia.define_class(employedPA, "s:pA and s:isEmployedBy value s:", Me);
+ ?employedPA(PA)[o(self)];
+ !order(PA, Me, bread(_)[o(c)], 1);
+ !order(PA, Me, milk(_)[o(c)], 1);
+ !order(PA, Me, bread(hovis)[o(c)], 1);
+ .send(PA, achieve, confirm_order(Me)).
+
+
++!order(PA, Order, Product, Qty)
+ <-
+ .send(PA, achieve, order(Order, Product, Qty));
+ Confirmed = confirmed(Order, Brand, Qty)[source(PA)];
+ .concat("+", Confirmed, WaitConfirmed); .wait(WaitConfirmed);
+ -Confirmed.
+
++order_complete(Order)[source(Shop)]
+ <-
+ -order_complete(Order)[source(Shop)];
+ !behave.
+
+
+
Added: trunk/applications/jasdl-owlapi/examples/commerce/src/asl/delivery_van.asl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/src/asl/delivery_van.asl (rev 0)
+++ trunk/applications/jasdl-owlapi/examples/commerce/src/asl/delivery_van.asl 2008-04-18 18:18:50 UTC (rev 1223)
@@ -0,0 +1,51 @@
+{include("common/society.asl")}
+
+!init.
+
++!init
+ <-
+ .my_name(Me);
+ ?isEmployedBy(Me, Employer)[o(s)];
+ .send(Employer, tell, available(Me)).
+
+
++!hasPosition(Me, X, Y)[source(Employer)] : .my_name(Me) & hasPosition(Me, X, Y) & isEmployedBy(Employer)
+ <-
+ .send(Employer, tell, hasPosition(Me, X, Y)).
+
++!hasPosition(Me, X, Y)[source(Employer)] :
+ .my_name(Me) &
+ not hasPosition(Me, X, Y) & // Destination must be specified
+ isEmployedBy(Employer)
+ <-
+ move_towards(X, Y);
+ .wait(10); // <- simulate movement speed
+ !!hasPosition(Me, X, Y)[source(Employer)].
+
+@load_all_2[atomic]
++!load([])[source(Employer)]
+ <-
+ .send(Employer, tell, loading_complete).
+
+@load_all_1[atomic]
++!load([Purchase|Purchases])[source(Employer)] :
+ isEmployedBy(Employer)
+ <-
+ load(Purchase); // Load purchase
+ !!load(Purchases)[source(Employer)].
+
+@unload_all_2[atomic]
++!unload([])[source(Employer)]
+ <-
+ .send(Employer, tell, unloading_complete).
+
+@unload_all_1[atomic]
++!unload([Purchase|Purchases])[source(Employer)] :
+ isEmployedBy(Employer)
+ <-
+ unload(Purchase); // Unload purchase
+ !!unload(Purchases)[source(Employer)]. // Unload remaining purchases
+
++?~cargo(Purchase) : not cargo(Purchase). // (not cargo) implies ~cargo for the delivery van
+
+
Added: trunk/applications/jasdl-owlapi/examples/commerce/src/asl/pa.asl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/src/asl/pa.asl (rev 0)
+++ trunk/applications/jasdl-owlapi/examples/commerce/src/asl/pa.asl 2008-04-18 18:18:50 UTC (rev 1223)
@@ -0,0 +1,31 @@
+{include("common/society.asl")}
+
+
+
++!order(Order, Product, Qty)[source(Employer)] : isEmployedBy(Employer)
+ <-
+ ?shop(Shop)[o(s)];
+ jasdl.ia.send(Shop, askOne, hasOrder(Employer, Order)[o(c)], hasOrder(Employer, Order)[o(c)]);
+ // get me a brand that is in stock
+ jasdl.ia.get_class_definition(Product, ProductDefinition);
+ jasdl.ia.define_class(productInStock, ProductDefinition);//, " and (c:hasInStock some integer [>= ",Qty ," ])");
+ jasdl.ia.send(Shop, askOne, productInStock(Brand)[o(self)], product(Brand)[o(c)]);
+ .print("Brand name: ", Brand);
+ /* Check against medical requirements of customer */
+ .send(Shop, achieve, add_to_order(Order, Brand, Qty));
+ Confirmed = confirmed(Order, Brand, Qty)[source(Shop)];
+ .concat("+", Confirmed, WaitConfirmed); .wait(WaitConfirmed);
+ -Confirmed;
+ .send(Employer, tell, Confirmed).
+
+
++!confirm_order(Order)[source(Employer)] : isEmployedBy(Employer)
+ <-
+ ?shop(Shop)[o(s)];
+ .send(Shop, achieve, confirm_order(Order)).
+
+
+
+
+
+
Added: trunk/applications/jasdl-owlapi/examples/commerce/src/asl/shop1.asl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/commerce/src/asl/shop1.asl (rev 0)
+++ trunk/applications/jasdl-owlapi/examples/commerce/src/asl/shop1.asl 2008-04-18 18:18:50 UTC (rev 1223)
@@ -0,0 +1,183 @@
+{include("common/society.asl")}
+
+/* Product catalogue could be specified in a file and imported at run-time */
+
+
+
++!add_to_order(Order, Brand, Qty)[source(PA)] :
+ product(Brand)[o(c)] & // check known product brand
+ hasCustomer(Order, Customer)[o(c)] & employs(Customer, PA)[o(s)] & // check PA is authorised to speak on behalf of customer whose order it is
+ hasInStock(Brand, StockLevel)[o(c)] & StockLevel>=Qty // check we have enough stock
+ <-
+
+ // get a unique purch...
[truncated message content] |
|
From: <jom...@us...> - 2008-04-18 17:41:27
|
Revision: 1222
http://jason.svn.sourceforge.net/jason/?rev=1222&view=rev
Author: jomifred
Date: 2008-04-18 10:41:10 -0700 (Fri, 18 Apr 2008)
Log Message:
-----------
fix bug in return of ? and !
Modified Paths:
--------------
trunk/applications/as-unit-test/src/jason/asunit/TestArch.java
trunk/applications/as-unit-test/src/jason/tests/TestAll.java
trunk/release-notes.txt
trunk/src/jason/asSemantics/VarsCluster.java
trunk/src/jason/asSyntax/PlanBodyImpl.java
Added Paths:
-----------
trunk/applications/as-unit-test/src/jason/tests/BugListReturnUnification.java
Modified: trunk/applications/as-unit-test/src/jason/asunit/TestArch.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/asunit/TestArch.java 2008-04-18 16:10:08 UTC (rev 1221)
+++ trunk/applications/as-unit-test/src/jason/asunit/TestArch.java 2008-04-18 17:41:10 UTC (rev 1222)
@@ -93,7 +93,7 @@
}
public void print(String s) {
- //System.out.println(s);
+ System.out.println(s);
output.append(s+"\n");
}
Added: trunk/applications/as-unit-test/src/jason/tests/BugListReturnUnification.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/BugListReturnUnification.java (rev 0)
+++ trunk/applications/as-unit-test/src/jason/tests/BugListReturnUnification.java 2008-04-18 17:41:10 UTC (rev 1222)
@@ -0,0 +1,37 @@
+package jason.tests;
+
+import jason.asunit.TestAgent;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class BugListReturnUnification {
+
+ TestAgent ag;
+
+ @Before
+ public void setupAg() {
+ ag = new TestAgent();
+ ag.setDebugMode(true);
+
+ // defines the agent's AgentSpeak code
+ ag.parseAScode(
+ "+!test1 <- L=[A,B]; ?bundle(L); jason.asunit.print(L). "+
+ "+?bundle([]). "+
+ "+?bundle([a|T]) <- ?bundle(T). "+
+
+ "+!test2 <- L=[A,B,C,D]; !bundle(L); jason.asunit.print(L). "+
+ "+!bundle([]). "+
+ "+!bundle([a|T]) <- !bundle(T). "
+ );
+ }
+
+ @Test
+ public void testContext() {
+ ag.addGoal("test1");
+ ag.assertPrint("[a,a]", 10);
+ ag.addGoal("test2");
+ ag.assertPrint("[a,a,a,a]", 10);
+ }
+
+}
Modified: trunk/applications/as-unit-test/src/jason/tests/TestAll.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2008-04-18 16:10:08 UTC (rev 1221)
+++ trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2008-04-18 17:41:10 UTC (rev 1222)
@@ -6,6 +6,7 @@
@RunWith(Suite.class)
@SuiteClasses({
+ BugListReturnUnification.class,
BugVarsInInitBels.class,
TestAddLogExprInBB.class,
TestGoalSource.class,
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2008-04-18 16:10:08 UTC (rev 1221)
+++ trunk/release-notes.txt 2008-04-18 17:41:10 UTC (rev 1222)
@@ -12,6 +12,7 @@
. add "source(self)" in goals without source
. correctly handle failure event caused by no relevant plans
. timeout in .wait does not cause a runtime exception
+. unification in return of ! and ?
-------------
Modified: trunk/src/jason/asSemantics/VarsCluster.java
===================================================================
--- trunk/src/jason/asSemantics/VarsCluster.java 2008-04-18 16:10:08 UTC (rev 1221)
+++ trunk/src/jason/asSemantics/VarsCluster.java 2008-04-18 17:41:10 UTC (rev 1222)
@@ -67,7 +67,7 @@
this.u = u;
}
- protected VarsCluster(VarTerm v1, VarTerm v2, Unifier u) {
+ public VarsCluster(VarTerm v1, VarTerm v2, Unifier u) {
id = ++idCount;
this.u = u;
add(v1);
Modified: trunk/src/jason/asSyntax/PlanBodyImpl.java
===================================================================
--- trunk/src/jason/asSyntax/PlanBodyImpl.java 2008-04-18 16:10:08 UTC (rev 1221)
+++ trunk/src/jason/asSyntax/PlanBodyImpl.java 2008-04-18 17:41:10 UTC (rev 1222)
@@ -184,15 +184,14 @@
public Term removeBody(int index) {
if (index == 0) {
+ Term oldvalue = term;
if (next == null) {
term = null; // becomes an empty
} else {
- Term oldvalue = term;
swap(next); // get values of text
next = next.getBodyNext();
- return oldvalue;
}
- return this;
+ return oldvalue;
} else {
return next.removeBody(index - 1);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-04-18 16:10:18
|
Revision: 1221
http://jason.svn.sourceforge.net/jason/?rev=1221&view=rev
Author: jomifred
Date: 2008-04-18 09:10:08 -0700 (Fri, 18 Apr 2008)
Log Message:
-----------
fix bug in .wait
Modified Paths:
--------------
trunk/release-notes.txt
trunk/src/jason/asSemantics/Agent.java
trunk/src/jason/asSemantics/IntendedMeans.java
trunk/src/jason/asSemantics/Unifier.java
trunk/src/jason/asSemantics/VarsCluster.java
trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
trunk/src/jason/asSyntax/parser/as2j.java
trunk/src/jason/stdlib/wait.java
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2008-04-17 21:52:42 UTC (rev 1220)
+++ trunk/release-notes.txt 2008-04-18 16:10:08 UTC (rev 1221)
@@ -11,6 +11,7 @@
. use nested source annotations in communication
. add "source(self)" in goals without source
. correctly handle failure event caused by no relevant plans
+. timeout in .wait does not cause a runtime exception
-------------
Modified: trunk/src/jason/asSemantics/Agent.java
===================================================================
--- trunk/src/jason/asSemantics/Agent.java 2008-04-17 21:52:42 UTC (rev 1220)
+++ trunk/src/jason/asSemantics/Agent.java 2008-04-18 16:10:08 UTC (rev 1221)
@@ -252,10 +252,10 @@
try {
// check if the class has "create" method -- singleton implementation
Method create = iaclass.getMethod("create", (Class[])null);
- return (InternalAction)create.invoke(null, (Object[])null);
- } catch (Exception e) {}
-
- objIA = (InternalAction)iaclass.newInstance();
+ objIA = (InternalAction)create.invoke(null, (Object[])null);
+ } catch (Exception e) {
+ objIA = (InternalAction)iaclass.newInstance();
+ }
internalActions.put(iaName, objIA);
}
return objIA;
Modified: trunk/src/jason/asSemantics/IntendedMeans.java
===================================================================
--- trunk/src/jason/asSemantics/IntendedMeans.java 2008-04-17 21:52:42 UTC (rev 1220)
+++ trunk/src/jason/asSemantics/IntendedMeans.java 2008-04-18 16:10:08 UTC (rev 1221)
@@ -90,6 +90,10 @@
return plan;
}
+ public void setUnif(Unifier unif) {
+ this.unif = unif;
+ }
+
public Unifier getUnif() {
return unif;
}
Modified: trunk/src/jason/asSemantics/Unifier.java
===================================================================
--- trunk/src/jason/asSemantics/Unifier.java 2008-04-17 21:52:42 UTC (rev 1220)
+++ trunk/src/jason/asSemantics/Unifier.java 2008-04-18 16:10:08 UTC (rev 1221)
@@ -41,7 +41,7 @@
private static Logger logger = Logger.getLogger(Unifier.class.getName());
- private HashMap<VarTerm, Term> function = new HashMap<VarTerm, Term>();
+ protected HashMap<VarTerm, Term> function = new HashMap<VarTerm, Term>();
/**
* @deprecated use t.apply(un) instead.
@@ -165,7 +165,7 @@
// ----- Unify for Terms
- private boolean unifyTerms(Term t1g, Term t2g) {
+ protected boolean unifyTerms(Term t1g, Term t2g) {
// if args are expressions, apply them and use their values
if (t1g.isArithExpr()) {
t1g = (Term) t1g.clone();
@@ -303,7 +303,7 @@
return true;
}
- private boolean setVarValue(VarTerm vt, Term value) {
+ protected boolean setVarValue(VarTerm vt, Term value) {
// if the var has a cluster, set value for all cluster
Term currentVl = function.get(vt);
if (currentVl != null && currentVl instanceof VarsCluster) {
Modified: trunk/src/jason/asSemantics/VarsCluster.java
===================================================================
--- trunk/src/jason/asSemantics/VarsCluster.java 2008-04-17 21:52:42 UTC (rev 1220)
+++ trunk/src/jason/asSemantics/VarsCluster.java 2008-04-18 16:10:08 UTC (rev 1221)
@@ -63,11 +63,11 @@
private Unifier u;
// used in clone
- private VarsCluster(Unifier u) {
+ protected VarsCluster(Unifier u) {
this.u = u;
}
- VarsCluster(VarTerm v1, VarTerm v2, Unifier u) {
+ protected VarsCluster(VarTerm v1, VarTerm v2, Unifier u) {
id = ++idCount;
this.u = u;
add(v1);
@@ -104,7 +104,7 @@
return false;
}
- boolean hasValue() {
+ public boolean hasValue() {
return vars != null && !vars.isEmpty();
}
Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
===================================================================
--- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2008-04-17 21:52:42 UTC (rev 1220)
+++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2008-04-18 16:10:08 UTC (rev 1221)
@@ -409,7 +409,7 @@
return new InternalActionLiteral(F, curAg);
} catch (Exception e) {
if (getArithFunction(F) == null) // it is not a registered function
- throw new ParseException(getSourceRef(F)+" The internal action class for '"+F+"' was not found!");
+ logger.warning(getSourceRef(F)+" The internal action class for '"+F+"' was not found!");
}
}
return new Literal(type,F);
Modified: trunk/src/jason/asSyntax/parser/as2j.java
===================================================================
--- trunk/src/jason/asSyntax/parser/as2j.java 2008-04-17 21:52:42 UTC (rev 1220)
+++ trunk/src/jason/asSyntax/parser/as2j.java 2008-04-18 16:10:08 UTC (rev 1221)
@@ -555,7 +555,7 @@
{if (true) return new InternalActionLiteral(F, curAg);}
} catch (Exception e) {
if (getArithFunction(F) == null) // it is not a registered function
- {if (true) throw new ParseException(getSourceRef(F)+" The internal action class for '"+F+"' was not found!");}
+ logger.warning(getSourceRef(F)+" The internal action class for '"+F+"' was not found!");
}
}
{if (true) return new Literal(type,F);}
Modified: trunk/src/jason/stdlib/wait.java
===================================================================
--- trunk/src/jason/stdlib/wait.java 2008-04-17 21:52:42 UTC (rev 1220)
+++ trunk/src/jason/stdlib/wait.java 2008-04-18 16:10:08 UTC (rev 1221)
@@ -31,8 +31,9 @@
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Atom;
+import jason.asSyntax.InternalActionLiteral;
+import jason.asSyntax.NumberTerm;
import jason.asSyntax.PlanBodyImpl;
-import jason.asSyntax.NumberTerm;
import jason.asSyntax.StringTerm;
import jason.asSyntax.Term;
import jason.asSyntax.Trigger;
@@ -176,7 +177,7 @@
si.peek().removeCurrentStep();
if (stopByTimeout && te != null) {
// fail the .wait
- si.peek().getPlan().getBody().add(0, new PlanBodyImpl(BodyType.internalAction, new Atom(".fail")));
+ si.peek().getPlan().getBody().add(0, new PlanBodyImpl(BodyType.internalAction, new InternalActionLiteral(".fail")));
}
if (si.isSuspended()) { // if the intention was suspended by .suspend
String k = suspend.SUSPENDED_INT+si.getId();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-04-17 21:52:47
|
Revision: 1220
http://jason.svn.sourceforge.net/jason/?rev=1220&view=rev
Author: jomifred
Date: 2008-04-17 14:52:42 -0700 (Thu, 17 Apr 2008)
Log Message:
-----------
allows singletons internal actions
Modified Paths:
--------------
trunk/applications/as-unit-test/src/jason/asunit/print.java
trunk/applications/as-unit-test/src/jason/tests/TestIF.java
trunk/examples/domestic-robot/HouseEnv.java
trunk/src/jason/asSemantics/Agent.java
trunk/src/jason/asSyntax/PlanBodyImpl.java
trunk/src/jason/stdlib/add_annot.java
trunk/src/jason/stdlib/add_nested_source.java
trunk/src/jason/stdlib/atom.java
trunk/src/jason/stdlib/concat.java
trunk/src/jason/stdlib/conditional.java
trunk/src/jason/stdlib/date.java
trunk/src/jason/stdlib/delete.java
trunk/src/jason/stdlib/difference.java
trunk/src/jason/stdlib/fail.java
trunk/src/jason/stdlib/ground.java
trunk/src/jason/stdlib/intersection.java
trunk/src/jason/stdlib/length.java
trunk/src/jason/stdlib/list.java
trunk/src/jason/stdlib/literal.java
trunk/src/jason/stdlib/max.java
trunk/src/jason/stdlib/member.java
trunk/src/jason/stdlib/min.java
trunk/src/jason/stdlib/my_name.java
trunk/src/jason/stdlib/nth.java
trunk/src/jason/stdlib/number.java
trunk/src/jason/stdlib/plan_label.java
trunk/src/jason/stdlib/print.java
trunk/src/jason/stdlib/println.java
trunk/src/jason/stdlib/random.java
trunk/src/jason/stdlib/reverse.java
trunk/src/jason/stdlib/sort.java
trunk/src/jason/stdlib/string.java
trunk/src/jason/stdlib/structure.java
trunk/src/jason/stdlib/substring.java
trunk/src/jason/stdlib/time.java
trunk/src/jason/stdlib/union.java
Modified: trunk/applications/as-unit-test/src/jason/asunit/print.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/asunit/print.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/applications/as-unit-test/src/jason/asunit/print.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -1,5 +1,6 @@
package jason.asunit;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Term;
@@ -7,6 +8,10 @@
public class print extends println {
+ public static InternalAction create() {
+ return new print();
+ }
+
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
TestArch arch = (TestArch)ts.getUserAgArch().getArchInfraTier();
Modified: trunk/applications/as-unit-test/src/jason/tests/TestIF.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestIF.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/applications/as-unit-test/src/jason/tests/TestIF.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -18,7 +18,7 @@
ag.parseAScode(
"b(3). " +
"+!test1 <- a1; "+
- " .conditional(b(X), {jason.asunit.print(X); b1}, {jason.asunit.print(no);b2}); "+
+ " .if( b(X), {jason.asunit.print(X); b1}, {jason.asunit.print(no)}); "+
" a2. "+
"+!test2 <- -b(_); !test1. "
);
@@ -36,7 +36,6 @@
public void test2() {
ag.addGoal("test2");
ag.assertPrint("no", 5);
- ag.assertAct("b2", 5);
ag.assertAct("a2", 5);
}
}
Modified: trunk/examples/domestic-robot/HouseEnv.java
===================================================================
--- trunk/examples/domestic-robot/HouseEnv.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/examples/domestic-robot/HouseEnv.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -62,7 +62,7 @@
@Override
public boolean executeAction(String ag, Structure action) {
- logger.fine("Agent "+ag+" doing "+action+" in the environment");
+ System.out.println("["+ag+"] doing: "+action);
boolean result = false;
if (action.equals(of)) { // of = open(fridge)
result = model.openFridge();
Modified: trunk/src/jason/asSemantics/Agent.java
===================================================================
--- trunk/src/jason/asSemantics/Agent.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/asSemantics/Agent.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -44,6 +44,7 @@
import jason.functions.Count;
import jason.functions.RuleToFunction;
import jason.runtime.Settings;
+import jason.stdlib.conditional;
import java.io.File;
import java.io.FileInputStream;
@@ -238,14 +239,24 @@
parser.agent(this);
}
- public InternalAction getIA(Structure action) throws Exception {
+ @SuppressWarnings("unchecked")
+ public InternalAction getIA(Structure action) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
String iaName = action.getFunctor();
+ if (iaName.equals(".if"))
+ return conditional.create();
if (iaName.charAt(0) == '.')
iaName = "jason.stdlib" + iaName;
InternalAction objIA = internalActions.get(iaName);
if (objIA == null) {
- objIA = (InternalAction) Class.forName(iaName).newInstance();
- internalActions.put(iaName, objIA);
+ Class iaclass = Class.forName(iaName);
+ try {
+ // check if the class has "create" method -- singleton implementation
+ Method create = iaclass.getMethod("create", (Class[])null);
+ return (InternalAction)create.invoke(null, (Object[])null);
+ } catch (Exception e) {}
+
+ objIA = (InternalAction)iaclass.newInstance();
+ internalActions.put(iaName, objIA);
}
return objIA;
}
Modified: trunk/src/jason/asSyntax/PlanBodyImpl.java
===================================================================
--- trunk/src/jason/asSyntax/PlanBodyImpl.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/asSyntax/PlanBodyImpl.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -171,12 +171,11 @@
public boolean add(int index, PlanBody bl) {
if (index == 0) {
+ PlanBody newpb = new PlanBodyImpl(this.formType, this.term);
+ newpb.setBodyNext(next);
swap(bl);
- PlanBody bak = this.next;
this.next = bl.getBodyNext();
- PlanBody last = bl.getLastBody();
- bl.setBodyNext(bak);
- last.setBodyNext(bl);
+ this.getLastBody().setBodyNext(newpb);
} else if (next != null) {
next.add(index - 1, bl);
}
Modified: trunk/src/jason/stdlib/add_annot.java
===================================================================
--- trunk/src/jason/stdlib/add_annot.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/add_annot.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -26,6 +26,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.ListTerm;
@@ -70,6 +71,13 @@
*/
public class add_annot extends DefaultInternalAction {
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new add_annot();
+ return singleton;
+ }
+
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
try {
Modified: trunk/src/jason/stdlib/add_nested_source.java
===================================================================
--- trunk/src/jason/stdlib/add_nested_source.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/add_nested_source.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -26,6 +26,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.ListTerm;
@@ -71,7 +72,14 @@
*/
public class add_nested_source extends DefaultInternalAction {
- @Override
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new add_nested_source();
+ return singleton;
+ }
+
+ @Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
try {
Term result = addAnnotToList(un, args[0], (Structure)args[1].clone());
Modified: trunk/src/jason/stdlib/atom.java
===================================================================
--- trunk/src/jason/stdlib/atom.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/atom.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -2,6 +2,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Term;
@@ -40,7 +41,14 @@
*/
public class atom extends DefaultInternalAction {
- @Override
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new atom();
+ return singleton;
+ }
+
+ @Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
try {
return args[0].isAtom();
Modified: trunk/src/jason/stdlib/concat.java
===================================================================
--- trunk/src/jason/stdlib/concat.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/concat.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -25,6 +25,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.ListTerm;
@@ -69,6 +70,13 @@
*/
public class concat extends DefaultInternalAction {
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new concat();
+ return singleton;
+ }
+
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Modified: trunk/src/jason/stdlib/conditional.java
===================================================================
--- trunk/src/jason/stdlib/conditional.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/conditional.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -28,6 +28,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
import jason.asSemantics.IntendedMeans;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.LogicalFormula;
@@ -35,9 +36,15 @@
import jason.asSyntax.Term;
// TODO: comments
-// TODO: find a way to change the name of the IA to .if
public class conditional extends DefaultInternalAction {
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new conditional();
+ return singleton;
+ }
+
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
try {
@@ -48,19 +55,18 @@
PlanBody whattoadd = null;
Iterator<Unifier> iu = logExpr.logicalConsequence(ts.getAg(), un);
- if (iu.hasNext()) {
- // THEN
+ if (iu.hasNext()) { // .if THEN
+ if ( !args[1].isPlanBody())
+ throw new JasonException("The second argument of .if must be a plan body term.");
+ whattoadd = (PlanBody)args[1];
un.compose(iu.next());
- whattoadd = (PlanBody)args[1];
- } else if (args.length == 3) {
- // ELSE
+ } else if (args.length == 3) { // .if ELSE
+ if ( !args[2].isPlanBody())
+ throw new JasonException("The third argument of .if must be a plan body term.");
whattoadd = (PlanBody)args[2];
}
if (whattoadd != null) {
- if ( !whattoadd.isPlanBody())
- throw new JasonException("The second and third arguments of .if must be a plan body term.");
-
IntendedMeans im = ts.getC().getSelectedIntention().peek();
PlanBody ifia = im.getCurrentStep();
whattoadd.setAsBodyTerm(false);
Modified: trunk/src/jason/stdlib/date.java
===================================================================
--- trunk/src/jason/stdlib/date.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/date.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -2,6 +2,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.NumberTermImpl;
@@ -38,7 +39,14 @@
*/
public class date extends DefaultInternalAction {
- /** date(YY,MM,DD) */
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new date();
+ return singleton;
+ }
+
+ /** date(YY,MM,DD) */
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
try {
Modified: trunk/src/jason/stdlib/delete.java
===================================================================
--- trunk/src/jason/stdlib/delete.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/delete.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -25,6 +25,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.ListTerm;
@@ -71,6 +72,13 @@
*/
public class delete extends DefaultInternalAction {
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new delete();
+ return singleton;
+ }
+
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
try {
Modified: trunk/src/jason/stdlib/difference.java
===================================================================
--- trunk/src/jason/stdlib/difference.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/difference.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -25,6 +25,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.ListTerm;
@@ -63,6 +64,13 @@
*/
public class difference extends DefaultInternalAction {
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new difference();
+ return singleton;
+ }
+
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Modified: trunk/src/jason/stdlib/fail.java
===================================================================
--- trunk/src/jason/stdlib/fail.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/fail.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -24,6 +24,7 @@
package jason.stdlib;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Term;
@@ -44,7 +45,14 @@
*/
public class fail extends DefaultInternalAction {
- @Override
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new fail();
+ return singleton;
+ }
+
+ @Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
return false;
}
Modified: trunk/src/jason/stdlib/ground.java
===================================================================
--- trunk/src/jason/stdlib/ground.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/ground.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -2,6 +2,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Term;
@@ -35,6 +36,13 @@
*/
public class ground extends DefaultInternalAction {
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new ground();
+ return singleton;
+ }
+
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
try {
Modified: trunk/src/jason/stdlib/intersection.java
===================================================================
--- trunk/src/jason/stdlib/intersection.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/intersection.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -25,6 +25,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.ListTerm;
@@ -63,6 +64,13 @@
*/
public class intersection extends DefaultInternalAction {
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new intersection();
+ return singleton;
+ }
+
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Modified: trunk/src/jason/stdlib/length.java
===================================================================
--- trunk/src/jason/stdlib/length.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/length.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -24,6 +24,7 @@
package jason.stdlib;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.ListTerm;
@@ -68,6 +69,13 @@
*/
public class length extends DefaultInternalAction {
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new length();
+ return singleton;
+ }
+
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Term l1 = args[0];
Modified: trunk/src/jason/stdlib/list.java
===================================================================
--- trunk/src/jason/stdlib/list.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/list.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -2,6 +2,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Term;
@@ -35,6 +36,13 @@
*/
public class list extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new list();
+ return singleton;
+ }
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Modified: trunk/src/jason/stdlib/literal.java
===================================================================
--- trunk/src/jason/stdlib/literal.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/literal.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -2,6 +2,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Term;
@@ -35,6 +36,13 @@
@see jason.stdlib.ground
*/
public class literal extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new literal();
+ return singleton;
+ }
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Modified: trunk/src/jason/stdlib/max.java
===================================================================
--- trunk/src/jason/stdlib/max.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/max.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -1,5 +1,6 @@
package jason.stdlib;
+import jason.asSemantics.InternalAction;
import jason.asSyntax.Term;
/**
@@ -52,6 +53,13 @@
*/
public class max extends min {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new max();
+ return singleton;
+ }
@Override
protected boolean compare(Term a, Term t) {
Modified: trunk/src/jason/stdlib/member.java
===================================================================
--- trunk/src/jason/stdlib/member.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/member.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -2,6 +2,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.ListTerm;
@@ -46,6 +47,13 @@
*/
public class member extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new member();
+ return singleton;
+ }
@Override
public Object execute(TransitionSystem ts, final Unifier un, Term[] args) throws Exception {
Modified: trunk/src/jason/stdlib/min.java
===================================================================
--- trunk/src/jason/stdlib/min.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/min.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -2,6 +2,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.ListTerm;
@@ -59,6 +60,13 @@
*/
public class min extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new min();
+ return singleton;
+ }
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Modified: trunk/src/jason/stdlib/my_name.java
===================================================================
--- trunk/src/jason/stdlib/my_name.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/my_name.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -25,6 +25,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Atom;
@@ -57,6 +58,13 @@
*/
public class my_name extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new my_name();
+ return singleton;
+ }
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Modified: trunk/src/jason/stdlib/nth.java
===================================================================
--- trunk/src/jason/stdlib/nth.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/nth.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -39,6 +39,13 @@
*/
public class nth extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new nth();
+ return singleton;
+ }
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Modified: trunk/src/jason/stdlib/number.java
===================================================================
--- trunk/src/jason/stdlib/number.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/number.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -2,6 +2,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Term;
@@ -32,6 +33,13 @@
*/
public class number extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new number();
+ return singleton;
+ }
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Modified: trunk/src/jason/stdlib/plan_label.java
===================================================================
--- trunk/src/jason/stdlib/plan_label.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/plan_label.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -25,6 +25,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Plan;
@@ -58,6 +59,13 @@
*/
public class plan_label extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new plan_label();
+ return singleton;
+ }
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Modified: trunk/src/jason/stdlib/print.java
===================================================================
--- trunk/src/jason/stdlib/print.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/print.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -58,6 +58,13 @@
*/
public class print extends println implements InternalAction {
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new println();
+ return singleton;
+ }
+
@Override
protected String getNewLine() {
return "";
Modified: trunk/src/jason/stdlib/println.java
===================================================================
--- trunk/src/jason/stdlib/println.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/println.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -23,6 +23,7 @@
package jason.stdlib;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.StringTerm;
@@ -43,6 +44,13 @@
*/
public class println extends DefaultInternalAction {
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new println();
+ return singleton;
+ }
+
protected String getNewLine() {
return "\n";
}
Modified: trunk/src/jason/stdlib/random.java
===================================================================
--- trunk/src/jason/stdlib/random.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/random.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -2,6 +2,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.NumberTermImpl;
@@ -28,6 +29,13 @@
*/
public class random extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new random();
+ return singleton;
+ }
private Random random = new Random();
Modified: trunk/src/jason/stdlib/reverse.java
===================================================================
--- trunk/src/jason/stdlib/reverse.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/reverse.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -25,6 +25,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.ListTerm;
@@ -64,6 +65,13 @@
*/
public class reverse extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new reverse();
+ return singleton;
+ }
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Modified: trunk/src/jason/stdlib/sort.java
===================================================================
--- trunk/src/jason/stdlib/sort.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/sort.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -26,6 +26,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.ListTerm;
@@ -81,6 +82,13 @@
*/
public class sort extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new sort();
+ return singleton;
+ }
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Modified: trunk/src/jason/stdlib/string.java
===================================================================
--- trunk/src/jason/stdlib/string.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/string.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -2,6 +2,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Term;
@@ -31,6 +32,13 @@
*/
public class string extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new string();
+ return singleton;
+ }
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Modified: trunk/src/jason/stdlib/structure.java
===================================================================
--- trunk/src/jason/stdlib/structure.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/structure.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -2,6 +2,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Term;
@@ -36,6 +37,13 @@
*/
public class structure extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new structure();
+ return singleton;
+ }
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Modified: trunk/src/jason/stdlib/substring.java
===================================================================
--- trunk/src/jason/stdlib/substring.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/substring.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -5,6 +5,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.NumberTermImpl;
@@ -44,6 +45,13 @@
*/
public class substring extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new substring();
+ return singleton;
+ }
@Override
public Object execute(TransitionSystem ts, final Unifier un, final Term[] args) throws Exception {
Modified: trunk/src/jason/stdlib/time.java
===================================================================
--- trunk/src/jason/stdlib/time.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/time.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -2,6 +2,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.NumberTermImpl;
@@ -38,6 +39,13 @@
*/
public class time extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new time();
+ return singleton;
+ }
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Modified: trunk/src/jason/stdlib/union.java
===================================================================
--- trunk/src/jason/stdlib/union.java 2008-04-17 17:34:11 UTC (rev 1219)
+++ trunk/src/jason/stdlib/union.java 2008-04-17 21:52:42 UTC (rev 1220)
@@ -25,6 +25,7 @@
import jason.JasonException;
import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.ListTerm;
@@ -61,6 +62,13 @@
@see jason.stdlib.intersection
*/
public class union extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new union();
+ return singleton;
+ }
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-04-17 17:34:18
|
Revision: 1219
http://jason.svn.sourceforge.net/jason/?rev=1219&view=rev
Author: jomifred
Date: 2008-04-17 10:34:11 -0700 (Thu, 17 Apr 2008)
Log Message:
-----------
plans body as term
first implementation (experimental) of .if internal action
Modified Paths:
--------------
trunk/applications/as-unit-test/src/jason/tests/TestAll.java
trunk/applications/as-unit-test/src/jason/tests/TestPlanbodyAsTerm.java
trunk/release-notes.txt
trunk/src/jason/asSyntax/PlanBody.java
trunk/src/jason/asSyntax/PlanBodyImpl.java
trunk/src/jason/asSyntax/VarTerm.java
trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
trunk/src/jason/asSyntax/parser/as2j.java
trunk/src/test/ASParserTest.java
Added Paths:
-----------
trunk/applications/as-unit-test/src/jason/tests/TestIF.java
trunk/src/jason/stdlib/conditional.java
Modified: trunk/applications/as-unit-test/src/jason/tests/TestAll.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2008-04-16 16:46:46 UTC (rev 1218)
+++ trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2008-04-17 17:34:11 UTC (rev 1219)
@@ -9,8 +9,9 @@
BugVarsInInitBels.class,
TestAddLogExprInBB.class,
TestGoalSource.class,
+ TestIF.class,
TestKQML.class,
- /* TestPlanbodyAsTerm.class, */
+ TestPlanbodyAsTerm.class,
TestPlanFailure.class,
TestVarInContext.class
})
Added: trunk/applications/as-unit-test/src/jason/tests/TestIF.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestIF.java (rev 0)
+++ trunk/applications/as-unit-test/src/jason/tests/TestIF.java 2008-04-17 17:34:11 UTC (rev 1219)
@@ -0,0 +1,42 @@
+package jason.tests;
+
+import jason.asunit.TestAgent;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestIF {
+
+ TestAgent ag;
+
+ // initialisation of the agent test
+ @Before
+ public void setupAg() {
+ ag = new TestAgent();
+
+ // defines the agent's AgentSpeak code
+ ag.parseAScode(
+ "b(3). " +
+ "+!test1 <- a1; "+
+ " .conditional(b(X), {jason.asunit.print(X); b1}, {jason.asunit.print(no);b2}); "+
+ " a2. "+
+ "+!test2 <- -b(_); !test1. "
+ );
+ }
+
+ @Test
+ public void test1() {
+ ag.addGoal("test1");
+ ag.assertPrint("3", 5);
+ ag.assertAct("b1", 5);
+ ag.assertAct("a2", 5);
+ }
+
+ @Test
+ public void test2() {
+ ag.addGoal("test2");
+ ag.assertPrint("no", 5);
+ ag.assertAct("b2", 5);
+ ag.assertAct("a2", 5);
+ }
+}
Modified: trunk/applications/as-unit-test/src/jason/tests/TestPlanbodyAsTerm.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestPlanbodyAsTerm.java 2008-04-16 16:46:46 UTC (rev 1218)
+++ trunk/applications/as-unit-test/src/jason/tests/TestPlanbodyAsTerm.java 2008-04-17 17:34:11 UTC (rev 1219)
@@ -16,23 +16,33 @@
// defines the agent's AgentSpeak code
ag.parseAScode(
- "+!start <- +g(a(1); b; c); ?g(X); !g(X). "+
- "+!test2 <- !g(!g2(1)). "+
- "+!test3 <- !g2(-1 + 2). "+
- "+!g(A; R) <- A; !g(R). "+
- "+!g(A) <- A." +
- "+!g2(A) <- jason.asunit.print(A)."
+ "+!start <- +g( {a(1); b; c}); ?g(X); !g(X). " +
+ "+!test2 <- !g( {!g2(1)}). "+
+ "+!test3 <- !g2(-1 + 2)."+
+ "+!test4 <- X = {a(1); b; c}; !g(X)."+
+
+ "+!g({A; R}) <- A; !g(R). "+
+ "+!g(A) <- A." +
+ "+!g2(A) <- jason.asunit.print(A)."
);
}
@Test
- public void testProgram1() {
+ public void testProgram1a() {
ag.addGoal("start");
- ag.assertBel("g(a(1);b;c)", 5);
+ ag.assertBel("g({a(1);b;c})", 5);
ag.assertAct("a(1)", 4);
ag.assertAct("b", 4);
ag.assertAct("c", 4);
}
+
+ @Test
+ public void testProgram1b() {
+ ag.addGoal("test4");
+ ag.assertAct("a(1)", 4);
+ ag.assertAct("b", 4);
+ ag.assertAct("c", 4);
+ }
@Test
public void testProgram2() {
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2008-04-16 16:46:46 UTC (rev 1218)
+++ trunk/release-notes.txt 2008-04-17 17:34:11 UTC (rev 1219)
@@ -2,6 +2,11 @@
version 1.1.1
-------------
+New features
+. Terms can be body plans enclosed by |{ ... }", as in the following
+ example:
+ test({ a1; !g; ?b(X); .print(X) }, 10)
+
Bugs fixed:
. use nested source annotations in communication
. add "source(self)" in goals without source
Modified: trunk/src/jason/asSyntax/PlanBody.java
===================================================================
--- trunk/src/jason/asSyntax/PlanBody.java 2008-04-16 16:46:46 UTC (rev 1218)
+++ trunk/src/jason/asSyntax/PlanBody.java 2008-04-17 17:34:11 UTC (rev 1219)
@@ -17,7 +17,7 @@
public BodyType getBodyType();
public Term getBodyTerm();
- public PlanBody getBodyNext();
+ public PlanBody getBodyNext();
public boolean isEmptyBody();
public int getPlanSize();
@@ -25,7 +25,10 @@
public void setBodyType(BodyType bt);
public void setBodyTerm(Term t);
public void setBodyNext(PlanBody bl);
+ public PlanBody getLastBody();
+ public boolean isBodyTerm();
+ public void setAsBodyTerm(boolean b);
public boolean add(PlanBody bl);
public boolean add(int index, PlanBody bl);
Modified: trunk/src/jason/asSyntax/PlanBodyImpl.java
===================================================================
--- trunk/src/jason/asSyntax/PlanBodyImpl.java 2008-04-16 16:46:46 UTC (rev 1218)
+++ trunk/src/jason/asSyntax/PlanBodyImpl.java 2008-04-17 17:34:11 UTC (rev 1219)
@@ -20,9 +20,11 @@
public static final String BODY_PLAN_FUNCTOR = ";";
private Term term = null;
- private PlanBody next = null;
+ private PlanBody next = null;
private BodyType formType = BodyType.none;
+ private boolean isTerm = false;
+
/** constructor for empty plan body */
public PlanBodyImpl() {
super(BODY_PLAN_FUNCTOR, 0);
@@ -60,6 +62,13 @@
term = t;
}
+ public boolean isBodyTerm() {
+ return isTerm;
+ }
+ public void setAsBodyTerm(boolean b) {
+ isTerm = b;
+ }
+
@Override
public boolean isPlanBody() {
return true;
@@ -152,12 +161,23 @@
next.add(bl);
return true;
}
+
+ public PlanBody getLastBody() {
+ if (next == null)
+ return this;
+ else
+ return next.getLastBody();
+ }
public boolean add(int index, PlanBody bl) {
if (index == 0) {
swap(bl);
- this.next = bl;
- } else {
+ PlanBody bak = this.next;
+ this.next = bl.getBodyNext();
+ PlanBody last = bl.getLastBody();
+ bl.setBodyNext(bak);
+ last.setBodyNext(bl);
+ } else if (next != null) {
next.add(index - 1, bl);
}
return true;
@@ -203,18 +223,29 @@
return new PlanBodyImpl();
PlanBodyImpl c = new PlanBodyImpl(formType, (Term)term.clone());
+ c.isTerm = isTerm;
if (next != null)
c.setBodyNext((PlanBody)getBodyNext().clone());
return c;
}
public String toString() {
- if (term == null)
+ if (term == null) {
return "";
- else if (next == null)
- return formType.toString() + term;
- else
- return formType.toString() + term + "; " + next;
+ } else {
+ String b, e;
+ if (isTerm) {
+ b = "{ ";
+ e = " }";
+ } else {
+ b = "";
+ e = "";
+ }
+ if (next == null)
+ return b+formType.toString() + term+e;
+ else
+ return b+formType.toString() + term + "; " + next+e;
+ }
}
/** get as XML */
Modified: trunk/src/jason/asSyntax/VarTerm.java
===================================================================
--- trunk/src/jason/asSyntax/VarTerm.java 2008-04-16 16:46:46 UTC (rev 1218)
+++ trunk/src/jason/asSyntax/VarTerm.java 2008-04-17 17:34:11 UTC (rev 1219)
@@ -874,7 +874,7 @@
}
// -----------------------
- // BodyLiteral interface implementation
+ // PlanBody interface implementation
// -----------------------
public BodyType getBodyType() {
@@ -898,6 +898,13 @@
return null;
}
+ public PlanBody getLastBody() {
+ if (value != null && getValue() instanceof PlanBody)
+ return ((PlanBody) getValue()).getLastBody();
+ else
+ return null;
+ }
+
public boolean isEmptyBody() {
if (value != null && getValue() instanceof PlanBody)
return ((PlanBody) getValue()).isEmptyBody();
@@ -927,6 +934,18 @@
((PlanBody) getValue()).setBodyNext(bl);
}
+ public boolean isBodyTerm() {
+ if (value != null && getValue() instanceof PlanBody)
+ return ((PlanBody) getValue()).isBodyTerm();
+ else
+ return false;
+ }
+
+ public void setAsBodyTerm(boolean b) {
+ if (value != null && getValue() instanceof PlanBody)
+ ((PlanBody) getValue()).setAsBodyTerm(b);
+ }
+
public boolean add(PlanBody bl) {
if (value != null && getValue() instanceof PlanBody)
return ((PlanBody) getValue()).add(bl);
Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
===================================================================
--- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2008-04-16 16:46:46 UTC (rev 1218)
+++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2008-04-17 17:34:11 UTC (rev 1219)
@@ -289,8 +289,8 @@
/* Plan */
Plan plan() : { Token k; Pred L = null;
Trigger T;
- Object C = null; PlanBody bl = null;
- Object B = null;
+ Object C = null;
+ PlanBody B = null;
int start = -1, end;}
{
[ k = <TK_LABEL_AT> L=pred() { start = k.beginLine; } ]
@@ -303,14 +303,13 @@
try { ial = checkInternalActionsInContext((LogicalFormula)C, curAg); } catch (Exception e) {}
if (ial != null)
throw new ParseException(getSourceRef(ial)+" The internal action '"+ial+"' can not be used in plan's context!");
- if (B != null) {
- if (!(B instanceof PlanBody))
- throw new ParseException(getSourceRef(B)+" Unknown body formula:"+B);
- bl = (PlanBody)B;
- if (bl.getBodyTerm().equals(Literal.LTrue))
- bl = (PlanBody)bl.getBodyNext();
- }
- Plan p = new Plan(L,T,(LogicalFormula)C, bl);
+ //if (B != null) {
+ //if (!(B instanceof PlanBody))
+ // throw new ParseException(getSourceRef(B)+" Unknown body formula:"+B);
+ //bl = (PlanBody)B;
+ if (B != null && B.getBodyTerm().equals(Literal.LTrue))
+ B = (PlanBody)B.getBodyNext();
+ Plan p = new Plan(L,T,(LogicalFormula)C, B);
p.setSrcLines(start,end);
p.setSrc(asSource);
return p;
@@ -341,21 +340,31 @@
/* Plan body */
-Object plan_body() : { Object F; Object R = null; }
+PlanBody plan_body() : { Object F; PlanBody R = null; }
{
F = body_formula()
[ ";" { if (!(F instanceof PlanBody)) throw new ParseException(getSourceRef(F)+" "+F+" is not a body literal!"); }
- R = plan_body() { if (!(R instanceof PlanBody)) throw new ParseException(getSourceRef(R)+" "+R+" is not a body literal!"); }
+ R = plan_body()
]
- { if (F instanceof PlanBody && R instanceof PlanBody) {
- ((PlanBody)F).setBodyNext( (PlanBody)R );
+ { if (F instanceof PlanBody) {
+ ((PlanBody)F).setBodyNext( R );
}
- return F;
+ return (PlanBody)F;
}
}
+PlanBody plan_body_term(): { PlanBody B = null; }
+{
+ "{"
+ B = plan_body()
+ "}"
+ { B.setAsBodyTerm(true);
+ return B;
+ }
+}
+
Object body_formula() :
{ BodyType formType = BodyType.action; Object B; }
{
@@ -448,18 +457,11 @@
Term term() : { Object o;}
{
- ( o=list()
- | o=log_expr() //plan_body() // plan_body includes literals/atoms/structures
+ ( o=list()
+ | o=plan_body_term()
+ | o=log_expr() // log_expr includes literals/atoms/structures
)
- { // if the result is a PlanBody action with size = 1, it is indeed a literal and not a body literal
- /*if (o instanceof PlanBody) {
- PlanBody bl = (PlanBody)o;
- if (bl.getBodyType() == BodyType.action && bl.getPlanSize() == 1) {
- o = bl.getBodyTerm();
- }
- }*/
- return changeToAtom(o);
- }
+ { return changeToAtom(o); }
}
@@ -548,6 +550,7 @@
( op2 = arithm_expr()
| op2 = string()
| op2 = list()
+ | op2 = plan_body_term()
)
{ if ( ((Term)op1).isInternalAction() && operator != RelationalOp.literalBuilder)
Modified: trunk/src/jason/asSyntax/parser/as2j.java
===================================================================
--- trunk/src/jason/asSyntax/parser/as2j.java 2008-04-16 16:46:46 UTC (rev 1218)
+++ trunk/src/jason/asSyntax/parser/as2j.java 2008-04-17 17:34:11 UTC (rev 1219)
@@ -316,8 +316,8 @@
final public Plan plan() throws ParseException {
Token k; Pred L = null;
Trigger T;
- Object C = null; PlanBody bl = null;
- Object B = null;
+ Object C = null;
+ PlanBody B = null;
int start = -1, end;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case TK_LABEL_AT:
@@ -357,14 +357,13 @@
try { ial = checkInternalActionsInContext((LogicalFormula)C, curAg); } catch (Exception e) {}
if (ial != null)
{if (true) throw new ParseException(getSourceRef(ial)+" The internal action '"+ial+"' can not be used in plan's context!");}
- if (B != null) {
- if (!(B instanceof PlanBody))
- {if (true) throw new ParseException(getSourceRef(B)+" Unknown body formula:"+B);}
- bl = (PlanBody)B;
- if (bl.getBodyTerm().equals(Literal.LTrue))
- bl = (PlanBody)bl.getBodyNext();
- }
- Plan p = new Plan(L,T,(LogicalFormula)C, bl);
+ //if (B != null) {
+ //if (!(B instanceof PlanBody))
+ // throw new ParseException(getSourceRef(B)+" Unknown body formula:"+B);
+ //bl = (PlanBody)B;
+ if (B != null && B.getBodyTerm().equals(Literal.LTrue))
+ B = (PlanBody)B.getBodyNext();
+ Plan p = new Plan(L,T,(LogicalFormula)C, B);
p.setSrcLines(start,end);
p.setSrc(asSource);
{if (true) return p;}
@@ -435,27 +434,36 @@
}
/* Plan body */
- final public Object plan_body() throws ParseException {
- Object F; Object R = null;
+ final public PlanBody plan_body() throws ParseException {
+ Object F; PlanBody R = null;
F = body_formula();
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case 37:
jj_consume_token(37);
if (!(F instanceof PlanBody)) {if (true) throw new ParseException(getSourceRef(F)+" "+F+" is not a body literal!");}
R = plan_body();
- if (!(R instanceof PlanBody)) {if (true) throw new ParseException(getSourceRef(R)+" "+R+" is not a body literal!");}
break;
default:
jj_la1[17] = jj_gen;
;
}
- if (F instanceof PlanBody && R instanceof PlanBody) {
- ((PlanBody)F).setBodyNext( (PlanBody)R );
+ if (F instanceof PlanBody) {
+ ((PlanBody)F).setBodyNext( R );
}
- {if (true) return F;}
+ {if (true) return (PlanBody)F;}
throw new Error("Missing return statement in function");
}
+ final public PlanBody plan_body_term() throws ParseException {
+ PlanBody B = null;
+ jj_consume_token(27);
+ B = plan_body();
+ jj_consume_token(28);
+ B.setAsBodyTerm(true);
+ {if (true) return B;}
+ throw new Error("Missing return statement in function");
+ }
+
final public Object body_formula() throws ParseException {
BodyType formType = BodyType.action; Object B;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
@@ -642,6 +650,9 @@
case 42:
o = list();
break;
+ case 27:
+ o = plan_body_term();
+ break;
case VAR:
case TK_TRUE:
case TK_FALSE:
@@ -662,13 +673,6 @@
jj_consume_token(-1);
throw new ParseException();
}
- // if the result is a PlanBody action with size = 1, it is indeed a literal and not a body literal
- /*if (o instanceof PlanBody) {
- PlanBody bl = (PlanBody)o;
- if (bl.getBodyType() == BodyType.action && bl.getPlanSize() == 1) {
- o = bl.getBodyTerm();
- }
- }*/
{if (true) return changeToAtom(o);}
throw new Error("Missing return statement in function");
}
@@ -940,6 +944,9 @@
case 42:
op2 = list();
break;
+ case 27:
+ op2 = plan_body_term();
+ break;
default:
jj_la1[38] = jj_gen;
jj_consume_token(-1);
@@ -1187,8 +1194,8 @@
return false;
}
- final private boolean jj_3R_14() {
- if (jj_scan_token(42)) return true;
+ final private boolean jj_3R_13() {
+ if (jj_3R_14()) return true;
return false;
}
@@ -1197,6 +1204,11 @@
return false;
}
+ final private boolean jj_3R_14() {
+ if (jj_scan_token(42)) return true;
+ return false;
+ }
+
final private boolean jj_3R_11() {
Token xsp;
xsp = jj_scanpos;
@@ -1214,11 +1226,6 @@
return false;
}
- final private boolean jj_3R_13() {
- if (jj_3R_14()) return true;
- return false;
- }
-
public as2jTokenManager token_source;
SimpleCharStream jj_input_stream;
public Token token, jj_nt;
@@ -1236,7 +1243,7 @@
jj_la1_1();
}
private static void jj_la1_0() {
- jj_la1_0 = new int[] {0x8000000,0x10cb00,0x8000000,0x80000000,0x8000000,0x10000,0x10cb00,0x8000000,0x8000000,0x20000000,0x10000,0x0,0x0,0x0,0x80000000,0x80000000,0x30cb80,0x0,0x0,0x80000000,0x80000000,0x800,0x10cb00,0x10c000,0x0,0x0,0x0,0x3acf80,0x0,0x200080,0x0,0x3acb80,0x3acb80,0x0,0x0,0x3acf80,0x3acb80,0x0,0x3acb80,0x0,0x0,0x0,0x3000,0x3000,0x0,0x32cb80,0x200080,0x0,};
+ jj_la1_0 = new int[] {0x8000000,0x10cb00,0x8000000,0x80000000,0x8000000,0x10000,0x10cb00,0x8000000,0x8000000,0x20000000,0x10000,0x0,0x0,0x0,0x80000000,0x80000000,0x30cb80,0x0,0x0,0x80000000,0x80000000,0x800,0x10cb00,0x10c000,0x0,0x0,0x0,0x83acf80,0x0,0x200080,0x0,0x3acb80,0x3acb80,0x0,0x0,0x3acf80,0x3acb80,0x0,0x83acb80,0x0,0x0,0x0,0x3000,0x3000,0x0,0x32cb80,0x200080,0x0,};
}
private static void jj_la1_1() {
jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0xc,0x0,0x0,0x0,0x0,0x0,0x1,0x2,0xc,0x10,0x10,0x0,0x20,0x4,0x5c,0x5c,0x0,0x0,0x0,0x80,0x400,0x200,0x488,0x200,0x400,0x800,0x488,0x488,0x800,0x2000,0x88,0x88,0x3fc000,0x488,0x3fc000,0xc,0xc,0xc00000,0xc00000,0x1000000,0x88,0x0,0x400,};
Added: trunk/src/jason/stdlib/conditional.java
===================================================================
--- trunk/src/jason/stdlib/conditional.java (rev 0)
+++ trunk/src/jason/stdlib/conditional.java 2008-04-17 17:34:11 UTC (rev 1219)
@@ -0,0 +1,81 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2003 Rafael H. Bordini, Jomi F. Hubner, et al.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://www.dur.ac.uk/r.bordini
+// http://www.inf.furb.br/~jomi
+//
+//----------------------------------------------------------------------------
+
+package jason.stdlib;
+
+import java.util.Iterator;
+
+import jason.JasonException;
+import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.IntendedMeans;
+import jason.asSemantics.TransitionSystem;
+import jason.asSemantics.Unifier;
+import jason.asSyntax.LogicalFormula;
+import jason.asSyntax.PlanBody;
+import jason.asSyntax.Term;
+
+// TODO: comments
+// TODO: find a way to change the name of the IA to .if
+public class conditional extends DefaultInternalAction {
+
+ @Override
+ public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
+ try {
+ if ( !(args[0] instanceof LogicalFormula))
+ throw new JasonException("The first argument of .if must be a logical formula.");
+
+ LogicalFormula logExpr = (LogicalFormula)args[0];
+ PlanBody whattoadd = null;
+
+ Iterator<Unifier> iu = logExpr.logicalConsequence(ts.getAg(), un);
+ if (iu.hasNext()) {
+ // THEN
+ un.compose(iu.next());
+ whattoadd = (PlanBody)args[1];
+ } else if (args.length == 3) {
+ // ELSE
+ whattoadd = (PlanBody)args[2];
+ }
+
+ if (whattoadd != null) {
+ if ( !whattoadd.isPlanBody())
+ throw new JasonException("The second and third arguments of .if must be a plan body term.");
+
+ IntendedMeans im = ts.getC().getSelectedIntention().peek();
+ PlanBody ifia = im.getCurrentStep();
+ whattoadd.setAsBodyTerm(false);
+ if (ifia.getPlanSize() == 1)
+ ifia.add(whattoadd);
+ else
+ ifia.add(1,whattoadd);
+ }
+ return true;
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw new JasonException("The internal action 'if' has not received the required arguments.");
+ } catch (JasonException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new JasonException("Error in internal action 'if': " + e, e);
+ }
+ }
+}
Modified: trunk/src/test/ASParserTest.java
===================================================================
--- trunk/src/test/ASParserTest.java 2008-04-16 16:46:46 UTC (rev 1218)
+++ trunk/src/test/ASParserTest.java 2008-04-17 17:34:11 UTC (rev 1219)
@@ -4,11 +4,12 @@
import jason.asSemantics.Agent;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
-import jason.asSyntax.PlanBody;
+import jason.asSyntax.Literal;
import jason.asSyntax.LogExpr;
import jason.asSyntax.LogicalFormula;
import jason.asSyntax.NumberTerm;
import jason.asSyntax.Plan;
+import jason.asSyntax.PlanBody;
import jason.asSyntax.RelExpr;
import jason.asSyntax.parser.as2j;
import jason.infra.centralised.CentralisedAgArch;
@@ -164,18 +165,18 @@
}
public void testParsingPlanBody() {
- // TODO: think about this
- /*
- Literal l = Literal.parseLiteral("p(a1;a2, a3, !g, ?b;.print(oi), 10)");
+ Literal l = Literal.parseLiteral("p( {a1(f);a2}, a3, {!g}, {?b;.print(oi) }, 10)");
+ assertEquals("p({ a1(f); a2 },a3,{ !g },{ ?b; .print(oi) },10)", l.toString());
assertEquals(5,l.getArity());
- assertTrue(l.getTerm(0) instanceof BodyLiteral);
+ assertTrue(l.getTerm(0) instanceof PlanBody);
assertTrue(l.getTerm(0).isPlanBody());
+ PlanBody pb = (PlanBody)l.getTerm(0);
+ assertTrue(pb.isBodyTerm());
assertFalse(l.getTerm(1).isPlanBody());
assertTrue(l.getTerm(2).isPlanBody());
assertTrue(l.getTerm(3).isPlanBody());
assertFalse(l.getTerm(4).isPlanBody());
- */
}
public void testParsingAllSources() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-04-16 16:46:53
|
Revision: 1218
http://jason.svn.sourceforge.net/jason/?rev=1218&view=rev
Author: jomifred
Date: 2008-04-16 09:46:46 -0700 (Wed, 16 Apr 2008)
Log Message:
-----------
correctly handle failure events caused by no relevant plans
minor changes in the jason team
Modified Paths:
--------------
trunk/applications/as-unit-test/src/jason/tests/TestAll.java
trunk/applications/jason-team/logging.properties
trunk/applications/jason-team/src/java/arch/ACArchitecture.java
trunk/applications/jason-team/src/java/arch/IdentifyCrashed.java
trunk/applications/jason-team/src/java/arch/WriteStatusThread.java
trunk/release-notes.txt
trunk/src/jason/asSemantics/TransitionSystem.java
Added Paths:
-----------
trunk/applications/as-unit-test/src/jason/tests/TestPlanFailure.java
Modified: trunk/applications/as-unit-test/src/jason/tests/TestAll.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2008-04-15 12:09:22 UTC (rev 1217)
+++ trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2008-04-16 16:46:46 UTC (rev 1218)
@@ -8,8 +8,10 @@
@SuiteClasses({
BugVarsInInitBels.class,
TestAddLogExprInBB.class,
+ TestGoalSource.class,
TestKQML.class,
- TestVarInContext.class /*,
- TestPlanbodyAsTerm.class*/
+ /* TestPlanbodyAsTerm.class, */
+ TestPlanFailure.class,
+ TestVarInContext.class
})
public class TestAll { }
Added: trunk/applications/as-unit-test/src/jason/tests/TestPlanFailure.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestPlanFailure.java (rev 0)
+++ trunk/applications/as-unit-test/src/jason/tests/TestPlanFailure.java 2008-04-16 16:46:46 UTC (rev 1218)
@@ -0,0 +1,49 @@
+package jason.tests;
+
+import jason.asunit.TestAgent;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestPlanFailure {
+
+ TestAgent ag;
+
+ // initialisation of the agent test
+ @Before
+ public void setupAg() {
+ ag = new TestAgent();
+
+ // defines the agent's AgentSpeak code
+ ag.parseAScode(
+ "+!test : true <- !g1(X); endtest; end(X). "+
+
+ "+!g1(X) : true <- inig1; !g2(X); endg1. "+
+ "+!g2(X) : true <- inig2; !g3(X); endg2. "+
+ "+!g3(X) : true <- inig2; !g4(X); endg3. "+
+ "+!g4(X) : true <- inig4; !g5(X); endg4. "+
+ "+!g5(_) : true <- .fail. "+
+ "-!g3(failure) : true <- infailg3. "+
+
+ "+!norel <- !j; endnorel. "+
+ "-!j <- infailj. "
+ );
+ }
+
+ @Test
+ public void testFailurePlan() {
+ ag.addGoal("test");
+ ag.assertAct("inig4", 10);
+ ag.assertAct("infailg3", 5);
+ ag.assertAct("endg2", 5);
+ ag.assertAct("endtest", 5);
+ ag.assertAct("end(failure)", 5);
+ }
+
+ @Test
+ public void testNoRelPlan() {
+ ag.addGoal("norel");
+ ag.assertAct("infailj", 10);
+ ag.assertAct("endnorel", 5);
+ }
+}
Modified: trunk/applications/jason-team/logging.properties
===================================================================
--- trunk/applications/jason-team/logging.properties 2008-04-15 12:09:22 UTC (rev 1217)
+++ trunk/applications/jason-team/logging.properties 2008-04-16 16:46:46 UTC (rev 1218)
@@ -4,10 +4,10 @@
#
# default Jason MAS Console
-handlers = jason.runtime.MASConsoleLogHandler, java.util.logging.FileHandler
+#handlers = jason.runtime.MASConsoleLogHandler, java.util.logging.FileHandler
# To use the ConsoleHandler, use the following line instead.
-#handlers= java.util.logging.ConsoleHandler, java.util.logging.FileHandler
+handlers= java.util.logging.ConsoleHandler, java.util.logging.FileHandler
# Default logging level. Other values are:
# SEVERE (only severe messages)
Modified: trunk/applications/jason-team/src/java/arch/ACArchitecture.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/ACArchitecture.java 2008-04-15 12:09:22 UTC (rev 1217)
+++ trunk/applications/jason-team/src/java/arch/ACArchitecture.java 2008-04-16 16:46:46 UTC (rev 1218)
@@ -61,6 +61,7 @@
@Override
public List<Literal> perceive() {
+ agDidPerceive(); // for crash control
return new ArrayList<Literal>(percepts); // it must be a copy!
}
Modified: trunk/applications/jason-team/src/java/arch/IdentifyCrashed.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/IdentifyCrashed.java 2008-04-15 12:09:22 UTC (rev 1217)
+++ trunk/applications/jason-team/src/java/arch/IdentifyCrashed.java 2008-04-16 16:46:46 UTC (rev 1218)
@@ -42,27 +42,23 @@
@Override
public List<Literal> perceive() {
- agThread = Thread.currentThread();
- doPercept();
+ agThread = Thread.currentThread();
+ agDidPerceive();
return super.perceive();
}
- private synchronized void doPercept() {
+ public synchronized void agDidPerceive() {
didPercept = true;
notifyAll();
}
- public boolean didPercept() {
- return didPercept;
+ private synchronized void waitPerceive() throws InterruptedException {
+ wait(maxCycleTime);
}
-
+
public boolean isCrashed() {
return !didPercept;
}
-
- private synchronized void waitPercept() throws InterruptedException {
- wait(maxCycleTime);
- }
@Override
public void stopAg() {
@@ -78,7 +74,7 @@
dead = true;
// gives some time to TS get the change in state
- waitPercept();
+ waitPerceive();
try {
if (isCrashed()) {
return fix2();
@@ -94,17 +90,23 @@
/** try to fix the agent: approach 2: interrupt the agent thread */
protected boolean fix2() throws Exception {
- getTS().getLogger().warning("fix2: I am still dead! Interrupting the agent thread...");
- // try to interrupt the agent thread.
- agThread.interrupt();
+ if (agThread != null) {
+ getTS().getLogger().warning("fix2: I am still dead! Interrupting the agent thread...");
+ // try to interrupt the agent thread.
+
+ agThread.interrupt();
- waitPercept();
- if (isCrashed()) {
- getTS().getLogger().warning("Interrupt doesn't work!!! The agent remains dead!");
- return fix3();
+ waitPerceive();
+ if (isCrashed()) {
+ getTS().getLogger().warning("Interrupt doesn't work!!! The agent remains dead!");
+ return fix3();
+ } else {
+ getTS().getLogger().warning("fix2: I am Ok now!");
+ return true;
+ }
} else {
- getTS().getLogger().warning("fix2: I am Ok now!");
- return true;
+ getTS().getLogger().warning("fix2: can not be used (thread == null).");
+ return fix3();
}
}
Modified: trunk/applications/jason-team/src/java/arch/WriteStatusThread.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/WriteStatusThread.java 2008-04-15 12:09:22 UTC (rev 1217)
+++ trunk/applications/jason-team/src/java/arch/WriteStatusThread.java 2008-04-16 16:46:46 UTC (rev 1218)
@@ -109,6 +109,7 @@
if (act.equals(WorldModel.Move.southwest.toString())) return "sw";
if (act.equals(WorldModel.Move.north.toString())) return "n ";
if (act.equals(WorldModel.Move.south.toString())) return "s ";
+ if (act.equals(WorldModel.Move.skip.toString())) return "sk";
return act;
}
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2008-04-15 12:09:22 UTC (rev 1217)
+++ trunk/release-notes.txt 2008-04-16 16:46:46 UTC (rev 1218)
@@ -5,6 +5,7 @@
Bugs fixed:
. use nested source annotations in communication
. add "source(self)" in goals without source
+. correctly handle failure event caused by no relevant plans
-------------
Modified: trunk/src/jason/asSemantics/TransitionSystem.java
===================================================================
--- trunk/src/jason/asSemantics/TransitionSystem.java 2008-04-15 12:09:22 UTC (rev 1217)
+++ trunk/src/jason/asSemantics/TransitionSystem.java 2008-04-16 16:46:46 UTC (rev 1218)
@@ -459,13 +459,13 @@
// Rule Achieve
case achieve:
- // free variables in an event cannot conflict with those in the plan
- body = (Literal)body.clone();
if (!body.hasSource()) {
// do not add source(self) in case the
// programmer set some annotation
body.addAnnot(BeliefBase.TSelf);
}
+ // free variables in an event cannot conflict with those in the plan
+ body = (Literal)body.clone();
body.makeVarsAnnon();
conf.C.addAchvGoal(body, conf.C.SI);
confP.step = State.StartRC;
@@ -473,12 +473,12 @@
// Rule Achieve as a New Focus (the !! operator)
case achieveNF:
- body = (Literal)body.clone();
if (!body.hasSource()) {
// do not add source(self) in case the
// programmer set some annotation
body.addAnnot(BeliefBase.TSelf);
}
+ body = (Literal)body.clone();
body.makeVarsAnnon();
conf.C.addAchvGoal(body, Intention.EmptyInt);
updateIntention();
@@ -635,8 +635,13 @@
// +!s: !b; !z
// should became
// +!s: !z
- im = i.pop(); // +!c above, old
- while (!im.unif.unifies(topIM.getTrigger().getLiteral(), im.getTrigger().getLiteral()) && i.size() > 0) {
+ im = i.peek();
+ if (im.isFinished() || !im.unif.unifies(topIM.getTrigger().getLiteral(), im.getCurrentStep().getBodyTerm()))
+ im = i.pop(); // +!c above
+
+ while (i.size() > 0 &&
+ !im.unif.unifies(topIM.getTrigger().getLiteral(), im.getTrigger().getLiteral()) &&
+ !im.unif.unifies(topIM.getTrigger().getLiteral(), im.getCurrentStep().getBodyTerm())) {
im = i.pop();
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-04-15 12:09:26
|
Revision: 1217
http://jason.svn.sourceforge.net/jason/?rev=1217&view=rev
Author: jomifred
Date: 2008-04-15 05:09:22 -0700 (Tue, 15 Apr 2008)
Log Message:
-----------
fix name of var in kqml plans
Modified Paths:
--------------
trunk/src/asl/kqmlPlans.asl
Modified: trunk/src/asl/kqmlPlans.asl
===================================================================
--- trunk/src/asl/kqmlPlans.asl 2008-04-15 11:51:25 UTC (rev 1216)
+++ trunk/src/asl/kqmlPlans.asl 2008-04-15 12:09:22 UTC (rev 1217)
@@ -26,16 +26,16 @@
+!add_all_kqml_received(_,[]).
@kqmlReceivedTellList2
-+!add_all_kqml_received(S,[H|T])
++!add_all_kqml_received(Sender,[H|T])
: .structure(H) &
.ground(H)
<- .add_nested_source(H, Sender, CA);
+CA;
- !add_all_kqml_received(S,T).
+ !add_all_kqml_received(Sender,T).
@kqmlReceivedTellList3
-+!add_all_kqml_received(S,[_|T])
- <- !add_all_kqml_received(S,T).
++!add_all_kqml_received(Sender,[_|T])
+ <- !add_all_kqml_received(Sender,T).
@kqmlReceivedUnTell
+!kqml_received(Sender, untell, Content, _)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-04-15 11:51:28
|
Revision: 1216
http://jason.svn.sourceforge.net/jason/?rev=1216&view=rev
Author: jomifred
Date: 2008-04-15 04:51:25 -0700 (Tue, 15 Apr 2008)
Log Message:
-----------
changes in class Vec of jason team
Modified Paths:
--------------
trunk/applications/jason-team/AC-Local-JasonTeam.mas2j
trunk/applications/jason-team/src/asl/dummy.asl
trunk/applications/jason-team/src/java/arch/LocalWorldModel.java
trunk/applications/jason-team/src/java/jia/Vec.java
trunk/applications/jason-team/src/java/jia/herd_position.java
trunk/applications/jason-team/src/java/test/TestBasicHerding.java
trunk/src/jason/asSemantics/TransitionSystem.java
trunk/src/jason/asSyntax/Literal.java
trunk/src/jason/asSyntax/VarTerm.java
Modified: trunk/applications/jason-team/AC-Local-JasonTeam.mas2j
===================================================================
--- trunk/applications/jason-team/AC-Local-JasonTeam.mas2j 2008-04-13 11:03:11 UTC (rev 1215)
+++ trunk/applications/jason-team/AC-Local-JasonTeam.mas2j 2008-04-15 11:51:25 UTC (rev 1216)
@@ -11,7 +11,7 @@
agents:
gaucho1 dummy.asl
- [verbose=1, gui=yes, write_status=yes, ac_sim_back_dir="./massim-server/backup",
+ [verbose=1, gui=no, write_status=yes, ac_sim_back_dir="./massim-server/backup",
host="localhost", port=12300, username=participant1, password="1"]
agentArchClass arch.ACArchitecture
agentClass agent.SelectEvent
Modified: trunk/applications/jason-team/src/asl/dummy.asl
===================================================================
--- trunk/applications/jason-team/src/asl/dummy.asl 2008-04-13 11:03:11 UTC (rev 1215)
+++ trunk/applications/jason-team/src/asl/dummy.asl 2008-04-15 11:51:25 UTC (rev 1216)
@@ -45,27 +45,28 @@
+pos(_,_,_) // new cycle
: cell(_,_,cow(_)) // I see cows
- <- jia.herd_position(X,Y); // compute new location
- .print("COWS! going to ",X,",",Y);
- -+target(X,Y). // go to there
-
-+pos(_,_,_)
- : not cell(_,_,cow(_)) // I see no cow
- <- -target(_,_);
- !move.
+ <- !decide_target.
/* -- what todo when arrive at location */
++!decide_target
+ : jia.herd_position(X,Y) & // compute new location
+ (not target(_,_) | (target(TX,TY) & (TX \== X | TY \== Y))) // no target OR new target?
+ <- .print("COWS! going to ",X,",",Y," previous target ",TX,",",TY);
+ -+target(X,Y).
+
+!decide_target // chose a new random pos
: not cell(_,_,cow(_))
<- ?random_pos(NX,NY);
.print("New random target: ",NX,",",NY);
-+target(NX,NY).
+
+!decide_target
<- .print("No need for a new target, consider last herding location.");
do(skip). // send an action so that the simulator does not wait for me.
+
/* -- plans to move to a destination represented in the belief target(X,Y)
-- (it is a kind of persistent goal)
*/
@@ -73,7 +74,7 @@
// if the target is changed, "restart" move
+target(NX,NY)
<- .drop_desire(move);
- jia.set_target(NX,NY);
+ jia.set_target(NX,NY);
!!move.
// I still do not know my location
Modified: trunk/applications/jason-team/src/java/arch/LocalWorldModel.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/LocalWorldModel.java 2008-04-13 11:03:11 UTC (rev 1215)
+++ trunk/applications/jason-team/src/java/arch/LocalWorldModel.java 2008-04-15 11:51:25 UTC (rev 1216)
@@ -60,11 +60,17 @@
public Location nearFree(Location l) throws Exception {
int w = 0;
+ List<Location> options = new ArrayList<Location>();
while (true) {
- for (int x=l.x-w; x<=l.x+w;x++)
- for (int y=l.y-w; y<=l.y+w;y++)
- if (isFree(x,y))
- return new Location(x,y);
+ options.clear();
+ for (int x=l.x-w; x<=l.x+w;x++) {
+ if (isFree(x,l.y-w))
+ options.add(new Location(x,l.y-w));
+ if (isFree(x,l.y+w))
+ options.add(new Location(x,l.y+w));
+ }
+ if (!options.isEmpty())
+ return options.get(random.nextInt(options.size()));
w++;
}
}
Modified: trunk/applications/jason-team/src/java/jia/Vec.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/Vec.java 2008-04-13 11:03:11 UTC (rev 1215)
+++ trunk/applications/jason-team/src/java/jia/Vec.java 2008-04-15 11:51:25 UTC (rev 1216)
@@ -2,36 +2,41 @@
import jason.environment.grid.Location;
+import java.util.ArrayList;
import java.util.List;
import arch.LocalWorldModel;
-public class Vec {
+public class Vec implements Cloneable {
public final int x,y;
+ public final double r,t;
public Vec(int x, int y) {
this.x = x;
this.y = y;
+ this.r = Math.sqrt(x*x + y*y);
+ this.t = Math.atan2(y,x);
}
/** create a vector based on a location in the model */
public Vec(LocalWorldModel model, Location l) {
this.x = l.x;
this.y = model.getHeight()-l.y-1;
+ this.r = Math.sqrt(x*x + y*y);
+ this.t = Math.atan2(y,x);
}
public int getX() { return x; }
public int getY() { return y; }
+ public double magnitude() { return r; }
+ public double angle() { return t; }
+
public Location getLocation(LocalWorldModel model) {
return new Location(x, model.getHeight()-y-1);
}
- public double magnitude() {
- return Math.sqrt(x*x + y*y);
- }
-
public Vec add(Vec v) {
return new Vec(x + v.x, y + v.y);
}
@@ -52,25 +57,69 @@
}
return false;
}
+
+ public Object clone() {
+ return this; // it is an immutable object, no need to create a new one
+ }
+
+
+ /**
+ * Provides info on which octant (0-7) the vector lies in.
+ * 0 indicates 0 radians +- PI/8 1-7 continue CCW.
+ * @return 0 - 7, depending on which direction the vector is pointing.
+ */
+ public int octant() {
+ double temp = t + Math.PI/8;
+ if (temp<0)
+ temp += Math.PI*2;
+ return ((int)(temp/(Math.PI/4))%8);
+ }
+
+ /**
+ * Provides info on which quadrant (0-3) the vector lies in.
+ * 0 indicates 0 radians +- PI/4 1-3 continue CCW.
+ * @return 0 - 3, depending on which direction the vector is pointing.
+ */
+ public int quadrant() {
+ double temp = t + Math.PI/4;
+ if (temp<0) temp += Math.PI*2;
+ return ((int)(temp/(Math.PI/2))%4);
+ }
+
+
+ //
+ // Useful static methods for list of vecs
+ //
+
public static Vec max(List<Vec> vs) {
Vec max = null;
- if (vs.size() > 0)
- max = vs.get(0);
for (Vec v: vs) {
- if (max.magnitude() < v.magnitude())
+ if (max == null || max.magnitude() < v.magnitude())
max = v;
}
return max;
}
- public static void cluster(List<Vec> vs, int maxstddev) {
+ public static List<Vec> sub(List<Vec> vs, Vec ref) {
+ List<Vec> r = new ArrayList<Vec>(vs.size());
+ for (Vec v: vs) {
+ r.add(v.sub(ref));
+ }
+ return r;
+ }
+
+ public static List<Vec> cluster(List<Vec> vs, int maxstddev) {
+ vs = new ArrayList<Vec>(vs);
Vec stddev = Vec.stddev(vs);
// remove max if stddev is too big
while (stddev.magnitude() > maxstddev) {
- vs.remove(Vec.max(vs));
+ Vec mean = Vec.mean(vs);
+ Vec max = Vec.max(Vec.sub(vs, mean));
+ vs.remove(max.add(mean));
stddev = Vec.stddev(vs);
}
+ return vs;
}
public static Vec mean(List<Vec> vs) {
Modified: trunk/applications/jason-team/src/java/jia/herd_position.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/herd_position.java 2008-04-13 11:03:11 UTC (rev 1215)
+++ trunk/applications/jason-team/src/java/jia/herd_position.java 2008-04-15 11:51:25 UTC (rev 1216)
@@ -50,7 +50,7 @@
if (cows.isEmpty())
return null;
- Vec.cluster(cows, 3); // find center/clusterise
+ cows = Vec.cluster(cows, 2); // find center/clusterise
Vec mean = Vec.mean(cows);
Modified: trunk/applications/jason-team/src/java/test/TestBasicHerding.java
===================================================================
--- trunk/applications/jason-team/src/java/test/TestBasicHerding.java 2008-04-13 11:03:11 UTC (rev 1215)
+++ trunk/applications/jason-team/src/java/test/TestBasicHerding.java 2008-04-15 11:51:25 UTC (rev 1216)
@@ -33,11 +33,12 @@
public void scenario1() {
cowboy = new Vec(3,5);
- cows = new Vec[4];
+ cows = new Vec[5];
cows[0] = new Vec(6,7);
cows[1] = new Vec(5,30);
cows[2] = new Vec(4,8);
cows[3] = new Vec(5,10);
+ cows[4] = new Vec(0,1);
for (int i=0; i<cows.length; i++)
model.addCow(cows[i].getLocation(model));
@@ -153,14 +154,8 @@
}
// find center/clusterise
+ cowsTarget = Vec.cluster(cowsTarget, 2);
Vec stddev = Vec.stddev(cowsTarget);
- assertEquals(new Vec(0,9), stddev);
-
- // remove max if stddev is too big
- while (stddev.magnitude() > 3) {
- cowsTarget.remove(Vec.max(cowsTarget));
- stddev = Vec.stddev(cowsTarget);
- }
assertTrue(stddev.magnitude() < 3);
Vec mean = Vec.mean(cowsTarget);
@@ -194,9 +189,7 @@
}
// find center/clusterise
- Vec.cluster(cowsTarget, 3);
- Vec stddev = Vec.stddev(cowsTarget);
- assertTrue(stddev.magnitude() < 3);
+ cowsTarget = Vec.cluster(cowsTarget, 2);
Vec mean = Vec.mean(cowsTarget);
assertEquals(new Vec(9,1), mean);
Modified: trunk/src/jason/asSemantics/TransitionSystem.java
===================================================================
--- trunk/src/jason/asSemantics/TransitionSystem.java 2008-04-13 11:03:11 UTC (rev 1215)
+++ trunk/src/jason/asSemantics/TransitionSystem.java 2008-04-15 11:51:25 UTC (rev 1216)
@@ -420,7 +420,7 @@
case internalAction:
boolean ok = false;
try {
- InternalAction ia = ((InternalActionLiteral)body).getIA(ag);
+ InternalAction ia = ((InternalActionLiteral)bTerm).getIA(ag);
Object oresult = ia.execute(this, u, body.getTermsArray());
if (oresult != null) {
ok = oresult instanceof Boolean && (Boolean)oresult;
Modified: trunk/src/jason/asSyntax/Literal.java
===================================================================
--- trunk/src/jason/asSyntax/Literal.java 2008-04-13 11:03:11 UTC (rev 1215)
+++ trunk/src/jason/asSyntax/Literal.java 2008-04-15 11:51:25 UTC (rev 1216)
@@ -77,20 +77,21 @@
}
public Literal(Literal l) {
- super((Pred) l);
- type = l.type;
+ super((Pred) l);
+ type = l.type;
}
public static Literal parseLiteral(String sLiteral) {
- as2j parser = new as2j(new StringReader(sLiteral));
try {
- return parser.literal();
+ as2j parser = new as2j(new StringReader(sLiteral));
+ return parser.literal();
} catch (Exception e) {
logger.log(Level.SEVERE,"Error parsing literal " + sLiteral,e);
return null;
}
- }
+ }
+
public static Literal tryParsingLiteral(String sLiteral) throws ParseException {
return new as2j(new StringReader(sLiteral)).literal();
}
Modified: trunk/src/jason/asSyntax/VarTerm.java
===================================================================
--- trunk/src/jason/asSyntax/VarTerm.java 2008-04-13 11:03:11 UTC (rev 1215)
+++ trunk/src/jason/asSyntax/VarTerm.java 2008-04-15 11:51:25 UTC (rev 1216)
@@ -110,7 +110,13 @@
}
vl = (Term)vl.clone(); // should clone here, since there is no cloning in unify
- // The below does not conform the rules in manual
+ // TODO: decide whether to use var annots in apply
+ // X = p[a]
+ // !X[b]
+ // what's the event:
+ // +!p[a]
+ // or
+ // +!p[a,b]
//if (vl.isPred() && this.hasAnnot()) // if this var has annots, add them in the value's annots (Experimental)
// ((Pred)vl).addAnnots(this.getAnnots());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-04-13 11:03:22
|
Revision: 1215
http://jason.svn.sourceforge.net/jason/?rev=1215&view=rev
Author: jomifred
Date: 2008-04-13 04:03:11 -0700 (Sun, 13 Apr 2008)
Log Message:
-----------
fig bug: add source(self) in goals without source
Modified Paths:
--------------
trunk/release-notes.txt
trunk/src/jason/asSemantics/TransitionSystem.java
Added Paths:
-----------
trunk/applications/as-unit-test/src/jason/tests/TestGoalSource.java
Added: trunk/applications/as-unit-test/src/jason/tests/TestGoalSource.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestGoalSource.java (rev 0)
+++ trunk/applications/as-unit-test/src/jason/tests/TestGoalSource.java 2008-04-13 11:03:11 UTC (rev 1215)
@@ -0,0 +1,30 @@
+package jason.tests;
+
+import jason.asunit.TestAgent;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestGoalSource {
+
+ TestAgent ag;
+
+ // initialisation of the agent test
+ @Before
+ public void setupAg() {
+ ag = new TestAgent();
+
+ // defines the agent's AgentSpeak code
+ ag.parseAScode(
+ "+!begin <- !g; !g[source(bob)]. "+
+ "+!g[source(A)] <- jason.asunit.print(A)."
+ );
+ }
+
+ @Test
+ public void testGoalSrouce() {
+ ag.addGoal("begin");
+ ag.assertPrint("self", 5);
+ ag.assertPrint("bob", 5);
+ }
+}
Property changes on: trunk/applications/as-unit-test/src/jason/tests/TestGoalSource.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2008-04-13 10:45:08 UTC (rev 1214)
+++ trunk/release-notes.txt 2008-04-13 11:03:11 UTC (rev 1215)
@@ -4,7 +4,9 @@
Bugs fixed:
. use nested source annotations in communication
+. add "source(self)" in goals without source
+
-------------
version 1.1.0
-------------
Modified: trunk/src/jason/asSemantics/TransitionSystem.java
===================================================================
--- trunk/src/jason/asSemantics/TransitionSystem.java 2008-04-13 10:45:08 UTC (rev 1214)
+++ trunk/src/jason/asSemantics/TransitionSystem.java 2008-04-13 11:03:11 UTC (rev 1215)
@@ -461,6 +461,11 @@
case achieve:
// free variables in an event cannot conflict with those in the plan
body = (Literal)body.clone();
+ if (!body.hasSource()) {
+ // do not add source(self) in case the
+ // programmer set some annotation
+ body.addAnnot(BeliefBase.TSelf);
+ }
body.makeVarsAnnon();
conf.C.addAchvGoal(body, conf.C.SI);
confP.step = State.StartRC;
@@ -469,6 +474,11 @@
// Rule Achieve as a New Focus (the !! operator)
case achieveNF:
body = (Literal)body.clone();
+ if (!body.hasSource()) {
+ // do not add source(self) in case the
+ // programmer set some annotation
+ body.addAnnot(BeliefBase.TSelf);
+ }
body.makeVarsAnnon();
conf.C.addAchvGoal(body, Intention.EmptyInt);
updateIntention();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-04-13 10:45:13
|
Revision: 1214
http://jason.svn.sourceforge.net/jason/?rev=1214&view=rev
Author: jomifred
Date: 2008-04-13 03:45:08 -0700 (Sun, 13 Apr 2008)
Log Message:
-----------
fix bug in communication: use nested source annotation
Modified Paths:
--------------
trunk/applications/as-unit-test/src/jason/asunit/TestArch.java
trunk/applications/as-unit-test/src/jason/tests/TestKQML.java
trunk/release-notes.txt
trunk/src/asl/kqmlPlans.asl
trunk/src/jason/asSyntax/Pred.java
trunk/src/jason/asSyntax/VarTerm.java
trunk/src/jason/stdlib/add_annot.java
trunk/src/jason/stdlib/package.html
trunk/src/jason/stdlib/send.java
trunk/src/test/ListTermTest.java
trunk/src/test/VarTermTest.java
Added Paths:
-----------
trunk/src/jason/stdlib/add_nested_source.java
Modified: trunk/applications/as-unit-test/src/jason/asunit/TestArch.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/asunit/TestArch.java 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/applications/as-unit-test/src/jason/asunit/TestArch.java 2008-04-13 10:45:08 UTC (rev 1214)
@@ -93,7 +93,7 @@
}
public void print(String s) {
- System.out.println(s);
+ //System.out.println(s);
output.append(s+"\n");
}
Modified: trunk/applications/as-unit-test/src/jason/tests/TestKQML.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestKQML.java 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/applications/as-unit-test/src/jason/tests/TestKQML.java 2008-04-13 10:45:08 UTC (rev 1214)
@@ -19,7 +19,8 @@
// defines the agent's AgentSpeak code
bob.parseAScode(
"+!simple_send <- .send(maria, tell, vl(10)); "+
- " .send(maria, achieve, goto(10,2)). " +
+ " .send(maria, achieve, goto(10,2)); " +
+ " .send(maria, tell, loves(maria,bob)[source(maria), source(mog)]). " +
"+!send_ask1 <- .send(maria, askOne, vl(_), vl(X)); " +
" .send(maria, askOne, vl(_)); " +
@@ -56,9 +57,10 @@
@Test
public void testSend() {
bob.addGoal("simple_send");
- bob.assertIdle(5); // bob sent the messages
- maria.assertBel("vl(10)", 5); // maria received tell
- maria.assertAct("act(10,2,bob)", 5); // maria received achieved
+ bob.assertIdle(5); // bob sent the messages
+ maria.assertBel("vl(10)[source(bob)]", 5); // maria received tell
+ maria.assertAct("act(10,2,bob)", 5); // maria received achieved
+ maria.assertBel("loves(maria,bob)[source(bob)[source(maria),source(mog)]]", 5);
}
@Test
@@ -92,7 +94,7 @@
bob.addGoal("simple_send");
bob.addGoal("send_askAll1");
bob.assertIdle(10);
- maria.assertIdle(10);
+ maria.assertIdle(15);
bob.assertPrint("[vl(10),vl(1),vl(2)]", 5);
bob.addGoal("send_askAll2");
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/release-notes.txt 2008-04-13 10:45:08 UTC (rev 1214)
@@ -1,7 +1,14 @@
------------
-version 1.1
------------
+-------------
+version 1.1.1
+-------------
+Bugs fixed:
+. use nested source annotations in communication
+
+-------------
+version 1.1.0
+-------------
+
New features
. Performance improvements: in general, applications run 30%
faster.
Modified: trunk/src/asl/kqmlPlans.asl
===================================================================
--- trunk/src/asl/kqmlPlans.asl 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/src/asl/kqmlPlans.asl 2008-04-13 10:45:08 UTC (rev 1214)
@@ -15,7 +15,7 @@
: .structure(Content) &
.ground(Content) &
not .list(Content)
- <- .add_annot(Content, source(Sender), CA);
+ <- .add_nested_source(Content, Sender, CA);
+CA.
@kqmlReceivedTellList
+!kqml_received(Sender, tell, Content, _)
@@ -29,7 +29,7 @@
+!add_all_kqml_received(S,[H|T])
: .structure(H) &
.ground(H)
- <- .add_annot(H, source(S), CA);
+ <- .add_nested_source(H, Sender, CA);
+CA;
!add_all_kqml_received(S,T).
@@ -39,7 +39,7 @@
@kqmlReceivedUnTell
+!kqml_received(Sender, untell, Content, _)
- <- .add_annot(Content, source(Sender), CA);
+ <- .add_nested_source(Content, Sender, CA);
-CA.
@@ -48,7 +48,7 @@
@kqmlReceivedAchieve
+!kqml_received(Sender, achieve, Content, _)
: not .list(Content)
- <- .add_annot(Content, source(Sender), CA);
+ <- .add_nested_source(Content, Sender, CA);
!!CA.
@kqmlReceivedAchieveList
+!kqml_received(Sender, achieve, Content, _)
@@ -61,7 +61,7 @@
@kqmlReceivedAchieveList2
+!add_all_kqml_achieve(Sender,[H|T])
- <- .add_annot(H, source(Sender), CA);
+ <- .add_nested_source(H, Sender, CA);
!!CA;
!add_all_kqml_achieve(Sender,T).
Modified: trunk/src/jason/asSyntax/Pred.java
===================================================================
--- trunk/src/jason/asSyntax/Pred.java 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/src/jason/asSyntax/Pred.java 2008-04-13 10:45:08 UTC (rev 1214)
@@ -65,7 +65,7 @@
}
/** to be used by atom */
- protected Pred(String functor, int termsSize) {
+ public Pred(String functor, int termsSize) {
super(functor, termsSize);
}
@@ -123,7 +123,7 @@
}
public void addAnnots(List<Term> l) {
- if (l == null) return;
+ if (l == null || l.isEmpty()) return;
ListTerm tail;
if (annots == null) {
annots = new ListTermImpl();
@@ -309,7 +309,7 @@
*/
public void addSource(Structure agName) {
if (agName != null) {
- Structure ts = new Structure("source");
+ Structure ts = new Structure("source", 1);
ts.addTerm(agName);
addAnnot(ts);
}
Modified: trunk/src/jason/asSyntax/VarTerm.java
===================================================================
--- trunk/src/jason/asSyntax/VarTerm.java 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/src/jason/asSyntax/VarTerm.java 2008-04-13 10:45:08 UTC (rev 1214)
@@ -111,9 +111,8 @@
vl = (Term)vl.clone(); // should clone here, since there is no cloning in unify
// The below does not conform the rules in manual
- //if (vl.isPred() && this.hasAnnot()) { // if this var has annots, add them in the value's annots (Experimental)
- // ((Pred)vl).addAnnots(this.getAnnots());
- //}
+ //if (vl.isPred() && this.hasAnnot()) // if this var has annots, add them in the value's annots (Experimental)
+ // ((Pred)vl).addAnnots(this.getAnnots());
value = vl;
resetHashCodeCache();
@@ -128,7 +127,7 @@
public boolean apply(Unifier u) {
if (value == null) {
Term vl = u.get(this);
- // System.out.println("applying="+t+"="+vl+" un="+this);
+ //System.out.println("applying "+this+"="+vl+" un="+u);
if (vl != null && !(vl instanceof VarsCluster)) {
setValue(vl);
value.apply(u); // in case t has var args
@@ -153,7 +152,7 @@
if (t == this) return true;
if (t instanceof Term) {
Term vl = getValue();
- // System.out.println("cheking equals form "+tAsTerm.getFunctor()+"
+ // System.out.println("checking equals form "+tAsTerm.getFunctor()+"
// and this "+this.getFunctor()+" my value "+vl);
if (vl != null) {
// compare the values
Modified: trunk/src/jason/stdlib/add_annot.java
===================================================================
--- trunk/src/jason/stdlib/add_annot.java 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/src/jason/stdlib/add_annot.java 2008-04-13 10:45:08 UTC (rev 1214)
@@ -64,6 +64,8 @@
unifies with <code>[a1[source(jomi)], a2[source(jomi)]]</code>.</li>
</ul>
+
+ @see jason.stdlib.add_nested_source
*/
public class add_annot extends DefaultInternalAction {
Added: trunk/src/jason/stdlib/add_nested_source.java
===================================================================
--- trunk/src/jason/stdlib/add_nested_source.java (rev 0)
+++ trunk/src/jason/stdlib/add_nested_source.java 2008-04-13 10:45:08 UTC (rev 1214)
@@ -0,0 +1,118 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2003 Rafael H. Bordini, Jomi F. Hubner, et al.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://www.dur.ac.uk/r.bordini
+// http://www.inf.furb.br/~jomi
+//
+//----------------------------------------------------------------------------
+
+
+package jason.stdlib;
+
+import jason.JasonException;
+import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.TransitionSystem;
+import jason.asSemantics.Unifier;
+import jason.asSyntax.ListTerm;
+import jason.asSyntax.ListTermImpl;
+import jason.asSyntax.Literal;
+import jason.asSyntax.Pred;
+import jason.asSyntax.Structure;
+import jason.asSyntax.Term;
+
+/**
+ <p>Internal action: <b><code>.add_nested_source</code></b>.
+
+ <p>Description: adds a source annotation to a literal (used in communication).
+
+ <p>Parameters:<ul>
+
+ <li>+ belief(s) (literal or list): the literal where the source annotation
+ is to be added. If this parameter is a list, all literals in the list
+ will have the source added.<br/>
+
+ <li>+ source (atom): the source.<br/>
+
+ <li>+/- annotated beliefs(s) (literal or list): this argument
+ unifies with the result of the source addition.<br/>
+
+ </ul>
+
+ <p>Examples:<ul>
+
+ <li> <code>.add_nested_source(a,jomi,B)</code>: <code>B</code>
+ unifies with <code>a[source(jomi)]</code>.</li>
+
+ <li> <code>.add_nested_source(a[source(bob)],jomi,B)</code>: <code>B</code>
+ unifies with <code>a[source(jomi)[source(bob)]]</code>.</li>
+
+ <li> <code>.add_annot([a1,a2], jomi, B)</code>: <code>B</code>
+ unifies with <code>[a1[source(jomi)], a2[source(jomi)]]</code>.</li>
+
+ </ul>
+
+ @see jason.stdlib.add_annot
+
+ */
+public class add_nested_source extends DefaultInternalAction {
+
+ @Override
+ public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
+ try {
+ Term result = addAnnotToList(un, args[0], (Structure)args[1].clone());
+ return un.unifies(result,args[2]);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw new JasonException("The internal action 'add_nested_source' requires three arguments.");
+ }
+ }
+
+ public Term addAnnotToList(Unifier unif, Term l, Structure source) {
+ if (l.isList()) {
+ ListTerm result = new ListTermImpl();
+ for (Term lTerm: (ListTerm)l) {
+ Term t = addAnnotToList( unif, lTerm, source);
+ if (t != null) {
+ result.add(t);
+ }
+ }
+ return result;
+ } else {
+ try {
+ // if it can be parsed as a literal and is not an atom, OK to add annot
+ Literal result;
+ if (l.isAtom())
+ result = new Literal(((Structure)l).getFunctor());
+ else
+ result = Literal.parseLiteral(l.toString());
+
+ // create the source annots
+ Pred ts = new Pred("source",1);
+ ts.addTerm(source);
+ ts.addAnnots(result.getAnnots("source"));
+
+ result.delSources();
+ result.addAnnot(ts);
+ return result;
+ } catch (Exception e) {
+ // no problem, the content is not a pred (it is a number,
+ // string, ....) received in a message, for instance
+ }
+ }
+ return null;
+ }
+}
Modified: trunk/src/jason/stdlib/package.html
===================================================================
--- trunk/src/jason/stdlib/package.html 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/src/jason/stdlib/package.html 2008-04-13 10:45:08 UTC (rev 1214)
@@ -90,6 +90,7 @@
<li>{@link jason.stdlib.string}: check whether an argument is a string.</li>
<li>{@link jason.stdlib.ground}: check whether an argument is ground.</li>
<li>{@link jason.stdlib.add_annot}: add an annotation in a literal.</li>
+ <li>{@link jason.stdlib.add_nested_source}: add a source in a literal.</li>
</ul>
Modified: trunk/src/jason/stdlib/send.java
===================================================================
--- trunk/src/jason/stdlib/send.java 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/src/jason/stdlib/send.java 2008-04-13 10:45:08 UTC (rev 1214)
@@ -33,7 +33,6 @@
import jason.asSemantics.Unifier;
import jason.asSyntax.ListTerm;
import jason.asSyntax.NumberTerm;
-import jason.asSyntax.Pred;
import jason.asSyntax.StringTerm;
import jason.asSyntax.Structure;
import jason.asSyntax.Term;
@@ -141,9 +140,10 @@
}
// remove source annots in the content (in case it is a pred)
- try {
- ((Pred)pcnt).delSources();
- } catch (Exception e) {}
+ // -- CHANGE: use nested annots
+ //try {
+ // ((Pred)pcnt).delSources();
+ //} catch (Exception e) {}
} catch (ArrayIndexOutOfBoundsException e) {
throw new JasonException("The internal action 'send' to '"+to+"' has not received three arguments.");
Modified: trunk/src/test/ListTermTest.java
===================================================================
--- trunk/src/test/ListTermTest.java 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/src/test/ListTermTest.java 2008-04-13 10:45:08 UTC (rev 1214)
@@ -1,6 +1,7 @@
package test;
import jason.asSemantics.Unifier;
+import jason.asSyntax.Atom;
import jason.asSyntax.ListTerm;
import jason.asSyntax.ListTermImpl;
import jason.asSyntax.Structure;
@@ -177,6 +178,15 @@
assertEquals(lt5.getTail(), null);
}
+ public void testTailUnify() {
+ ListTerm lt5 = ListTermImpl.parseList("[H|T]");
+ Unifier u = new Unifier();
+ u.unifies(new VarTerm("H"), new Atom("a"));
+ u.unifies(new VarTerm("T"), ListTermImpl.parseList("[b,c]"));
+ lt5.apply(u);
+ assertEquals("[a,b,c]",lt5.toString());
+ }
+
public void testGround() {
ListTerm l = ListTermImpl.parseList("[c,b,a,x,y,d]");
assertTrue(l.isGround());
Modified: trunk/src/test/VarTermTest.java
===================================================================
--- trunk/src/test/VarTermTest.java 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/src/test/VarTermTest.java 2008-04-13 10:45:08 UTC (rev 1214)
@@ -6,7 +6,6 @@
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.ArithExpr;
-import jason.asSyntax.Atom;
import jason.asSyntax.DefaultTerm;
import jason.asSyntax.ListTerm;
import jason.asSyntax.ListTermImpl;
@@ -255,11 +254,13 @@
// X[a,b,c] = p[a,c,b,d] ok (X is p)
assertTrue(u.unifies(v1, p1));
assertEquals(u.get("X").toString(), "p(t1,t2)");
+ v1.apply(u);
+ assertEquals("p(t1,t2)",v1.toString());
}
public void testVarWithAnnots2() {
// test vars annots
-
+
// X[a] = Y[a,b] - ok
VarTerm v1 = VarTerm.parseVar("X[a]");
VarTerm v2 = VarTerm.parseVar("Y[a,b]");
@@ -271,7 +272,7 @@
assertFalse(u.unifies(v2, v1));
assertTrue(u.unifies(v1, v2));
- assertTrue(u.unifies(new Atom("vvv"), v1));
+ assertTrue(u.unifies(new Literal("vvv"), v1));
v1.apply(u);
assertEquals("vvv", v1.toString());
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-04-10 21:40:17
|
Revision: 1213
http://jason.svn.sourceforge.net/jason/?rev=1213&view=rev
Author: jomifred
Date: 2008-04-10 14:40:07 -0700 (Thu, 10 Apr 2008)
Log Message:
-----------
creates jason x dummies files (actually we have dummies x dummies)
(see readme info for how to launch)
Modified Paths:
--------------
trunk/applications/jason-team/AC-Local-JasonTeam.mas2j
trunk/applications/jason-team/readme.txt
trunk/applications/jason-team/src/java/arch/CowboyArch.java
trunk/applications/jason-team/src/java/env/ACViewer.java
Added Paths:
-----------
trunk/applications/jason-team/AC-Local-Dummies.mas2j
trunk/applications/jason-team/dummies.xml
trunk/applications/jason-team/gauchos.xml
Added: trunk/applications/jason-team/AC-Local-Dummies.mas2j
===================================================================
--- trunk/applications/jason-team/AC-Local-Dummies.mas2j (rev 0)
+++ trunk/applications/jason-team/AC-Local-Dummies.mas2j 2008-04-10 21:40:07 UTC (rev 1213)
@@ -0,0 +1,46 @@
+/* Jason Team for the
+ * Multi-Agent Programming Contest 2008
+ * (http://cig.in.tu-clausthal.de/AgentContest)
+ *
+ * Configuration for contest simulator running local
+ *
+ */
+
+MAS dummies {
+ infrastructure: Centralised
+
+ agents:
+ dummy1 dummy.asl
+ [verbose=1, gui=no, write_status=no, ac_sim_back_dir="",
+ host="localhost", port=12300, username=botagent1, password="1"]
+ agentArchClass arch.ACArchitecture
+ agentClass agent.SelectEvent
+ beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","cell(_,_,key)","corral(_,_,_,_)","pratio(_)");
+ dummy2 dummy.asl
+ [verbose=1,host="localhost", port=12300, username=botagent2, password="2"]
+ agentArchClass arch.ACArchitecture
+ agentClass agent.SelectEvent
+ beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","cell(_,_,key)","corral(_,_,_,_)","pratio(_)");
+ dummy3 dummy.asl
+ [verbose=1,host="localhost", port=12300, username=botagent3, password="3"]
+ agentArchClass arch.ACArchitecture
+ agentClass agent.SelectEvent
+ beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","cell(_,_,key)","corral(_,_,_,_)","pratio(_)");
+ dummy4 dummy.asl
+ [verbose=1,host="localhost", port=12300, username=botagent4, password="4"]
+ agentArchClass arch.ACArchitecture
+ agentClass agent.SelectEvent
+ beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","cell(_,_,key)","corral(_,_,_,_)","pratio(_)");
+ dummy5 dummy.asl
+ [verbose=1,host="localhost", port=12300, username=botagent5, password="5"]
+ agentArchClass arch.ACArchitecture
+ agentClass agent.SelectEvent
+ beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","cell(_,_,key)","corral(_,_,_,_)","pratio(_)");
+ dummy6 dummy.asl
+ [verbose=1,host="localhost", port=12300, username=botagent6, password="6"]
+ agentArchClass arch.ACArchitecture
+ agentClass agent.SelectEvent
+ beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","cell(_,_,key)","corral(_,_,_,_)","pratio(_)");
+
+ aslSourcePath: "src/asl";
+}
Property changes on: trunk/applications/jason-team/AC-Local-Dummies.mas2j
___________________________________________________________________
Name: svn:executable
+ *
Modified: trunk/applications/jason-team/AC-Local-JasonTeam.mas2j
===================================================================
--- trunk/applications/jason-team/AC-Local-JasonTeam.mas2j 2008-04-10 15:26:59 UTC (rev 1212)
+++ trunk/applications/jason-team/AC-Local-JasonTeam.mas2j 2008-04-10 21:40:07 UTC (rev 1213)
@@ -6,37 +6,37 @@
*
*/
-MAS miners {
+MAS jason_cowboys {
infrastructure: Centralised
agents:
- dummy1 dummy.asl
+ gaucho1 dummy.asl
[verbose=1, gui=yes, write_status=yes, ac_sim_back_dir="./massim-server/backup",
host="localhost", port=12300, username=participant1, password="1"]
agentArchClass arch.ACArchitecture
agentClass agent.SelectEvent
beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","cell(_,_,key)","corral(_,_,_,_)","pratio(_)");
- dummy2 dummy.asl
+ gaucho2 dummy.asl
[verbose=1,host="localhost", port=12300, username=participant2, password="2"]
agentArchClass arch.ACArchitecture
agentClass agent.SelectEvent
beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","cell(_,_,key)","corral(_,_,_,_)","pratio(_)");
- dummy3 dummy.asl
+ gaucho3 dummy.asl
[verbose=1,host="localhost", port=12300, username=participant3, password="3"]
agentArchClass arch.ACArchitecture
agentClass agent.SelectEvent
beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","cell(_,_,key)","corral(_,_,_,_)","pratio(_)");
- dummy4 dummy.asl
+ gaucho4 dummy.asl
[verbose=1,host="localhost", port=12300, username=participant4, password="4"]
agentArchClass arch.ACArchitecture
agentClass agent.SelectEvent
beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","cell(_,_,key)","corral(_,_,_,_)","pratio(_)");
- dummy5 dummy.asl
+ gaucho5 dummy.asl
[verbose=1,host="localhost", port=12300, username=participant5, password="5"]
agentArchClass arch.ACArchitecture
agentClass agent.SelectEvent
beliefBaseClass agent.UniqueBelsBB("gsize(_,_)","steps(_)","cell(_,_,key)","corral(_,_,_,_)","pratio(_)");
- dummy6 dummy.asl
+ gaucho6 dummy.asl
[verbose=1,host="localhost", port=12300, username=participant6, password="6"]
agentArchClass arch.ACArchitecture
agentClass agent.SelectEvent
Added: trunk/applications/jason-team/dummies.xml
===================================================================
--- trunk/applications/jason-team/dummies.xml (rev 0)
+++ trunk/applications/jason-team/dummies.xml 2008-04-10 21:40:07 UTC (rev 1213)
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+
+<!--
+
+ This file was generated by Jason 1.1
+ http://jason.sf.net
+
+ April 10, 2008 - 23:19:55
+-->
+
+<project name ="miners"
+ basedir="."
+ default="run">
+
+ <property name="mas2j.project.file" value="AC-Local-Dummies.mas2j"/>
+ <property name="debug" value=""/> <!-- use "-debug" to run in debug mode -->
+ <property name="build.dir" value="${basedir}/bin/classes" />
+
+ <property name="jasonJar" value="../../lib/jason.jar"/>
+
+ <path id="project.classpath">
+ <pathelement location="${basedir}"/>
+ <pathelement location="${build.dir}"/>
+ <pathelement location="${jasonJar}"/>
+ <fileset dir="${basedir}/lib" > <include name="*.jar" /> </fileset>
+
+ </path>
+
+ <!-- tasks the user can override in his/her c-build.xml script -->
+ <target name="user-init">
+ </target>
+ <target name="user-end">
+ </target>
+
+ <target name="init">
+ <mkdir dir="${build.dir}" />
+ <antcall target="user-init" />
+ </target>
+
+ <target name="compile" depends="init">
+ <condition property="srcdir" value="${basedir}/src/java" else="${basedir}" >
+ <available file="${basedir}/src/java" />
+ </condition>
+ <javac srcdir="${srcdir}" destdir="${build.dir}" debug="true" optimize="true" >
+ <classpath refid="project.classpath"/>
+ </javac>
+ </target>
+
+ <target name="jar" depends="compile">
+ <delete file="${ant.project.name}.jar" />
+ <copy file="${jasonJar}" tofile="${ant.project.name}.jar" />
+ <copy file="${mas2j.project.file}" tofile="default.mas2j" />
+ <jar update="yes" jarfile="${ant.project.name}.jar" >
+ <fileset dir="${basedir}">
+ <include name="**/*.asl" />
+ <include name="**/*.mas2j" />
+ </fileset>
+ <fileset dir="${build.dir}">
+ <include name="**/*.class" />
+ </fileset>
+ </jar>
+ <delete file="default.mas2j" />
+ </target>
+
+
+ <target name="jnlp" depends="jar" >
+ <mkdir dir="${basedir}/${ant.project.name}-jws"/>
+ <java classname="jason.infra.centralised.CreateJNLP"
+ failonerror="true" fork="yes" dir="${basedir}/${ant.project.name}-jws" >
+ <classpath refid="project.classpath"/>
+ <arg line="${ant.project.name} ${mas2j.project.file}"/>
+ </java>
+ <copy todir="${basedir}/${ant.project.name}-jws" failonerror="no">
+ <fileset dir="${basedir}/lib" includes="**/*.jar" />
+ <fileset dir="${basedir}" includes="${ant.project.name}.jar" />
+ <fileset dir="/Users/jomi/Jason/Jason-svn/src/images" includes="Jason-GMoreau-Icon.jpg" />
+ </copy>
+ <signjar jar="${basedir}/${ant.project.name}-jws/${ant.project.name}.jar" alias="jason"
+ storepass="rbjhja" keypass="rbjhja" keystore="/Users/jomi/Jason/Jason-svn/src/jasonKeystore" />
+ <echo message="**" />
+ <echo message="** Java Web Start application created in directory ${ant.project.name}-jws" />
+ <echo message="** Update the codebase (in the second line of the .jnlp file)" />
+ <echo message="** with the URL where you will upload the application." />
+ <echo message="**" />
+ </target>
+
+
+ <target name="run" depends="compile" >
+ <echo message="Running project ${ant.project.name}" />
+ <java classname="jason.infra.centralised.RunCentralisedMAS"
+ failonerror="true" fork="yes" dir="${basedir}" >
+ <classpath refid="project.classpath"/>
+ <arg line="${mas2j.project.file} ${debug} "/>
+ <jvmarg line="-Xmx750M"/>
+ </java>
+ <antcall target="user-end" />
+ </target>
+
+ <target name="clean" >
+ <delete failonerror="no" includeEmptyDirs="true" verbose="true">
+ <fileset dir="${basedir}" includes="**/*.class"/>
+ </delete>
+ </target>
+
+
+
+</project>
Added: trunk/applications/jason-team/gauchos.xml
===================================================================
--- trunk/applications/jason-team/gauchos.xml (rev 0)
+++ trunk/applications/jason-team/gauchos.xml 2008-04-10 21:40:07 UTC (rev 1213)
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+
+<!--
+
+ This file was generated by Jason 1.1
+ http://jason.sf.net
+
+ April 10, 2008 - 23:22:26
+-->
+
+<project name ="jason_cowboys"
+ basedir="."
+ default="run">
+
+ <property name="mas2j.project.file" value="AC-Local-JasonTeam.mas2j"/>
+ <property name="debug" value=""/> <!-- use "-debug" to run in debug mode -->
+ <property name="build.dir" value="${basedir}/bin/classes" />
+
+ <property name="jasonJar" value="../../lib/jason.jar"/>
+
+ <path id="project.classpath">
+ <pathelement location="${basedir}"/>
+ <pathelement location="${build.dir}"/>
+ <pathelement location="${jasonJar}"/>
+ <fileset dir="${basedir}/lib" > <include name="*.jar" /> </fileset>
+
+ </path>
+
+ <!-- tasks the user can override in his/her c-build.xml script -->
+ <target name="user-init">
+ </target>
+ <target name="user-end">
+ </target>
+
+ <target name="init">
+ <mkdir dir="${build.dir}" />
+ <antcall target="user-init" />
+ </target>
+
+ <target name="compile" depends="init">
+ <condition property="srcdir" value="${basedir}/src/java" else="${basedir}" >
+ <available file="${basedir}/src/java" />
+ </condition>
+ <javac srcdir="${srcdir}" destdir="${build.dir}" debug="true" optimize="true" >
+ <classpath refid="project.classpath"/>
+ </javac>
+ </target>
+
+ <target name="jar" depends="compile">
+ <delete file="${ant.project.name}.jar" />
+ <copy file="${jasonJar}" tofile="${ant.project.name}.jar" />
+ <copy file="${mas2j.project.file}" tofile="default.mas2j" />
+ <jar update="yes" jarfile="${ant.project.name}.jar" >
+ <fileset dir="${basedir}">
+ <include name="**/*.asl" />
+ <include name="**/*.mas2j" />
+ </fileset>
+ <fileset dir="${build.dir}">
+ <include name="**/*.class" />
+ </fileset>
+ </jar>
+ <delete file="default.mas2j" />
+ </target>
+
+
+ <target name="jnlp" depends="jar" >
+ <mkdir dir="${basedir}/${ant.project.name}-jws"/>
+ <java classname="jason.infra.centralised.CreateJNLP"
+ failonerror="true" fork="yes" dir="${basedir}/${ant.project.name}-jws" >
+ <classpath refid="project.classpath"/>
+ <arg line="${ant.project.name} ${mas2j.project.file}"/>
+ </java>
+ <copy todir="${basedir}/${ant.project.name}-jws" failonerror="no">
+ <fileset dir="${basedir}/lib" includes="**/*.jar" />
+ <fileset dir="${basedir}" includes="${ant.project.name}.jar" />
+ <fileset dir="/Users/jomi/Jason/Jason-svn/src/images" includes="Jason-GMoreau-Icon.jpg" />
+ </copy>
+ <signjar jar="${basedir}/${ant.project.name}-jws/${ant.project.name}.jar" alias="jason"
+ storepass="rbjhja" keypass="rbjhja" keystore="/Users/jomi/Jason/Jason-svn/src/jasonKeystore" />
+ <echo message="**" />
+ <echo message="** Java Web Start application created in directory ${ant.project.name}-jws" />
+ <echo message="** Update the codebase (in the second line of the .jnlp file)" />
+ <echo message="** with the URL where you will upload the application." />
+ <echo message="**" />
+ </target>
+
+
+ <target name="run" depends="compile" >
+ <echo message="Running project ${ant.project.name}" />
+ <java classname="jason.infra.centralised.RunCentralisedMAS"
+ failonerror="true" fork="yes" dir="${basedir}" >
+ <classpath refid="project.classpath"/>
+ <arg line="${mas2j.project.file} ${debug} "/>
+ <jvmarg line="-Xmx750M"/>
+ </java>
+ <antcall target="user-end" />
+ </target>
+
+ <target name="clean" >
+ <delete failonerror="no" includeEmptyDirs="true" verbose="true">
+ <fileset dir="${basedir}" includes="**/*.class"/>
+ </delete>
+ </target>
+
+
+
+</project>
Modified: trunk/applications/jason-team/readme.txt
===================================================================
--- trunk/applications/jason-team/readme.txt 2008-04-10 15:26:59 UTC (rev 1212)
+++ trunk/applications/jason-team/readme.txt 2008-04-10 21:40:07 UTC (rev 1213)
@@ -13,25 +13,28 @@
To run this team:
1. update sources of Jason
- cd Jason-svn
- svn update
- ant plugin
+ cd Jason-svn
+ svn update
+ ant plugin
2. run massim-server
- cd applications/jason-team/massim-server
- ./startServer.sh
+ cd applications/jason-team/massim-server
+ ./startServer.sh
-3. run massim-agents (6 agents developed by the ContestTeam)
- cd ../massim-agents
- ./startAgents.sh
+3. run dummies (written in Jason)
+ ant -f dummies.xml
+
+ or those written by the Contest developers
+ cd ../massim-agents
+ ./startAgents.sh
-4. run Jason dummies (for now we do not have a team)
+4. run Jason team
a. by JasonIDE
../../bin/jason.sh
open an run AC-Local-JasonTeam.mas2j
- b. by Ant (only after run once by JasonIDE)
- ant -f bin/build.xml
+ b. by Ant
+ ant -f gauchos.xml
5. start the simulation
go to shell running startServer.sh and press ENTER
Modified: trunk/applications/jason-team/src/java/arch/CowboyArch.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/CowboyArch.java 2008-04-10 15:26:59 UTC (rev 1212)
+++ trunk/applications/jason-team/src/java/arch/CowboyArch.java 2008-04-10 21:40:07 UTC (rev 1213)
@@ -111,7 +111,7 @@
if (gui) {
view = new WorldView("Herding (view of cowboy "+(getMyId()+1)+") -- against "+opponent,model);
}
- if (massimBackDir != null) {
+ if (massimBackDir != null && massimBackDir.length() > 0) {
acView = new ACViewer(massimBackDir, w, h);
acView.setPriority(Thread.MIN_PRIORITY);
acView.start();
Modified: trunk/applications/jason-team/src/java/env/ACViewer.java
===================================================================
--- trunk/applications/jason-team/src/java/env/ACViewer.java 2008-04-10 15:26:59 UTC (rev 1212)
+++ trunk/applications/jason-team/src/java/env/ACViewer.java 2008-04-10 21:40:07 UTC (rev 1213)
@@ -118,12 +118,12 @@
public void run() {
while (true) {
try {
+ sleep(500);
File lastFile = getLastFile(getLastFile(massimServerBackupDir));
if (lastFile != null) {
logger.info("getting scenario from "+lastFile);
updateWorld(lastFile);
}
- sleep(500);
} catch (InterruptedException e) {
return;
} catch (NoSuchElementException e) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-04-10 15:27:07
|
Revision: 1212
http://jason.svn.sourceforge.net/jason/?rev=1212&view=rev
Author: jomifred
Date: 2008-04-10 08:26:59 -0700 (Thu, 10 Apr 2008)
Log Message:
-----------
improvement in jason team (32 cows)
Modified Paths:
--------------
trunk/applications/jason-team/massim-server/conf/serverconfig.xml
trunk/applications/jason-team/src/java/arch/LocalWorldModel.java
trunk/applications/jason-team/src/java/jia/Search.java
trunk/applications/jason-team/src/java/jia/Vec.java
trunk/applications/jason-team/src/java/jia/herd_position.java
trunk/applications/jason-team/src/java/test/TestBasicHerding.java
trunk/src/templates/build-template.xml
Modified: trunk/applications/jason-team/massim-server/conf/serverconfig.xml
===================================================================
--- trunk/applications/jason-team/massim-server/conf/serverconfig.xml 2008-04-10 07:17:08 UTC (rev 1211)
+++ trunk/applications/jason-team/massim-server/conf/serverconfig.xml 2008-04-10 15:26:59 UTC (rev 1212)
@@ -12,14 +12,17 @@
xmlobserverpath="."
xmlstatisticsobserver="massim.simulation.GridSimulationXMLStatisticsObserver"
file-simulationlog="./log"
- visualisationobserver="massim.simulation.GridSimulationVisualizationObserver"
+ visualisationobserver=""
>
+
+<!-- visualisationobserver="massim.simulation.GridSimulationVisualizationObserver" -->
+
<configuration
xmlns:meta="http://www.tu-clausthal.de/"
sizex="70"
sizey="70"
- maxNumberOfSteps="500"
+ maxNumberOfSteps="700"
numberOfAgents="12"
numberOfObstacles="200"
Modified: trunk/applications/jason-team/src/java/arch/LocalWorldModel.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/LocalWorldModel.java 2008-04-10 07:17:08 UTC (rev 1211)
+++ trunk/applications/jason-team/src/java/arch/LocalWorldModel.java 2008-04-10 15:26:59 UTC (rev 1212)
@@ -62,11 +62,9 @@
int w = 0;
while (true) {
for (int x=l.x-w; x<=l.x+w;x++)
- if (isFree(x,l.y))
- return new Location(x,l.y);
- for (int y=l.y-w; y<=l.y+w;y++)
- if (isFree(l.x,y))
- return new Location(l.x,y);
+ for (int y=l.y-w; y<=l.y+w;y++)
+ if (isFree(x,y))
+ return new Location(x,y);
w++;
}
}
Modified: trunk/applications/jason-team/src/java/jia/Search.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/Search.java 2008-04-10 07:17:08 UTC (rev 1211)
+++ trunk/applications/jason-team/src/java/jia/Search.java 2008-04-10 15:26:59 UTC (rev 1212)
@@ -6,6 +6,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
+import java.util.LinkedList;
import java.util.List;
import java.util.logging.Logger;
@@ -71,6 +72,19 @@
return searchAlg.busca(root);
}
+ public List<Nodo> normalPath(Nodo n) {
+ List<Nodo> r = new LinkedList<Nodo>();
+ while (n != null) {
+ r.add(0,n);
+ n = n.getPai();
+ }
+ return r;
+ }
+
+ public Location getNodeLocation(Nodo n) {
+ return ((GridState)n.getEstado()).pos;
+ }
+
public WorldModel.Move firstAction(Nodo solution) {
Nodo root = solution;
Estado prev1 = null;
Modified: trunk/applications/jason-team/src/java/jia/Vec.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/Vec.java 2008-04-10 07:17:08 UTC (rev 1211)
+++ trunk/applications/jason-team/src/java/jia/Vec.java 2008-04-10 15:26:59 UTC (rev 1212)
@@ -64,6 +64,15 @@
return max;
}
+ public static void cluster(List<Vec> vs, int maxstddev) {
+ Vec stddev = Vec.stddev(vs);
+ // remove max if stddev is too big
+ while (stddev.magnitude() > maxstddev) {
+ vs.remove(Vec.max(vs));
+ stddev = Vec.stddev(vs);
+ }
+ }
+
public static Vec mean(List<Vec> vs) {
if (vs.isEmpty())
return new Vec(0,0);
@@ -75,9 +84,6 @@
return new Vec(x/vs.size(), y/vs.size());
}
-
-
-
public static Vec stddev(List<Vec> vs) {
if (vs.isEmpty())
return new Vec(0,0);
Modified: trunk/applications/jason-team/src/java/jia/herd_position.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/herd_position.java 2008-04-10 07:17:08 UTC (rev 1211)
+++ trunk/applications/jason-team/src/java/jia/herd_position.java 2008-04-10 15:26:59 UTC (rev 1212)
@@ -13,7 +13,7 @@
import arch.CowboyArch;
import arch.LocalWorldModel;
-import env.WorldModel;
+import busca.Nodo;
/**
* Gives a good location to herd cows
@@ -30,7 +30,6 @@
LocalWorldModel model = ((CowboyArch)ts.getUserAgArch()).getModel();
-
Location agTarget = getAgTarget(model);
if (agTarget != null) {
agTarget = model.nearFree(agTarget);
@@ -44,6 +43,29 @@
}
public Location getAgTarget(LocalWorldModel model) throws Exception {
+ List<Vec> cows = new ArrayList<Vec>();
+ for (Location c: model.getCows()) {
+ cows.add(new Vec(model, c));
+ }
+ if (cows.isEmpty())
+ return null;
+
+ Vec.cluster(cows, 3); // find center/clusterise
+
+ Vec mean = Vec.mean(cows);
+
+ // run A* to see the cluster target in n steps
+ Search s = new Search(model, mean.getLocation(model), model.getCorralCenter(), null, false, false, false, null);
+ List<Nodo> np = s.normalPath(s.search());
+
+ int stepsFromCenter = (int)Vec.max(cows).sub(mean).magnitude()+1;
+ int n = Math.min(stepsFromCenter, np.size());
+
+ Vec ctarget = new Vec(model, s.getNodeLocation(np.get(n)));
+ Vec agTarget = mean.sub(ctarget).add(mean); // .product(1.5)
+ return agTarget.getLocation(model);
+
+ /*
List<Vec> cowsTarget = new ArrayList<Vec>();
for (Location c: model.getCows()) {
Search s = new Search(model, c, model.getCorralCenter(), null, false, false, false, null);
@@ -66,6 +88,7 @@
} else {
return null;
}
+ */
}
}
Modified: trunk/applications/jason-team/src/java/test/TestBasicHerding.java
===================================================================
--- trunk/applications/jason-team/src/java/test/TestBasicHerding.java 2008-04-10 07:17:08 UTC (rev 1211)
+++ trunk/applications/jason-team/src/java/test/TestBasicHerding.java 2008-04-10 15:26:59 UTC (rev 1212)
@@ -16,11 +16,9 @@
import arch.LocalWorldModel;
import busca.Nodo;
-import env.WorldModel;
public class TestBasicHerding {
- Vec cow;
Vec[] cows;
Vec cowboy;
LocalWorldModel model;
@@ -29,12 +27,14 @@
public void scenario() {
model = new LocalWorldModel(50,50);
model.setCorral(new Location(0,49), new Location(2,49));
-
- cow = new Vec(6,7);
+ model.wall(7, 44, 7, 49);
+ }
+
+ public void scenario1() {
cowboy = new Vec(3,5);
cows = new Vec[4];
- cows[0] = cow;
+ cows[0] = new Vec(6,7);
cows[1] = new Vec(5,30);
cows[2] = new Vec(4,8);
cows[3] = new Vec(5,10);
@@ -44,13 +44,33 @@
}
+ public void scenario2() {
+ cowboy = new Vec(11,3);
+
+ cows = new Vec[9];
+ cows[0] = new Vec(8,0);
+ cows[1] = new Vec(9,0);
+ cows[2] = new Vec(10,0);
+ cows[3] = new Vec(8,1);
+ cows[4] = new Vec(9,1);
+ cows[5] = new Vec(10,1);
+ cows[6] = new Vec(8,2);
+ cows[7] = new Vec(9,2);
+ cows[8] = new Vec(10,2);
+
+ for (int i=0; i<cows.length; i++)
+ model.addCow(cows[i].getLocation(model));
+
+ }
+
@Test
public void testVect() {
+ scenario1();
//assertEquals(new Vec(6,7), cow.add(cowboy));
//assertEquals(new Location(6,42), cow.add(cowboy).getLocation(model));
assertEquals(new Location(3,44), cowboy.getLocation(model));
assertEquals(new Location(1,49), model.getCorralCenter());
- assertEquals(new Vec(3,2), cow.sub(cowboy)); //new Vec(model, cowboy.getLocation(model), cow.add(cowboy).getLocation(model)));
+ assertEquals(new Vec(3,2), new Vec(6,7).sub(cowboy)); //new Vec(model, cowboy.getLocation(model), cow.add(cowboy).getLocation(model)));
}
/*
@@ -83,8 +103,9 @@
*/
+ /*
@Test
- public void moreCows() throws Exception {
+ public void moveCows1() throws Exception {
// get the location the cows should go
List<Vec> cowsTarget = new ArrayList<Vec>();
for (int i=0; i<cows.length; i++) {
@@ -119,6 +140,86 @@
Nodo path = s.search();
//System.out.println(path.g() + " " + path.montaCaminho());
assertEquals(14, path.g());
+ }
+ */
+
+ @Test
+ public void moveCows2() throws Exception {
+ scenario1();
+ List<Vec> cowsTarget = new ArrayList<Vec>();
+ for (int i=0; i<cows.length; i++) {
+ cowsTarget.add(cows[i]);
+ }
+
+ // find center/clusterise
+ Vec stddev = Vec.stddev(cowsTarget);
+ assertEquals(new Vec(0,9), stddev);
+
+ // remove max if stddev is too big
+ while (stddev.magnitude() > 3) {
+ cowsTarget.remove(Vec.max(cowsTarget));
+ stddev = Vec.stddev(cowsTarget);
+ }
+ assertTrue(stddev.magnitude() < 3);
+
+ Vec mean = Vec.mean(cowsTarget);
+ assertEquals(new Vec(5,8), mean);
+
+ int stepsFromCenter = (int)Vec.max(cowsTarget).sub(mean).magnitude()+1;
+ assertEquals(3, stepsFromCenter);
+
+ // run A* to see the cluster target in n steps
+ Search s = new Search(model, mean.getLocation(model), model.getCorralCenter(), null, false, false, false, null);
+ List<Nodo> np = s.normalPath(s.search());
+ int n = Math.min(stepsFromCenter, np.size());
+ assertEquals(3, n);
+
+ Vec ctarget = new Vec(model, s.getNodeLocation(np.get(n)));
+ assertEquals(new Vec(3,5), ctarget);
+
+ Vec agTarget = mean.sub(ctarget).product(1.0).add(mean);
+ assertEquals(new Vec(7,11), agTarget);
+
+ Location byIA = new herd_position().getAgTarget(model);
+ assertEquals(byIA, agTarget.getLocation(model));
}
+
+ @Test
+ public void moveCows3() throws Exception {
+ scenario2();
+ List<Vec> cowsTarget = new ArrayList<Vec>();
+ for (int i=0; i<cows.length; i++) {
+ cowsTarget.add(cows[i]);
+ }
+
+ // find center/clusterise
+ Vec.cluster(cowsTarget, 3);
+ Vec stddev = Vec.stddev(cowsTarget);
+ assertTrue(stddev.magnitude() < 3);
+
+ Vec mean = Vec.mean(cowsTarget);
+ assertEquals(new Vec(9,1), mean);
+
+ // run A* to see the cluster target in n steps
+ Search s = new Search(model, mean.getLocation(model), model.getCorralCenter(), null, false, false, false, null);
+ List<Nodo> np = s.normalPath(s.search());
+ //System.out.println(np);
+
+ int stepsFromCenter = (int)Vec.max(cowsTarget).sub(mean).magnitude()+1;
+ assertEquals(2, stepsFromCenter);
+ int n = Math.min(stepsFromCenter, np.size());
+ assertEquals(2, n);
+
+ Vec ctarget = new Vec(model, s.getNodeLocation(np.get(n)));
+ assertEquals(new Vec(8,3), ctarget);
+
+ Vec agTarget = mean.sub(ctarget).add(mean);
+ Location agLoc = model.nearFree(agTarget.getLocation(model));
+ assertEquals(new Location(11,49), agLoc);
+
+ Location byIA = new herd_position().getAgTarget(model);
+ assertEquals(byIA, agTarget.getLocation(model));
+ }
+
}
Modified: trunk/src/templates/build-template.xml
===================================================================
--- trunk/src/templates/build-template.xml 2008-04-10 07:17:08 UTC (rev 1211)
+++ trunk/src/templates/build-template.xml 2008-04-10 15:26:59 UTC (rev 1212)
@@ -37,7 +37,10 @@
</target>
<target name="compile" depends="init">
- <javac srcdir="${basedir}" destdir="${build.dir}" debug="true" optimize="true" >
+ <condition property="srcdir" value="${basedir}/src/java" else="${basedir}" >
+ <available file="${basedir}/src/java" />
+ </condition>
+ <javac srcdir="${srcdir}" destdir="${build.dir}" debug="true" optimize="true" >
<classpath refid="project.classpath"/>
</javac>
</target>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-04-10 07:17:12
|
Revision: 1211
http://jason.svn.sourceforge.net/jason/?rev=1211&view=rev
Author: jomifred
Date: 2008-04-10 00:17:08 -0700 (Thu, 10 Apr 2008)
Log Message:
-----------
use / instead of File.separator in Include class.
Modified Paths:
--------------
trunk/applications/as-unit-test/src/example/TestExample.java
trunk/applications/jason-moise/build.xml
trunk/applications/jason-moise/readme.txt
trunk/src/jason/asSemantics/Agent.java
trunk/src/jason/asSyntax/directives/Include.java
trunk/src/jason/bb/TextPersistentBB.java
trunk/src/jason/util/asl2xml.java
trunk/src/test/ASParserTest.java
Modified: trunk/applications/as-unit-test/src/example/TestExample.java
===================================================================
--- trunk/applications/as-unit-test/src/example/TestExample.java 2008-04-09 19:05:06 UTC (rev 1210)
+++ trunk/applications/as-unit-test/src/example/TestExample.java 2008-04-10 07:17:08 UTC (rev 1211)
@@ -23,9 +23,9 @@
}
@Test
- public void testBels() {
- ag.assertBel("b(20)",0);
- ag.assertBel("not b",0);
+ public void testInitialBels() {
+ ag.assertBel("b(20)",0); // agent must believe "b(20)" without any reasoning
+ ag.assertBel("not b",0);
ag.assertBel("not b(5)",0);
ag.assertBel("b(10) & b(20) & not b(60)",0);
}
Modified: trunk/applications/jason-moise/build.xml
===================================================================
--- trunk/applications/jason-moise/build.xml 2008-04-09 19:05:06 UTC (rev 1210)
+++ trunk/applications/jason-moise/build.xml 2008-04-10 07:17:08 UTC (rev 1211)
@@ -8,7 +8,7 @@
<property environment="env"/>
<property name="version" value="1"/>
- <property name="release" value="0.1"/>
+ <property name="release" value="1"/>
<property name="moiseDir" value="${env.HOME}/Moise/Moise-svn" />
<property name="distDir" value="${env.HOME}/tmp/jmoise-${version}.${release}" />
<property name="distFile" value="${env.HOME}/jason-moise-${version}.${release}" />
Modified: trunk/applications/jason-moise/readme.txt
===================================================================
--- trunk/applications/jason-moise/readme.txt 2008-04-09 19:05:06 UTC (rev 1210)
+++ trunk/applications/jason-moise/readme.txt 2008-04-10 07:17:08 UTC (rev 1211)
@@ -9,4 +9,4 @@
and start it. The chapter 4 of doc/tutorial.pdf explains in details
the examples.
-Note: Jason 1.0.1 is required.
+Note: Jason 1.1 is required.
Modified: trunk/src/jason/asSemantics/Agent.java
===================================================================
--- trunk/src/jason/asSemantics/Agent.java 2008-04-09 19:05:06 UTC (rev 1210)
+++ trunk/src/jason/asSemantics/Agent.java 2008-04-10 07:17:08 UTC (rev 1211)
@@ -127,18 +127,18 @@
boolean parsingOk = true;
if (asSrc != null) {
+ asSrc = asSrc.replaceAll("\\\\", "/");
setASLSrc(asSrc);
if (asSrc.startsWith(Include.CRPrefix)) {
// loads the class from a jar file (for example)
- asSrc = asSrc.replaceAll("\\\\", "/");
parseAS(Agent.class.getResource(asSrc.substring(Include.CRPrefix.length())).openStream());
} else {
// check whether source is an URL string
try {
parsingOk = parseAS(new URL(asSrc));
} catch (MalformedURLException e) {
- parsingOk = parseAS(asSrc);
+ parsingOk = parseAS(new File(asSrc));
}
}
}
@@ -192,7 +192,7 @@
}
public void setASLSrc(String file) {
- if (file != null && file.startsWith("."+File.separator))
+ if (file != null && file.startsWith("./"))
file = file.substring(2);
aslSource = file;
}
@@ -214,17 +214,17 @@
}
/** Adds beliefs and plans form a file */
- public boolean parseAS(String asFileName) {
+ public boolean parseAS(File asFile) {
try {
- parseAS(new FileInputStream(asFileName));
- logger.fine("as2j: AgentSpeak program '" + asFileName + "' parsed successfully!");
+ parseAS(new FileInputStream(asFile));
+ logger.fine("as2j: AgentSpeak program '" + asFile + "' parsed successfully!");
return true;
} catch (FileNotFoundException e) {
- logger.log(Level.SEVERE, "as2j: the AgentSpeak source file '"+asFileName+"' was not found!");
+ logger.log(Level.SEVERE, "as2j: the AgentSpeak source file '"+asFile+"' was not found!");
} catch (ParseException e) {
logger.log(Level.SEVERE, "as2j: parsing error:" + e.getMessage());
} catch (Exception e) {
- logger.log(Level.SEVERE, "as2j: error parsing \"" + asFileName + "\"", e);
+ logger.log(Level.SEVERE, "as2j: error parsing \"" + asFile + "\"", e);
}
return false;
}
Modified: trunk/src/jason/asSyntax/directives/Include.java
===================================================================
--- trunk/src/jason/asSyntax/directives/Include.java 2008-04-09 19:05:06 UTC (rev 1210)
+++ trunk/src/jason/asSyntax/directives/Include.java 2008-04-10 07:17:08 UTC (rev 1211)
@@ -27,7 +27,7 @@
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
if (outerContent == null)
return null;
- String file = ((StringTerm)directive.getTerm(0)).getString();
+ String file = ((StringTerm)directive.getTerm(0)).getString().replaceAll("\\\\", "/");
try {
String outerPrefix = outerContent.getASLSrc(); // the source file that has the include directive
InputStream in;
@@ -38,7 +38,7 @@
file = checkPathAndFixWithSourcePath(file, aslSourcePath, outerPrefix);
in = new URL(file).openStream();
- } if (outerPrefix.startsWith(CRPrefix)) {
+ } if (outerPrefix.startsWith(CRPrefix)) {
// outer is loaded from a resource ("application".jar) file, used for java web start
int posSlash = outerPrefix.lastIndexOf("/");
@@ -89,7 +89,7 @@
return f;
} else if (srcpath != null) {
for (String path: srcpath) {
- File newname = new File(path + File.separator + f.toString());
+ File newname = new File(path + "/" + f.toString());
if (newname.exists()) {
try {
return newname.getCanonicalFile().toString();
@@ -104,7 +104,7 @@
return urlPrefix + f;
} else if (srcpath != null) {
for (String path: srcpath) {
- String newname = urlPrefix + path + File.separator + f;
+ String newname = urlPrefix + path + "/" + f;
if (testURLSrc(newname)) {
return newname;
}
Modified: trunk/src/jason/bb/TextPersistentBB.java
===================================================================
--- trunk/src/jason/bb/TextPersistentBB.java 2008-04-09 19:05:06 UTC (rev 1210)
+++ trunk/src/jason/bb/TextPersistentBB.java 2008-04-10 07:17:08 UTC (rev 1211)
@@ -26,7 +26,7 @@
file = new File(ag.getTS().getUserAgArch().getAgName() + ".bb");
logger.fine("reading from file " + file);
if (file.exists()) {
- ag.parseAS(file.getAbsolutePath());
+ ag.parseAS(file.getAbsoluteFile());
ag.addInitialBelsInBB();
}
} catch (RevisionFailedException e) {
Modified: trunk/src/jason/util/asl2xml.java
===================================================================
--- trunk/src/jason/util/asl2xml.java 2008-04-09 19:05:06 UTC (rev 1210)
+++ trunk/src/jason/util/asl2xml.java 2008-04-10 07:17:08 UTC (rev 1211)
@@ -2,6 +2,7 @@
import jason.asSemantics.Agent;
+import java.io.File;
import java.io.StringReader;
import java.io.StringWriter;
@@ -43,7 +44,7 @@
Agent loadAg(String file) throws Exception {
Agent ag = new Agent();
- if (ag.parseAS(file)) {
+ if (ag.parseAS(new File(file))) {
ag.setASLSrc(file);
ag.addInitialBelsInBB();
return ag;
Modified: trunk/src/test/ASParserTest.java
===================================================================
--- trunk/src/test/ASParserTest.java 2008-04-09 19:05:06 UTC (rev 1210)
+++ trunk/src/test/ASParserTest.java 2008-04-10 07:17:08 UTC (rev 1211)
@@ -36,13 +36,13 @@
arch.setArchInfraTier(new CentralisedAgArch());
ag.setTS(new TransitionSystem(ag, null, null, arch));
- assertTrue(ag.parseAS("src/asl/kqmlPlans.asl"));
- assertTrue(ag.parseAS("examples/auction/ag1.asl"));
+ assertTrue(ag.parseAS(new File("src/asl/kqmlPlans.asl")));
+ assertTrue(ag.parseAS(new File("examples/auction/ag1.asl")));
Plan p = ag.getPL().get("l__0");
assertEquals(p.getBody().getPlanSize(), 1);
assertEquals(((PlanBody)p.getBody()).getBodyType(), PlanBody.BodyType.internalAction);
- assertTrue(ag.parseAS("examples/auction/ag2.asl"));
- assertTrue(ag.parseAS("examples/auction/ag3.asl"));
+ assertTrue(ag.parseAS(new File("examples/auction/ag2.asl")));
+ assertTrue(ag.parseAS(new File("examples/auction/ag3.asl")));
}
public void testLogicalExpr() throws Exception {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-04-09 19:05:14
|
Revision: 1210
http://jason.svn.sourceforge.net/jason/?rev=1210&view=rev
Author: jomifred
Date: 2008-04-09 12:05:06 -0700 (Wed, 09 Apr 2008)
Log Message:
-----------
fix bug in jar generation (windows)
Modified Paths:
--------------
trunk/build.xml
trunk/src/jason/asSemantics/Agent.java
trunk/src/jason/environment/grid/Location.java
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2008-04-09 17:07:30 UTC (rev 1209)
+++ trunk/build.xml 2008-04-09 19:05:06 UTC (rev 1210)
@@ -15,7 +15,7 @@
<property name="dist.properties" value="${basedir}/bin/dist.properties" />
<property name="version" value="1" />
- <property name="release" value="1" />
+ <property name="release" value="1.1" />
<property name="distDir" value="${env.HOME}/tmp/x/Jason-${version}.${release}" />
<property name="distFile" value="${env.HOME}/Jason-${version}.${release}" />
Modified: trunk/src/jason/asSemantics/Agent.java
===================================================================
--- trunk/src/jason/asSemantics/Agent.java 2008-04-09 17:07:30 UTC (rev 1209)
+++ trunk/src/jason/asSemantics/Agent.java 2008-04-09 19:05:06 UTC (rev 1210)
@@ -131,6 +131,7 @@
if (asSrc.startsWith(Include.CRPrefix)) {
// loads the class from a jar file (for example)
+ asSrc = asSrc.replaceAll("\\\\", "/");
parseAS(Agent.class.getResource(asSrc.substring(Include.CRPrefix.length())).openStream());
} else {
// check whether source is an URL string
Modified: trunk/src/jason/environment/grid/Location.java
===================================================================
--- trunk/src/jason/environment/grid/Location.java 2008-04-09 17:07:30 UTC (rev 1209)
+++ trunk/src/jason/environment/grid/Location.java 2008-04-09 19:05:06 UTC (rev 1210)
@@ -1,7 +1,7 @@
package jason.environment.grid;
public final class Location {
- public final int x, y;
+ public int x, y;
public Location(int x, int y) {
this.x = x;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-04-09 17:07:36
|
Revision: 1209
http://jason.svn.sourceforge.net/jason/?rev=1209&view=rev
Author: jomifred
Date: 2008-04-09 10:07:30 -0700 (Wed, 09 Apr 2008)
Log Message:
-----------
add jadeTools in build.xml
Modified Paths:
--------------
trunk/build.xml
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2008-04-09 13:27:38 UTC (rev 1208)
+++ trunk/build.xml 2008-04-09 17:07:30 UTC (rev 1209)
@@ -8,6 +8,7 @@
<property name="jasonJar" value="${basedir}/lib/jason.jar" />
<property name="jadeJar" value="${basedir}/lib/jade.jar" />
<property name="jadeHttpJar" value="${basedir}/lib/http.jar" />
+ <property name="jadeToolsJar" value="${basedir}/lib/jadeTools.jar" />
<property name="jasonSJar" value="${basedir}/lib/s-jason.jar" />
<property name="build.dir" value="${basedir}/bin/classes" />
@@ -26,6 +27,7 @@
<pathelement location="${saciJar}" />
<pathelement location="${jadeJar}" />
<pathelement location="${jadeHttpJar}" />
+ <pathelement location="${jadeToolsJar}" />
</path>
<path id="project.classpath">
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-04-09 13:28:08
|
Revision: 1208
http://jason.svn.sourceforge.net/jason/?rev=1208&view=rev
Author: jomifred
Date: 2008-04-09 06:27:38 -0700 (Wed, 09 Apr 2008)
Log Message:
-----------
improve jason team (18 cows collected!)
Modified Paths:
--------------
trunk/applications/jason-team/src/asl/dummy.asl
trunk/applications/jason-team/src/java/arch/ACArchitecture.java
trunk/applications/jason-team/src/java/arch/LocalWorldModel.java
trunk/applications/jason-team/src/java/arch/WriteStatusThread.java
trunk/applications/jason-team/src/java/env/WorldModel.java
trunk/applications/jason-team/src/java/jia/Search.java
trunk/applications/jason-team/src/java/jia/herd_position.java
trunk/applications/jason-team/todo.org
Added Paths:
-----------
trunk/applications/jason-team/src/java/jia/dist.java
Modified: trunk/applications/jason-team/src/asl/dummy.asl
===================================================================
--- trunk/applications/jason-team/src/asl/dummy.asl 2008-04-08 21:34:26 UTC (rev 1207)
+++ trunk/applications/jason-team/src/asl/dummy.asl 2008-04-09 13:27:38 UTC (rev 1208)
@@ -24,9 +24,17 @@
// find a free random location
random_pos(X,Y) :-
pos(AgX,AgY,_) &
- jia.random(RX,40) & X = (RX-20)+AgX & X > 0 &
- jia.random(RY,40,5) & Y = (RY-20)+AgY &
- not jia.obstacle(X,Y).
+ jia.random(RX,40) & RX > 5 & X = (RX-20)+AgX & X > 0 &
+ jia.random(RY,40,5) & RY > 5 & Y = (RY-20)+AgY &
+ not jia.obstacle(X,Y).
+
+// whether some location X,Y has an agent and I am near that location
+agent_in_target :-
+ pos(AgX,AgY,_) &
+ target(TX,TY) &
+ (cell(TX,TY,ally(_)) | cell(TX,TY,enemy(_)) | cell(TX,TY,cow(_))) &
+ jia.dist(TX,TY,AgX,AgY,D) &
+ D <= 2. // this number should be the same used by A* (DIST_FOR_AG_OBSTACLE constant)
/* -- initial goal */
@@ -40,6 +48,11 @@
<- jia.herd_position(X,Y); // compute new location
.print("COWS! going to ",X,",",Y);
-+target(X,Y). // go to there
+
++pos(_,_,_)
+ : not cell(_,_,cow(_)) // I see no cow
+ <- -target(_,_);
+ !move.
/* -- what todo when arrive at location */
@@ -47,8 +60,11 @@
+!decide_target // chose a new random pos
: not cell(_,_,cow(_))
<- ?random_pos(NX,NY);
+ .print("New random target: ",NX,",",NY);
-+target(NX,NY).
-+!decide_target.
++!decide_target
+ <- .print("No need for a new target, consider last herding location.");
+ do(skip). // send an action so that the simulator does not wait for me.
/* -- plans to move to a destination represented in the belief target(X,Y)
-- (it is a kind of persistent goal)
@@ -70,8 +86,10 @@
// find a new destination
+!move
: pos(X,Y,_) &
- (not target(_,_) | // I have no target OR
- target(X,Y) | // I am at target OR
+ (not target(_,_) | // I have no target OR
+ target(X,Y) | // I am at target OR
+ jia_obstacle(X,Y) | // An obstacle was discovered in the target
+ agent_in_target | // there is an agent in the target
(target(BX,BY) & jia.direction(X, Y, BX, BY, skip))) // is impossible to go to target
<- !decide_target.
Modified: trunk/applications/jason-team/src/java/arch/ACArchitecture.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/ACArchitecture.java 2008-04-08 21:34:26 UTC (rev 1207)
+++ trunk/applications/jason-team/src/java/arch/ACArchitecture.java 2008-04-09 13:27:38 UTC (rev 1208)
@@ -142,7 +142,10 @@
}
void newCycle() {
- logger.info("last action sent is "+lastActionInCurrentCycle+". The following was not sent: "+toExecute);
+ String w = "";
+ if (lastActionInCurrentCycle == null) w = "*** ";
+ logger.info(w+"Last sent action was "+lastActionInCurrentCycle+" for cycle "+getCycle()+". The following was not sent: "+toExecute);
+
setLastAct(lastActionInCurrentCycle);
lastActionInCurrentCycle = null;
Modified: trunk/applications/jason-team/src/java/arch/LocalWorldModel.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/LocalWorldModel.java 2008-04-08 21:34:26 UTC (rev 1207)
+++ trunk/applications/jason-team/src/java/arch/LocalWorldModel.java 2008-04-09 13:27:38 UTC (rev 1208)
@@ -59,7 +59,7 @@
}
public Location nearFree(Location l) throws Exception {
- int w = 1;
+ int w = 0;
while (true) {
for (int x=l.x-w; x<=l.x+w;x++)
if (isFree(x,l.y))
Modified: trunk/applications/jason-team/src/java/arch/WriteStatusThread.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/WriteStatusThread.java 2008-04-08 21:34:26 UTC (rev 1207)
+++ trunk/applications/jason-team/src/java/arch/WriteStatusThread.java 2008-04-09 13:27:38 UTC (rev 1208)
@@ -100,6 +100,7 @@
}
public String shortActionFormat(String act) {
+ if (act == null) return "";
if (act.equals(WorldModel.Move.east.toString())) return "e ";
if (act.equals(WorldModel.Move.northeast.toString())) return "ne";
if (act.equals(WorldModel.Move.southeast.toString())) return "se";
Modified: trunk/applications/jason-team/src/java/env/WorldModel.java
===================================================================
--- trunk/applications/jason-team/src/java/env/WorldModel.java 2008-04-08 21:34:26 UTC (rev 1207)
+++ trunk/applications/jason-team/src/java/env/WorldModel.java 2008-04-09 13:27:38 UTC (rev 1208)
@@ -57,7 +57,7 @@
@Override
public boolean isFree(int x, int y) {
- return super.isFree(x,y) && !hasObject(ENEMY, x, y) && !hasObject(COW, x, y) && !hasObject(CORRAL, x, y);
+ return super.isFree(x,y) && !hasObject(ENEMY, x, y) && !hasObject(AGENT, x, y) && !hasObject(COW, x, y) && !hasObject(CORRAL, x, y);
}
public WorldView getView() {
Modified: trunk/applications/jason-team/src/java/jia/Search.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/Search.java 2008-04-08 21:34:26 UTC (rev 1207)
+++ trunk/applications/jason-team/src/java/jia/Search.java 2008-04-09 13:27:38 UTC (rev 1208)
@@ -18,6 +18,8 @@
import env.WorldModel;
public class Search {
+
+ public static final int DIST_FOR_AG_OBSTACLE = 2;
final LocalWorldModel model;
final Location from, to;
@@ -187,9 +189,9 @@
return;
if (ia.considerCorralAsObstacles && ia.model.hasObject(WorldModel.CORRAL, newl))
return;
- if (ia.considerAgentsAsObstacles && ia.model.hasObject(WorldModel.AGENT,newl) && ia.from.maxBorder(newl) <= 2)
+ if (ia.considerAgentsAsObstacles && ia.model.hasObject(WorldModel.AGENT,newl) && ia.from.maxBorder(newl) <= Search.DIST_FOR_AG_OBSTACLE)
return;
- if (ia.considerCowsAsObstacles && ia.model.hasObject(WorldModel.COW,newl) && ia.from.maxBorder(newl) <= 2)
+ if (ia.considerCowsAsObstacles && ia.model.hasObject(WorldModel.COW,newl) && ia.from.maxBorder(newl) <= Search.DIST_FOR_AG_OBSTACLE)
return;
int cost = 1;
Added: trunk/applications/jason-team/src/java/jia/dist.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/dist.java (rev 0)
+++ trunk/applications/jason-team/src/java/jia/dist.java 2008-04-09 13:27:38 UTC (rev 1208)
@@ -0,0 +1,30 @@
+package jia;
+
+import java.util.logging.Level;
+
+import jason.asSemantics.*;
+import jason.asSyntax.*;
+import jason.environment.grid.Location;
+
+/**
+ * Gets the distance between two points.
+ *
+ * @author jomi
+ */
+public class dist extends DefaultInternalAction {
+
+ @Override
+ public Object execute(TransitionSystem ts, Unifier un, Term[] terms) throws Exception {
+ try {
+ int iagx = (int) ((NumberTerm) terms[0]).solve();
+ int iagy = (int) ((NumberTerm) terms[1]).solve();
+ int itox = (int) ((NumberTerm) terms[2]).solve();
+ int itoy = (int) ((NumberTerm) terms[3]).solve();
+ int dist = new Location(iagx, iagy).maxBorder(new Location(itox, itoy));
+ return un.unifies(terms[4], new NumberTermImpl(dist));
+ } catch (Throwable e) {
+ ts.getLogger().log(Level.SEVERE, "dist error: "+e, e);
+ }
+ return false;
+ }
+}
Modified: trunk/applications/jason-team/src/java/jia/herd_position.java
===================================================================
--- trunk/applications/jason-team/src/java/jia/herd_position.java 2008-04-08 21:34:26 UTC (rev 1207)
+++ trunk/applications/jason-team/src/java/jia/herd_position.java 2008-04-09 13:27:38 UTC (rev 1208)
@@ -30,9 +30,13 @@
LocalWorldModel model = ((CowboyArch)ts.getUserAgArch()).getModel();
- Location agTarget = model.nearFree(getAgTarget(model));
- return un.unifies(terms[0], new NumberTermImpl(agTarget.x)) &&
- un.unifies(terms[1], new NumberTermImpl(agTarget.y));
+
+ Location agTarget = getAgTarget(model);
+ if (agTarget != null) {
+ agTarget = model.nearFree(agTarget);
+ return un.unifies(terms[0], new NumberTermImpl(agTarget.x)) &&
+ un.unifies(terms[1], new NumberTermImpl(agTarget.y));
+ }
} catch (Throwable e) {
ts.getLogger().log(Level.SEVERE, "herd_position error: "+e, e);
}
Modified: trunk/applications/jason-team/todo.org
===================================================================
--- trunk/applications/jason-team/todo.org 2008-04-08 21:34:26 UTC (rev 1207)
+++ trunk/applications/jason-team/todo.org 2008-04-09 13:27:38 UTC (rev 1208)
@@ -1,3 +1,4 @@
+* faster simulator
* develop a team of dummies to play against
** what is a dummy strategy?
* base components
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gf...@us...> - 2008-04-08 21:34:29
|
Revision: 1207
http://jason.svn.sourceforge.net/jason/?rev=1207&view=rev
Author: gfronza
Date: 2008-04-08 14:34:26 -0700 (Tue, 08 Apr 2008)
Log Message:
-----------
MANIFEST.MF changed to the new plug-in version: 1.1.1.
Modified Paths:
--------------
trunk/applications/jason-eclipse-plugin/META-INF/MANIFEST.MF
Modified: trunk/applications/jason-eclipse-plugin/META-INF/MANIFEST.MF
===================================================================
--- trunk/applications/jason-eclipse-plugin/META-INF/MANIFEST.MF 2008-04-08 16:38:29 UTC (rev 1206)
+++ trunk/applications/jason-eclipse-plugin/META-INF/MANIFEST.MF 2008-04-08 21:34:26 UTC (rev 1207)
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: JasonIDE Plug-in
Bundle-SymbolicName: net.sourceforge.jasonide;singleton:=true
-Bundle-Version: 1.0.1
+Bundle-Version: 1.1.1
Bundle-Activator: net.sourceforge.jasonide.Activator
Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|