|
From: <tom...@us...> - 2008-03-17 19:13:39
|
Revision: 1157
http://jason.svn.sourceforge.net/jason/?rev=1157&view=rev
Author: tomklapiscak
Date: 2008-03-17 12:13:28 -0700 (Mon, 17 Mar 2008)
Log Message:
-----------
New and improved semantically-enriched knowledge sharing protocol implemented and working.
Improvements to mapping system.
Architectural improvements (SELiteral class now follows "decorator" design pattern).
Various bug-fixes.
travel_agent example updated
Modified Paths:
--------------
trunk/applications/jasdl-owlapi/examples/travel_agent/config.mas2j
trunk/applications/jasdl-owlapi/examples/travel_agent/customer.asl
trunk/applications/jasdl-owlapi/examples/travel_agent/travel_agent.asl
trunk/applications/jasdl-owlapi/src/jasdl/architecture/IncomingPropContProcessingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/architecture/JasdlAgArch.java
trunk/applications/jasdl-owlapi/src/jasdl/architecture/OutgoingPropContProcessingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/architecture/PropContProcessingStrategy.java
trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java
trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlConfigurator.java
trunk/applications/jasdl-owlapi/src/jasdl/asSyntax/JasdlPlanLibrary.java
trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlBeliefBase.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/MappingManager.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/ToAxiomConverter.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/alias/AliasFactory.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteral.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralAllDifferentAssertion.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralClassAssertion.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralDataPropertyAssertion.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralFactory.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralObjectPropertyAssertion.java
trunk/applications/jasdl-owlapi/src/jasdl/bridge/seliteral/SELiteralPropertyAssertion.java
trunk/applications/jasdl-owlapi/src/jasdl/ia/define_class.java
Added Paths:
-----------
trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/parsing/
trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/parsing/NSPrefixEntityChecker.java
trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/parsing/URIEntityChecker.java
Modified: trunk/applications/jasdl-owlapi/examples/travel_agent/config.mas2j
===================================================================
--- trunk/applications/jasdl-owlapi/examples/travel_agent/config.mas2j 2008-03-17 08:41:44 UTC (rev 1156)
+++ trunk/applications/jasdl-owlapi/examples/travel_agent/config.mas2j 2008-03-17 19:13:28 UTC (rev 1157)
@@ -32,10 +32,16 @@
agents:
travel_agent
travel_agent.asl
- [
- jasdl_ontologies="travel,places",
+ [
+ jasdl_agent_name = "travelagent",
+ // implication, "default" is a reserved ontology name
+ // also, "self"
+ jasdl_default_mapping_strategies="jasdl.bridge.alias.DecapitaliseMappingStrategy", // applied to incoming ontologies and those given no automapping
+ //TODO: what about when automapping causes a conflict?! anonymous aliasing?
+
+ jasdl_ontologies="travel",
jasdl_travel_uri="http://www.dur.ac.uk/t.g.klapiscak/onts/travel.owl",
- jasdl_travel_mapping_strategies="jasdl.bridge.alias.DecapitaliseMappingStrategy",
+ //jasdl_travel_mapping_strategies="jasdl.bridge.alias.DecapitaliseMappingStrategy",
jasdl_travel_mapping_manual="small_beach=beach",
jasdl_places_uri="http://www.dur.ac.uk/t.g.klapiscak/onts/places.owl",
@@ -51,13 +57,18 @@
customer
customer.asl
- [
- jasdl_ontologies="holidays",
+ [
+ jasdl_agent_name = "customer",
+
+ jasdl_ontologies="holidays,places",
//jasdl_holidays_uri="file:///home/tom/Desktop/Project/workspace/jason/applications/jasdl-owlapi/examples/travel_agent/ontologies/travel.owl",
jasdl_holidays_uri="http://www.dur.ac.uk/t.g.klapiscak/onts/travel.owl",
jasdl_holidays_mapping_strategies="jasdl.bridge.alias.DecapitaliseMappingStrategy",
- jasdl_holidays_mapping_manual="small_beach=beach, luxuriousHotel=LuxuryHotel" // arbitrary primitive mappings handled correctly
+ jasdl_holidays_mapping_manual="small_beach=beach, luxuriousHotel=LuxuryHotel", // arbitrary primitive mappings handled correctly
+ jasdl_places_uri="http://www.dur.ac.uk/t.g.klapiscak/onts/places.owl",
+ jasdl_places_mapping_strategies="jasdl.bridge.alias.DecapitaliseMappingStrategy"
+
/* Example per-agent proxy settings used for ontology instantiation */
//jasdl_http_proxy="127.0.0.1:3128"
//jasdl_https_proxy="127.0.0.1:8080"
Modified: trunk/applications/jasdl-owlapi/examples/travel_agent/customer.asl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/travel_agent/customer.asl 2008-03-17 08:41:44 UTC (rev 1156)
+++ trunk/applications/jasdl-owlapi/examples/travel_agent/customer.asl 2008-03-17 19:13:28 UTC (rev 1157)
@@ -18,27 +18,37 @@
*
*/
+//+luxuriousHotel(L)[o(holidays), source(Source)]
+luxuriousHotel(L)[o(holidays), source(Source)]
<-
- /* 1 */ .print("The ", L, " luxurious hotel is available");
- /* 2 */ jasdl.ia.define_class(query, "city and hasAccommodation value ", L);
- /* 3 */ .send(Source, askOne, query(City)[o(holidays)], query(City)[o(holidays)]);
- /* 4 */ .print(L, " is located in the city ", City);
+ ?hotel(L)[o(holidays)];
+ .print("The ", L, " luxurious hotel is available");
+ jasdl.ia.define_class(query, "holidays:city and holidays:hasAccommodation value self:", L);
+ .send(Source, askOne, query(City)[o(self)], query(City)[o(self)]);
+ .print(L, " is located in the city ", City);
+
// check given hotel is located in a destination that has some museums
- jasdl.ia.define_class(q2, "{",L,"} and isLocatedAt some (hasActivity some museums)");
- .send(Source, askOne, q2(Hotel)[o(holidays)], q2(Hotel)[o(holidays)]);
+ jasdl.ia.define_class(q2, "{self:",L,"} and holidays:isLocatedAt some (holidays:hasActivity some holidays:museums)");
+ .send(Source, askOne, q2(Hotel)[o(self)], q2(Hotel)[o(self)]);
.print(Hotel, " is located in a city with some museums");
// bundle([h_1...h_n]) demonstrates how JASDL deals with nested se-content
// in particular, this query bundles together an arbitrary number of queries into a single message
- .send(Source, askOne, bundle( [ luxuriousHotel(H1)[o(holidays)], hotel(H2)[o(holidays)], activity(H3)[o(holidays)] ] ), Response);
+ .send(Source, askOne, bundle( [ luxuriousHotel(H1)[o(holidays)], hotel(H2)[o(holidays)], activity(H3)[o(holidays)], q2(H4)[o(self)] ] ), Response);
.print("Bundled query response: ", Response);
.send(Source, tell, example_KSAA_complete).
+
+all_different(XS)[o(holidays), source(Source)]
<-
- .print(XS, " are mutually distinct individuals, according to ", Source).
+ .print(XS, " are mutually distinct individuals, according to ", Source);
+ .send(Source, tell, building(travel_lodge)[o(places)]);
+ .wait(1000); // wait to ensure travel_agent has had a chance to add this information to its belief base
+ jasdl.ia.define_class(q3, "(places:place and places:building) and holidays:hotel");
+ .send(Source, askOne, q3(Hotel)[o(self)], q3(Hotel)[o(self)]);
+ .print(Hotel, " is a building and a hotel").
+
Modified: trunk/applications/jasdl-owlapi/examples/travel_agent/travel_agent.asl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/travel_agent/travel_agent.asl 2008-03-17 08:41:44 UTC (rev 1156)
+++ trunk/applications/jasdl-owlapi/examples/travel_agent/travel_agent.asl 2008-03-17 19:13:28 UTC (rev 1157)
@@ -44,16 +44,7 @@
+museums(scienceMuseum)[o(travel)];
+hasActivity(london, scienceMuseum)[o(travel)];
+hotel(travel_lodge)[o(travel)];
-
- +building(hilton)[o(places)];
-
- ?place(Place)[o(places)];
- .print(Place);
-
- jasdl.ia.define_class(q2, "(places:place and places:building) and travel:hotel");
- ?q2(X)[o(self)];
- .print(X);
-
+
.print("Completed: Updating Belief Base 1").
Modified: trunk/applications/jasdl-owlapi/src/jasdl/architecture/IncomingPropContProcessingStrategy.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/architecture/IncomingPropContProcessingStrategy.java 2008-03-17 08:41:44 UTC (rev 1156)
+++ trunk/applications/jasdl-owlapi/src/jasdl/architecture/IncomingPropContProcessingStrategy.java 2008-03-17 19:13:28 UTC (rev 1157)
@@ -19,29 +19,152 @@
*/
package jasdl.architecture;
+import static jasdl.architecture.JasdlAgArch.ANON_ANNOTATION_FUNCTOR;
import static jasdl.architecture.JasdlAgArch.NAMED_ANNOTATION_FUNCTOR;
-import static jasdl.architecture.JasdlAgArch.ANON_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.seliteral.SELiteral;
+import jasdl.util.DuplicateMappingException;
import jasdl.util.JasdlException;
import jasdl.util.NotEnrichedException;
+import jason.asSyntax.Atom;
+import jason.asSyntax.ListTerm;
import jason.asSyntax.Literal;
+import jason.asSyntax.StringTerm;
+import jason.asSyntax.Structure;
+import jason.asSyntax.Term;
+import java.net.URI;
+import java.net.URISyntaxException;
+
public class IncomingPropContProcessingStrategy implements PropContProcessingStrategy{
- public Literal process(Literal l, JasdlAgent agent) throws JasdlException{
+ public Literal process(Literal l, JasdlAgent agent, String src) throws JasdlException{
try{
- SELiteral sl = new SELiteral(l, agent); // note, l might not (yet) be a valid se-literal (mappings may be performed below) so factory cannot be used
- // replace physical URI with ontology label if known, else instantiate and assign anonymous label
+ Literal result;
+ agent.getLogger().fine("Processing incoming "+l);
+
+ SELiteral sl = new SELiteral(l, agent);
sl.unqualifyOntologyAnnotation();
+ result = processAllDifferent(sl);
+ if(result!=null) return result;
+ result = processNamed(sl, agent);
+ if(result!=null) return result;
- return sl; // not able to modify literal functors directly
+ result = processAnon(sl, agent);
+ if(result!=null) return result;
+
}catch(NotEnrichedException e){
// do nothing
- return l;
}
+ return l;
+
}
+ private Literal processAllDifferent(SELiteral sl){
+ if(sl.getLiteral().getFunctor().equals(AliasFactory.OWL_ALL_DIFFERENT_FUNCTOR.toString())){
+ return sl.getLiteral();
+ }else{
+ return null;
+ }
+ }
+
+ private Literal processNamed(SELiteral sl, JasdlAgent agent) throws JasdlException{
+ ListTerm nameds = sl.getLiteral().getAnnots(NAMED_ANNOTATION_FUNCTOR);
+ if(nameds.size() == 1){
+ // get named annotation
+ Term _named = nameds.get(0);
+ if(!(_named instanceof Structure)){
+ throw new JasdlException("Invalid "+NAMED_ANNOTATION_FUNCTOR+" annotation: "+_named);
+ }
+ Structure named = (Structure)_named;
+ if(named.getArity() != 1){
+ throw new JasdlException("Invalid "+NAMED_ANNOTATION_FUNCTOR+" annotation arity: "+_named);
+ }
+
+ // get expression
+ Term expressionTerm = named.getTerm(0);
+ if(!(expressionTerm instanceof StringTerm)){
+ throw new JasdlException("Invalid "+NAMED_ANNOTATION_FUNCTOR+" annotation term: "+expressionTerm);
+ }
+ String expression = strip(expressionTerm.toString(), "\""); // quotes stripped
+
+
+ URI uri;
+ try {
+ uri = new URI(expression);
+ } catch (URISyntaxException e) {
+ throw new JasdlException("Invalid entity URI in "+expression);
+ }
+ Alias local = agent.getAliasManager().getLeft(agent.toEntity(uri)); // will already be present by definition
+
+ // create new (SE) Literal
+ sl.mutateFunctor(local.getFunctor().toString());
+
+
+ sl.getLiteral().delAnnot(named); // drop named, no longer needed
+ return sl.getLiteral(); // not able to modify literal functors directly
+ }else{
+ return null;
+ }
+ }
+
+ private Literal processAnon(SELiteral sl, JasdlAgent agent) throws JasdlException{
+ ListTerm anons = sl.getLiteral().getAnnots(ANON_ANNOTATION_FUNCTOR);
+ if(anons.size() == 1){
+ // Get Anon annotation
+ Term _anon = anons.get(0);
+ if(!(_anon instanceof Structure)){
+ throw new JasdlException("Invalid "+ANON_ANNOTATION_FUNCTOR+" annotation: "+_anon);
+ }
+ Structure anon = (Structure)_anon;
+ if(anon.getArity() != 2){
+ throw new JasdlException("Invalid "+ANON_ANNOTATION_FUNCTOR+" annotation arity: "+_anon);
+ }
+
+ // Get expression
+ Term expressionTerm = anon.getTerm(0);
+ if(!(expressionTerm instanceof StringTerm)){
+ throw new JasdlException("Invalid "+ANON_ANNOTATION_FUNCTOR+" annotation expression term: "+expressionTerm);
+ }
+ String expression = strip(expressionTerm.toString(), "\""); // quotes stripped
+
+ // Parse prequisite ontology URIs
+ Term prereqsTerm = anon.getTerm(1);
+ if(!(prereqsTerm instanceof ListTerm)){
+ throw new JasdlException("Invalid "+ANON_ANNOTATION_FUNCTOR+" annotation prereqs term: "+expressionTerm);
+ }
+ ListTerm prereqs = (ListTerm)prereqsTerm;
+ for(Term _prereqTerm : prereqs){
+ if(!(_prereqTerm instanceof StringTerm)){
+ throw new JasdlException("Invalid "+ANON_ANNOTATION_FUNCTOR+" prereq: "+_prereqTerm);
+ }
+ StringTerm prereqTerm = (StringTerm)_prereqTerm;
+ String prereq = strip(prereqTerm.toString(), "\""); // quotes stripped
+ agent.getOntology(prereq);
+ }
+
+ // do we already know this expression?
+ Atom functor = new Atom(sl.getLiteral().getFunctor());
+ try{
+ agent.defineClass(functor, sl.getOntologyLabel(), expression, agent.getManchesterURIDescriptionParser()); // Instantiate defined expression
+ }catch(DuplicateMappingException e){
+ // do nothing
+ }
+
+ // drop anon annotation, no longer needed
+ sl.getLiteral().delAnnot(anon);
+
+ return sl.getLiteral();
+ }else{
+ return null;
+ }
+
+ }
+
+
}
Modified: trunk/applications/jasdl-owlapi/src/jasdl/architecture/JasdlAgArch.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/architecture/JasdlAgArch.java 2008-03-17 08:41:44 UTC (rev 1156)
+++ trunk/applications/jasdl-owlapi/src/jasdl/architecture/JasdlAgArch.java 2008-03-17 19:13:28 UTC (rev 1157)
@@ -30,8 +30,8 @@
import jason.asSyntax.Term;
import jason.asSyntax.VarTerm;
-import java.util.PriorityQueue;
import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Logger;
public class JasdlAgArch extends AgArch {
@@ -48,7 +48,7 @@
super.checkMail();
// temporary set to hold processed message clones
- Queue<Message> tempMail = new PriorityQueue<Message>();
+ Queue<Message> tempMail = new ConcurrentLinkedQueue<Message>();
Queue<Message> mail = getTS().getC().getMailBox();
// mustn't affect original message object, otherwise effects are global (i.e. at infrastructure level)
@@ -67,21 +67,21 @@
mail.addAll(tempMail);
if(!mail.isEmpty()){
- getLogger().info("Pending messages: "+mail);
+ getLogger().fine("Pending messages: "+mail);
}
}
@Override
public void sendMsg(Message msg) throws Exception {
processMessage(msg, outgoingStrategy);
- getLogger().info("Sending message: "+msg);
+ getLogger().fine("Sending message: "+msg);
super.sendMsg(msg);
}
@Override
public void broadcast(Message msg) throws Exception {
processMessage(msg, outgoingStrategy);
- getLogger().finest("Broadcasting message: "+msg);
+ getLogger().fine("Broadcasting message: "+msg);
super.broadcast(msg);
}
@@ -98,28 +98,30 @@
Object propcont = msg.getPropCont();
if(propcont == null){
return;
- }
+ }
if(propcont instanceof Structure){ // only Structures require processing
- propcont = processStructure((Structure)propcont, strategy);
+ msg.setPropCont(processStructure((Structure)propcont, strategy, msg.getSender()));
}
- msg.setPropCont(propcont);
+
}
- private Structure processStructure(Structure struct, PropContProcessingStrategy strategy) throws JasdlException{
+ private Structure processStructure(Structure struct, PropContProcessingStrategy strategy, String src) throws JasdlException{
- // Process outer SE-enriched content
- if(struct instanceof Literal){ // processing strategies only apply to Literals
- Literal l = (Literal)struct;
- try{
- struct = strategy.process(l, getAgent());
- }catch(JasdlException e){
- e.printStackTrace();
- }
- }
+
// recurse down terms and lists (for "bundled" SE-enriched content)
if(struct.getArity()>0){ // if we have any terms to process!
+ // Process outer SE-enriched content
+ if(struct instanceof Literal){ // processing strategies only apply to Literals
+ Literal l = (Literal)struct;
+ try{
+ struct = strategy.process(l, getAgent(), src);
+ }catch(JasdlException e){
+ e.printStackTrace();
+ }
+ }
+
//int i=0;
//for(Term _term : struct.getTerms()){ - mustn't use in case struct is a list
if(struct.isVar()){
@@ -129,7 +131,7 @@
ListTermImpl newList = new ListTermImpl(); // a "clone"
for(Term e : ((ListTerm)struct).getAsList()){
if(e instanceof Structure){
- Structure alteredTerm = (Structure)processStructure((Structure)e, strategy);
+ Structure alteredTerm = (Structure)processStructure((Structure)e, strategy, src);
newList.append(alteredTerm);
}
}
@@ -139,7 +141,7 @@
Term _term = struct.getTerm(i);
if(_term instanceof Structure){
Structure term = (Structure)_term;
- Structure alteredTerm = (Structure)processStructure(term, strategy);
+ Structure alteredTerm = (Structure)processStructure(term, strategy, src);
struct.setTerm(i, alteredTerm); // modifies original struct
}
}
Modified: trunk/applications/jasdl-owlapi/src/jasdl/architecture/OutgoingPropContProcessingStrategy.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/architecture/OutgoingPropContProcessingStrategy.java 2008-03-17 08:41:44 UTC (rev 1156)
+++ trunk/applications/jasdl-owlapi/src/jasdl/architecture/OutgoingPropContProcessingStrategy.java 2008-03-17 19:13:28 UTC (rev 1157)
@@ -24,8 +24,10 @@
import jasdl.asSemantics.JasdlAgent;
import jasdl.bridge.alias.Alias;
import jasdl.bridge.seliteral.SELiteral;
+import jasdl.bridge.seliteral.SELiteralAllDifferentAssertion;
import jasdl.util.JasdlException;
import jasdl.util.NotEnrichedException;
+import jasdl.util.UnknownMappingException;
import jason.asSyntax.ListTerm;
import jason.asSyntax.ListTermImpl;
import jason.asSyntax.Literal;
@@ -38,6 +40,8 @@
import java.util.HashSet;
import java.util.Set;
+import org.semanticweb.owl.model.OWLNamedObject;
+import org.semanticweb.owl.model.OWLObject;
import org.semanticweb.owl.model.OWLOntology;
public class OutgoingPropContProcessingStrategy implements PropContProcessingStrategy {
@@ -51,22 +55,39 @@
* @param l
* @throws JasdlException
*/
- public Literal process(Literal l, JasdlAgent agent) throws JasdlException {
+ public Literal process(Literal l, JasdlAgent agent, String src) throws JasdlException {
+ agent.getLogger().fine("Processing outgoing "+l);
+
+ Literal result = l;
try{
- SELiteral sl = new SELiteral(l, agent);
+ SELiteral sl = agent.getSELiteralFactory().create(l);
+
+ // qualify o
+ sl.qualifyOntologyAnnotation();
- StringTerm expression = new StringTermImpl( agent.getManchesterObjectRenderer().render(sl.toOWLObject()));
+ OWLObject obj = sl.toOWLObject();
+ String expression = agent.getManchesterObjectRenderer().render(obj);
+ StringTerm expressionTerm = new StringTermImpl(expression);
+ Alias alias = sl.toAlias();
-
- Alias alias = sl.toAlias();
- if(alias.getLabel().equals(agent.getPersonalOntologyLabel())){ // do we have an anonymous run-time defined class?
+ if(obj instanceof OWLNamedObject){
+ // unambiguously refer to named entity
+ if(!(sl instanceof SELiteralAllDifferentAssertion)){// not required if all_different
+ Structure named = new Structure(NAMED_ANNOTATION_FUNCTOR);
+ named.addTerm(expressionTerm);
+ sl.getLiteral().addAnnot(named);
+ }
+
+ }else{ // we have an anonymous run-time defined class
+
+ // construct anon annotation
Structure anon = new Structure(ANON_ANNOTATION_FUNCTOR);
- anon.addTerm(expression);
+ anon.addTerm(expressionTerm);
// add set of prerequisite ontologies
Set<OWLOntology> prereqs = new HashSet<OWLOntology>();
- String[] tokens = expression.toString().split(" ");
+ String[] tokens = expression.toString().split("[ |\n]");
for(String token : tokens){
try {
URI entityURI = new URI(token);
@@ -74,36 +95,24 @@
prereqs.add(agent.getLogicalURIManager().getLeft(ontologyURI));
} catch (URISyntaxException e) {
// do nothing, probably a keyword
+ } catch(UnknownMappingException e){
+ // do nothing, probably a keyword
}
}
ListTerm list = new ListTermImpl();
for(OWLOntology prereq : prereqs){
- list.add(agent.getLabelManager().getLeft(prereq));
+ list.add( new StringTermImpl(agent.getPhysicalURIManager().getRight(prereq).toString()) );
}
anon.addTerm(list);
- l.addAnnot(anon);
-
- // drop o, not needed
- sl.dropOntologyAnnotation();
-
- }else{
- // qualify o
- sl.qualifyOntologyAnnotation();
-
- // unambiguously refer to named entity
- Structure named = new Structure(NAMED_ANNOTATION_FUNCTOR);
- named.addTerm(expression);
- sl.addAnnot(named);
- }
-
-
-
- return sl;
+ sl.getLiteral().addAnnot(anon);
+ }
+ result = sl.getLiteral();
}catch(NotEnrichedException e){
// do nothing
- return l;
}
+ return result;
}
+
}
Modified: trunk/applications/jasdl-owlapi/src/jasdl/architecture/PropContProcessingStrategy.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/architecture/PropContProcessingStrategy.java 2008-03-17 08:41:44 UTC (rev 1156)
+++ trunk/applications/jasdl-owlapi/src/jasdl/architecture/PropContProcessingStrategy.java 2008-03-17 19:13:28 UTC (rev 1157)
@@ -24,5 +24,5 @@
import jason.asSyntax.Literal;
public interface PropContProcessingStrategy {
- public Literal process(Literal propcont, JasdlAgent agent) throws JasdlException;
+ public Literal process(Literal propcont, JasdlAgent agent, String src) throws JasdlException;
}
Modified: trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java 2008-03-17 08:41:44 UTC (rev 1156)
+++ trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java 2008-03-17 19:13:28 UTC (rev 1157)
@@ -1,5 +1,8 @@
package jasdl.asSemantics;
+import static jasdl.util.Common.strip;
+import jasdl.asSemantics.parsing.NSPrefixEntityChecker;
+import jasdl.asSemantics.parsing.URIEntityChecker;
import jasdl.asSyntax.JasdlPlanLibrary;
import jasdl.bb.JasdlBeliefBase;
import jasdl.bridge.ToAxiomConverter;
@@ -7,9 +10,13 @@
import jasdl.bridge.alias.Alias;
import jasdl.bridge.alias.AliasFactory;
import jasdl.bridge.alias.AliasManager;
+import jasdl.bridge.alias.DecapitaliseMappingStrategy;
+import jasdl.bridge.alias.MappingStrategy;
import jasdl.bridge.label.LabelManager;
import jasdl.bridge.label.OntologyURIManager;
import jasdl.bridge.seliteral.SELiteralFactory;
+import jasdl.util.DuplicateMappingException;
+import jasdl.util.InvalidSELiteralException;
import jasdl.util.JasdlException;
import jasdl.util.UnknownMappingException;
import jason.JasonException;
@@ -21,7 +28,10 @@
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
import java.util.Set;
+import java.util.Vector;
import jmca.asSemantics.JmcaAgent;
@@ -29,25 +39,18 @@
import org.mindswap.pellet.PelletOptions;
import org.mindswap.pellet.owlapi.Reasoner;
import org.semanticweb.owl.apibinding.OWLManager;
-import org.semanticweb.owl.expression.OWLEntityChecker;
-import org.semanticweb.owl.model.OWLClass;
-import org.semanticweb.owl.model.OWLDataProperty;
-import org.semanticweb.owl.model.OWLDataType;
import org.semanticweb.owl.model.OWLDescription;
import org.semanticweb.owl.model.OWLEntity;
-import org.semanticweb.owl.model.OWLIndividual;
-import org.semanticweb.owl.model.OWLObject;
-import org.semanticweb.owl.model.OWLObjectProperty;
import org.semanticweb.owl.model.OWLOntology;
import org.semanticweb.owl.model.OWLOntologyCreationException;
import org.semanticweb.owl.model.OWLOntologyManager;
-import org.semanticweb.owl.model.OWLRuntimeException;
import org.semanticweb.owl.util.ShortFormProvider;
-import uk.ac.manchester.cs.owl.OWLClassImpl;
import uk.ac.manchester.cs.owl.mansyntaxrenderer.ManchesterOWLSyntaxOWLObjectRendererImpl;
public class JasdlAgent extends JmcaAgent {
+ public static List<MappingStrategy> DEFAULT_MAPPING_STRATEGIES = Arrays.asList( new MappingStrategy[] { new DecapitaliseMappingStrategy()} );
+
private OWLOntologyManager ontologyManager;
private Reasoner reasoner;
private AliasManager aliasManager;
@@ -58,12 +61,26 @@
private OntologyURIManager logicalURIManager;
private OntologyURIManager physicalURIManager;
private ManchesterOWLSyntaxOWLObjectRendererImpl manchesterObjectRenderer;
- private ManchesterOWLSyntaxDescriptionParser manchesterDescriptionParser;
+ private ManchesterOWLSyntaxDescriptionParser manchesterNsPrefixDescriptionParser;
+ private ManchesterOWLSyntaxDescriptionParser manchesterURIDescriptionParser;
+
+ private List<MappingStrategy> defaultMappingStrategies;
+
+ public static String ANON_LABEL_PREFIX = "anon_label_";
+ public static String ANON_ALIAS_PREFIX = "anon_alias_";
+
+ /**
+ * Since Jason doesn't initialise an agent name in time
+ */
+ private String agentName;
+
public JasdlAgent(){
super();
+ defaultMappingStrategies = DEFAULT_MAPPING_STRATEGIES;
+
// instantiate managers
aliasManager = new AliasManager();
labelManager = new LabelManager();
@@ -84,9 +101,9 @@
}
}); // we want fully qualified entity references
- manchesterDescriptionParser = new ManchesterOWLSyntaxDescriptionParser(ontologyManager.getOWLDataFactory(), new NSPrefixEntityChecker(this));
-
-
+ manchesterNsPrefixDescriptionParser = new ManchesterOWLSyntaxDescriptionParser(ontologyManager.getOWLDataFactory(), new NSPrefixEntityChecker(this));
+ manchesterURIDescriptionParser = new ManchesterOWLSyntaxDescriptionParser(ontologyManager.getOWLDataFactory(), new URIEntityChecker(this));
+
// instantiate (Pellet) reasoner
PelletOptions.USE_TRACING = true;
reasoner = new Reasoner(ontologyManager);
@@ -102,25 +119,112 @@
public TransitionSystem initAg(AgArch arch, BeliefBase bb, String src, Settings stts) throws JasonException {
if(!(bb instanceof JasdlBeliefBase)){
throw new JasdlException("JASDL must be used in combination with the jasdl.bb.OwlBeliefBase class");
- }
-
- ((JasdlBeliefBase)bb).setAgent(this);
-
-
+ }
+ ((JasdlBeliefBase)bb).setAgent(this);
// load .mas2j JASDL configuration
JasdlConfigurator config = new JasdlConfigurator(this);
- config.configure(stts);
+ config.configure(stts);
return super.initAg(arch, bb, src, stts);
}
+
+
+
+ /**
+ * Convenience method to (polymorphically) create an entity from resource URI (if known).
+ * TODO: where should this sit?
+ * @param uri URI of resource to create entity from
+ * @return entity identified by URI
+ * @throws UnknownReferenceException if OWLObject not known
+ */
+ public OWLEntity toEntity(URI uri) throws JasdlException{
+ URI ontURI;
+ try {
+ ontURI = new URI(uri.getScheme(), uri.getSchemeSpecificPart(), null);
+ } catch (URISyntaxException e) {
+ throw new JasdlException("Invalid entity URI "+uri);
+ }
+ OWLOntology ontology = getLogicalURIManager().getLeft(ontURI);
+ // clumsy approach, but I can't find any way of achieving this polymorphically (i.e. retrieve an OWLEntity from a URI) using OWL-API
+ OWLEntity entity;
+ if(ontology.containsClassReference(uri)){
+ entity = getOntologyManager().getOWLDataFactory().getOWLClass(uri);
+ }else if (ontology.containsObjectPropertyReference(uri)){
+ entity = getOntologyManager().getOWLDataFactory().getOWLObjectProperty(uri);
+ }else if (ontology.containsDataPropertyReference(uri)){
+ entity = getOntologyManager().getOWLDataFactory().getOWLDataProperty(uri);
+ }else if (ontology.containsIndividualReference(uri)){
+ entity = getOntologyManager().getOWLDataFactory().getOWLIndividual(uri);
+ }else{
+ throw new UnknownMappingException("Unknown ontology resource URI: "+uri);
+ }
+ return entity;
+ }
+ /**
+ * Convenience method to parse a string into a URI and return the associated ontology.
+ * Ontology is instantiated and assigned a unique anonymous label if unknown.
+ * @param uri
+ * @return
+ * @throws JasdlException
+ */
+ public OWLOntology getOntology(String _uri) throws JasdlException{
+ URI uri;
+ try {
+ uri = new URI( strip(_uri, "\"")); // quotes stripped
+ } catch (URISyntaxException e) {
+ throw new InvalidSELiteralException("Invalid physical ontology URI "+_uri+". Reason: "+e);
+ }
+ return getOntology(uri);
+ }
+
+ /**
+ * Convenience method to return the ontology associated with a URI.
+ * Ontology is instantiated and assigned a unique anonymous label if unknown.
+ * @param uri
+ * @return
+ * @throws JasdlException
+ */
+ public OWLOntology getOntology(URI uri) throws JasdlException{
+ OWLOntology ontology;
+ try{
+ ontology = getPhysicalURIManager().getLeft(uri);
+ }catch(UnknownMappingException e){
+ // instantiate novel ontology
+ // create a guaranteed unique anonymous label
+ String label;
+ Atom labelAtom;
+ int i = 0;
+ while(true){
+ label = ANON_LABEL_PREFIX+i;
+ labelAtom = new Atom(label);
+ if(!getLabelManager().isKnownLeft(labelAtom)){
+ break;
+ }
+ i++;
+ }
+ ontology = loadOntology(labelAtom, uri);
+ }
+ return ontology;
+ }
+ /**
+ * Calls loadOntology with default mapping strategies.
+ * For incoming ontologies and those with unspecified mapping strategies.
+ * @param label
+ * @param uri
+ * @return
+ * @throws JasdlException
+ */
+ public OWLOntology loadOntology(Atom label, URI uri) throws JasdlException{
+ return loadOntology(label, uri, defaultMappingStrategies);
+ }
/**
- * Convenience method to instantiate an ontology, load it into reasoner and map it to a label
+ * Convenience method to instantiate an ontology, load it into reasoner and map it to a label.
* @param uri
* @throws JasdlException
*/
- public void loadOntology(Atom label, URI uri) throws JasdlException{
+ public OWLOntology loadOntology(Atom label, URI uri, List<MappingStrategy> strategies) throws JasdlException{
try{
OWLOntology ontology = ontologyManager.loadOntologyFromPhysicalURI(uri);
Set<OWLOntology> imports = ontologyManager.getImportsClosure(ontology);
@@ -129,249 +233,190 @@
labelManager.put(label, ontology);
physicalURIManager.put(ontology, uri);
logicalURIManager.put(ontology, ontology.getURI());
+ getLogger().fine("Loaded ontology from "+uri+" and assigned label "+label);
+ applyMappingStrategies(ontology, strategies);
+ return ontology;
}catch(OWLOntologyCreationException e){
- throw new JasdlException("Error loading ontology "+uri+". Reason: "+e);
- }
+ getLogger().warning("Placeholder ontology substituted for unreachable "+uri);
+ return createOntology(label, uri); // can't load it, just create a blank (for unqualification of ontology annotations for example)
+ }
}
-
- public void createOntology(Atom label, URI uri) throws JasdlException{
+ /**
+ * Creates and fully maps a blank ontology. Used for example for "owl" ontology, containing
+ * axioms referencing "owl:thing" and "owl:nothing", and for personal ontologies containing
+ * axioms referencing run-time defined anonymous classes.
+ * @param label
+ * @param uri
+ * @throws JasdlException
+ */
+ public OWLOntology createOntology(Atom label, URI uri) throws JasdlException{
try{
OWLOntology ontology = getOntologyManager().createOntology( uri );
getLabelManager().put(label, ontology);
getPhysicalURIManager().put(ontology, uri);
getLogicalURIManager().put(ontology, uri);
- getReasoner().loadOntology(ontology);
+ getReasoner().loadOntology(ontology);
+ return ontology;
} catch (OWLOntologyCreationException e) {
throw new JasdlException("Error instantiating OWL ontology. Reason: "+e);
}
}
- public Atom getPersonalOntologyLabel(){
- return new Atom("self");
+ /**
+ * When a duplicate mapping is encountered, an anonymous alias is created for the offending resource
+ * @param ontology
+ * @param strategies
+ * @throws JasdlException
+ */
+ private void applyMappingStrategies(OWLOntology ontology, List<MappingStrategy> strategies) throws JasdlException{
+ // we need to construct a reasoner specifically for this to isolate entities from just one ontology
+ Reasoner reasoner = new Reasoner(getOntologyManager());
+ Set<OWLOntology> imports = getOntologyManager().getImportsClosure(ontology);
+ reasoner.loadOntologies(imports);
+
+ List<OWLEntity> entities = new Vector<OWLEntity>();
+ entities.addAll(reasoner.getClasses());
+ entities.addAll(reasoner.getProperties());
+ entities.addAll(reasoner.getIndividuals());
+
+ Atom label = getLabelManager().getLeft(ontology);
+
+ for(OWLEntity entity : entities){
+ try{
+ String _functor = entity.getURI().getFragment();
+ for(MappingStrategy strategy : strategies){
+ _functor = strategy.apply(_functor);
+ }
+ Atom functor = new Atom(_functor);
+ getAliasManager().put(AliasFactory.INSTANCE.create(functor, label), entity);
+ }catch(DuplicateMappingException e){
+ // generate an anonymous alias for this entity
+ String functor;
+ Alias anonAlias;
+ int i = 0;
+ while(true){
+ functor = ANON_ALIAS_PREFIX + i;
+ anonAlias = AliasFactory.INSTANCE.create(new Atom(functor), label);
+ if(!getAliasManager().isKnownLeft(anonAlias)){
+ break;
+ }
+ i++;
+ }
+ getAliasManager().put(anonAlias, entity);
+ }
+ }
}
-
- public URI getPersonalOntologyURI() {
- return URI.create("http://www.dur.ac.uk/t.g.klapiscak/"+getPersonalOntologyLabel()+".owl");
- }
+ public OWLDescription defineClass(Atom functor, String expression, ManchesterOWLSyntaxDescriptionParser parser) throws JasdlException{
+ return defineClass(functor, getPersonalOntologyLabel(), expression, parser);
+ }
- public OWLDescription defineClass(Atom functor, String expression) throws JasdlException{
+ public OWLDescription defineClass(Atom functor, Atom label, String expression, ManchesterOWLSyntaxDescriptionParser parser) throws JasdlException{
+ Alias alias = AliasFactory.INSTANCE.create(functor, label);
+ if(getAliasManager().isKnownLeft(alias)){
+ throw new DuplicateMappingException("New class definition with alias "+alias+" overlaps with an existing ontological entity");
+ }
OWLDescription desc;
try{
- desc = getManchesterDescriptionParser().parse(expression);
- }catch(Exception e){
- e.printStackTrace();
+ desc = parser.parse(expression);
+ }catch(Exception e){
throw new JasdlException("Could not parse expression "+expression+". Reason: "+e);
- }
-
- Alias alias = AliasFactory.INSTANCE.create(functor, getPersonalOntologyLabel());
- getAliasManager().put(alias, desc);
-
+ }
+ getAliasManager().put(alias, desc);
+ getLogger().fine("Defined new class with alias "+alias);
return desc;
}
+
+ /**
+ * *Must* be unique within society!
+ * @return
+ */
+ public String getAgentName(){
+ return agentName;
+ }
+
+ public void setAgentName(String agentName){
+ this.agentName = agentName;
+ }
+
+
+
+ public List<MappingStrategy> getDefaultMappingStrategies() {
+ return defaultMappingStrategies;
+ }
+
+ public void setDefaultMappingStrategies(List<MappingStrategy> defaultMappingStrategies) {
+ this.defaultMappingStrategies = defaultMappingStrategies;
+ }
+
+
+
+ public Atom getPersonalOntologyLabel(){
+ return new Atom("self");
+ }
+
+ public URI getPersonalOntologyURI() {
+ return getPersonalOntologyURI(new Atom(getAgentName()));
+ }
+
+ public URI getPersonalOntologyURI(Atom label) {
+ return URI.create("http://www.dur.ac.uk/t.g.klapiscak/"+label+".owl");
+ }
+
+
public AliasManager getAliasManager() {
return aliasManager;
}
-
-
public LabelManager getLabelManager() {
return labelManager;
}
-
-
public OWLOntologyManager getOntologyManager() {
return ontologyManager;
}
-
-
-
-
public OntologyURIManager getPhysicalURIManager() {
return physicalURIManager;
- }
+ }
-
-
-
public OntologyURIManager getLogicalURIManager() {
return logicalURIManager;
}
-
-
-
+
public Reasoner getReasoner() {
return reasoner;
}
-
-
-
-
-
-
+
public SELiteralFactory getSELiteralFactory() {
return seLiteralFactory;
}
-
-
-
-
public ToAxiomConverter getToAxiomConverter() {
return toAxiomConverter;
}
-
-
-
-
public ToSELiteralConverter getToSELiteralConverter() {
return toSELiteralConverter;
}
-
-
public ManchesterOWLSyntaxOWLObjectRendererImpl getManchesterObjectRenderer() {
return manchesterObjectRenderer;
}
-
-
-
- public ManchesterOWLSyntaxDescriptionParser getManchesterDescriptionParser() {
- return manchesterDescriptionParser;
- }
-
- /**
- * Convenience method to (polymorphically) create an entity from resource URI (if known).
- * TODO: where should this sit?
- * @param uri URI of resource to create entity from
- * @return entity identified by URI
- * @throws UnknownReferenceException if OWLObject not known
- */
- public OWLEntity toEntity(URI uri) throws JasdlException{
- URI ontURI;
- try {
- ontURI = new URI(uri.getScheme(), uri.getSchemeSpecificPart(), null);
- } catch (URISyntaxException e) {
- throw new JasdlException("Invalid entity URI "+uri);
- }
- OWLOntology ontology = getLogicalURIManager().getLeft(ontURI);;
-
- // clumsy approach, but I can't find any way of achieving this polymorphically (i.e. retrieve an OWLObject from a URI) using OWL-API
- OWLEntity entity;
- if(ontology.containsClassReference(uri)){
- entity = getOntologyManager().getOWLDataFactory().getOWLClass(uri);
- }else if (ontology.containsObjectPropertyReference(uri)){
- entity = getOntologyManager().getOWLDataFactory().getOWLObjectProperty(uri);
- }else if (ontology.containsDataPropertyReference(uri)){
- entity = getOntologyManager().getOWLDataFactory().getOWLDataProperty(uri);
- }else if (ontology.containsIndividualReference(uri)){
- entity = getOntologyManager().getOWLDataFactory().getOWLIndividual(uri);
- }else{
- throw new UnknownMappingException("Unknown ontology resource URI: "+uri);
- }
- return entity;
+ public ManchesterOWLSyntaxDescriptionParser getManchesterNsPrefixDescriptionParser() {
+ return manchesterNsPrefixDescriptionParser;
}
-
-
-
- private class NSPrefixEntityChecker implements OWLEntityChecker{
-
- private JasdlAgent agent;
-
- public NSPrefixEntityChecker(JasdlAgent agent){
- this.agent = agent;
- }
-
- public OWLClass getOWLClass(String name) {
- OWLEntity entity = convert(name);
- if(entity == null){
- return null;
- }
- if(entity.isOWLClass()){
- return entity.asOWLClass();
- }else{
- return null;
- }
- }
-
- public OWLDataProperty getOWLDataProperty(String name) {
- OWLEntity entity = convert(name);
- if(entity == null){
- return null;
- }
- if(entity.isOWLDataProperty()){
- return entity.asOWLDataProperty();
- }else{
- return null;
- }
- }
-
- public OWLDataType getOWLDataType(String name) {
- OWLEntity entity = convert(name);
- if(entity == null){
- return null;
- }
- if(entity.isOWLDataType()){
- return entity.asOWLDataType();
- }else{
- return null;
- }
- }
-
- public OWLIndividual getOWLIndividual(String name) {
- OWLEntity entity = convert(name);
- if(entity == null){
- return null;
- }
- if(entity.isOWLIndividual()){
- return entity.asOWLIndividual();
- }else{
- return null;
- }
- }
-
- public OWLObjectProperty getOWLObjectProperty(String name) {
- OWLEntity entity = convert(name);
- if(entity == null){
- return null;
- }
- if(entity.isOWLObjectProperty()){
- return entity.asOWLObjectProperty();
- }else{
- return null;
- }
- }
-
- private OWLEntity convert(String name){
- String[] tokens = name.split(":");
- try {
- Atom functor = new Atom(tokens[1]);
- Atom label = new Atom(tokens[0]);
- Alias alias = AliasFactory.INSTANCE.create(functor, label);
- return (OWLEntity)agent.getAliasManager().getRight(alias); // guaranteed to be an entity? Not for anonymous classes!
- } catch (Exception e) {
- return null;
- }
- }
-
-
+ public ManchesterOWLSyntaxDescriptionParser getManchesterURIDescriptionParser() {
+ return manchesterURIDescriptionParser;
}
-
-
-
-
-
}
Modified: trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlConfigurator.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlConfigurator.java 2008-03-17 08:41:44 UTC (rev 1156)
+++ trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlConfigurator.java 2008-03-17 19:13:28 UTC (rev 1157)
@@ -6,32 +6,30 @@
import jasdl.bridge.alias.Alias;
import jasdl.bridge.alias.AliasFactory;
import jasdl.bridge.alias.MappingStrategy;
-import jasdl.util.DuplicateMappingException;
import jasdl.util.JasdlException;
-import jasdl.util.UnknownMappingException;
import jason.asSyntax.Atom;
import jason.runtime.Settings;
import java.lang.reflect.Constructor;
import java.net.URI;
-import java.net.URISyntaxException;
+import java.util.Arrays;
import java.util.List;
-import java.util.Set;
import java.util.Vector;
-import org.mindswap.pellet.owlapi.Reasoner;
import org.semanticweb.owl.model.OWLEntity;
import org.semanticweb.owl.model.OWLOntology;
-import org.semanticweb.owl.model.OWLOntologyCreationException;
public class JasdlConfigurator {
private static String MAS2J_PREFIX = "jasdl";
private static String MAS2J_ONTOLOGIES = "_ontologies";
private static String MAS2J_URI = "_uri";
private static String MAS2J_MAPPING_STRATEGIES = "_mapping_strategies";
- private static String MAS2J_MAPPING_MANUAL = "_mapping_manual";
+ private static String MAS2J_MAPPING_MANUAL = "_mapping_manual";
+ private static String MAS2J_AGENT_NAME = "_agent_name";
+ public static List<Atom> reservedOntologyLabels = Arrays.asList( new Atom[] {new Atom("default"), new Atom("self")});
+
private JasdlAgent agent;
public JasdlConfigurator(JasdlAgent agent){
@@ -40,11 +38,17 @@
public void configure(Settings stts) throws JasdlException{
try{
+ // load agent name
+ agent.setAgentName(prepareUserParameter( stts, MAS2J_PREFIX + MAS2J_AGENT_NAME ));
+
+ // load default mapping strategies
+ agent.setDefaultMappingStrategies(getMappingStrategies(stts, new Atom("default"))); //implication "default" is a reserved ontology label
+
loadOntologies(stts);
applyManualMappings(stts);
- applyMiscMappings();
- applyMappingStrategies(stts);
+ applyMiscMappings();
+
}catch(JasdlException e){
throw new JasdlException("JASDL agent encountered error during configuration. Reason: "+e);
}
@@ -58,16 +62,24 @@
private void loadOntologies(Settings stts) throws JasdlException{
String[] labels = splitUserParameter( stts, MAS2J_PREFIX + MAS2J_ONTOLOGIES );
for(String label : labels){
+ if(reservedOntologyLabels.contains(label)){
+ throw new JasdlException(label+" is a reserved ontology label");
+ }
URI physicalURI;
try {
physicalURI = new URI(prepareUserParameter( stts, MAS2J_PREFIX + "_" + label + MAS2J_URI ));
- agent.loadOntology(new Atom(label), physicalURI);
+ agent.loadOntology(new Atom(label), physicalURI, getMappingStrategies(stts, new Atom(label)));
} catch (Exception e) {
throw new JasdlException("Unable to instantiate ontology \""+label+"\". Reason: "+e);
}
}
}
+ /**
+ * Overrides auto mappings!
+ * @param stts
+ * @throws JasdlException
+ */
private void applyManualMappings(Settings stts) throws JasdlException{
for(Atom label : agent.getLabelManager().getLefts()){
String[] mappings = splitUserParameter(stts, MAS2J_PREFIX + "_" + label + MAS2J_MAPPING_MANUAL);
@@ -78,6 +90,11 @@
Alias alias = AliasFactory.INSTANCE.create(new Atom(split[0].trim()), label);
URI uri = URI.create(ontology.getURI() + "#" + split[1].trim());
OWLEntity entity = agent.toEntity(uri);
+
+ if(agent.getAliasManager().isKnownRight(entity)){ // manual mappings override automatic ones
+ agent.getAliasManager().removeByRight(entity);
+ }
+
agent.getAliasManager().put(alias, entity);
}
}
@@ -92,53 +109,29 @@
* Applies mappings to all resources in an ontology according to composition of supplied strategies.
* @param stts .mas2j settings
*/
- private void applyMappingStrategies(Settings stts) throws JasdlException{
- for(Atom label : agent.getLabelManager().getLefts()){
- List<MappingStrategy> strategies = new Vector<MappingStrategy>();
- String[] strategyNames = splitUserParameter(stts, MAS2J_PREFIX + "_" + label + MAS2J_MAPPING_STRATEGIES);
- for(String strategyName : strategyNames){
- if(strategyName.length() > 0){
- try {
- Class cls = Class.forName(strategyName);
- Constructor ct = cls.getConstructor(new Class[] {});
- MappingStrategy strategy = (MappingStrategy)ct.newInstance(new Object[] {});
- if(strategy == null){
- throw new JasdlException("Unknown mapping strategy class: "+strategy);
- }else{
- strategies.add(strategy);
- }
- }catch (Throwable e) {
- throw new JasdlException("Error instantiating mapping strategy "+strategyName+". Reason: "+e);
+ private List<MappingStrategy> getMappingStrategies(Settings stts, Atom label) throws JasdlException{
+ List<MappingStrategy> strategies = new Vector<MappingStrategy>();
+ String[] strategyNames = splitUserParameter(stts, MAS2J_PREFIX + "_" + label + MAS2J_MAPPING_STRATEGIES);
+ for(String strategyName : strategyNames){
+ if(strategyName.length() > 0){
+ try {
+ Class cls = Class.forName(strategyName);
+ Constructor ct = cls.getConstructor(new Class[] {});
+ MappingStrategy strategy = (MappingStrategy)ct.newInstance(new Object[] {});
+ if(strategy == null){
+ throw new JasdlException("Unknown mapping strategy class: "+strategy);
+ }else{
+ strategies.add(strategy);
}
+ }catch (Throwable e) {
+ throw new JasdlException("Error instantiating mapping strategy "+strategyName+". Reason: "+e);
}
}
-
- OWLOntology ontology = agent.getLabelManager().getRight(label);
-
- // we need to construct a reasoner specifically for this to isolate entities from just one ontology
- Reasoner reasoner = new Reasoner(agent.getOntologyManager());
- Set<OWLOntology> imports = agent.getOntologyManager().getImportsClosure(ontology);
- reasoner.loadOntologies(imports);
-
- List<OWLEntity> entities = new Vector<OWLEntity>();
- entities.addAll(reasoner.getClasses());
- entities.addAll(reasoner.getProperties());
- entities.addAll(reasoner.getIndividuals());
-
- for(OWLEntity entity : entities){
- try{
- String _functor = entity.getURI().getFragment();
- for(MappingStrategy strategy : strategies){
- _functor = strategy.apply(_functor);
- }
- Atom functor = new Atom(_functor);
- agent.getAliasManager().put(AliasFactory.INSTANCE.create(functor, label), entity);
- }catch(DuplicateMappingException e){
- // only apply mapping strategies to entities that have not been manually mapped already
- }
- }
-
- }
+ }
+ if(strategies.size() == 0){
+ strategies = agent.getDefaultMappingStrategies();
+ }
+ return strategies;
}
/**
Added: trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/parsing/NSPrefixEntityChecker.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/parsing/NSPrefixEntityChecker.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/parsing/NSPrefixEntityChecker.java 2008-03-17 19:13:28 UTC (rev 1157)
@@ -0,0 +1,103 @@
+package jasdl.asSemantics.parsing;
+import jasdl.asSemantics.JasdlAgent;
+import jasdl.bridge.alias.Alias;
+import jasdl.bridge.alias.AliasFactory;
+import jason.asSyntax.Atom;
+
+import org.semanticweb.owl.expression.OWLEntityChecker;
+import org.semanticweb.owl.model.OWLClass;
+import org.semanticweb.owl.model.OWLDataProperty;
+import org.semanticweb.owl.model.OWLDataType;
+import org.semanticweb.owl.model.OWLEntity;
+import org.semanticweb.owl.model.OWLIndividual;
+import org.semanticweb.owl.model.OWLObjectProperty;
+
+/**
+ * For parsing class-expressions defined with entities in the alias label:functor format.
+ * E.g. "(travel:hotel and travel:hasActivity some travel:museums) and owl:thing"
+ * @author Tom Klapiscak
+ *
+ */
+public class NSPrefixEntityChecker implements OWLEntityChecker{
+
+ private JasdlAgent agent;
+
+ public NSPrefixEntityChecker(JasdlAgent agent){
+ this.agent = agent;
+ }
+
+ public OWLClass getOWLClass(String name) {
+ OWLEntity entity = convert(name);
+ if(entity == null){
+ return null;
+ }
+ if(entity.isOWLClass()){
+ return entity.asOWLClass();
+ }else{
+ return null;
+ }
+ }
+
+ public OWLDataProperty getOWLDataProperty(String name) {
+ OWLEntity entity = convert(name);
+ if(entity == null){
+ return null;
+ }
+ if(entity.isOWLDataProperty()){
+ return entity.asOWLDataProperty();
+ }else{
+ return null;
+ }
+ }
+
+ public OWLDataType getOWLDataType(String name) {
+ OWLEntity entity = convert(name);
+ if(entity == null){
+ return null;
+ }
+ if(entity.isOWLDataType()){
+ return entity.asOWLDataType();
+ }else{
+ return null;
+ }
+ }
+
+ public OWLIndividual getOWLIndividual(String name) {
+ OWLEntity entity = convert(name);
+ if(entity == null){
+ // TODO: instantiate individuals?
+ return null;
+ }
+ if(entity.isOWLIndividual()){
+ return entity.asOWLIndividual();
+ }else{
+ return null;
+ }
+ }
+
+ public OWLObjectProperty getOWLObjectProperty(String name) {
+ OWLEntity entity = convert(name);
+ if(entity == null){
+ return null;
+ }
+ if(entity.isOWLObjectProperty()){
+ return entity.asOWLObjectProperty();
+ }else{
+ return null;
+ }
+ }
+
+ private OWLEntity convert(String name){
+ String[] tokens = name.split(":");
+ try {
+ Atom functor = new Atom(tokens[1]);
+ Atom label = new Atom(tokens[0]);
+ Alias alias = AliasFactory.INSTANCE.create(functor, label);
+ return (OWLEntity)agent.getAliasManager().getRight(alias); // guaranteed to be an entity? Not for anonymous classes!
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+
+ }
\ No newline at end of file
Added: trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/parsing/URIEntityChecker.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/parsing/URIEntityChecker.java (rev 0)
+++ trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/parsing/URIEntityChecker.java 2008-03-17 19:13:28 UTC (rev 1157)
@@ -0,0 +1,99 @@
+package jasdl.asSemantics.parsing;
+
+import jasdl.asSemantics.JasdlAgent;
+
+import java.net.URI;
+
+import org.semanticweb.owl.expression.OWLEntityChecker;
+import org.semanticweb.owl.model.OWLClass;
+import org.semanticweb.owl.model.OWLDataProperty;
+import org.semanticweb.owl.model.OWLDataType;
+import org.semanticweb.owl.model.OWLEntity;
+import org.semanticweb.owl.model.OWLIndividual;
+import org.semanticweb.owl.model.OWLObjectProperty;
+
+/**
+ * For parsing class-expressions where entities are defined by their fully-qualified URIs.
+ * E.g. "http://www.dur.ac.uk.t.g.klapiscak/travel.owl#Hotel and http://www.dur.ac.uk.t.g.klapiscak/travel.owl#Accommodation".
+ * @author tom
+ *
+ */
+public class URIEntityChecker implements OWLEntityChecker{
+
+ private JasdlAgent agent;
+
+ public URIEntityChecker(JasdlAgent agent){
+ this.agent = agent;
+ }
+
+ public OWLClass getOWLClass(String uri) {
+ OWLEntity entity = convert(uri);
+ if(entity == null){
+ return null;
+ }
+ if(entity.isOWLClass()){
+ return entity.asOWLClass();
+ }else{
+ return null;
+ }
+ }
+
+ public OWLDataProperty getOWLDataProperty(String uri) {
+ OWLEntity entity = convert(uri);
+ if(entity == null){
+ return null;
+ }
+ if(entity.isOWLDataProperty()){
+ return entity.asOWLDataProperty();
+ }else{
+ return null;
+ }
+ }
+
+ public OWLDataType getOWLDataType(String uri) {
+ OWLEntity entity = convert(uri);
+ if(entity == null){
+ return null;
+ }
+ if(entity.isOWLDataType()){
+ return entity.asOWLDataType();
+ }else{
+ return null;
+ }
+ }
+
+ public OWLIndividual getOWLIndividual(String uri) {
+ OWLEntity entity = convert(uri);
+ if(entity == null){
+ return null;
+ }
+ if(entity.isOWLIndividual()){
+ return entity.asOWLIndividual();
+ }else{
+ return null;
+ }
+ }
+
+ public OWLObjectProperty getOWLObjectProperty(String uri) {
+ OWLEntity entity = convert(uri);
+ if(entity == null){
+ return null;
+ }
+ if(entity.isOWLObjectProperty()){
+ return entity.asOWLObjectProperty();
+ }else{
+ return null;
+ }
+ }
+
+ private OWLEntity convert(String _uri){
+ try {
+ URI uri = new URI(_uri);
+ return agent.toEntity(uri);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+
+}
\ No newline at end of file
Modified: trunk/applications/jasdl-owlapi/src/jasdl/asSyntax/JasdlPlanLibrary.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/asSyntax/JasdlPlanLibrary.java 2008-03-17 08:41:44 UTC (rev 1156)
+++ trunk/applications/jasdl-owlapi/src/jasdl/asSyntax/JasdlPlanLibrary.java 2008-03-17 19:13:28 UTC (rev 1157)
@@ -21,7 +21,6 @@
import static jasdl.util.Common.getTEOp;
import jasdl.asSemantics.JasdlAgent;
-import jasdl.bridge.alias.Alias;
import jasdl.bridge.seliteral.SELiteral;
import jasdl.util.JasdlException;
import jasdl.util.NotEnrichedException;
@@ -58,6 +57,7 @@
}catch(NotEnrichedException e){
super.add(p);
}catch(Exception e){
+ e.printStackTrace();
throw new JasdlException("Exception caught while initialising JasdlPlanLibrary: "+e);
}
}
@@ -136,8 +136,8 @@
Collections.reverse(functors);
for(String functor : functors){
- Literal imaginaryLiteral = mutateLiteral(l, functor);
- Trigger imaginaryTrigger = new Trigger(getTEOp(te), te.getType(), imaginaryLiteral);
+ sl.mutateFunctor(functor);
+ Trigger imaginaryTrigger = new Trigger(getTEOp(te), te.getType(), sl.getLiteral());
moreGeneral.add(imaginaryTrigger);
}
return moreGeneral;
@@ -163,17 +163,6 @@
return os;
}
- /**
- * Creates a new literal identical except functor is replaced by new functor
- * @param original the original literal
- * @param newFunctor functor to replace the original functor with
- * @return
- */
- private static Literal mutateLiteral(Literal original, String newFunctor){
- Literal mutated = new Literal(newFunctor); // negation dealt with by ~ prefix
- mutated.addTerms(original.getTerms());
- mutated.addAnnots(original.getAnnots());
- return mutated;
- }
+
}
Modified: trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlBeliefBase.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlBeliefBase.java 2008-03-17 08:41:44 UTC (rev 1156)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlBeliefBase.java 2008-03-17 19:13:28 UTC (rev 1157)
@@ -24,13 +24,14 @@
private JasdlAgent agent;
@Override
- public boolean add(Literal l) {
+ public boolean add(Literal l) {
getLogger().fine("Adding "+l);
try{
SELiteral sl = agent.getSELiteralFactory().create(l);
+ getLogger().fine("... "+sl);
OWLOntology ontology = sl.getOntology();
OWLIndividualAxiom axiom = sl.createAxiom();
- getLogger().fine("... as axiom: "+axiom);
+ getLogger().fine("..... as axiom: "+axiom);
AddAxiom add = new AddAxiom(ontology, axiom);
agent.getOntologyManager().applyChange(add);
agent.getReasoner().refresh();
@@ -43,7 +44,8 @@
}
return true;
- }catch(NotEnrichedException e){
+ }catch(NotEnrichedException e){
+ getLogger().fine("... semantically-naive");
return super.add(l); // semantically-naive, use standard Jason mechanisms
}catch(Exception e){
getLogger().warning("Exception caught adding SELiteral "+l+" to belief base: ");
@@ -112,11 +114,11 @@
Set<OWLIndividual> is = diff.getOWLIndividuals();
Set<OWLIndividual> js = ((OWLDifferentIndividualsAxiom)axiom).getIndividuals();
if(is.containsAll(js)){
- found.setTerm(0, l.getTerm(0)); // Sets are equivalent, change to original ordering
+ found.getLiteral().setTerm(0, l.getTerm(0)); // Sets are equivalent, change to original ordering
}
}
- relevant.add(found);
+ relevant.add(found.getLiteral());
}
getLogger().fine("... found: "+relevant);
}catch(NotEnrichedException e){
Modified: trunk/applications/jasdl-owlapi/src/jasdl/bridge/MappingManager.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/MappingManager.java 2008-03-17 08:41:44 UTC (rev 1156)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/MappingManager.java 2008-03-17 19:13:28 UTC (rev 1157)
@@ -94,4 +94,14 @@
public Set<Y> getRights(){
return yToXMap.keySet();
}
+
+ public void removeByLeft(X x){
+ Y y = xToYMap.remove(x);
+ yToXMap.remove(y);
+ }
+
+ public void removeByRight(Y y){
+ X x = yToXMap.remove(y);
+ xToYMap.remove(x);
+ }
}
Modified: trunk/applications/jasdl-owlapi/src/jasdl/bridge/ToAxiomConverter.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/ToAxiomConverter.java 2008-03-17 08:41:44 UTC (rev 1156)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/ToAxiomConverter.java 2008-03-17 19:13:28 UTC (rev 1157)
@@ -91,7 +91,7 @@
* @throws JasdlException
*/
public OWLIndividualAxiom create(SELiteral sl) throws JasdlException{
- if(!sl.isGround()){
+ if(!sl.getLiteral().isGround()){
throw new JasdlException("Cannot create an axiom from unground SELiteral "+sl);
}
Set<OWLIndividualAxiom> axioms = convert(sl, false);
@@ -133,7 +133,7 @@
Set<OWLIndividual> is = new HashSet<OWLIndividual>();
OWLDescription desc = sl.getOWLDescription();
- if(sl.isGround()){
+ if(sl.getLiteral().isGround()){
OWLIndividual i = sl.getOWLIndividual();
if(!checkForExistence || agent.getReasoner().hasType(i, desc)){
is.add(i);
@@ -196,7 +196,7 @@
Set<OWLIndividual> os = new HashSet<OWLIndividual>();
OWLIndividual s = sl.getSu...
[truncated message content] |