|
From: <tom...@us...> - 2008-04-03 01:24:28
|
Revision: 1202
http://jason.svn.sourceforge.net/jason/?rev=1202&view=rev
Author: tomklapiscak
Date: 2008-04-02 18:24:25 -0700 (Wed, 02 Apr 2008)
Log Message:
-----------
Implemented experimental annotation gathering functionality (using Bebops library). Disabled by default, can be enabled in .mas2j (jasdl_useAnnotationGathering="true").
Implemented jasdl.ia.is_annotation_gathering_enabled and jasdl_ia.is_belief_revision_enabled internal actions to test status of experiemental features.
Implemented jasdl.ia.set_annotation_gathering_enabled and jasdl.ia.set_belief_revision_enabled internal actions to complement .mas2j settings.
Implemented workaround for strange behaviour when using Pellets isConsistent(OWLOntology) method (with agent.isBBConsistent() method).
Modified Paths:
--------------
trunk/applications/jasdl-owlapi/build.xml
trunk/applications/jasdl-owlapi/examples/travel_agent/config.mas2j
trunk/applications/jasdl-owlapi/examples/travel_agent/travel_agent.asl
trunk/applications/jasdl-owlapi/lib/bebops.jar
trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java
trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlConfigurator.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/bridge/factory/AxiomToSELiteralConverter.java
trunk/applications/jasdl-owlapi/src/jasdl/test/JasdlBeliefBaseTest.java
trunk/applications/jasdl-owlapi/src/jasdl/util/exception/JasdlException.java
Added Paths:
-----------
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
Modified: trunk/applications/jasdl-owlapi/build.xml
===================================================================
--- trunk/applications/jasdl-owlapi/build.xml 2008-04-02 21:13:50 UTC (rev 1201)
+++ trunk/applications/jasdl-owlapi/build.xml 2008-04-03 01:24:25 UTC (rev 1202)
@@ -2,12 +2,16 @@
<property name="jason.dir" value="../.."/>
<property name="apps.dir" value="${jason.dir}/applications"/>
<property name="jmca.dir" value="${apps.dir}/jmca"/>
+ <property name="bebops.dir" value="${apps.dir}/bebops"/>
+ <property name="bebops.jar" value="${bebops.dir}/lib/bebops.jar"/>
<property name="asunit.dir" value="${apps.dir}/as-unit-test"/>
<property name="source.dir" value="${basedir}/src" />
<property name="build.dir" value="${basedir}/bin" />
<property name="apidocs.dir" value="${basedir}/doc/api" />
- <property name="jar.file" value="${basedir}/lib/jasdl.jar" />
+ <property name="lib.dir" value="${basedir}/lib" />
+ <property name="jasdl.jar" value="${lib.dir}/jasdl.jar" />
+
<path id="project.classpath">
<pathelement location="${jason.dir}/lib/jason.jar"/>
@@ -26,21 +30,27 @@
<target name="init">
<tstamp/>
<mkdir dir="${build.dir}"/>
+ <available file="${bebops.dir}" type="dir" property="bebops.available"/>
</target>
- <target name="compile" depends="init">
+ <target name="bebops" depends="init" if="bebops.available">
+ <ant dir="${bebops.dir}" inheritAll="false"/>
+ <copy file="${bebops.jar}" todir="${lib.dir}"/>
+ </target>
+
+ <target name="compile" depends="init, bebops">
<javac srcdir="src" destdir="${build.dir}" debug="true" deprecation="true" optimize="true" nowarn="true" source="1.5" target="1.5">
<classpath refid="project.classpath" />
</javac>
</target>
<target name="jar" depends="compile">
- <jar destfile="${jar.file}" basedir="./bin" includes="**/*.class"/>
+ <jar destfile="${jasdl.jar}" basedir="./bin" includes="**/*.class"/>
</target>
<target name="clean">
<delete dir="${build.dir}"/>
- <delete file="${jar.file}"/>
+ <delete file="${jasdl.jar}"/>
<delete dir="${apidocs.dir}"/>
</target>
Modified: trunk/applications/jasdl-owlapi/examples/travel_agent/config.mas2j
===================================================================
--- trunk/applications/jasdl-owlapi/examples/travel_agent/config.mas2j 2008-04-02 21:13:50 UTC (rev 1201)
+++ trunk/applications/jasdl-owlapi/examples/travel_agent/config.mas2j 2008-04-03 01:24:25 UTC (rev 1202)
@@ -32,6 +32,7 @@
travel_agent.asl
[
jasdl_useBeliefRevision = "true", // use experimental DL-based belief revision mechanism
+ jasdl_useAnnotationGathering = "true", // use experimental annotation gathering mechanism
/*
* To use FaCT++, set the below. Must have libFaCTPlusPlusJNI.so in /usr/lib (or the equivalent for Mac or Windows)
Modified: trunk/applications/jasdl-owlapi/examples/travel_agent/travel_agent.asl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/travel_agent/travel_agent.asl 2008-04-02 21:13:50 UTC (rev 1201)
+++ trunk/applications/jasdl-owlapi/examples/travel_agent/travel_agent.asl 2008-04-03 01:24:25 UTC (rev 1202)
@@ -19,12 +19,12 @@
*/
!start(total).
-!start(ubb1).!example_UBB_1.!end(ubb1).
-!start(ubb2).!example_UBB_2.!end(ubb2).
+!start(ubb1).!example_UBB.!end(ubb1).
+!start(ubb2).!example_brf.!end(ubb2).
!start(qbb).!example_QBB.!end(qbb).
!start(rpp).!example_RPP.!end(rpp).
!start(all_different).!example_all_different.!end(all_different).
-//!example_annotation_gathering.
+!start(annnotation_gathering).!example_annotation_gathering.!end(annnotation_gathering).
!start(ksaa).!example_KSAA.!end(ksaa).
//!end(total) is within example_KSAA_complete to allow inter-agent communication to finish
@@ -42,9 +42,9 @@
.print("Execution time for counter ",A,": ",TotalTime,"s").
@example_ubb_1[atomic]
-+!example_UBB_1
++!example_UBB
<-
- .print("Example: Updating Belief Base 1");
+ .print("Example: Updating Belief Base");
+hotel(hilton)[o(travel)]; // hilton is a hotel
+hasRating(hilton, threeStarRating)[o(travel)]; // hilton has three-star rating
+town(london)[o(travel)];
@@ -58,12 +58,23 @@
+museums(scienceMuseum)[o(travel)];
+hasActivity(london, scienceMuseum)[o(travel)];
+hotel(travel_lodge)[o(travel)];
- .print("Completed: Updating Belief Base 1").
+ .print("Completed: Updating Belief Base").
+
+@example_brf[atomic]
++!example_brf
+ <-
+ jasdl.ia.is_belief_revision_enabled(true);
+ !example_brf_continue.
-@example_ubb_2[atomic]
-+!example_UBB_2
+@example_brf_fail[atomic]
+-!example_brf
+ <-
+ .print("Belief revision feature disabled, skipping").
+
+@example_brf_continue[atomic]
++!example_brf_continue
<-
- .print("Example: Updating Belief Base 2");
+ .print("Example: Belief Revision");
jasdl.ia.define_class(tiny, "travel:urbanArea and travel:hasActivity max 1 travel:activity");
+tiny(newcastle)[o(self), source(tom)];
@@ -83,25 +94,19 @@
+ruralArea(somewhere)[o(travel), source(tom)];
?ruralArea(somewhere)[o(travel)];
-
-
-
- .print("DL-based belief revision is enabled"); // without, the above test-goal will fail, since legacy mechanism simply removes incoming inconsistent beliefs
-
-
// since the classes destination and and contact are disjoint (and ruralArea is a subclass of destination),
// and since we trust ben less than tom, the belief addition below will fail (and tom's assertion above will persist),
// thus failing the whole plan.
+contact(somewhere)[o(travel), source(ben)];
- .print("Failed: Updating Belief Base 2").
+ .print("Failed: Belief Revision").
-@example_UBB_2_failure[atomic]
--!example_UBB_2
+@example_brf_continue_fail[atomic]
+-!example_brf_continue
<-
// Notice this does not hold, since belief revision rejected the less trusted assertion made by ben.
?~contact(somewhere)[o(travel)];
- .print("Completed: Updating Belief Base 2").
+ .print("Completed: Belief Revision").
@example_qbb[atomic, breakpoint]
+!example_QBB
@@ -157,18 +162,22 @@
@example_all_different[atomic]
+!example_all_different
<-
- .print("Example: all_different assertion");
+
+
+ .print("Example: all_different assertion");
+destination(butlins)[o(travel)];
+hotel(butlins_hotel)[o(travel)];
+hasAccommodation(butlins, butlins_hotel)[o(travel)];
+yoga(butlins_yoga)[o(travel)];
- +sunbathing(butlins_sunbathing)[o(travel)];
+ +sunbathing(butlins_sunbathing)[o(travel)];
+hasActivity(butlins, butlins_yoga)[o(travel)];
+ //jasdl.ia.all_different([butlins_yoga, butlins_sunbathing], travel); - DEPRECATED (see below)
+hasActivity(butlins, butlins_sunbathing)[o(travel)];
- //jasdl.ia.all_different([butlins_yoga, butlins_sunbathing], travel); - DEPRECATED (see below)
- +all_different([butlins_yoga, butlins_sunbathing])[o(self), something]; // all_different now represented as an se-literal. We can now query, inspect and send these assertions
+ +all_different([butlins_yoga, butlins_sunbathing])[o(self)]; // all_different now represented as an se-literal. We can now query, inspect and send these assertions
+
// Query below will not succeed unless butlins_yoga and butlins_sunbathing are different individuals since family destination requires min 2 *different* activities.
// Note: OWL doesn't make UNA and since these individuals do not belong to disjoint classes, therefore they must be explicitly asserted as different.
+
?familyDestination(butlins)[o(travel)];
?all_different([butlins_yoga, butlins_sunbathing, hilton])[o(self)];
/* ?all_different([hilton, fourSeasons])[o(travel)]; */ // Will fail, since hilton and fourSeasons cannot be established as distinct
@@ -178,6 +187,17 @@
@example_annotation_gathering[atomic]
+!example_annotation_gathering
<-
+ jasdl.ia.is_annotation_gathering_enabled(true); // why does True not fail immediately? possible Jason bug?
+ !example_annotation_gathering_continue.
+
+@example_annotation_gathering_fail[atomic]
+-!example_annotation_gathering
+ <-
+ .print("Annotation gathering feature disabled, skipping").
+
+@example_annotation_gathering_continue[atomic]
++!example_annotation_gathering_continue
+ <-
.print("Example: annotation gathering");
+ruralArea(kingsworthy)[o(travel), annotation];
?destination(kingsworthy)[o(travel), annotation];
@@ -190,9 +210,10 @@
+urbanArea(x)[o(travel), source(tom)];
+ruralArea(y)[o(travel), source(ben)];
// because knowledge from tom and ben contributed to the inference that x and y are distinct
- ?all_different([x,y])[o(travel), source(tom), source(ben)];
+ ?all_different([x,y])[o(self), source(tom), source(ben)];
// notice "something" annotation is gathered (added in !example_all_different) here since it all_different assertion contributes to this inference
+ +all_different([butlins_yoga, butlins_sunbathing])[o(self), something];
?familyDestination(butlins)[o(travel), something];
.print("Complete: annotation gathering").
Modified: trunk/applications/jasdl-owlapi/lib/bebops.jar
===================================================================
(Binary files differ)
Modified: trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java 2008-04-02 21:13:50 UTC (rev 1201)
+++ trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java 2008-04-03 01:24:25 UTC (rev 1202)
@@ -98,10 +98,12 @@
private HashMap<Atom, Float> trustMap;
private boolean beliefRevisionEnabled;
+ private boolean annotationGatheringEnabled;
private List<MappingStrategy> defaultMappingStrategies = JasdlConfigurator.DEFAULT_MAPPING_STRATEGIES;
- public JasdlAgent(){
+
+ public JasdlAgent() throws Exception{
super();
// instantiate managers
@@ -160,7 +162,7 @@
public List<Literal> getABoxState() throws JasdlException{
List<Literal> bels = new Vector<Literal>();
for(OWLOntology ontology : ontologyManager.getOntologies()){
- for(OWLIndividualAxiom axiom : ontology.getIndividualAxioms()){
+ for(OWLIndividualAxiom axiom : ontology.getIndividualAxioms()){
Literal l = axiomToSELiteralConverter.convert(axiom).getLiteral();
bels.add(l);
}
@@ -184,10 +186,12 @@
public List<Literal>[] brf(Literal beliefToAdd, Literal beliefToDel, Intention i) throws RevisionFailedException {
// TODO: what annotations should revision contractions contain? all! (or none? - same effect)
+
// No! the same. -a[x] only undermines assertions leading to a[x]!
// if we are performing belief-revision all annotations will be gathered (shortcut - use none?) ensuring axiom will be obliterated
// annotations never solely lead to conflicts.
+ // TODO: these is a bug hiding in this somewhere. Using below causes strange failures
if(!isBeliefRevisionEnabled()){ // if experimental feature is disabled
return super.brf(beliefToAdd, beliefToDel, i);
}
@@ -210,13 +214,19 @@
BeliefBaseSemiRevisor bbrev = new BeliefBaseSemiRevisor(axiomToAdd, getOntologyManager(), new JasdlReasonerFactory(), getLogger());
List<OWLAxiom> contractList = bbrev.revise(new TBoxAxiomKernelsetFilter(), new JasdlIncisionFunction(this, sl));
- // will only have reached here if new belief is accepted.
- addList.add(beliefToAdd);
+
for(OWLAxiom contract : contractList){
removeList.add(axiomToSELiteralConverter.convert((OWLIndividualAxiom)contract).getLiteral());
}
- revisionApplied = true;
+ if(!removeList.isEmpty()){
+ getLogger().info("brf: contracted "+removeList);
+ revisionApplied = true;
+ }
+
+ addList.add(beliefToAdd); // will only reach here if belief accepted (or bef is disabled)
+
}catch(BebopsRevisionFailedException e){
+ getLogger().info("brf: rejected "+e.getMessage());
throw new RevisionFailedException(); // propagate upwards
}catch(NotEnrichedException e){
// can't perform DL-based belief revision on SN-Literals
@@ -233,6 +243,7 @@
// Need to perform removals before additions so our ontology instance never becomes inconsistent
for(Literal removed : removeList){
+
boolean ok = false;
if(revisionApplied){
ok = true;
@@ -246,7 +257,8 @@
}
ok = believes(removed, u);
if(ok) removed.apply(u);
- }
+ }
+
if(ok){
if(getBB().remove(removed)){
if(toReturn == null){
@@ -545,7 +557,8 @@
}
} catch (OWLReasonerException e) {
throw new JasdlException("Unable to refresh reasoner. Reason: "+e);
- }
+ }
+
}
@@ -561,9 +574,25 @@
Log4JLogger kb_logger = (Log4JLogger)pellet.getKB().log;
kb_logger.getLogger().setLevel(level);
}
- }
+ }
/**
+ * For some reason, use of pellet's isConsistent(OWLOntology) method causes strange behaviour.
+ * So we wrap it's isConsistent() method here.
+ * TODO: resolve this issue properly
+ * @return
+ * @throws JasdlException
+ */
+ public boolean isBBConsistent() throws JasdlException{
+ if(getReasoner() instanceof org.mindswap.pellet.owlapi.Reasoner){
+ return((org.mindswap.pellet.owlapi.Reasoner)getReasoner()).isConsistent();
+ }else{
+ //TODO: FaCT++
+ throw new JasdlException("isBBConsistent not implemented for FaCT++ reasoner");
+ }
+ }
+
+ /**
* *Must* be unique within society!
* @return
*/
@@ -676,7 +705,20 @@
return trustMap.get(name);
}
+
+
+ public boolean isAnnotationGatheringEnabled() {
+ return annotationGatheringEnabled;
+ }
+
+
+
+ public void setAnnotationGatheringEnabled(boolean annotationGatheringEnabled) {
+ this.annotationGatheringEnabled = annotationGatheringEnabled;
+ }
+
+
}
Modified: trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlConfigurator.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlConfigurator.java 2008-04-02 21:13:50 UTC (rev 1201)
+++ trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlConfigurator.java 2008-04-03 01:24:25 UTC (rev 1202)
@@ -20,6 +20,7 @@
import java.util.Vector;
import java.util.logging.Level;
+import org.mindswap.pellet.PelletOptions;
import org.semanticweb.owl.inference.OWLReasoner;
import org.semanticweb.owl.model.OWLEntity;
import org.semanticweb.owl.model.OWLOntology;
@@ -34,14 +35,15 @@
public static String MAS2J_TRUSTRATING = "_trustRating";
public static String MAS2J_KNOWNAGENTS = "_knownAgents";
public static String MAS2J_USEBELIEFREVISION = "_useBeliefRevision";
+ public static String MAS2J_USEANNOTATIONGATHERING = "_useAnnotationGathering";
public static String MAS2J_REASONERCLASS = "_reasonerClass";
public static List<MappingStrategy> DEFAULT_MAPPING_STRATEGIES = Arrays.asList( new MappingStrategy[] { new DecapitaliseMappingStrategy()} );
public static String DEFAULT_REASONER_CLASS = "org.mindswap.pellet.owlapi.Reasoner";
public static boolean DEFAULT_USEBELIEFREVISION = false;
+ public static boolean DEFAULT_USEANNOTATIONGATHERING = false;
-
/**
* List of reserved ontology labels. Currently:
* <ul>
@@ -65,6 +67,7 @@
loadReasoner(stts);
loadDefaultMappingStrategies(stts);
setUseBeliefRevision(stts);
+ setUseAnnotationGathering(stts);
loadOntologies(stts);
applyManualMappings(stts);
loadKnownAgents(stts);
@@ -108,7 +111,17 @@
}
}
+ private void setUseAnnotationGathering(Settings stts) throws JasdlException{
+ try{
+ // set whether to use belief revision or not
+ String useAnnotationGathering = prepareUserParameter(stts, MAS2J_PREFIX + MAS2J_USEANNOTATIONGATHERING);
+ agent.setAnnotationGatheringEnabled(Boolean.parseBoolean(useAnnotationGathering));
+ }catch(JasdlConfigurationException e){
+ agent.setAnnotationGatheringEnabled(DEFAULT_USEANNOTATIONGATHERING);
+ }
+ }
+
/**
* Load ontologies as specified in .mas2j settings
* @param stts .mas2j settings
Modified: trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlBeliefBase.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlBeliefBase.java 2008-04-02 21:13:50 UTC (rev 1201)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlBeliefBase.java 2008-04-03 01:24:25 UTC (rev 1202)
@@ -45,7 +45,8 @@
boolean containsAxiom = ontology.containsAxiom(axiom);
if(!containsAxiom){
- agent.getOntologyManager().applyChange(new AddAxiom(ontology, axiom));
+ agent.getOntologyManager().applyChange(new AddAxiom(ontology, axiom));
+ agent.refreshReasoner();
}
boolean containsAllAnnots = true;
@@ -55,13 +56,16 @@
if(!ontology.containsAxiom(annotAxiom)){
containsAllAnnots = false;
agent.getOntologyManager().applyChange(new AddAxiom(ontology, annotAxiom));
+ agent.refreshReasoner();
}
- }
+ }
- if(!containsAxiom || !containsAllAnnots){
- agent.refreshReasoner();
- if(!agent.isBeliefRevisionEnabled()){ // if brf disabled, resort to legacy consistency maintenance mechanism
- if(!agent.getReasoner().isConsistent(ontology)){
+
+
+ if(!containsAxiom || !containsAllAnnots){
+ if(!agent.isBeliefRevisionEnabled()){ // if brf disabled, resort to legacy consistency maintenance mechanism
+ if(!agent.isBBConsistent()){
+ getLogger().info("legacy consistency assurance: rejected "+axiom);
RemoveAxiom rem = new RemoveAxiom(ontology, axiom);
agent.getOntologyManager().applyChange(rem);
agent.refreshReasoner();
@@ -192,6 +196,8 @@
getLogger().fine("Getting relevancies for "+l);
+
+
Set<Literal> relevant = new HashSet<Literal>();
try{
SELiteral sl = agent.getSELiteralFactory().construct(l);
Modified: trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlIncisionFunction.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlIncisionFunction.java 2008-04-02 21:13:50 UTC (rev 1201)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlIncisionFunction.java 2008-04-03 01:24:25 UTC (rev 1202)
@@ -15,7 +15,7 @@
import bebops.common.IncisionFunction;
-public class JasdlIncisionFunction implements IncisionFunction{
+public class JasdlIncisionFunction extends IncisionFunction{
private JasdlAgent agent;
@@ -39,23 +39,21 @@
* Currently calculated using ASSERTED source annotations only.
* No source annotation is taken as trust = 0;
*/
- public Set<OWLAxiom> apply(Set<Set<OWLAxiom>> kernelset) {
+ public Set<OWLAxiom> applyToOne(Set<OWLAxiom> akernel){
try{
Set<OWLAxiom> chosen = new HashSet<OWLAxiom>();
- for(Set<OWLAxiom> akernel : kernelset){
- if(!akernel.isEmpty()){
- OWLAxiom leastTrusted = null; // guaranteed to take a value
- float minTrustRating = 1f;
- for(OWLAxiom axiom : akernel){
- float trustRating = getTrustRating(axiom);
- agent.getLogger().finest("Trust rating of "+axiom+"="+trustRating);
- if(trustRating <= minTrustRating){
- minTrustRating = trustRating;
- leastTrusted = axiom;
- }
+ if(!akernel.isEmpty()){
+ OWLAxiom leastTrusted = null; // guaranteed to take a value
+ float minTrustRating = 1f;
+ for(OWLAxiom axiom : akernel){
+ float trustRating = getTrustRating(axiom);
+ agent.getLogger().finest("Trust rating of "+axiom+"="+trustRating);
+ if(trustRating <= minTrustRating){
+ minTrustRating = trustRating;
+ leastTrusted = axiom;
}
- chosen.add(leastTrusted);
- }
+ }
+ chosen.add(leastTrusted);
}
return chosen;
}catch(Exception e){
@@ -66,6 +64,7 @@
/**
* Currently returns the trust rating of the most trusted source. Future work will look at better ways of calculating this.
+ * TODO: Essentially duplicating work here. Annotation gathering (performed by AxiomToSELiteralConverter) requires axiom-pinponting - so does contraction.
* @param axiom
* @return
* @throws JasdlException
Modified: trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/AxiomToSELiteralConverter.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/AxiomToSELiteralConverter.java 2008-04-02 21:13:50 UTC (rev 1201)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/AxiomToSELiteralConverter.java 2008-04-03 01:24:25 UTC (rev 1202)
@@ -1,6 +1,8 @@
package jasdl.bridge.factory;
import jasdl.asSemantics.JasdlAgent;
+import jasdl.bb.JasdlReasonerFactory;
+import jasdl.bb.TBoxAxiomKernelsetFilter;
import jasdl.bridge.mapping.aliasing.Alias;
import jasdl.bridge.mapping.aliasing.AllDifferentPlaceholder;
import jasdl.bridge.seliteral.SELiteral;
@@ -17,20 +19,27 @@
import java.util.List;
import java.util.Set;
import java.util.Vector;
+import java.util.logging.Logger;
+import org.semanticweb.owl.inference.OWLReasonerException;
import org.semanticweb.owl.model.OWLAxiom;
import org.semanticweb.owl.model.OWLAxiomAnnotationAxiom;
import org.semanticweb.owl.model.OWLClassAssertionAxiom;
import org.semanticweb.owl.model.OWLConstant;
import org.semanticweb.owl.model.OWLDataPropertyAssertionAxiom;
import org.semanticweb.owl.model.OWLDifferentIndividualsAxiom;
+import org.semanticweb.owl.model.OWLException;
import org.semanticweb.owl.model.OWLIndividual;
import org.semanticweb.owl.model.OWLIndividualAxiom;
import org.semanticweb.owl.model.OWLObjectPropertyAssertionAxiom;
import org.semanticweb.owl.model.OWLOntology;
+import org.semanticweb.owl.model.OWLOntologyChangeException;
+import org.semanticweb.owl.model.OWLOntologyCreationException;
import org.semanticweb.owl.model.OWLTypedConstant;
+import bebops.pinpointing.KernelOperator;
+
/**
* Accepts an arbitrary OWLIndividualAxiom and, depending on its type, creates a SE-Literal encoding of it.
* Will always result in a ground SELiteral (since OWLIndividualAxioms must always be ground)<p>
@@ -50,7 +59,8 @@
*/
private JasdlAgent agent;
- public AxiomToSELiteralConverter(JasdlAgent agent){
+
+ public AxiomToSELiteralConverter(JasdlAgent agent) throws OWLReasonerException, OWLOntologyCreationException, OWLOntologyChangeException{
this.agent = agent;
}
@@ -59,19 +69,53 @@
* TODO: Shift to a factory?
* @param sl
*/
- public static List<Term> getAssertedAnnotations(OWLAxiom axiom, OWLOntology ontology){
+ public List<Term> getAssertedAnnotations(OWLAxiom axiom){
List<Term> result = new Vector<Term>();
- // get annotations
- Set<OWLAxiomAnnotationAxiom> annotAxioms = axiom.getAnnotationAxioms(ontology);
- for(OWLAxiomAnnotationAxiom annotAxiom : annotAxioms){ // remember, possibly semantically-naive payload!
- Term annot = Literal.parse(annotAxiom.getAnnotation().getAnnotationValueAsConstant().getLiteral());
- result.add(annot);
+ // get annotations from all known ontologies
+ for(OWLOntology ontology : agent.getOntologyManager().getOntologies()){
+ Set<OWLAxiomAnnotationAxiom> annotAxioms = axiom.getAnnotationAxioms(ontology);
+ for(OWLAxiomAnnotationAxiom annotAxiom : annotAxioms){ // remember, possibly semantically-naive payload!
+ Term annot = Literal.parse(annotAxiom.getAnnotation().getAnnotationValueAsConstant().getLiteral());
+ result.add(annot);
+ }
}
return result;
}
+ public List<Term> getInferredAnnotations(OWLAxiom axiom) throws JasdlException{
+ try {
+ List<Term> annots = new Vector<Term>();
+ KernelOperator kernelOperator = new KernelOperator(agent.getOntologyManager(), new JasdlReasonerFactory());
+ //Set<OWLAxiom> supportingAxioms = OWLReasonerAdapter.flattenSetOfSets((kernelOperator.apply(axiom, true)));
+ Set<OWLAxiom> supportingAxioms = (new TBoxAxiomKernelsetFilter()).applyToOne((kernelOperator.applySingle(axiom, true)));
+ getLogger().finest("Explanation for "+axiom+": "+supportingAxioms);
+ for(OWLAxiom supportingAxiom : supportingAxioms){
+ annots.addAll(getAssertedAnnotations(supportingAxiom));
+ }
+ getLogger().finest("Annotations: "+annots);
+ return annots;
+ } catch (OWLException e) {
+ throw new JasdlException("Annotation gathering failed for "+axiom, e);
+ }
+ }
+
/**
+ * Utility method to get the annotations of an axiom as an array of terms within the ontology referenced by alias
+ * @param alias
+ * @param axiom
+ * @return
+ * @throws UnknownMappingException
+ */
+ private Term[] getAnnots(Alias alias, OWLAxiom axiom) throws JasdlException{
+ List<Term> annots = getAssertedAnnotations(axiom);
+ if(agent.isAnnotationGatheringEnabled()) annots.addAll(getInferredAnnotations(axiom)); // optional, experimental feature
+ return (Term[])annots.toArray(new Term[annots.size()]);
+ }
+
+
+
+ /**
* Polymorphically applies appropriate factory method depending on specialisation of axiom
* @param axiom
* @return
@@ -176,18 +220,10 @@
return agent.getSELiteralFactory().construct(alias, is, getAnnots(alias, axiom));
}
- /**
- * Utility method to get the annotations of an axiom as an array of terms within the ontology referenced by alias
- * @param alias
- * @param axiom
- * @return
- * @throws UnknownMappingException
- */
- private Term[] getAnnots(Alias alias, OWLAxiom axiom) throws UnknownMappingException{
- OWLOntology ontology = agent.getLabelManager().getRight(alias.getLabel());
- List<Term> collection = getAssertedAnnotations(axiom, ontology);
- return (Term[])collection.toArray(new Term[collection.size()]);
- }
+ public Logger getLogger(){
+ return agent.getLogger();
+ }
+
}
Added: trunk/applications/jasdl-owlapi/src/jasdl/ia/is_annotation_gathering_enabled.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/ia/is_annotation_gathering_enabled.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/ia/is_annotation_gathering_enabled.java 2008-04-03 01:24:25 UTC (rev 1202)
@@ -0,0 +1,61 @@
+/*
+ * 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.ia;
+
+import jasdl.asSemantics.JasdlAgent;
+import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.TransitionSystem;
+import jason.asSemantics.Unifier;
+import jason.asSyntax.Literal;
+import jason.asSyntax.Term;
+
+import java.util.logging.Logger;
+
+/**
+ * @author Tom Klapiscak
+ *
+ * Usage jasdl.ia.define_class(classname, classexpr, label), where:
+ * - classname is an atomic name used to refer to this class in future. Must begin with a lowercase letter and not clash with any AgentSpeak keyword
+ * - classexpr is a expression defining this class
+ *
+ * Changed class name to atom only - forces valid alias syntax
+ *
+ */
+public class is_annotation_gathering_enabled extends DefaultInternalAction {
+
+
+ private Logger logger = Logger.getLogger("jasdl."+is_annotation_gathering_enabled.class.getName());
+
+ @Override
+ public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
+ try {
+ JasdlAgent agent = (JasdlAgent)ts.getAg();
+ Literal res = agent.isAnnotationGatheringEnabled() ? Literal.LTrue : Literal.LFalse;
+ return un.unifies(args[0], res);
+ } catch (Exception e) {
+ logger.warning("Error in internal action 'jasdl.ia.is_annotation_gathering_enabled'! Reason:");
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+
+
+}
\ No newline at end of file
Added: trunk/applications/jasdl-owlapi/src/jasdl/ia/is_belief_revision_enabled.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/ia/is_belief_revision_enabled.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/ia/is_belief_revision_enabled.java 2008-04-03 01:24:25 UTC (rev 1202)
@@ -0,0 +1,61 @@
+/*
+ * 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.ia;
+
+import jasdl.asSemantics.JasdlAgent;
+import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.TransitionSystem;
+import jason.asSemantics.Unifier;
+import jason.asSyntax.Literal;
+import jason.asSyntax.Term;
+
+import java.util.logging.Logger;
+
+/**
+ * @author Tom Klapiscak
+ *
+ * Usage jasdl.ia.define_class(classname, classexpr, label), where:
+ * - classname is an atomic name used to refer to this class in future. Must begin with a lowercase letter and not clash with any AgentSpeak keyword
+ * - classexpr is a expression defining this class
+ *
+ * Changed class name to atom only - forces valid alias syntax
+ *
+ */
+public class is_belief_revision_enabled extends DefaultInternalAction {
+
+
+ private Logger logger = Logger.getLogger("jasdl."+is_belief_revision_enabled.class.getName());
+
+ @Override
+ public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
+ try {
+ JasdlAgent agent = (JasdlAgent)ts.getAg();
+ Literal res = agent.isBeliefRevisionEnabled() ? Literal.LTrue : Literal.LFalse;
+ return un.unifies(args[0], res);
+ } catch (Exception e) {
+ logger.warning("Error in internal action 'jasdl.ia.is_belief_revision_enabled'! Reason:");
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+
+
+}
\ No newline at end of file
Added: trunk/applications/jasdl-owlapi/src/jasdl/ia/set_annotation_gathering_enabled.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/ia/set_annotation_gathering_enabled.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/ia/set_annotation_gathering_enabled.java 2008-04-03 01:24:25 UTC (rev 1202)
@@ -0,0 +1,67 @@
+/*
+ * 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.ia;
+
+import jasdl.asSemantics.JasdlAgent;
+import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.TransitionSystem;
+import jason.asSemantics.Unifier;
+import jason.asSyntax.Literal;
+import jason.asSyntax.Term;
+
+import java.util.logging.Logger;
+
+/**
+ * @author Tom Klapiscak
+ *
+ * Usage jasdl.ia.define_class(classname, classexpr, label), where:
+ * - classname is an atomic name used to refer to this class in future. Must begin with a lowercase letter and not clash with any AgentSpeak keyword
+ * - classexpr is a expression defining this class
+ *
+ * Changed class name to atom only - forces valid alias syntax
+ *
+ */
+public class set_annotation_gathering_enabled extends DefaultInternalAction {
+
+
+ private Logger logger = Logger.getLogger("jasdl."+set_annotation_gathering_enabled.class.getName());
+
+ @Override
+ public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
+ try {
+ JasdlAgent agent = (JasdlAgent)ts.getAg();
+ if(args[0].equals(Literal.LTrue)){
+ agent.setAnnotationGatheringEnabled((true));
+ }else if(args[0].equals(Literal.LFalse)){
+ agent.setAnnotationGatheringEnabled(false);
+ }else{
+ throw new Exception("Argument must be boolean");
+ }
+ return true;
+ } catch (Exception e) {
+ logger.warning("Error in internal action 'jasdl.ia.set_annotation_gathering_enabled'! Reason:");
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+
+
+}
\ No newline at end of file
Added: trunk/applications/jasdl-owlapi/src/jasdl/ia/set_belief_revision_enabled.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/ia/set_belief_revision_enabled.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/ia/set_belief_revision_enabled.java 2008-04-03 01:24:25 UTC (rev 1202)
@@ -0,0 +1,67 @@
+/*
+ * 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.ia;
+
+import jasdl.asSemantics.JasdlAgent;
+import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.TransitionSystem;
+import jason.asSemantics.Unifier;
+import jason.asSyntax.Literal;
+import jason.asSyntax.Term;
+
+import java.util.logging.Logger;
+
+/**
+ * @author Tom Klapiscak
+ *
+ * Usage jasdl.ia.define_class(classname, classexpr, label), where:
+ * - classname is an atomic name used to refer to this class in future. Must begin with a lowercase letter and not clash with any AgentSpeak keyword
+ * - classexpr is a expression defining this class
+ *
+ * Changed class name to atom only - forces valid alias syntax
+ *
+ */
+public class set_belief_revision_enabled extends DefaultInternalAction {
+
+
+ private Logger logger = Logger.getLogger("jasdl."+set_belief_revision_enabled.class.getName());
+
+ @Override
+ public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
+ try {
+ JasdlAgent agent = (JasdlAgent)ts.getAg();
+ if(args[0].equals(Literal.LTrue)){
+ agent.setBeliefRevisionEnabled(true);
+ }else if(args[0].equals(Literal.LFalse)){
+ agent.setBeliefRevisionEnabled(false);
+ }else{
+ throw new Exception("Argument must be boolean");
+ }
+ return true;
+ } catch (Exception e) {
+ logger.warning("Error in internal action 'jasdl.ia.set_belief_revision_enabled'! Reason:");
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+
+
+}
\ No newline at end of file
Modified: trunk/applications/jasdl-owlapi/src/jasdl/test/JasdlBeliefBaseTest.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/test/JasdlBeliefBaseTest.java 2008-04-02 21:13:50 UTC (rev 1201)
+++ trunk/applications/jasdl-owlapi/src/jasdl/test/JasdlBeliefBaseTest.java 2008-04-03 01:24:25 UTC (rev 1202)
@@ -165,7 +165,10 @@
*/
private static int NUM_ENTITIES_TEST_ADD = 3;
@Test
- public void testAddLiteral() throws Exception{
+ public void testAddLiteral() throws Exception{
+ // ensure annotation gathering disabled for this test - we are only checking handling of annotation additions is correct
+ agent.setAnnotationGatheringEnabled(false);
+
Atom[][] annotSets = new Atom[][] {new Atom[]{}, new Atom[] {new Atom("x")}, new Atom[] {new Atom("x"), new Atom("y")} }; // TODO: No real reason to check annotation handling for ALL types of entity - exactly the same code is used
for(OWLOntology ontology : agent.getOntologyManager().getOntologies()){ // test against all known ontologies
for(int run=0; run<=1; run++){ // run twice to ensure duplicate additions are rejected
Modified: trunk/applications/jasdl-owlapi/src/jasdl/util/exception/JasdlException.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/util/exception/JasdlException.java 2008-04-02 21:13:50 UTC (rev 1201)
+++ trunk/applications/jasdl-owlapi/src/jasdl/util/exception/JasdlException.java 2008-04-03 01:24:25 UTC (rev 1202)
@@ -23,6 +23,11 @@
public class JasdlException extends JasonException {
+
+ public JasdlException(String msg, Exception cause) {
+ super(msg, cause);
+ }
+
public JasdlException(String message){
super(message);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|