|
From: <tom...@us...> - 2008-04-02 17:05:27
|
Revision: 1192
http://jason.svn.sourceforge.net/jason/?rev=1192&view=rev
Author: tomklapiscak
Date: 2008-04-02 10:05:13 -0700 (Wed, 02 Apr 2008)
Log Message:
-----------
Structural improvements.
Modified Paths:
--------------
trunk/applications/jasdl-owlapi/build.xml
Removed Paths:
-------------
trunk/applications/jasdl-owlapi/src/jasdl/bridge/AllDifferentPlaceholder.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/ToSELiteralConverter.java
Modified: trunk/applications/jasdl-owlapi/build.xml
===================================================================
--- trunk/applications/jasdl-owlapi/build.xml 2008-04-02 17:00:03 UTC (rev 1191)
+++ trunk/applications/jasdl-owlapi/build.xml 2008-04-02 17:05:13 UTC (rev 1192)
@@ -1,13 +1,18 @@
<project basedir="." default="jar" name="jasdl">
- <property name="source.dir" value="${basedir}/src" />
- <property name="build.dir" value="${basedir}/bin" />
- <property name="apidocs.dir" value="${basedir}/doc/api" />
- <property name="jar.file" value="${basedir}/lib/jasdl.jar" />
+ <property name="jason.dir" value="../.."/>
+ <property name="apps.dir" value="${jason.dir}/applications"/>
+ <property name="jmca.dir" value="${apps.dir}/jmca"/>
+ <property name="asunit.dir" value="${apps.dir}/as-unit-test"/>
+ <property name="source.dir" value="${basedir}/src" />
+ <property name="build.dir" value="${basedir}/bin" />
+ <property name="apidocs.dir" value="${basedir}/doc/api" />
+ <property name="jar.file" value="${basedir}/lib/jasdl.jar" />
<path id="project.classpath">
- <pathelement location="../../lib/jason.jar"/>
- <pathelement location="../../applications/jmca/lib/jmca.jar"/>
+ <pathelement location="${jason.dir}/lib/jason.jar"/>
+ <pathelement location="${jmca.dir}/lib/jmca.jar"/>
+ <pathelement location="${asunit.dir}/lib/asunit.jar"/>
<fileset dir="./lib">
<include name="**/*.jar"/>
</fileset>
Deleted: trunk/applications/jasdl-owlapi/src/jasdl/bridge/AllDifferentPlaceholder.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/AllDifferentPlaceholder.java 2008-04-02 17:00:03 UTC (rev 1191)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/AllDifferentPlaceholder.java 2008-04-02 17:05:13 UTC (rev 1192)
@@ -1,118 +0,0 @@
-package jasdl.bridge;
-
-import jason.asSyntax.Atom;
-
-import java.net.URI;
-import java.util.Set;
-
-import org.semanticweb.owl.model.OWLAnnotation;
-import org.semanticweb.owl.model.OWLAnnotationAxiom;
-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.OWLEntityVisitor;
-import org.semanticweb.owl.model.OWLException;
-import org.semanticweb.owl.model.OWLIndividual;
-import org.semanticweb.owl.model.OWLNamedObjectVisitor;
-import org.semanticweb.owl.model.OWLObject;
-import org.semanticweb.owl.model.OWLObjectProperty;
-import org.semanticweb.owl.model.OWLObjectVisitor;
-import org.semanticweb.owl.model.OWLOntology;
-
-/**
- * Since the all_different has no concrete entity associated with it, we create a "placeholder" so that it remains consistent with
- * JASDL's mapping mechanisms. Entities of this type will be intercepted and dealt with differently.
- * Associated with an ontology label which determines hash-code - required since each ontology must have its own placeholder to reference
- * @author tom
- *
- */
-public class AllDifferentPlaceholder implements OWLEntity {
- private Atom label;
-
- public AllDifferentPlaceholder(Atom label){
- this.label = label;
- }
-
- public void accept(OWLEntityVisitor visitor) {
- }
-
- public Set<OWLAnnotationAxiom> getAnnotationAxioms(OWLOntology ontology) {
- return null;
- }
-
- public Set<OWLAnnotation> getAnnotations(OWLOntology ontology) {
- return null;
- }
-
- public Set<OWLAnnotation> getAnnotations(OWLOntology ontology, URI annotationURI) {
- return null;
- }
-
- public void accept(OWLObjectVisitor visitor) {
-
- }
-
- public void accept(OWLNamedObjectVisitor visitor) {
- }
-
- public URI getURI() {
- return null;
- }
-
- public boolean equals(Object other){
- if(!(other instanceof AllDifferentPlaceholder)){
- return false;
- }
- return label.equals(((AllDifferentPlaceholder)other).label);
- }
-
- public int hashCode(){
- return label.hashCode();
- }
-
- public OWLClass asOWLClass() {
- return null;
- }
-
- public OWLDataProperty asOWLDataProperty() {
- return null;
- }
-
- public OWLDataType asOWLDataType() {
- return null;
- }
-
- public OWLIndividual asOWLIndividual() {
- return null;
- }
-
- public OWLObjectProperty asOWLObjectProperty() {
- return null;
- }
-
- public boolean isOWLClass() {
- return false;
- }
-
- public boolean isOWLDataProperty() {
- return false;
- }
-
- public boolean isOWLDataType() {
- return false;
- }
-
- public boolean isOWLIndividual() {
- return false;
- }
-
- public boolean isOWLObjectProperty() {
- return false;
- }
-
- public int compareTo(OWLObject arg0) {
- return 0;
- }
-
-}
Deleted: trunk/applications/jasdl-owlapi/src/jasdl/bridge/MappingManager.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/MappingManager.java 2008-04-02 17:00:03 UTC (rev 1191)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/MappingManager.java 2008-04-02 17:05:13 UTC (rev 1192)
@@ -1,105 +0,0 @@
-package jasdl.bridge;
-
-import jasdl.util.DuplicateMappingException;
-import jasdl.util.UnknownMappingException;
-
-import java.util.HashMap;
-import java.util.Set;
-import java.util.logging.Logger;
-
-/**
- * A bi-directional hash map that enforces 1 to 1 mappings.
- *
- * @author Tom Klapiscak
- *
- * @param <X>
- * @param <Y>
- */
-public class MappingManager<X extends Object, Y extends Object> {
- private Logger logger = Logger.getLogger(this.getClass().toString());
-
- private HashMap<X, Y> xToYMap;
-
- private HashMap<Y, X> yToXMap;
-
- public MappingManager(){
- xToYMap = new HashMap<X, Y>();
- yToXMap = new HashMap<Y, X>();
- }
-
- /**
- * Maps an x to a y and visa-versa.
- * 1 <-> 1 relationships enforced to prevent ambiguous mapping.
- * @param alias
- * @param entity
- * @throws DuplicateMappingException if either alias or entity is already mapped (thus breaking 1 <-> 1 constraint)
- */
- public void put(X x, Y y) throws DuplicateMappingException{
- logger.fine("mapping "+x+" <-> "+y);
-
- if(isKnownLeft(x)){
- throw new DuplicateMappingException("Duplicate mapping on "+x);
- }
- if(isKnownRight(y)){
- throw new DuplicateMappingException("Duplicate mapping on "+y);
- }
-
- xToYMap.put(x, y);
- yToXMap.put(y, x);
- }
-
- /**
- * Gets the alias associated with an entity
- * @param entity
- * @return
- * @throws UnknownMappingException if entity is unknown (not mapped)
- */
- public X getLeft(Y y) throws UnknownMappingException{
- X x = yToXMap.get(y);
- if(x == null){
- throw new UnknownMappingException("Unknown mapping "+y);
- }
- return x;
- }
-
- /**
- * Gets the entity associated with an alias
- * @param alias
- * @return
- * @throws UnknownMappingException if alias is unknown (not mapped)
- */
- public Y getRight(X x) throws UnknownMappingException{
- Y y = xToYMap.get(x);
- if(y == null){
- throw new UnknownMappingException("Unknown mapping "+x);
- }
- return y;
- }
-
-
- public boolean isKnownLeft(X x){
- return xToYMap.containsKey(x);
- }
-
- public boolean isKnownRight(Y y){
- return yToXMap.containsKey(y);
- }
-
- public Set<X> getLefts(){
- return xToYMap.keySet();
- }
-
- 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);
- }
-}
Deleted: trunk/applications/jasdl-owlapi/src/jasdl/bridge/ToAxiomConverter.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/ToAxiomConverter.java 2008-04-02 17:00:03 UTC (rev 1191)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/ToAxiomConverter.java 2008-04-02 17:05:13 UTC (rev 1192)
@@ -1,268 +0,0 @@
-/*
- * 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;
-
-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 ToAxiomConverter {
-
- private JasdlAgent agent;
-
- public ToAxiomConverter(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
Deleted: trunk/applications/jasdl-owlapi/src/jasdl/bridge/ToSELiteralConverter.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bridge/ToSELiteralConverter.java 2008-04-02 17:00:03 UTC (rev 1191)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bridge/ToSELiteralConverter.java 2008-04-02 17:05:13 UTC (rev 1192)
@@ -1,224 +0,0 @@
-package jasdl.bridge;
-
-import jasdl.asSemantics.JasdlAgent;
-import jasdl.bridge.alias.Alias;
-import jasdl.bridge.seliteral.SELiteral;
-import jasdl.bridge.xsd.XSDDataType;
-import jasdl.bridge.xsd.XSDDataTypeUtils;
-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 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 ToSELiteralConverter {
-
- /**
- * The agent this converter is working on behalf of. Required for access to managers.
- */
- private JasdlAgent agent;
-
- public ToSELiteralConverter(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());
- Literal l = construct(alias);
- Atom i = agent.getAliasManager().getLeft(axiom.getIndividual()).getFunctor(); // TODO: what if individual is previously undefined? possible?
- l.addTerm(i);
-
- SELiteral sl = agent.getSELiteralFactory().create(l);
- sl.getLiteral().addAnnots(getAssertedAnnotations(axiom, sl.getOntology()));
- return sl;
- }
-
- /**
- * 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());
- Literal l = construct(alias);
- Atom s = agent.getAliasManager().getLeft(axiom.getSubject()).getFunctor();
- l.addTerm(s);
- Atom o = agent.getAliasManager().getLeft(axiom.getObject()).getFunctor();
- l.addTerm(o);
-
- SELiteral sl = agent.getSELiteralFactory().create(l);
- sl.getLiteral().addAnnots(getAssertedAnnotations(axiom, sl.getOntology()));
- return sl;
- }
-
- /**
- * 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());
- Literal l = construct(alias);
- Atom s = agent.getAliasManager().getLeft(axiom.getSubject()).getFunctor();
- l.addTerm(s);
-
- Term o;
- 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)){
- o = DefaultTerm.parse("\""+constant.getLiteral().toString()+"\"");
- }else if(XSDDataTypeUtils.isBooleanType(xsd)){
- if(Boolean.parseBoolean(ot.getLiteral().toString())){
- o = Literal.LTrue;
- }else{
- o = Literal.LFalse;
- }
- }else{
- o = DefaultTerm.parse(constant.getLiteral().toString());
- }
- }else{
- throw new JasdlException("JASDL does not support untyped data ranges such as: "+axiom);
- }
-
- l.addTerm(o);
-
- SELiteral sl = agent.getSELiteralFactory().create(l);
- sl.getLiteral().addAnnots(getAssertedAnnotations(axiom, sl.getOntology()));
- return sl;
- }
-
- /**
- * 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{
- ListTerm list = new ListTermImpl(); // TODO: override this object's unify method to perform set, not list, unification?
- Set<OWLIndividual> is = axiom.getIndividuals();
- if(is.size() == 0){
- throw new JasdlException("All different assertion must contain some individuals! "+axiom);
- }
- Alias iAlias = null;
- for(OWLIndividual i : is){
- iAlias = agent.getAliasManager().getLeft(i);
- list.add(iAlias.getFunctor());
- }
- // hack, get a reference back to ontology by examining one of the individuals
- Alias alias = agent.getAliasManager().getLeft(new AllDifferentPlaceholder(iAlias.getLabel()));
- Literal l = construct(alias);
-
- l.addTerm(list);
-
- SELiteral sl = agent.getSELiteralFactory().create(l);
- sl.getLiteral().addAnnots(getAssertedAnnotations(axiom, sl.getOntology()));
- return sl;
- }
-
-
- /**
- * 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 Literal construct(Alias alias){
- // 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;
- }
- Literal l = new Literal(sign, functor);
-
- // add ontology annotation
- Structure o = new Structure(SELiteral.ONTOLOGY_ANNOTATION_FUNCTOR);
- o.addTerm(alias.getLabel());
- l.addAnnot(o);
-
- return l;
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|