|
From: <tom...@us...> - 2008-04-02 17:09:56
|
Revision: 1193
http://jason.svn.sourceforge.net/jason/?rev=1193&view=rev
Author: tomklapiscak
Date: 2008-04-02 10:09:55 -0700 (Wed, 02 Apr 2008)
Log Message:
-----------
Structural Improvements.
Modified Paths:
--------------
trunk/applications/jasdl-owlapi/examples/travel_agent/config.mas2j
trunk/applications/jasdl-owlapi/src/jasdl/architecture/IncomingPropContProcessingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/architecture/OutgoingPropContProcessingStrategy.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/asSemantics/parsing/NSPrefixEntityChecker.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/revision/JasdlIncisionFunction.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/bridge/seliteral/SELiteralPropertyAssertion.java
trunk/applications/jasdl-owlapi/src/jasdl/test/JasdlBeliefBaseTest.java
Added Paths:
-----------
trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/
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/util/xsd/
trunk/applications/jasdl-owlapi/src/jasdl/util/xsd/XSDDataType.java
trunk/applications/jasdl-owlapi/src/jasdl/util/xsd/XSDDataTypeUtils.java
Removed Paths:
-------------
trunk/applications/jasdl-owlapi/src/jasdl/bridge/alias/
trunk/applications/jasdl-owlapi/src/jasdl/bridge/label/
trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralFactory.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/xsd/
trunk/applications/jasdl-owlapi/src/jasdl/test/blank.asl
trunk/applications/jasdl-owlapi/src/jasdl/util/xsd/XSDDataType.java
trunk/applications/jasdl-owlapi/src/jasdl/util/xsd/XSDDataTypeUtils.java
Modified: trunk/applications/jasdl-owlapi/examples/travel_agent/config.mas2j
===================================================================
--- trunk/applications/jasdl-owlapi/examples/travel_agent/config.mas2j 2008-04-02 17:05:13 UTC (rev 1192)
+++ trunk/applications/jasdl-owlapi/examples/travel_agent/config.mas2j 2008-04-02 17:09:55 UTC (rev 1193)
@@ -40,12 +40,12 @@
* jasdl_reasonerClass = "uk.ac.manchester.cs.factplusplus.owlapi.Reasoner",
*/
- jasdl_default_mapping_strategies="jasdl.bridge.alias.DecapitaliseMappingStrategy", // applied to incoming ontologies and those given no automapping
+ jasdl_default_mapping_strategies="jasdl.bridge.mapping.aliasing.DecapitaliseMappingStrategy", // applied to incoming ontologies and those given no automapping
jasdl_ontologies="travel",
jasdl_travel_uri="http://www.dur.ac.uk/t.g.klapiscak/onts/travel.owl",
- /*jasdl_travel_mapping_strategies="jasdl.bridge.alias.DecapitaliseMappingStrategy",*/ // defaults can be overriden per-ontology here
+ /*jasdl_travel_mapping_strategies="jasdl.bridge.mapping.aliasing.DecapitaliseMappingStrategy",*/ // defaults can be overriden per-ontology here
jasdl_travel_mapping_manual="small_beach=beach", // these manual mappings will override any automatic mappings made by strategies,
// static trust ratings, mainly for testing purposes - likely to change
@@ -61,17 +61,17 @@
customer
customer.asl
[
- /* jasdl_default_mapping_strategies="jasdl.bridge.alias.DecapitaliseMappingStrategy", */ // defaults to this
+ /* jasdl_default_mapping_strategies="jasdl.bridge.mapping.aliasing.DecapitaliseMappingStrategy", */ // defaults to this
jasdl_useBeliefRevision = "true",
jasdl_ontologies="holidays,places",
jasdl_holidays_uri="http://www.dur.ac.uk/t.g.klapiscak/onts/travel.owl",
- jasdl_holidays_mapping_strategies="jasdl.bridge.alias.DecapitaliseMappingStrategy",
+ jasdl_holidays_mapping_strategies="jasdl.bridge.mapping.aliasing.DecapitaliseMappingStrategy",
jasdl_holidays_mapping_manual="small_beach=beach, luxuriousHotel=LuxuryHotel", // for demonstration of arbitrary primitive mappings being handled correctly
jasdl_places_uri="http://www.dur.ac.uk/t.g.klapiscak/onts/places.owl",
- jasdl_places_mapping_strategies="jasdl.bridge.alias.DecapitaliseMappingStrategy"
+ jasdl_places_mapping_strategies="jasdl.bridge.mapping.aliasing.DecapitaliseMappingStrategy"
]
agentArchClass jasdl.architecture.JasdlAgArch
agentClass jasdl.asSemantics.JasdlAgent
Modified: trunk/applications/jasdl-owlapi/src/jasdl/architecture/IncomingPropContProcessingStrategy.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/architecture/IncomingPropContProcessingStrategy.java 2008-04-02 17:05:13 UTC (rev 1192)
+++ trunk/applications/jasdl-owlapi/src/jasdl/architecture/IncomingPropContProcessingStrategy.java 2008-04-02 17:09:55 UTC (rev 1193)
@@ -23,8 +23,8 @@
import static jasdl.architecture.JasdlAgArch.NAMED_ANNOTATION_FUNCTOR;
import static jasdl.util.Common.strip;
import jasdl.asSemantics.JasdlAgent;
-import jasdl.bridge.alias.Alias;
-import jasdl.bridge.alias.AliasFactory;
+import jasdl.bridge.factory.AliasFactory;
+import jasdl.bridge.mapping.aliasing.Alias;
import jasdl.bridge.seliteral.SELiteral;
import jasdl.util.DuplicateMappingException;
import jasdl.util.JasdlException;
Modified: trunk/applications/jasdl-owlapi/src/jasdl/architecture/OutgoingPropContProcessingStrategy.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/architecture/OutgoingPropContProcessingStrategy.java 2008-04-02 17:05:13 UTC (rev 1192)
+++ trunk/applications/jasdl-owlapi/src/jasdl/architecture/OutgoingPropContProcessingStrategy.java 2008-04-02 17:09:55 UTC (rev 1193)
@@ -59,7 +59,7 @@
Literal result = l;
try{
- SELiteral sl = agent.getSELiteralFactory().create(l);
+ SELiteral sl = agent.getSELiteralFactory().construct(l);
// qualify o
sl.qualifyOntologyAnnotation();
Modified: trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java 2008-04-02 17:05:13 UTC (rev 1192)
+++ trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java 2008-04-02 17:09:55 UTC (rev 1193)
@@ -9,18 +9,18 @@
import jasdl.bb.revision.JasdlIncisionFunction;
import jasdl.bb.revision.JasdlReasonerFactory;
import jasdl.bb.revision.TBoxAxiomKernelsetFilter;
-import jasdl.bridge.AllDifferentPlaceholder;
-import jasdl.bridge.ToAxiomConverter;
-import jasdl.bridge.ToSELiteralConverter;
-import jasdl.bridge.alias.Alias;
-import jasdl.bridge.alias.AliasFactory;
-import jasdl.bridge.alias.AliasManager;
-import jasdl.bridge.alias.DefinitionManager;
-import jasdl.bridge.alias.MappingStrategy;
-import jasdl.bridge.label.LabelManager;
-import jasdl.bridge.label.OntologyURIManager;
+import jasdl.bridge.factory.AliasFactory;
+import jasdl.bridge.factory.AxiomToSELiteralConverter;
+import jasdl.bridge.factory.SELiteralFactory;
+import jasdl.bridge.factory.SELiteralToAxiomConverter;
+import jasdl.bridge.mapping.aliasing.Alias;
+import jasdl.bridge.mapping.aliasing.AliasManager;
+import jasdl.bridge.mapping.aliasing.AllDifferentPlaceholder;
+import jasdl.bridge.mapping.aliasing.DefinitionManager;
+import jasdl.bridge.mapping.aliasing.MappingStrategy;
+import jasdl.bridge.mapping.label.LabelManager;
+import jasdl.bridge.mapping.label.OntologyURIManager;
import jasdl.bridge.seliteral.SELiteral;
-import jasdl.bridge.seliteral.SELiteralFactory;
import jasdl.util.DuplicateMappingException;
import jasdl.util.InvalidSELiteralException;
import jasdl.util.JasdlException;
@@ -57,6 +57,7 @@
import org.semanticweb.owl.inference.OWLReasonerException;
import org.semanticweb.owl.model.OWLAxiom;
import org.semanticweb.owl.model.OWLClass;
+import org.semanticweb.owl.model.OWLDataFactory;
import org.semanticweb.owl.model.OWLDescription;
import org.semanticweb.owl.model.OWLEntity;
import org.semanticweb.owl.model.OWLEquivalentClassesAxiom;
@@ -77,8 +78,8 @@
private AliasManager aliasManager;
private LabelManager labelManager;
private SELiteralFactory seLiteralFactory;
- private ToSELiteralConverter toSELiteralConverter;
- private ToAxiomConverter toAxiomConverter;
+ private AxiomToSELiteralConverter axiomToSELiteralConverter;
+ private SELiteralToAxiomConverter SELiteralToAxiomConverter;
private OntologyURIManager logicalURIManager;
private OntologyURIManager physicalURIManager;
private ManchesterOWLSyntaxOWLObjectRendererImpl manchesterObjectRenderer;
@@ -111,8 +112,8 @@
definitionManager = new DefinitionManager();
seLiteralFactory = new SELiteralFactory(this);
- toAxiomConverter = new ToAxiomConverter(this);
- toSELiteralConverter = new ToSELiteralConverter(this);
+ SELiteralToAxiomConverter = new SELiteralToAxiomConverter(this);
+ axiomToSELiteralConverter = new AxiomToSELiteralConverter(this);
knownAgentNames = new Vector<String>();
trustMap = new HashMap<Atom, Float>();
@@ -134,35 +135,8 @@
}
- public void setReasoner(OWLReasoner reasoner){
- this.reasoner = reasoner;
- }
- public void addKnownAgentName(String name){
- knownAgentNames.add(name);
- }
- public List<String> getKnownAgentNames(){
- return knownAgentNames;
- }
-
-
- public void setReasonerLogLevel(org.apache.log4j.Level level){
- if(reasoner instanceof org.mindswap.pellet.owlapi.Reasoner){
- org.mindswap.pellet.owlapi.Reasoner pellet = (org.mindswap.pellet.owlapi.Reasoner)reasoner;
- Log4JLogger abox_logger = (Log4JLogger)pellet.getKB().getABox().log;
- abox_logger.getLogger().setLevel(level);
-
- Log4JLogger taxonomy_logger = (Log4JLogger)pellet.getKB().getTaxonomy().log;
- taxonomy_logger.getLogger().setLevel(level);
-
- Log4JLogger kb_logger = (Log4JLogger)pellet.getKB().log;
- kb_logger.getLogger().setLevel(level);
- }
- }
-
-
-
@Override
public TransitionSystem initAg(AgArch arch, BeliefBase bb, String src, Settings stts) throws JasonException {
if(!(bb instanceof JasdlBeliefBase)){
@@ -192,7 +166,7 @@
List<Literal> bels = new Vector<Literal>();
for(OWLOntology ontology : ontologyManager.getOntologies()){
for(OWLIndividualAxiom axiom : ontology.getIndividualAxioms()){
- Literal l = toSELiteralConverter.convert(axiom).getLiteral();
+ Literal l = axiomToSELiteralConverter.convert(axiom).getLiteral();
bels.add(l);
}
}
@@ -236,7 +210,7 @@
}else if(beliefToAdd != null){
try{
getLogger().fine("Revise: +"+beliefToAdd);
- SELiteral sl = getSELiteralFactory().create(beliefToAdd);
+ SELiteral sl = getSELiteralFactory().construct(beliefToAdd);
OWLAxiom axiomToAdd = sl.createAxiom();
BeliefBaseSemiRevisor bbrev = new BeliefBaseSemiRevisor(axiomToAdd, getOntologyManager(), new JasdlReasonerFactory(), getLogger());
List<OWLAxiom> contractList = bbrev.revise(new TBoxAxiomKernelsetFilter(), new JasdlIncisionFunction(this, sl));
@@ -244,7 +218,7 @@
// will only have reached here if new belief is accepted.
addList.add(beliefToAdd);
for(OWLAxiom contract : contractList){
- removeList.add(toSELiteralConverter.convert((OWLIndividualAxiom)contract).getLiteral());
+ removeList.add(axiomToSELiteralConverter.convert((OWLIndividualAxiom)contract).getLiteral());
}
revisionApplied = true;
}catch(RevisionFailedException e){
@@ -579,6 +553,21 @@
}
}
+
+ public void setReasonerLogLevel(org.apache.log4j.Level level){
+ if(reasoner instanceof org.mindswap.pellet.owlapi.Reasoner){
+ org.mindswap.pellet.owlapi.Reasoner pellet = (org.mindswap.pellet.owlapi.Reasoner)reasoner;
+ Log4JLogger abox_logger = (Log4JLogger)pellet.getKB().getABox().log;
+ abox_logger.getLogger().setLevel(level);
+
+ Log4JLogger taxonomy_logger = (Log4JLogger)pellet.getKB().getTaxonomy().log;
+ taxonomy_logger.getLogger().setLevel(level);
+
+ Log4JLogger kb_logger = (Log4JLogger)pellet.getKB().log;
+ kb_logger.getLogger().setLevel(level);
+ }
+ }
+
/**
* *Must* be unique within society!
* @return
@@ -586,20 +575,15 @@
public String getAgentName(){
return getTS().getUserAgArch().getAgName();
}
-
public List<MappingStrategy> getDefaultMappingStrategies() {
return defaultMappingStrategies;
}
-
-
public void setDefaultMappingStrategies(List<MappingStrategy> defaultMappingStrategies) {
this.defaultMappingStrategies = defaultMappingStrategies;
}
-
-
public Atom getPersonalOntologyLabel(){
return new Atom("self");
}
@@ -612,7 +596,6 @@
return URI.create("http://www.dur.ac.uk/t.g.klapiscak/self"+label+".owl");
}
-
public AliasManager getAliasManager() {
return aliasManager;
}
@@ -637,8 +620,6 @@
return definitionManager;
}
-
-
public OWLReasoner getReasoner() {
return reasoner;
}
@@ -647,12 +628,12 @@
return seLiteralFactory;
}
- public ToAxiomConverter getToAxiomConverter() {
- return toAxiomConverter;
+ public SELiteralToAxiomConverter getSELiteralToAxiomConverter() {
+ return SELiteralToAxiomConverter;
}
- public ToSELiteralConverter getToSELiteralConverter() {
- return toSELiteralConverter;
+ public AxiomToSELiteralConverter getAxiomToSELiteralConverter() {
+ return axiomToSELiteralConverter;
}
public ManchesterOWLSyntaxOWLObjectRendererImpl getManchesterObjectRenderer() {
@@ -666,7 +647,31 @@
public ManchesterOWLSyntaxDescriptionParser getManchesterURIDescriptionParser() {
return manchesterURIDescriptionParser;
}
+
+ public boolean isBeliefRevisionEnabled() {
+ return beliefRevisionEnabled;
+ }
+ public void setBeliefRevisionEnabled(boolean beliefRevisionEnabled) {
+ this.beliefRevisionEnabled = beliefRevisionEnabled;
+ }
+
+ public OWLDataFactory getOWLDataFactory(){
+ return getOntologyManager().getOWLDataFactory();
+ }
+
+ public void setReasoner(OWLReasoner reasoner){
+ this.reasoner = reasoner;
+ }
+
+ public void addKnownAgentName(String name){
+ knownAgentNames.add(name);
+ }
+
+ public List<String> getKnownAgentNames(){
+ return knownAgentNames;
+ }
+
public void setTrustRating(Atom name, float trust){
trustMap.remove(name);
trustMap.put(name, trust);
@@ -676,19 +681,7 @@
return trustMap.get(name);
}
-
-
-
-
- public boolean isBeliefRevisionEnabled() {
- return beliefRevisionEnabled;
- }
-
- public void setBeliefRevisionEnabled(boolean beliefRevisionEnabled) {
- this.beliefRevisionEnabled = beliefRevisionEnabled;
- }
-
}
Modified: trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlConfigurator.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlConfigurator.java 2008-04-02 17:05:13 UTC (rev 1192)
+++ trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlConfigurator.java 2008-04-02 17:09:55 UTC (rev 1193)
@@ -2,10 +2,10 @@
import static jasdl.util.Common.DELIM;
import static jasdl.util.Common.strip;
-import jasdl.bridge.alias.Alias;
-import jasdl.bridge.alias.AliasFactory;
-import jasdl.bridge.alias.DecapitaliseMappingStrategy;
-import jasdl.bridge.alias.MappingStrategy;
+import jasdl.bridge.factory.AliasFactory;
+import jasdl.bridge.mapping.aliasing.Alias;
+import jasdl.bridge.mapping.aliasing.DecapitaliseMappingStrategy;
+import jasdl.bridge.mapping.aliasing.MappingStrategy;
import jasdl.util.JasdlConfigurationException;
import jasdl.util.JasdlException;
import jason.asSyntax.Atom;
Modified: trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/parsing/NSPrefixEntityChecker.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/parsing/NSPrefixEntityChecker.java 2008-04-02 17:05:13 UTC (rev 1192)
+++ trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/parsing/NSPrefixEntityChecker.java 2008-04-02 17:09:55 UTC (rev 1193)
@@ -1,7 +1,7 @@
package jasdl.asSemantics.parsing;
import jasdl.asSemantics.JasdlAgent;
-import jasdl.bridge.alias.Alias;
-import jasdl.bridge.alias.AliasFactory;
+import jasdl.bridge.factory.AliasFactory;
+import jasdl.bridge.mapping.aliasing.Alias;
import jason.asSyntax.Atom;
import org.semanticweb.owl.expression.OWLEntityChecker;
Modified: trunk/applications/jasdl-owlapi/src/jasdl/asSyntax/JasdlPlanLibrary.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/asSyntax/JasdlPlanLibrary.java 2008-04-02 17:05:13 UTC (rev 1192)
+++ trunk/applications/jasdl-owlapi/src/jasdl/asSyntax/JasdlPlanLibrary.java 2008-04-02 17:09:55 UTC (rev 1193)
@@ -53,7 +53,7 @@
@Override
public void add(Plan p) throws JasonException {
try{
- agent.getSELiteralFactory().create(p.getTrigger().getLiteral());
+ agent.getSELiteralFactory().construct(p.getTrigger().getLiteral());
super.add(new SEPlan(agent, p));
}catch(NotEnrichedException e){
super.add(p);
@@ -142,7 +142,7 @@
*/
public static List<Trigger> getMoreGeneralTriggers(JasdlAgent agent, Trigger te) throws JasdlException{
Literal l = te.getLiteral();
- SELiteral sl = agent.getSELiteralFactory().create(l);
+ SELiteral sl = agent.getSELiteralFactory().construct(l);
if(l.negated()){
throw new JasdlException("JASDL cannot generalise strongly negated triggers");
Modified: trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlBeliefBase.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlBeliefBase.java 2008-04-02 17:05:13 UTC (rev 1192)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlBeliefBase.java 2008-04-02 17:09:55 UTC (rev 1193)
@@ -41,7 +41,7 @@
getLogger().fine("Adding "+l);
try{
- SELiteral sl = agent.getSELiteralFactory().create(l);
+ SELiteral sl = agent.getSELiteralFactory().construct(l);
OWLIndividualAxiom axiom = sl.createAxiom();
OWLOntology ontology = sl.getOntology();
@@ -92,7 +92,7 @@
getLogger().fine("Contracting "+l);
try{
- SELiteral sl = agent.getSELiteralFactory().create(l);
+ SELiteral sl = agent.getSELiteralFactory().construct(l);
OWLOntology ontology = sl.getOntology();
OWLIndividualAxiom axiom = sl.createAxiom();
@@ -157,8 +157,8 @@
}catch(NotEnrichedException e){
return super.remove(l); // semantically-naive, use standard Jason mechanisms
}catch(Exception e){
- getLogger().warning("Exception caught removing SELiteral "+l+" from belief base: ");
- e.printStackTrace();
+ getLogger().fine("Exception caught removing SELiteral "+l+" from belief base: ");
+ //e.printStackTrace();
return false;
}
}
@@ -167,7 +167,7 @@
public Literal contains(Literal l) {
agent.getLogger().fine("Contains: "+l);
try {
- SELiteral sl = agent.getSELiteralFactory().create(l);
+ SELiteral sl = agent.getSELiteralFactory().construct(l);
OWLIndividualAxiom axiom = sl.createAxiom();
if(sl.getOntology().containsAxiom(axiom)){
Iterator<Literal> it = getCandidateBeliefs(l, null);
@@ -184,6 +184,7 @@
}
}
+
@Override
@@ -195,10 +196,10 @@
Set<Literal> relevant = new HashSet<Literal>();
try{
- SELiteral sl = agent.getSELiteralFactory().create(l);
- Set<OWLIndividualAxiom> axioms = sl.getAxioms();
+ SELiteral sl = agent.getSELiteralFactory().construct(l);
+ Set<OWLIndividualAxiom> axioms = sl.getAxioms(); // <- really just a wrapper for this method
for(OWLIndividualAxiom axiom : axioms){
- SELiteral found = agent.getToSELiteralConverter().convert(axiom);
+ SELiteral found = agent.getAxiomToSELiteralConverter().convert(axiom);
// hack, gets around non-consistent ordering of OWLDifferentIndividualAxiom individuals
// -- just check list membership is equivalent (i.e. treat as sets)
@@ -211,10 +212,8 @@
}
}
- relevant.add(found.getLiteral());
+ relevant.add(found.getLiteral());
-
-
}
getLogger().fine("... found: "+relevant);
if(relevant.isEmpty()){
Modified: trunk/applications/jasdl-owlapi/src/jasdl/bb/revision/JasdlIncisionFunction.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bb/revision/JasdlIncisionFunction.java 2008-04-02 17:05:13 UTC (rev 1192)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bb/revision/JasdlIncisionFunction.java 2008-04-02 17:09:55 UTC (rev 1193)
@@ -73,7 +73,7 @@
if(axiom.equals(toAddLiteral.createAxiom())){ // hack to get the annotations of the NOT YET ADDED toAdd axiom
sources = toAddLiteral.getLiteral().getSources();
}else{
- SELiteral sl = agent.getToSELiteralConverter().convert((OWLIndividualAxiom)axiom); // kernel filter ensures axiom is an OWLIndividualAxiom
+ SELiteral sl = agent.getAxiomToSELiteralConverter().convert((OWLIndividualAxiom)axiom); // kernel filter ensures axiom is an OWLIndividualAxiom
sources = sl.getLiteral().getSources();
}
agent.getLogger().finest("Sources of "+axiom+"="+sources);
Copied: trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/AliasFactory.java (from rev 1190, trunk/applications/jasdl-owlapi/src/jasdl/bridge/alias/AliasFactory.java)
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/AliasFactory.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/AliasFactory.java 2008-04-02 17:09:55 UTC (rev 1193)
@@ -0,0 +1,64 @@
+package jasdl.bridge.factory;
+
+import jasdl.bridge.mapping.aliasing.Alias;
+import jasdl.bridge.seliteral.SELiteral;
+import jasdl.util.JasdlException;
+import jason.asSyntax.Atom;
+
+/**
+ * A convenient singleton factory providing methods to create JASDL alias objects.
+ *
+ * @author Tom Klapiscak
+ *
+ */
+public class AliasFactory {
+ public static Atom OWL_NAMESPACE_LABEL = new Atom("owl");
+
+ /**
+ * A singleton alias mapped to the universal owl:thing concept
+ */
+ public static Alias OWL_THING = new Alias(new Atom("thing"), OWL_NAMESPACE_LABEL);
+
+ /**
+ * A singleton alias mapped to the universal owl:nothing concept
+ */
+ public static Alias OWL_NOTHING = new Alias(new Atom("nothing"), OWL_NAMESPACE_LABEL);
+
+
+ public static Atom OWL_NOTHING_FUNCTOR = new Atom("nothing");
+ public static Atom OWL_ALL_DIFFERENT_FUNCTOR = new Atom("all_different");
+
+
+ /**
+ * Singleton instance we should use.
+ */
+ public static AliasFactory INSTANCE = new AliasFactory();
+
+ private AliasFactory(){
+ }
+
+ /**
+ * Create an alias to represent an SELiteral. Literal functor becomes alias functor.
+ * Literal ontology label becomes alias label;
+ * If l is negated (and a unary class assertion) then functor is prefixed with "~".
+ * @param sl the SELiteral the alias will represent
+ * @return an alias representing the supplied SELiteral
+ */
+ public Alias create(SELiteral sl) throws JasdlException{
+ return new Alias( (sl.getLiteral().negated()?"~":"") + sl.getLiteral().getFunctor(), sl.getOntologyLabel());
+ }
+
+ /**
+ * Create an alias from an atomic functor and label
+ * @param functor
+ * @param label
+ * @return
+ */
+ public Alias create(Atom functor, Atom label){
+ return new Alias(functor, label);
+ }
+
+ public Alias all_different(Atom label){
+ return new Alias(OWL_ALL_DIFFERENT_FUNCTOR, label);
+ }
+}
Added: trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/AxiomToSELiteralConverter.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/AxiomToSELiteralConverter.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/AxiomToSELiteralConverter.java 2008-04-02 17:09:55 UTC (rev 1193)
@@ -0,0 +1,193 @@
+package jasdl.bridge.factory;
+
+import jasdl.asSemantics.JasdlAgent;
+import jasdl.bridge.mapping.aliasing.Alias;
+import jasdl.bridge.mapping.aliasing.AllDifferentPlaceholder;
+import jasdl.bridge.seliteral.SELiteral;
+import jasdl.util.InvalidSELiteralException;
+import jasdl.util.JasdlException;
+import jasdl.util.UnknownMappingException;
+import jasdl.util.xsd.XSDDataType;
+import jasdl.util.xsd.XSDDataTypeUtils;
+import jason.asSyntax.Atom;
+import jason.asSyntax.DefaultTerm;
+import jason.asSyntax.Literal;
+import jason.asSyntax.Term;
+
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+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.OWLIndividual;
+import org.semanticweb.owl.model.OWLIndividualAxiom;
+import org.semanticweb.owl.model.OWLObjectPropertyAssertionAxiom;
+import org.semanticweb.owl.model.OWLOntology;
+import org.semanticweb.owl.model.OWLTypedConstant;
+
+
+/**
+ * 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>
+ * For example:
+ * <ul>
+ * <li>ClassAssertion(Hotel hilton) -> hotel(hilton)[o(travel)]</li>
+ * <li>ObjectPropertyAssertion(hasRating hilton ThreeStarRating) -> hasRating(hilton,threeStarRating)[o(travel)]</li>
+ * <li>DifferentIndividuals( fourSeasons hilton ) -> all_different([hilton,fourSeasons])[o(travel)]</li>
+ * </ul>
+ * @author Tom Klapiscak
+ *
+ */
+public class AxiomToSELiteralConverter {
+
+ /**
+ * The agent this converter is working on behalf of. Required for access to managers.
+ */
+ private JasdlAgent agent;
+
+ public AxiomToSELiteralConverter(JasdlAgent agent){
+ this.agent = agent;
+ }
+
+ /**
+ * Fetches and deseralises and returns all ASSERTED annotations of the supplied axiom.
+ * TODO: Shift to a factory?
+ * @param sl
+ */
+ public static List<Term> getAssertedAnnotations(OWLAxiom axiom, OWLOntology ontology){
+ 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);
+ }
+ return result;
+ }
+
+
+ /**
+ * Polymorphically applies appropriate factory method depending on specialisation of axiom
+ * @param axiom
+ * @return
+ * @throws JasdlException if specialisation of axiom is not of an appropriate type for conversion to a SELiteral
+ */
+ public SELiteral convert(OWLIndividualAxiom axiom) throws JasdlException{
+ if(axiom instanceof OWLClassAssertionAxiom){
+ return convert((OWLClassAssertionAxiom)axiom);
+ }else if(axiom instanceof OWLObjectPropertyAssertionAxiom){
+ return convert((OWLObjectPropertyAssertionAxiom)axiom);
+ }else if(axiom instanceof OWLDataPropertyAssertionAxiom){
+ return convert((OWLDataPropertyAssertionAxiom)axiom);
+ }else if(axiom instanceof OWLDifferentIndividualsAxiom){
+ return convert((OWLDifferentIndividualsAxiom) axiom);
+ }else{
+ throw new JasdlException(axiom+" is not of an appropriate type for conversion to a SELiteral");
+ }
+ }
+
+
+ /**
+ * Convert an axiom asserting class membership to a unary SELiteral
+ * @param axiom the axiom to convert
+ * @return a unary SELiteral encoding of axiom
+ * @throws JasdlException
+ */
+ public SELiteral convert(OWLClassAssertionAxiom axiom) throws JasdlException{
+ Alias alias = agent.getAliasManager().getLeft(axiom.getDescription());
+ Atom individual = agent.getAliasManager().getLeft(axiom.getIndividual()).getFunctor(); // TODO: what if individual is previously undefined? possible?
+ return agent.getSELiteralFactory().construct(alias, individual, getAnnots(alias, axiom));
+ }
+
+ /**
+ * Convert an axiom asserting that two individuals are related by an object property to a binary SELiteral
+ * @param axiom the axiom to convert
+ * @return an binary SELiteral encoding of axiom
+ * @throws JasdlException
+ */
+ public SELiteral convert(OWLObjectPropertyAssertionAxiom axiom) throws JasdlException{
+ Alias alias = agent.getAliasManager().getLeft(axiom.getProperty().asOWLObjectProperty());
+ Atom subject = agent.getAliasManager().getLeft(axiom.getSubject()).getFunctor();
+ Atom object = agent.getAliasManager().getLeft(axiom.getObject()).getFunctor();
+ return agent.getSELiteralFactory().construct(alias, subject, object, getAnnots(alias, axiom));
+ }
+
+ /**
+ * Convert an axiom asserting that two individuals are related by a data property to a binary SELiteral
+ * @param axiom the axiom to convert
+ * @return a binary SELiteral encoding of axiom
+ * @throws JasdlException
+ */
+ public SELiteral convert(OWLDataPropertyAssertionAxiom axiom) throws JasdlException{
+ Alias alias = agent.getAliasManager().getLeft(axiom.getProperty().asOWLDataProperty());
+ Atom subject = agent.getAliasManager().getLeft(axiom.getSubject()).getFunctor();
+ Term object;
+ OWLConstant constant = axiom.getObject();
+ if(constant.isTyped()){
+ OWLTypedConstant ot = constant.asOWLTypedConstant();
+ XSDDataType xsd = XSDDataTypeUtils.get(ot.getDataType().toString());
+ // surround with quotes if necessary for representation in AgentSpeak syntax
+ if(XSDDataTypeUtils.isStringType(xsd)){
+ object = DefaultTerm.parse("\""+constant.getLiteral().toString()+"\"");
+ }else if(XSDDataTypeUtils.isBooleanType(xsd)){
+ if(Boolean.parseBoolean(ot.getLiteral().toString())){
+ object = Literal.LTrue;
+ }else{
+ object = Literal.LFalse;
+ }
+ }else{
+ object = DefaultTerm.parse(constant.getLiteral().toString());
+ }
+ }else{
+ throw new JasdlException("JASDL does not support untyped data ranges such as: "+axiom);
+ }
+ return agent.getSELiteralFactory().construct(alias, subject, object, getAnnots(alias, axiom));
+ }
+
+ /**
+ * Convert an axiom asserting that a set of individuals are distinct to a unary SELiteral (whose term is a list and functor is "all_different")
+ * @param axiom the axiom to convert
+ * @return a unary SELiteral (whose term is a list and functor is "all_different") encoding of axiom
+ * @throws JasdlException
+ */
+ public SELiteral convert(OWLDifferentIndividualsAxiom axiom) throws JasdlException{
+ Set<OWLIndividual> _is = axiom.getIndividuals();
+ if(_is.size() == 0){
+ throw new InvalidSELiteralException("All different assertion must contain some individuals! "+axiom);
+ }
+ Atom[] is = new Atom[_is.size()];
+ Atom label = null;
+ int j = 0;
+ for(OWLIndividual i : _is){
+ Alias iAlias = agent.getAliasManager().getLeft(i);
+ if(label == null){
+ // hack, get a reference back to ontology by examining one of the individuals
+ label = iAlias.getLabel();
+ }
+ is[j] = iAlias.getFunctor();
+ j++;
+ }
+ Alias alias = agent.getAliasManager().getLeft(new AllDifferentPlaceholder(label));
+ 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()]);
+ }
+
+
+}
Copied: trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/SELiteralFactory.java (from rev 1190, trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralFactory.java)
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/SELiteralFactory.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/SELiteralFactory.java 2008-04-02 17:09:55 UTC (rev 1193)
@@ -0,0 +1,147 @@
+package jasdl.bridge.factory;
+
+import static jasdl.util.Common.DOMAIN;
+
+import java.util.Arrays;
+
+import jasdl.asSemantics.JasdlAgent;
+import jasdl.bridge.mapping.aliasing.Alias;
+import jasdl.bridge.mapping.aliasing.AllDifferentPlaceholder;
+import jasdl.bridge.seliteral.SELiteral;
+import jasdl.util.InvalidSELiteralException;
+import jasdl.util.JasdlException;
+import jason.asSyntax.Atom;
+import jason.asSyntax.DefaultTerm;
+import jason.asSyntax.ListTerm;
+import jason.asSyntax.ListTermImpl;
+import jason.asSyntax.Literal;
+import jason.asSyntax.Structure;
+import jason.asSyntax.Term;
+
+import org.semanticweb.owl.model.OWLDataProperty;
+import org.semanticweb.owl.model.OWLDescription;
+import org.semanticweb.owl.model.OWLObject;
+import org.semanticweb.owl.model.OWLObjectProperty;
+
+public class SELiteralFactory {
+
+ private JasdlAgent agent;
+
+ public SELiteralFactory(JasdlAgent agent){
+ this.agent = agent;
+ }
+
+ /**
+ * Polymorphically creates a specific type of SELiteral based on the properties of the supplied literal
+ * @param l
+ * @return
+ * @throws JasdlException
+ */
+ public SELiteral construct(Literal l) throws JasdlException{
+ SELiteral sl = new SELiteral(l, agent); // so we can use convenience methods on a processed seliteral
+ OWLObject entity = sl.toOWLObject();
+ if(sl.getLiteral().getArity() == 1){
+ if(entity instanceof OWLDescription){
+ return sl.asClassAssertion();
+ }else if(entity instanceof AllDifferentPlaceholder){
+ //if(!l.isGround()) throw new JasdlException("JASDL does not currently support unground all_different assertions such as "+l);
+ // TODO: can ensure this here (due to unground TG all_different literals), where should I? axiom converter?
+ if(l.negated()) throw new JasdlException("JASDL does not currently support negated all_different assertions such as "+l+", since OWL makes the UNA by default and JASDL doesn't allow this to be overridden");
+ return sl.asAllDifferentAssertion();
+ }else{
+ throw new InvalidSELiteralException(sl+" does not refer to a known class or an all_different assertion");
+ }
+ }else if(sl.getLiteral().getArity() == 2){
+ if(sl.getLiteral().negated()) throw new JasdlException("JASDL does not currently support negated property assertions such as "+sl);
+ if(!sl.getLiteral().getTerm(DOMAIN).isGround()) throw new JasdlException("JASDL cannot handle left-unground property assertions such as "+sl);
+ if(entity instanceof OWLObjectProperty){
+ return sl.asObjectPropertyAssertion();
+ }else if(entity instanceof OWLDataProperty){
+ return sl.asDataPropertyAssertion();
+ }else{
+ throw new InvalidSELiteralException(sl+" does not refer to a known object or data property");
+ }
+ }else{
+ throw new InvalidSELiteralException(sl+" must be either unary or binary");
+ }
+ }
+
+
+
+
+ public SELiteral construct(boolean sign, Atom functor, Term[] terms, Term[] annots, Atom label) throws JasdlException{
+ Literal l = new Literal(sign, functor);
+
+ // add "o"
+ Structure o = new Structure(SELiteral.ONTOLOGY_ANNOTATION_FUNCTOR);
+ o.addTerm(label);
+ l.addAnnot(o);
+
+ l.addTerms(Arrays.asList(terms));
+ if(annots!=null){
+ l.addAnnots(Arrays.asList(annots));
+ }
+ if(l.negated()){
+ if(
+ (l.getFunctor().equals("thing") || l.getFunctor().equals("nothing")) || // special case: reject ~thing and ~nothing
+ (l.getArity() == 2) || //special case: reject negated property assertions
+ (l.getFunctor().equals(AliasFactory.OWL_ALL_DIFFERENT_FUNCTOR.getFunctor())) // special case: reject ~all_different assertions
+ ){
+ throw new InvalidSELiteralException(l+" is invalid");
+ }
+ }
+ return construct(l);
+ }
+
+ public SELiteral construct(boolean sign, Atom functor, Atom individual, Term[] annots, Atom label) throws JasdlException{
+ return construct(sign, functor, new Term[] {individual}, annots, label);
+ }
+
+ public SELiteral construct(boolean sign, Atom functor, Atom subject, Term object, Term[] annots, Atom label) throws JasdlException{
+ return construct(sign, functor, new Term[] {subject, object}, annots, label);
+ }
+
+ public SELiteral construct(boolean sign, Atom[] _is, Term[] annots, Atom label) throws JasdlException{
+ ListTerm is = new ListTermImpl();// TODO: override this object's unify method to perform set, not list, unification + equality?
+ for(Atom i : _is){
+ is.add(i);
+ }
+ return construct(sign, AliasFactory.OWL_ALL_DIFFERENT_FUNCTOR, new Term[] {is}, annots, label);
+ }
+
+
+ /**
+ * Common SELiteral construction code: sets functor, negation (based on presence of "~" prefix) and ontology annotation.
+ * Results in a SELiteral with no arguments.
+ * @param alias the alias from which to construct this SELiteral
+ * @return an SELiteral corresponding to alias with no arguments
+ */
+ public SELiteral construct(Alias alias, Term[] terms, Term[] annots) throws JasdlException{
+ // construct a new literal (with no terms) based on alias
+ boolean sign = true;
+ String functor = alias.getFunctor().toString();
+ //~ might be present
+ if(functor.startsWith("~")){
+ functor = functor.substring(1);
+ sign = false;
+ }
+ return construct(sign, new Atom(functor), terms, annots, alias.getLabel());
+ }
+
+
+ public SELiteral construct(Alias alias, Atom individual, Term[] annots) throws JasdlException{
+ return construct(alias, new Term[] {individual}, annots);
+ }
+
+ public SELiteral construct(Alias alias, Atom subject, Term object, Term[] annots) throws JasdlException{
+ return construct(alias, new Term[] {subject, object}, annots);
+ }
+
+ public SELiteral construct(Alias alias, Atom[] _is, Term[] annots) throws JasdlException{
+ ListTerm is = new ListTermImpl();// TODO: override this object's unify method to perform set, not list, unification + equality?
+ for(Atom i : _is){
+ is.add(i);
+ }
+ return construct(alias, new Term[] {is}, annots);
+ }
+}
Added: trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/SELiteralToAxiomConverter.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/SELiteralToAxiomConverter.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/factory/SELiteralToAxiomConverter.java 2008-04-02 17:09:55 UTC (rev 1193)
@@ -0,0 +1,268 @@
+/*
+ * 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.factory;
+
+import static jasdl.util.Common.RANGE;
+import jasdl.asSemantics.JasdlAgent;
+import jasdl.bb.revision.IndividualAxiomToDescriptionConverter;
+import jasdl.bridge.seliteral.SELiteral;
+import jasdl.bridge.seliteral.SELiteralAllDifferentAssertion;
+import jasdl.bridge.seliteral.SELiteralClassAssertion;
+import jasdl.bridge.seliteral.SELiteralDataPropertyAssertion;
+import jasdl.bridge.seliteral.SELiteralObjectPropertyAssertion;
+import jasdl.util.InvalidSELiteralException;
+import jasdl.util.JasdlException;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.semanticweb.owl.inference.OWLReasonerException;
+import org.semanticweb.owl.model.OWLConstant;
+import org.semanticweb.owl.model.OWLDataProperty;
+import org.semanticweb.owl.model.OWLDescription;
+import org.semanticweb.owl.model.OWLDifferentIndividualsAxiom;
+import org.semanticweb.owl.model.OWLIndividual;
+import org.semanticweb.owl.model.OWLIndividualAxiom;
+import org.semanticweb.owl.model.OWLObjectProperty;
+import org.semanticweb.owl.model.OWLTypedConstant;
+
+
+/**
+ * Accepts an arbitrary SEliteral and, depending on its type, creates an OWLIndividualAxiom encoding of it.
+ * This factory can be used in one of two ways: for <i>creation</i> or for <i>retrieval</i>.<p>
+ *
+ * Creation will always return a encoding regardless of whether the axiom is entailed by the ontology.
+ * In this case, the SELiteral must be ground and only a <b>single</b> SELiteral can be returned.<p>
+ *
+ * Retrieval, on the other hand, will result in an empty list if the axiom is not entailed by the ontology, otherwise
+ * a list containing SELiteral encodings of <b>all</b> entailments is returned. The retrieval operation can deal
+ * with unground SELiterals, in which case unground terms will be treated as "wildcards" that match any (suitable) resource.<p>
+ *
+ * Creation example:
+ * <ul>
+ * <li>hotel(hilton)[o(travel)] -> ClassAssertion(Hotel hilton)</li>
+ * <li>hasRating(hilton,threeStarRating)[o(travel)] -> ObjectPropertyAssertion(hasRating hilton ThreeStarRating)</li>
+ * <li>all_different([hilton,fourSeasons])[o(travel)] -> DifferentIndividuals( fourSeasons hilton )</li>
+ * </ul><p>
+ *
+ * Retrieval example:
+ * <ul>
+ * <li>hotel(hilton)[o(travel)] -> [ClassAssertion(Hotel hilton)]</li>
+ * <li>hasRating(hilton,X)[o(travel)] -> [ObjectPropertyAssertion(hasRating hilton OneStarRating), ObjectPropertyAssertion(hasRating hilton TwoStarRating), ObjectPropertyAssertion(hasRating hilton ThreeStarRating)]</li>
+ * <li>hotel(threeStarRating)[o(travel)] -> []</li>
+ * <li>~hotel(threeStarRating)[o(travel)] -> [ObjectComplementOf(ClassAssertion(Hotel threeStarRating))]</li>
+ * </ul>
+ * @author Tom Klapiscak
+ *
+ */
+public class SELiteralToAxiomConverter {
+
+ private JasdlAgent agent;
+
+ public SELiteralToAxiomConverter(JasdlAgent agent){
+ this.agent = agent;
+ }
+
+
+ public Set<OWLIndividualAxiom> retrieve(SELiteral sl) throws JasdlException{
+ return convert(sl, true);
+ }
+
+ /**
+ * <b>Create</b> an axiomatic encoding of sl. Specific type of axiom dependent on specific type of sl.
+ * sl must be <b>ground</b>
+ * @param sl the SE-Literal to encode
+ * @return a single encoding of sl - regardless of whether it is entailed or not
+ * @throws JasdlException
+ */
+ public OWLIndividualAxiom create(SELiteral sl) throws JasdlException{
+ if(!sl.getLiteral().isGround()){
+ throw new JasdlException("Cannot create an axiom from unground SELiteral "+sl);
+ }
+ Set<OWLIndividualAxiom> axioms = convert(sl, false);
+ if(axioms.isEmpty()){
+ throw new JasdlException("Error creating axiom from "+sl);
+ }
+ return (OWLIndividualAxiom)axioms.toArray()[0];
+ }
+
+ /**
+ * Polymorphically apply a factory method dependent on the specific type of sl
+ * @param sl the SE-Literal to encode
+ * @param checkForExistence if true, results will only be returned in they are entailed - if false, a successful encoding will guarantee a result
+ * @return a set of entailments matching sl
+ * @throws JasdlException
+ */
+ private Set<OWLIndividualAxiom> convert(SELiteral sl, boolean checkForExistence) throws JasdlException{
+ if(sl instanceof SELiteralClassAssertion){
+ return convert((SELiteralClassAssertion)sl, checkForExistence);
+ }else if(sl instanceof SELiteralObjectPropertyAssertion){
+ return create((SELiteralObjectPropertyAssertion)sl, checkForExistence);
+ }else if(sl instanceof SELiteralDataPropertyAssertion){
+ return create((SELiteralDataPropertyAssertion)sl, checkForExistence);
+ }else if(sl instanceof SELiteralAllDifferentAssertion){
+ return create((SELiteralAllDifferentAssertion)sl, checkForExistence);
+ }else{
+ throw new InvalidSELiteralException("JASDL does not know how to handle SELiterals like "+sl);
+ }
+ }
+
+ /**
+ * Convert a unary SELiteral (asserting a class membership of an individual) to its axiomatic encoding
+ * @param sl the SELiteral to convert
+ * @param checkForExistence if true, results will only be returned in they are entailed - if false, a successful encoding will guarantee a result
+ * @return an axiomatic encoding of sl
+ * @throws JasdlException
+ */
+ private Set<OWLIndividualAxiom> convert(SELiteralClassAssertion sl, boolean checkForExistence) throws JasdlException{
+ try {
+ Set<OWLIndividual> is = new HashSet<OWLIndividual>();
+ OWLDescription desc = sl.getOWLDescription();
+
+ if(sl.getLiteral().isGround()){
+ OWLIndividual i = sl.getOWLIndividual();
+ if(!checkForExistence || agent.getReasoner().hasType(i, desc, false)){
+ is.add(i);
+ }
+ }else{
+ is.addAll(agent.getReasoner().getIndividuals(desc, false));
+ }
+ Set<OWLIndividualAxiom> axioms = new HashSet<OWLIndividualAxiom>();
+ for(OWLIndividual i : is){
+ axioms.add(agent.getOntologyManager().getOWLDataFactory().getOWLClassAssertionAxiom(i, desc));
+ }
+ return axioms;
+ } catch (OWLReasonerException e) {
+ throw new JasdlException("Unable to convert "+sl+" to axiom. Reason: "+e);
+ }
+ }
+
+ /**
+ * Convert a unary all_different SELiteral (asserting distinctness of a set of individuals) to its axiomatic encoding
+ * @param sl the SELiteral to convert
+ * @param checkForExistence if true, results will only be returned in they are entailed - if false, a successful encoding will guarantee a result
+ * @return an axiomatic encoding of sl
+ * @throws JasdlException
+ */
+ public Set<OWLIndividualAxiom> create(SELiteralAllDifferentAssertion sl, boolean checkForExistence) throws JasdlException{
+ try {
+ Set<OWLIndividual> _is = sl.getOWLIndividuals();
+ Object[] is = _is.toArray();
+ if(is.length == 0){
+ throw new JasdlException("All different assertion must contain some individuals! "+sl);
+ }
+ // check they are mutually distinct (if we are checking for existence)
+ boolean distinct = true;
+ if(checkForExistence){
+ for(int i=0; i<is.length; i++){
+ for(int j=i+1; j<is.length; j++){
+ // create a description that is satisfiable iff the two individuals are different. TODO: request in-built OWL-API support for this
+ OWLDifferentIndividualsAxiom axiom = agent.getOntologyManager().getOWLDataFactory().getOWLDifferentIndividualsAxiom(_is);
+ IndividualAxiomToDescriptionConverter conv = new IndividualAxiomToDescriptionConverter(agent.getOntologyManager().getOWLDataFactory());
+ axiom.accept(conv);
+ if(!agent.getReasoner().isSatisfiable(conv.getDescription())){//.isDifferentFrom((OWLIndividual)is[i], (OWLIndividual)is[j])){
+ distinct = false;
+ break;
+ }
+ }
+ if(!distinct) break;
+ }
+ }
+ Set<OWLIndividualAxiom> axioms = new HashSet<OWLIndividualAxiom>();
+ Set<OWLIndividual> different = new HashSet<OWLIndividual>();
+ if(!checkForExistence || distinct){
+ for(int i=0; i<is.length; i++){
+ different.add((OWLIndividual)is[i]);
+ }
+ OWLDifferentIndividualsAxiom axiom = agent.getOntologyManager().getOWLDataFactory().getOWLDifferentIndividualsAxiom(different);
+ axioms.add(axiom);
+ }
+ return axioms;
+ } catch (OWLReasonerException e) {
+ throw new JasdlException("Unable to convert "+sl+" to axiom. Reason: "+e);
+ }
+ }
+
+ /**
+ * Convert a binary SELiteral (asserting that two individuals are related by an object property) to its axiomatic encoding
+ * @param sl the SELiteral to convert
+ * @param checkForExistence if true, results will only be returned in they are entailed - if false, a successful encoding will guarantee a result
+ * @return an axiomatic encoding of sl
+ * @throws JasdlException
+ */
+ public Set<OWLIndividualAxiom> create(SELiteralObjectPropertyAssertion sl, boolean checkForExistence) throws JasdlException{
+ try {
+ Set<OWLIndividual> os = new HashSet<OWLIndividual>();
+ OWLIndividual s = sl.getSubject();
+ OWLObjectProperty p = sl.getPredicate();
+ if(sl.getLiteral().getTerm(RANGE).isGround()){
+ OWLIndividual o = sl.getObject();
+ if(!checkForExistence || agent.getReasoner().hasObjectPropertyRelationship(s, p, o)){
+ os.add(o);
+ }
+ }else{
+ os.addAll(agent.getReasoner().getRelatedIndividuals(s, p));
+ }
+ Set<OWLIndividualAxiom> axioms = new HashSet<OWLIndividualAxiom>();
+ for(OWLIndividual o : os){
+ axioms.add(agent.getOntologyManager().getOWLDataFactory().getOWLObjectPropertyAssertionAxiom(s, p, o));
+ }
+ return axioms;
+ } catch (OWLReasonerException e) {
+ throw new JasdlException("Unable to convert "+sl+" to axiom. Reason: "+e);
+ }
+ }
+
+ /**
+ * Convert a binary SELiteral (asserting that an individual is related to a datatype literal) to its axiomatic encoding
+ * @param sl the SELiteral to convert
+ * @param checkForExistence if true, results will only be returned in they are entailed - if false, a successful encoding will guarantee a result
+ * @return an axiomatic encoding of sl
+ * @throws JasdlException
+ */
+ public Set<OWLIndividualAxiom> create(SELiteralDataPropertyAssertion sl, boolean checkForExistence) throws JasdlException{
+ try {
+ Set<OWLConstant> os = new HashSet<OWLConstant>();
+ OWLIndividual s = sl.getSubject();
+ OWLDataProperty p = sl.getPredicate();
+ if(sl.getLiteral().getTerm(RANGE).isGround()){
+ OWLTypedConstant o = sl.getObject();
+ if(!checkForExistence || agent.getReasoner().hasDataPropertyRelationship(s, p, o)){
+ os.add(o);
+ }
+ }else{
+ os.addAll(agent.getReasoner().getRelatedValues(s, p));
+ }
+ Set<OWLIndividualAxiom> axioms = new HashSet<OWLIndividualAxiom>();
+ for(OWLConstant o : os){
+ axioms.add(agent.getOntologyManager().getOWLDataFactory().getOWLDataPropertyAssertionAxiom(s, p, o));
+ }
+ return axioms;
+ } catch (OWLReasonerException e) {
+ throw new JasdlException("Unable to convert "+sl+" to axiom. Reason: "+e);
+ }
+ }
+
+
+
+
+
+
+}
\ No newline at end of file
Modified: trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteral.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteral.java 2008-04-02 17:05:13 UTC (rev 1192)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteral.java 2008-04-02 17:09:55 UTC (rev 1193)
@@ -1,8 +1,8 @@
package jasdl.bridge.seliteral;
import jasdl.asSemantics.JasdlAgent;
-import jasdl.bridge.alias.Alias;
-import jasdl.bridge.alias.AliasFactory;
+import jasdl.bridge.factory.AliasFactory;
+import jasdl.bridge.mapping.aliasing.Alias;
import jasdl.util.InvalidSELiteralException;
import jasdl.util.JasdlException;
import jasdl.util.NotEnrichedException;
@@ -149,7 +149,7 @@
*/
public OWLIndividualAxiom createAxiom() throws JasdlException{
if(axiom == null || !USE_CACHING){
- axiom = agent.getToAxiomConverter().create(this);
+ axiom = agent.getSELiteralToAxiomConverter().create(this);
}
return axiom;
}
@@ -159,7 +159,7 @@
*/
public Set<OWLIndividualAxiom> getAxioms() throws JasdlException{
if(axioms == null || !USE_CACHING){
- axioms = agent.getToAxiomConverter().retrieve(this);
+ axioms = agent.getSELiteralToAxiomConverter().retrieve(this);
}
return axioms;
}
Modified: trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralDataPropertyAssertion.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralDataPropertyAssertion.java 2008-04-02 17:05:13 UTC (rev 1192)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralDataPropertyAssertion.java 2008-04-02 17:09:55 UTC (rev 1193)
@@ -4,10 +4,10 @@
import static jasdl.util.Common.strip;
import static jasdl.util.Common.surroundedBy;
import jasdl.asSemantics.JasdlAgent;
-import jasdl.bridge.xsd.XSDDataType;
-import jasdl.bridge.xsd.XSDDataTypeUtils;
import jasdl.util.InvalidSELiteralException;
import jasdl.util.JasdlException;
+import jasdl.util.xsd.XSDDataType;
+import jasdl.util.xsd.XSDDataTypeUtils;
import jason.asSyntax.Literal;
import jason.asSyntax.Term;
Deleted: trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralFactory.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralFactory.java 2008-04-02 17:05:13 UTC (rev 1192)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralFactory.java 2008-04-02 17:09:55 UTC (rev 1193)
@@ -1,57 +0,0 @@
-package jasdl.bridge.seliteral;
-
-import static jasdl.util.Common.DOMAIN;
-import jasdl.asSemantics.JasdlAgent;
-import jasdl.bridge.AllDifferentPlaceholder;
-import jasdl.util.InvalidSELiteralException;
-import jasdl.util.JasdlException;
-import jason.asSyntax.Literal;
-
-import org.semanticweb.owl.model.OWLDataProperty;
-import org.semanticweb.owl.model.OWLDescription;
-import org.semanticweb.owl.model.OWLObject;
-import org.semanticweb.owl.model.OWLObjectProperty;
-
-public class SELiteralFactory {
-
- private JasdlAgent agent;
-
- public SELiteralFactory(JasdlAgent agent){
- this.agent = agent;
- }
-
- /**
- * Polymorphically creates a specific type of SELiteral based on the properties of the supplied literal
- * @param l
- * @return
- * @throws JasdlException
- */
- public SELiteral create(Literal l) throws JasdlException{
- SELiteral sl = new SELiteral(l, agent); // so we can use convenience methods on a processed seliteral
- OWLObject entity = sl.toOWLObject();
- if(sl.getLiteral().getArity() == 1){
- if(entity instanceof OWLDescription){
- return sl.asClassAssertion();
- }else if(entity instanceof AllDifferentPlaceholder){
- //if(!l.isGround()) throw new JasdlException("JASDL does not currently support unground all_different assertions such as "+l);
- // TODO: can ensure this here (due to unground TG all_different literals), where should I? axiom converter?
- if(l.negated()) throw new JasdlException("JASDL does not currently support negated all_different assertions such as "+l+", since OWL makes the UNA by default and JASDL doesn't allow this to be overridden");
- return sl.asAllDifferentAssertion();
- }else{
- throw new InvalidSELiteralException(sl+" does not refer to a known class or an all_different assertion");
- }
- }else if(sl.getLiteral().getArity() == 2){
- if(sl.getLiteral().negated()) throw new JasdlException("JASDL does not currently support negated property assertions such as "+sl);
- if(!sl.getLiteral().getTerm(DOMAIN).isGround()) throw new JasdlException("JASDL cannot handle left-unground property assertions such as "+sl);
- if(entity instanceof OWLObjectProperty){
- return sl.asObjectPropertyAssertion();
- }else if(entity instanceof OWLDataProperty){
- return sl.asDataPropertyAssertion();
- }else{
- throw new InvalidSELiteralException(sl+" does not refer to a known object or data property");
- }
- }else{
- throw new InvalidSELiteralException(sl+" must be either unary or binary");
- }
- }
-}
Modified: trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralPropertyAssertion.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralPropertyAssertion.java 2008-04-02 17:05:13 UTC (rev 1192)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralPropertyAssertion.java 2008-04-02 17:09:55 UTC (rev 1193)
@@ -5,7 +5,7 @@
import org.semanticweb.owl.model.OWLIndividual;
import jasdl.asSemantics.JasdlAgent;
-import jasdl.bridge.alias.AliasFactory;
+import jasdl.bridge.factory.AliasFactory;
import jasdl.util.JasdlException;
import jason.asSyntax.Literal;
Modified: trunk/applications/jasdl-owlapi/src/jasdl/test/JasdlBeliefBaseTest.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/test/JasdlBeliefBaseTest.java 2008-04-02 17:05:13 UTC (rev 1192)
+++ trunk/applications/jasdl-owlapi/src/jasdl/test/JasdlBeliefBaseTest.java 2008-04-02 17:09:55 UTC (rev 1193)
@@ -7,29 +7,28 @@
import jasdl.architecture.JasdlAgArch;
import jasdl.asSemantics.JasdlAgent;
import jasdl.bb.JasdlBeliefBase;
-import jasdl.bridge.alias.Alias;
+import jasdl.bridge.factory.AliasFactory;
+import jasdl.bridge.mapping.aliasing.Alias;
import jasdl.bridge.seliteral.SELiteral;
-import jasdl.bridge.xsd.XSDDataType;
-import jasdl.bridge.xsd.XSDDataTypeUtils;
+import jasdl.util.JasdlException;
+import jasdl.util.xsd.XSDDataType;
+import jasdl.util.xsd.XSDDataTypeUtils;
import jason.architecture.AgArch;
import jason.architecture.AgArchInfraTier;
import jason.asSyntax.Atom;
-import jason.asSyntax.DefaultTerm;
+import jason.asSyntax.ListTerm;
+import jason.asSyntax.ListTermImpl;
import jason.asSyntax.Literal;
-import jason.asSyntax.Structure;
+import jason.asSyntax.StringTermImpl;
import jason.asSyntax.Term;
-import jason.bb.BeliefBase;
import jason.bb.DefaultBeliefBase;
import jason.infra.centralised.CentralisedAgArch;
import jason.mas2j.ClassParameters;
import jason.runtime.Settings;
import java.lang.reflect.Constructor;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
import java.util.Set;
import junit.framework.TestCase;
@@ -56,6 +55,7 @@
* A seperate test suite must be developed for belief bases employing the legacy rollback consistency assurance mechanism.
*
* TODO: contruct special testing ontology to better cover all test cases
+ * TODO: Perhaps we shouldn't be testing literal transation functionality here (i.e. in add)?
*
* @author Tom Klapiscak
*
@@ -66,7 +66,7 @@
public static String JASDL_AGENT_CLASS = "jasdl.asSemantics.JasdlAgent";
public static String JASDL_BELIEF_BASE_CLASS = "jasdl.bb.JasdlBeliefBase";
- public static String TEST_ONTOLOGY_LABEL = "test";
+ public static Atom TEST_ONTOLOGY_LABEL = new Atom("test");
public static String TEST_ONTOLOGY_URI = "http://www.dur.ac.uk/t.g.klapiscak/onts/travel.owl";
protected JasdlAgArch arch;
@@ -87,10 +87,9 @@
public void setUp() throws Exception {
// Use default manual mappings, mapping strategies and reasoner class. No known agents + trust ratings
Settings stts = new Settings();
- stts.addOption(MAS2J_PREFIX + MAS2J_ONTOLOGIES, TEST_ONTOLOGY_LABEL);
+ stts.addOption(MAS2J_PREFIX + MAS2J_ONTOLOGIES, TEST_ONTOLOGY_LABEL.getFunctor());
stts.addOption(MAS2J_PREFIX + "_" + TEST_ONTOLOGY_LABEL + MAS2J_URI, TEST_ONTOLOGY_URI);
stts.addOption(MAS2J_PREFIX + MAS2J_USEBELIEFREVISION, "true"); // Must be enabled (we don't want legacy consistency assurance!) - remember brf is skipped by this
- String aslFile = getClass().getResource("blank.asl").toExternalForm();
// load arch
Class cls = Class.forName(JASDL_AG_ARCH_CLASS);
@@ -98,7 +97,7 @@
AgArch arch = (AgArch)ct.newInstance(new Object[] {});
AgArchInfraTier archInfraTier = new CentralisedAgArch();
...
[truncated message content] |