|
From: <tom...@us...> - 2008-04-02 02:21:30
|
Revision: 1190
http://jason.svn.sourceforge.net/jason/?rev=1190&view=rev
Author: tomklapiscak
Date: 2008-04-01 19:21:21 -0700 (Tue, 01 Apr 2008)
Log Message:
-----------
Improved JasdlBeliefBase test and added (incomplete) remove test. Fixed bugs in the annotation handling of the remove operation.
Modified Paths:
--------------
trunk/applications/jasdl-owlapi/examples/travel_agent/ontologies/travel.owl
trunk/applications/jasdl-owlapi/examples/travel_agent/travel_agent.asl
trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java
trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlBeliefBase.java
trunk/applications/jasdl-owlapi/src/jasdl/test/JasdlBeliefBaseTest.java
Modified: trunk/applications/jasdl-owlapi/examples/travel_agent/ontologies/travel.owl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/travel_agent/ontologies/travel.owl 2008-04-01 23:35:02 UTC (rev 1189)
+++ trunk/applications/jasdl-owlapi/examples/travel_agent/ontologies/travel.owl 2008-04-02 02:21:21 UTC (rev 1190)
@@ -46,7 +46,6 @@
<owl:ObjectProperty rdf:about="#hasAccommodation">
<rdfs:range rdf:resource="#Accommodation"/>
<rdfs:domain rdf:resource="#Destination"/>
- <rdfs:subPropertyOf rdf:resource="#hasThing"/>
</owl:ObjectProperty>
@@ -56,7 +55,6 @@
<owl:ObjectProperty rdf:about="#hasActivity">
<rdfs:range rdf:resource="#Activity"/>
<rdfs:domain rdf:resource="#Destination"/>
- <rdfs:subPropertyOf rdf:resource="#hasThing"/>
<owl:inverseOf rdf:resource="#isOfferedAt"/>
</owl:ObjectProperty>
@@ -67,7 +65,6 @@
<owl:ObjectProperty rdf:about="#hasContact">
<rdfs:domain rdf:resource="#Activity"/>
<rdfs:range rdf:resource="#Contact"/>
- <rdfs:subPropertyOf rdf:resource="#hasThing"/>
</owl:ObjectProperty>
@@ -76,7 +73,6 @@
<owl:ObjectProperty rdf:about="#hasDestination">
<rdfs:range rdf:resource="#Destination"/>
- <rdfs:subPropertyOf rdf:resource="#hasThing"/>
</owl:ObjectProperty>
@@ -87,7 +83,6 @@
<rdf:type rdf:resource="&owl;TransitiveProperty"/>
<rdfs:domain rdf:resource="#Destination"/>
<rdfs:range rdf:resource="#Destination"/>
- <rdfs:subPropertyOf rdf:resource="#hasThing"/>
</owl:ObjectProperty>
@@ -98,24 +93,17 @@
<rdf:type rdf:resource="&owl;FunctionalProperty"/>
<rdfs:domain rdf:resource="#Accommodation"/>
<rdfs:range rdf:resource="#AccommodationRating"/>
- <rdfs:subPropertyOf rdf:resource="#hasThing"/>
</owl:ObjectProperty>
- <!-- http://www.owl-ontologies.com/travel.owl#hasThing -->
-
- <owl:ObjectProperty rdf:about="#hasThing"/>
-
-
-
<!-- http://www.owl-ontologies.com/travel.owl#isLocatedAt -->
<owl:ObjectProperty rdf:about="#isLocatedAt">
+ <rdf:type rdf:resource="&owl11;IrreflexiveProperty"/>
<rdfs:domain rdf:resource="#Accommodation"/>
<rdfs:range rdf:resource="#Destination"/>
<owl:inverseOf rdf:resource="#hasAccommodation"/>
- <rdfs:subPropertyOf rdf:resource="#hasThing"/>
</owl:ObjectProperty>
@@ -127,7 +115,6 @@
>Generalised to apply to accommodations as well</rdfs:comment>
<rdfs:domain rdf:resource="#Activity"/>
<rdfs:range rdf:resource="#Destination"/>
- <rdfs:subPropertyOf rdf:resource="#hasThing"/>
</owl:ObjectProperty>
@@ -138,7 +125,6 @@
<rdfs:domain rdf:resource="#Destination"/>
<rdfs:range rdf:resource="#Destination"/>
<owl:inverseOf rdf:resource="#hasPart"/>
- <rdfs:subPropertyOf rdf:resource="#hasThing"/>
</owl:ObjectProperty>
@@ -158,24 +144,32 @@
<owl:DatatypeProperty rdf:about="#hasCity">
<rdfs:domain rdf:resource="#Contact"/>
- <rdfs:subPropertyOf rdf:resource="#hasData"/>
<rdfs:range rdf:resource="&xsd;string"/>
</owl:DatatypeProperty>
- <!-- http://www.owl-ontologies.com/travel.owl#hasData -->
+ <!-- http://www.owl-ontologies.com/travel.owl#hasDate -->
- <owl:DatatypeProperty rdf:about="#hasData"/>
+ <owl:DatatypeProperty rdf:about="#hasDate">
+ <rdfs:range rdf:resource="&xsd;date"/>
+ </owl:DatatypeProperty>
+ <!-- http://www.owl-ontologies.com/travel.owl#hasDateTime -->
+
+ <owl:DatatypeProperty rdf:about="#hasDateTime">
+ <rdfs:range rdf:resource="&xsd;dateTime"/>
+ </owl:DatatypeProperty>
+
+
+
<!-- http://www.owl-ontologies.com/travel.owl#hasEMail -->
<owl:DatatypeProperty rdf:about="#hasEMail">
<rdf:type rdf:resource="&owl;FunctionalProperty"/>
<rdfs:domain rdf:resource="#Contact"/>
- <rdfs:subPropertyOf rdf:resource="#hasData"/>
<rdfs:range rdf:resource="&xsd;string"/>
</owl:DatatypeProperty>
@@ -188,7 +182,6 @@
<rdfs:comment
>Stated in local currency</rdfs:comment>
<rdfs:domain rdf:resource="#Accommodation"/>
- <rdfs:subPropertyOf rdf:resource="#hasData"/>
<rdfs:range rdf:resource="&xsd;double"/>
</owl:DatatypeProperty>
@@ -198,18 +191,24 @@
<owl:DatatypeProperty rdf:about="#hasStreet">
<rdfs:domain rdf:resource="#Contact"/>
- <rdfs:subPropertyOf rdf:resource="#hasData"/>
<rdfs:range rdf:resource="&xsd;string"/>
</owl:DatatypeProperty>
+ <!-- http://www.owl-ontologies.com/travel.owl#hasTime -->
+
+ <owl:DatatypeProperty rdf:about="#hasTime">
+ <rdfs:range rdf:resource="&xsd;time"/>
+ </owl:DatatypeProperty>
+
+
+
<!-- http://www.owl-ontologies.com/travel.owl#hasZipCode -->
<owl:DatatypeProperty rdf:about="#hasZipCode">
<rdf:type rdf:resource="&owl;FunctionalProperty"/>
<rdfs:domain rdf:resource="#Contact"/>
- <rdfs:subPropertyOf rdf:resource="#hasData"/>
<rdfs:range rdf:resource="&xsd;string"/>
</owl:DatatypeProperty>
Modified: trunk/applications/jasdl-owlapi/examples/travel_agent/travel_agent.asl
===================================================================
--- trunk/applications/jasdl-owlapi/examples/travel_agent/travel_agent.asl 2008-04-01 23:35:02 UTC (rev 1189)
+++ trunk/applications/jasdl-owlapi/examples/travel_agent/travel_agent.asl 2008-04-02 02:21:21 UTC (rev 1190)
@@ -83,6 +83,9 @@
+ruralArea(somewhere)[o(travel), source(tom)];
?ruralArea(somewhere)[o(travel)];
+
+ +isLocatedAt(x, x)[o(travel)]; // rejected since isLocated at is irreflexive
+
.print("DL-based belief revision is enabled"); // without, the above test-goal will fail, since legacy mechanism simply removes incoming inconsistent beliefs
// since the classes destination and and contact are disjoint (and ruralArea is a subclass of destination),
Modified: trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java 2008-04-01 23:35:02 UTC (rev 1189)
+++ trunk/applications/jasdl-owlapi/src/jasdl/asSemantics/JasdlAgent.java 2008-04-02 02:21:21 UTC (rev 1190)
@@ -214,6 +214,10 @@
public List<Literal>[] brf(Literal beliefToAdd, Literal beliefToDel, Intention i) throws RevisionFailedException {
+ // TODO: what annotations should revision contractions contain? all! (or none? - same effect)
+ // No! the same. -a[x] only undermines assertions leading to a[x]!
+ // if we are performing belief-revision all annotations will be gathered (shortcut - use none?) ensuring axiom will be obliterated
+ // annotations never solely lead to conflicts.
if(!isBeliefRevisionEnabled()){ // if experimental feature is disabled
return super.brf(beliefToAdd, beliefToDel, i);
Modified: trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlBeliefBase.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlBeliefBase.java 2008-04-01 23:35:02 UTC (rev 1189)
+++ trunk/applications/jasdl-owlapi/src/jasdl/bb/JasdlBeliefBase.java 2008-04-02 02:21:21 UTC (rev 1190)
@@ -14,8 +14,7 @@
import jason.asSyntax.Term;
import jason.bb.DefaultBeliefBase;
-import java.util.Collections;
-import java.util.Comparator;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -90,41 +89,68 @@
*/
@Override
public boolean remove(Literal l) {
+
getLogger().fine("Contracting "+l);
try{
SELiteral sl = agent.getSELiteralFactory().create(l);
OWLOntology ontology = sl.getOntology();
- OWLIndividualAxiom axiom = sl.createAxiom();
+ OWLIndividualAxiom axiom = sl.createAxiom();
+
boolean result = false; // -> at least *something* must be removed for this to be true!
BeliefBaseContractor contractor = new BeliefBaseContractor(agent.getOntologyManager(), new JasdlReasonerFactory(), agent.getLogger());
List<OWLAxiom> contractList = contractor.contract(axiom, new TBoxAxiomKernelsetFilter(), new JasdlIncisionFunction(agent, sl));
// NOTE: this technique only really makes sense with annotation gathering!
- for(OWLAxiom contract : contractList){ // removals corresponds to l and all l's whose removal will undermine it
+ for(OWLAxiom contract : contractList){ // removals correspond to l and all assertions whose removal will undermine l
+ //agent.refreshReasoner();
- // for each annotation to this axiom, remove it if l has it
- List<OWLAxiomAnnotationAxiom> annotationsToRemove = new Vector<OWLAxiomAnnotationAxiom>(); // to avoid concurrency issues
+ // fail if axiom not contained in ontology
+ if(!ontology.containsAxiom(contract)){
+ continue;
+ }
+
+ // construct annot axiom->term map (avoids unecessary parsing of terms)
+ HashMap<OWLAxiomAnnotationAxiom, Term> annotAxiomToTermMap = new HashMap<OWLAxiomAnnotationAxiom, Term>();
for(OWLAxiomAnnotationAxiom annotAxiom : contract.getAnnotationAxioms(ontology)){
- Term annot = Literal.parse(annotAxiom.getAnnotation().getAnnotationValueAsConstant().getLiteral());
- if(l.hasAnnot(annot)){
- annotationsToRemove.add(annotAxiom);
- result = true;
- }
+ Term annotTerm = Literal.parse(annotAxiom.getAnnotation().getAnnotationValueAsConstant().getLiteral());
+ annotAxiomToTermMap.put(annotAxiom, annotTerm);
}
- for(OWLAxiom annotationToRemove : annotationsToRemove){
- agent.getOntologyManager().applyChange(new RemoveAxiom(ontology, annotationToRemove));
+ // if l only has "o" annotations. Remember, "o" isn't stored in ontology
+ // note: literals without "o" are semantically-naive and so will be caught below
+ if(sl.getSemanticallyNaiveAnnotations().isEmpty()){
+ // remove axiom and all annotations
+ for(OWLAxiomAnnotationAxiom annotAxiom : annotAxiomToTermMap.keySet()){
+ agent.getOntologyManager().applyChange(new RemoveAxiom(ontology, annotAxiom));
+ }
+ agent.getOntologyManager().applyChange(new RemoveAxiom(ontology, contract));
+ result = true;
+ continue;
}
- // remove source(self) and source(percept). TODO: right thing to do?
- // remove assertion if no annotation axioms left
+
+ // first check axiom has all annotations of l except for "o" (otherwise fail)
+ if(!annotAxiomToTermMap.values().containsAll(sl.getSemanticallyNaiveAnnotations())){
+ continue;
+ }
+
+ result = true;
+
+ // remove all axiom annotations (implicitly possessed also by l)
+ for(OWLAxiomAnnotationAxiom annotAxiom : annotAxiomToTermMap.keySet()){
+ agent.getOntologyManager().applyChange(new RemoveAxiom(ontology, annotAxiom));
+ }
+
+ // remove source(self) and source(percept). TODO: right thing to do?
+
+ // if no annotation axioms left, remove assertion
Set<OWLAxiomAnnotationAxiom> remaining = contract.getAnnotationAxioms(ontology);
if(remaining.isEmpty()){
agent.getOntologyManager().applyChange(new RemoveAxiom(ontology, contract));
- result = true;
- }
+ }
+
}
agent.refreshReasoner();
return result;
Modified: trunk/applications/jasdl-owlapi/src/jasdl/test/JasdlBeliefBaseTest.java
===================================================================
--- trunk/applications/jasdl-owlapi/src/jasdl/test/JasdlBeliefBaseTest.java 2008-04-01 23:35:02 UTC (rev 1189)
+++ trunk/applications/jasdl-owlapi/src/jasdl/test/JasdlBeliefBaseTest.java 2008-04-02 02:21:21 UTC (rev 1190)
@@ -18,6 +18,7 @@
import jason.asSyntax.Literal;
import jason.asSyntax.Structure;
import jason.asSyntax.Term;
+import jason.bb.BeliefBase;
import jason.bb.DefaultBeliefBase;
import jason.infra.centralised.CentralisedAgArch;
import jason.mas2j.ClassParameters;
@@ -30,7 +31,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import java.util.Vector;
import junit.framework.TestCase;
@@ -55,6 +55,8 @@
* No thought it given to consistency of additions. This is dealt with by the brf before these methods are called.
* 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
+ *
* @author Tom Klapiscak
*
*/
@@ -102,94 +104,184 @@
bb = (JasdlBeliefBase)agent.getBB();
testbb = new DefaultBeliefBase();
-
- /*
- // ensure initial state of testbb contained predefinitions from bb's ABox
- // Add in reverse order, so iterator ordering is identical
- List<Literal> state = new Vector<Literal>();
- Iterator<Literal> bbit = bb.iterator();
- while(bbit.hasNext()){
- state.add(bbit.next());
- }
- Collections.reverse(state);
- for(Literal l : state){
- testbb.add(l);
- }
- */
-
-
+
// we are not worrying about ordering of iterator anymore
Iterator<Literal> bbit = bb.iterator();
while(bbit.hasNext()){
testbb.add(bbit.next());
- }
+ }
-
-
-
}
@After
public void tearDown() throws Exception {
}
+
+
+ private Literal constructSELiteral(boolean sign, String functor, Term[] terms, Term[] annots, String label){
+ Literal l = new Literal(sign, functor);
+ addO(l, label);
+ l.addTerms(Arrays.asList(terms));
+ if(annots!=null){
+ l.addAnnots(Arrays.asList(annots));
+ }
+ return l;
+ }
+
+ private Literal constructSELiteral(boolean sign, String functor, Term[] terms, String[] _annots, String label){
+ Term[] annots = null;
+ if(_annots != null){
+ annots = new Term[_annots.length];
+ for(int i=0; i<_annots.length; i++){
+ annots[i] = DefaultTerm.parse(_annots[i]);
+ }
+ }
+ return constructSELiteral(sign, functor, terms, annots, label);
+ }
+
+ private Literal constructClass(boolean sign, String functor, String i, String[] annots, String label){
+ return constructSELiteral(sign, functor, new Term[] {new Atom(i)}, annots, label);
+ }
+
+ private Literal constructObjectProperty(boolean sign, String functor, String s, String o, String[] annots, String label){
+ return constructSELiteral(sign, functor, new Term[] {new Atom(s), new Atom(o)}, annots, label);
+ }
+
+ private Literal constructDataProperty(boolean sign, String functor, String s, String o, String[] annots, String label){
+ return constructSELiteral(sign, functor, new Term[] {new Atom(s), DefaultTerm.parse(o)}, annots, label);
+ }
+
+
+
+
+ private Literal constructSELiteral(boolean sign, String functor, Term[] terms, String label){
+ return constructSELiteral(sign, functor, terms, (Term[])null, label);
+ }
+
+ private Literal constructClass(boolean sign, String functor, String i, String label){
+ return constructSELiteral(sign, functor, new Term[] {new Atom(i)}, label);
+ }
+
+ private Literal constructObjectProperty(boolean sign, String functor, String s, String o, String label){
+ return constructSELiteral(sign, functor, new Term[] {new Atom(s), new Atom(o)}, label);
+ }
+
+ private Literal constructDataProperty(boolean sign, String functor, String s, String o, String label){
+ return constructSELiteral(sign, functor, new Term[] {new Atom(s), DefaultTerm.parse(o)}, label);
+ }
+
+ /**
+ * Adds the ontology annotation with the specified label to the supplied literal
+ * @param l
+ */
+ private void addO(Literal l, String label){
+ Structure o = new Structure(SELiteral.ONTOLOGY_ANNOTATION_FUNCTOR);
+ o.addTerm(new Atom(label));
+ l.addAnnot(o);
+ }
+
+ private static boolean[] signs = new boolean[] {true, false};
+
+
@Test
- public void testAddLiteral() throws Exception{
+ public void testRemoveLiteral() throws Exception{
+ // contractor is tested more thoroughly elsewhere
- boolean[] signs = new boolean[] {true, false};
+ /** Testing annotation handling */
+ //for(boolean sign : signs){
+ boolean sign = true;
+ Literal l = constructClass(sign, "hotel", "a", TEST_ONTOLOGY_LABEL);
+ Literal l_x = constructClass(sign, "hotel", "a", new String[] {"x"}, TEST_ONTOLOGY_LABEL);
+ Literal l_xy = constructClass(sign, "hotel", "a", new String[] {"x", "y"}, TEST_ONTOLOGY_LABEL);
+
+ testRemoveIndividualAssertion(l);
+ testRemoveIndividualAssertion(l_x);
+ testRemoveIndividualAssertion(l_xy);
+
+ testAddIndividualAssertion(l);
+ testRemoveIndividualAssertion(l);
+
+
+ testAddIndividualAssertion(l_x);
+ testRemoveIndividualAssertion(l);
+ testRemoveIndividualAssertion(l_x);
+
+ testAddIndividualAssertion(l_x);
+ testRemoveIndividualAssertion(l_x);
+ testRemoveIndividualAssertion(l);
+
+
+ testAddIndividualAssertion(l_x);
+ testRemoveIndividualAssertion(l_xy);
+ testRemoveIndividualAssertion(l);
+
+ testAddIndividualAssertion(l_x);
+ testRemoveIndividualAssertion(l);
+ testRemoveIndividualAssertion(l_xy);
+
+
+
+ //}
+
+ //l = constructClass();
+
+ }
+
+
+ //@Test
+ public void notestAddLiteral() throws Exception{
+ String[][] annotSets = new String[][] {new String[]{}, new String[] {"x"}, new String[] {"x", "y"} };
for(OWLOntology ontology : agent.getOntologyManager().getOntologies()){
for(int run=0; run<=1; run++){ // run twice to ensure duplicate additions are rejected
for(boolean sign : signs){
- for(OWLClass cls : ontology.getReferencedClasses()){
- Alias alias = agent.getAliasManager().getLeft(cls);
- String label = alias.getLabel().getFunctor();
- String functor = alias.getFunctor().getFunctor();
- assertAddClass(sign, functor, "a", label);
- assertAddClass(sign, functor, "b", label);
- }
- for(OWLObjectProperty oprop : ontology.getReferencedObjectProperties()){
- Alias alias = agent.getAliasManager().getLeft(oprop);
- String label = alias.getLabel().getFunctor();
- String functor = alias.getFunctor().getFunctor();
- assertAddObjectProperty(sign, functor, "a", "b", label);
- assertAddObjectProperty(sign, functor, "b", "a", label);
- assertAddObjectProperty(sign, functor, "a", "a", label); // irreflexive properties shouldn't be rejected at this stage
- }
-
- for(OWLDataProperty dprop : ontology.getReferencedDataProperties()){
- Alias alias = agent.getAliasManager().getLeft(dprop);
- String label = alias.getLabel().getFunctor();
- String functor = alias.getFunctor().getFunctor();
- XSDDataType typ = XSDDataTypeUtils.get(((OWLDataType)dprop.getRanges(ontology).toArray()[0]).toString());
- if(typ == XSDDataType.XSD_BOOLEAN){
- assertAddDataProperty(sign, functor, "a", "false", label);
- assertAddDataProperty(sign, functor, "a", "true", label);
- }else if(typ == XSDDataType.XSD_DATE){
- assertAddDataProperty(sign, functor, "a", "\"2007-12-20\"", label);
- }else if(typ == XSDDataType.XSD_DATETIME){
- assertAddDataProperty(sign, functor, "a", "\"2007-12-20T20:16:55\"", label);
- }else if(typ == XSDDataType.XSD_DOUBLE){
- assertAddDataProperty(sign, functor, "a", "22.0", label);
- }else if(typ == XSDDataType.XSD_FLOAT){
- assertAddDataProperty(sign, functor, "a", "0.5", label);
- }else if(typ == XSDDataType.XSD_INT){
- assertAddDataProperty(sign, functor, "a", "22", label);
- }else if(typ == XSDDataType.XSD_STRING){
- assertAddDataProperty(sign, functor, "a", "\"Winchester\"", label);
- }else if(typ == XSDDataType.XSD_TIME){
- assertAddDataProperty(sign, functor, "a", "\"20:16:57\"", label);
+ for(String[] annots : annotSets){
+ for(OWLClass cls : ontology.getReferencedClasses()){
+ Alias alias = agent.getAliasManager().getLeft(cls);
+ String label = alias.getLabel().getFunctor();
+ String functor = alias.getFunctor().getFunctor();
+ testAddIndividualAssertion(constructClass(sign, functor, "a", annots, label));
+ testAddIndividualAssertion(constructClass(sign, functor, "b", annots, label));
}
+ for(OWLObjectProperty oprop : ontology.getReferencedObjectProperties()){
+ Alias alias = agent.getAliasManager().getLeft(oprop);
+ String label = alias.getLabel().getFunctor();
+ String functor = alias.getFunctor().getFunctor();
+ testAddIndividualAssertion(constructObjectProperty(sign, functor, "a", "b", annots, label));
+ testAddIndividualAssertion(constructObjectProperty(sign, functor, "b", "a", annots, label));
+ testAddIndividualAssertion(constructObjectProperty(sign, functor, "a", "a", annots, label)); // irreflexive properties shouldn't be rejected at this stage
+ }
+
+ for(OWLDataProperty dprop : ontology.getReferencedDataProperties()){
+ Alias alias = agent.getAliasManager().getLeft(dprop);
+ String label = alias.getLabel().getFunctor();
+ String functor = alias.getFunctor().getFunctor();
+ XSDDataType typ = XSDDataTypeUtils.get(((OWLDataType)dprop.getRanges(ontology).toArray()[0]).toString());
+ if(typ == XSDDataType.XSD_BOOLEAN){
+ testAddIndividualAssertion(constructDataProperty(sign, functor, "a", "false", annots, label));
+ testAddIndividualAssertion(constructDataProperty(sign, functor, "a", "true", annots, label));
+ }else if(typ == XSDDataType.XSD_DATE){
+ testAddIndividualAssertion(constructDataProperty(sign, functor, "a", "\"2007-12-20\"", annots, label));
+ }else if(typ == XSDDataType.XSD_DATETIME){
+ testAddIndividualAssertion(constructDataProperty(sign, functor, "a", "\"2007-12-20T20:16:55\"", annots, label));
+ }else if(typ == XSDDataType.XSD_FLOAT){
+ testAddIndividualAssertion(constructDataProperty(sign, functor, "a", "0.5", annots, label));
+ }else if(typ == XSDDataType.XSD_INT){
+ testAddIndividualAssertion(constructDataProperty(sign, functor, "a", "22", annots, label));
+ }else if(typ == XSDDataType.XSD_STRING){
+ testAddIndividualAssertion(constructDataProperty(sign, functor, "a", "\"Winchester\"", annots, label));
+ }else if(typ == XSDDataType.XSD_TIME){
+ testAddIndividualAssertion(constructDataProperty(sign, functor, "a", "\"20:16:57\"", annots, label));
+ }
+ }
}
}
}
}
-
-
-
Set<Literal> expected = new HashSet<Literal>();
Iterator<Literal> testbbit = testbb.iterator();
@@ -201,111 +293,49 @@
Iterator<Literal> bbit = bb.iterator();
while(bbit.hasNext()){
actual.add(bbit.next());
- }
-
+ }
assertEquals(expected, actual);
}
-
- /**
- * Constructs functor and annotations (including ontology annotation) of a SE-Literal.
- * @param sign
- * @param functor
- * @param annots
- * @return
- */
- private Literal constructSELiteral(boolean sign, String functor, String label){
- Literal l = new Literal(sign, functor);
- addO(l, label);
- return l;
+
+
+ private void testAddIndividualAssertion(Literal l){
+ // special case: reject ~thing and ~nothing
+ if(l.negated() && (l.getFunctor().equals("thing") || l.getFunctor().equals("nothing"))){
+ assertFalse(bb.add(l));return;
+ }
+ //special case: reject negated property assertions
+ if(l.negated() && l.getArity() == 2){
+ assertFalse(bb.add(l));return;
+ }
+ System.out.print("Adding: "+l);
+ //cloning necessary since Jason's default bb.add affects l passed to it
+ boolean expected = testbb.add((Literal)l.clone());
+ boolean actual = bb.add((Literal)l.clone());
+ assertEquals(expected, actual);
+ System.out.println(" ... Result: "+actual);
}
- /**
- * Adds the ontology annotation with the specified label to the supplied literal
- * @param l
- */
- private void addO(Literal l, String label){
- Structure o = new Structure(SELiteral.ONTOLOGY_ANNOTATION_FUNCTOR);
- o.addTerm(new Atom(label));
- l.addAnnot(o);
- }
-
- /**
- * Constructs SE-Literal, adds terms
- * recognises special cases (i.e. negated properties)
- * otherwise, ensures behaviour is identical to Jason's BB.
- * Additionally, tries with "x", then "y" annots added.
- * @param sign
- * @param functor
- * @param annots
- * @param is
- * @param expected
- */
- private void assertAdd(boolean sign, String functor, List<Term> is, String label){
- Term[][] annotSets = new Term[][] {new Term[]{}, new Term[] {new Atom("x")}, new Term[] {new Atom("x"), new Atom("y")} };
- for(Term[] annots : annotSets){
- Literal l = constructSELiteral(sign, functor, label);
- l.addTerms(is);
- l.addAnnots(Arrays.asList(annots));
- // special case: reject ~thing and ~nothing
- if(!sign && (functor.equals("thing") || functor.equals("nothing"))){
- assertFalse(bb.add(l));return;
- }
- //special case: reject negated property assertions
- if(!sign && l.getArity() == 2){
- assertFalse(bb.add(l));return;
- }
- //System.out.println("Adding: "+l);
- assertEquals(testbb.add((Literal)l.clone()), bb.add((Literal)l.clone())); // cloning necessary since Jason's default bb.add affects l passed to it
+
+ private void testRemoveIndividualAssertion(Literal l){
+ // special case: reject ~thing and ~nothing
+ if(l.negated() && (l.getFunctor().equals("thing") || l.getFunctor().equals("nothing"))){
+ assertFalse(bb.remove(l));return;
}
- }
-
-
- /**
- * Convenience method for testing class assertion additions (unary literals)
- *
- * @param sign
- * @param functor
- * @param annots
- * @param i
- * @param expected
- */
- private void assertAddClass(boolean sign, String functor, String i, String label){
- assertAdd(sign, functor, Collections.singletonList((Term)new Atom(i)), label);
- }
-
- /**
- * Convenience method for testing class assertion additions (unary literals)
- *
- * @param sign
- * @param functor
- * @param annots
- * @param i
- * @param expected
- */
- private void assertAddDataProperty(boolean sign, String functor, String s, String o, String label){
- assertAdd(sign, functor, Arrays.asList(new Term[] {new Atom(s), DefaultTerm.parse(o)}), label);
+ //special case: reject negated property assertions
+ if(l.negated() && l.getArity() == 2){
+ assertFalse(bb.remove(l));return;
+ }
+ System.out.print("Removing: "+l);
+ boolean expected = testbb.remove((Literal)l.clone());
+ boolean actual = bb.remove((Literal)l.clone());
+ assertEquals(expected, actual);
+ System.out.println(" ... Result: "+actual);
}
- /**
- * Convenience method for testing class assertion additions (unary literals)
- *
- * @param sign
- * @param functor
- * @param annots
- * @param i
- * @param expected
- */
- private void assertAddObjectProperty(boolean sign, String functor, String s, String o, String label){
- assertAdd(sign, functor, Arrays.asList(new Term[] {new Atom(s), new Atom(o)}), label);
- }
@Test
- public void testRemoveLiteral() {
- }
-
- @Test
public void testContainsLiteral() {
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|