📄 damltest.java
字号:
DAMLClass tallMan = m.getDAMLClass( ns + "TallMan" );
assertNotNull( "Class TallMan should not be null", tallMan );
DAMLList tm = tallMan.prop_intersectionOf().getList();
assertNotNull( "Value of intersection should not be null", tm );
assertEquals( "Tall man should be an intersection of size 2", 2, tm.getCount() );
// Car is a complement of Person
DAMLClass car = m.getDAMLClass( ns + "Car" );
assertNotNull( "Class Car should not be null", car );
DAMLClass carSuper = (DAMLClass) car.getSuperClasses(false).next();
assertNotNull( "Car should have a super-class", carSuper );
assertTrue( "Car super-class should be a complement", carSuper.isComplement() );
assertTrue( "Car super-class should be a complement of Person", carSuper.prop_complementOf().hasValue( person ) );
// Height is an enumeration of three values
DAMLClass height = m.getDAMLClass( ns + "Height" );
assertNotNull( "Class Height should not be null", height );
assertTrue( "Height should be an enumeration", height.isEnumeration() );
assertEquals( "Height should be an enumeration of 3 elements", 3, height.prop_oneOf().getList().getCount() );
// daml:subClassOf is processed as rdfs:subClassOf
DAMLModel m0 = getCleanModel();
m0.getLoader().setLoadImportedOntologies( true );
m0.read( "file:testing/ontology/daml/test-cases.daml", "http://dickinson-i-4/daml/tests/test-cases.daml", null );
String tcNs = "http://dickinson-i-4/daml/tests/test-cases.daml#";
DAMLClass subClassBug0 = m0.getDAMLClass( tcNs + "SubClassBug0" );
DAMLClass subClassBug1 = m0.getDAMLClass( tcNs + "SubClassBug1" );
assertNotNull( "Class SubClassBug0 should not be null", subClassBug0 );
assertNotNull( "Class SubClassBug1 should not be null", subClassBug1 );
assertTrue( "SubClassBug1 should have SubClassBug0 as a super-class", subClassBug1.hasSuperClass( subClassBug0 ) );
assertTrue( "SubClassBug0 should have SubClassBug1 as a sub-class", subClassBug0.hasSubClass( subClassBug1 ) );
// defined properties are those that mention this class as domain
DAMLClass defProp0 = m0.getDAMLClass( tcNs + "DefProp0" );
DAMLClass defProp1 = m0.getDAMLClass( tcNs + "DefProp1" );
DAMLClass defProp2 = m0.getDAMLClass( tcNs + "DefProp2" );
assertNotNull( "Class DefProp0 should not be null", defProp0 );
assertNotNull( "Class DefProp1 should not be null", defProp1 );
assertNotNull( "Class DefProp2 should not be null", defProp2 );
int nP0 = countIteration( defProp0.getDefinedProperties(), true, "Defined property of DefProp0, closed" );
int nP0nc = countIteration( defProp0.getDefinedProperties( false ), true, "Defined property of DefProp0, not closed" );
int nP1 = countIteration( defProp1.getDefinedProperties(), true, "Defined property of DefProp1, closed" );
int nP1nc = countIteration( defProp1.getDefinedProperties( false ), true, "Defined property of DefProp1, not closed" );
int nP2 = countIteration( defProp2.getDefinedProperties(), true, "Defined property of DefProp2, closed" );
int nP2nc = countIteration( defProp2.getDefinedProperties( false ), true, "Defined property of DefProp2, not closed" );
assertEquals( "Defined properties of DefProp0 should number 11", 11, nP0 );
assertEquals( "Defined properties of DefProp0 (non-closed) should number 11", 11, nP0nc );
assertEquals( "Defined properties of DefProp1 should number 11", 11, nP1 );
assertEquals( "Defined properties of DefProp1 (non-closed) should number 0", 0, nP1nc );
assertEquals( "Defined properties of DefProp2 should number 12", 12, nP2 );
assertEquals( "Defined properties of DefProp2 (non-closed) should number 1", 1, nP2nc );
assertEquals( "Defined properties of DefProp2 should number 12", 12, nP2 );
assertEquals( "Defined properties of DefProp2 (non-closed) should number 1", 1, nP2nc );
// Bug report by Thorsten Liebig
DAMLClass tl_one = m0.getDAMLClass( tcNs + "tl_one" );
assertNotNull( "Class tl_one should not be null", tl_one );
int tl_one_supers0 = countIteration( tl_one.prop_subClassOf().getAll( ), true, "prop_subClassOf " );
int tl_one_supers1 = countIteration( tl_one.getSuperClasses( false ), true, "getSuperClasses ");
assertEquals( "Should be four super-classes of tl_one by prop_subClassOf", 4, tl_one_supers0 );
assertEquals( "Should be two super-classes of tl_one by getSuperClasses", 2, tl_one_supers1 );
// Bug report by Andrei S. Lopatenko
DAMLClass researcher = m0.getDAMLClass( tcNs + "Researcher" );
assertNotNull( "Class Researcher should not be null", researcher );
int researcherSupers = countIteration( researcher.getSuperClasses( false ), true, "Super-class of researcher" );
assertEquals( "Should be 2 super-classes of researcher", 2, researcherSupers );
}
/**
* Test equivalance classes
*/
public void testEquivalence() {
String ns = "http://dickinson-i-4/daml/tests/test-cases.daml#";
DAMLModel m = getCleanModel();
// don't allow any additional info to load
m.read( "file:testing/ontology/daml/test-cases.daml", "http://dickinson-i-4/daml/tests/test-cases.daml", null );
// get the root object
DAMLInstance root = m.getDAMLInstance( ns + "x0" );
assertNotNull( "Instance x0 should not be null", root );
// should really be 4 under daml rules, but only 1 under rdfs with no support for daml entailments
assertEquals( "Number of elements in equivalence class should be 1", 1,
countIteration( root.getEquivalentValues(), true, "Member of equivalence class to x0: " ) );
// now it's the classes' turn ...
DAMLClass cRoot = m.getDAMLClass( ns + "C0" );
assertNotNull( "Class C0 should not be null", cRoot );
// should be 4 under daml semantic rules, but only 1 under rdfs
assertEquals( "Number of elements in equivalence class should be 1", 1,
countIteration( cRoot.getSameClasses(), true, "sameClass as C0: " ) );
// and now the properties ...
DAMLProperty pRoot = m.getDAMLProperty( ns + "p0" );
assertNotNull( "Property p0 should not be null", pRoot );
// should be 4 under daml semantics rules, but only 1 under rdfs
assertEquals( "Number of elements in equivalence class should be 1", 1,
countIteration( pRoot.getSameProperties(), true, "sameProperty as p0: " ) );
// check that daml:type is recognised as equivalent to rdf:type
Resource dClass = m.getResource( ns + "CDaml" );
assertNotNull( "Resource dClass should not be null", dClass );
assertTrue( "Resource dClass should be a daml class", dClass.canAs( DAMLClass.class ) );
// check that class equivalence is considered during type testing
DAMLClass cD0 = m.getDAMLClass( ns + "D0" );
DAMLClass cD1 = m.getDAMLClass( ns + "D1" );
DAMLInstance d1 = m.getDAMLInstance( ns + "d1" );
assertNotNull( "Class D0 should not be null", cD0 );
assertNotNull( "Class D1 should not be null", cD1 );
assertNotNull( "Instance d1 should not be null", d1 );
assertTrue( "Instance d1 should have class D1", d1.hasRDFType( cD1 ) );
// RDFS reasoner can't do class equivalence assertTrue( "Instance d1 should have class D0", d1.hasRDFType( cD0 ) );
// check equivalence on properties, pd0 and pd1 are the same
DAMLProperty pd0 = m.getDAMLProperty( ns + "pd0" );
DAMLProperty pd1 = m.getDAMLProperty( ns + "pd1" );
assertNotNull( "Property pd0 should not be null", pd0 );
assertNotNull( "Property pd1 should not be null", pd1 );
DAMLInstance d2 = m.getDAMLInstance( ns + "d2" );
assertNotNull( "Instance d2 should not be null", d2 );
// check that d2 has d1 as a property value under pd0, and pd1 (it's equivalent)
assertTrue( "d2 should have d1 as a value for pd0", d2.accessProperty( pd0 ).hasValue( d1 ) );
// RDFS reasoner can't do property equivalence assertTrue( "d2 should have d1 as a value for pd1", d2.accessProperty( pd1 ).hasValue( d1 ) );
DAMLProperty pd2 = m.getDAMLProperty( ns + "pd2" );
DAMLProperty pd3 = m.getDAMLProperty( ns + "pd3" );
assertNotNull( "Property pd2 should not be null", pd2 );
assertNotNull( "Property pd3 should not be null", pd3 );
// we know that 'd1 pd3 d2', which implies 'd1 pd2 d2' since pd2 is a super-prop of pd3
assertTrue( "d2 should have d1 as a value for pd3", d2.accessProperty( pd3 ).hasValue( d1 ) );
assertTrue( "d2 should have d1 as a value for pd2", d2.accessProperty( pd2 ).hasValue( d1 ) );
}
/**
* Unit tests on DAMLProperty and its subclasses
*/
public void testProperty() {
DAMLModel m = getCleanModel();
m.read( "file:testing/ontology/daml/daml_oil_2001_03/daml+oil-ex.daml", "http://www.daml.org/2001/03/daml+oil-ex", null );
assertTrue( "loadStatus should be true for successful load", m.getLoadSuccessful() );
String ns = "http://www.daml.org/2001/03/daml+oil-ex#";
// Tests on property objects themselves
DAMLProperty hasMother = m.getDAMLProperty( ns + "hasMother" );
assertNotNull( "hasMother property should not be null", hasMother );
assertTrue( "hasMother property should be a unique property", hasMother.isUnique() );
DAMLProperty hasParent = m.getDAMLProperty( ns + "hasParent" );
assertNotNull( "hasParent property should not be null", hasParent );
DAMLClass female = m.getDAMLClass( ns + "Female" );
assertNotNull( "Class Female should not be null", female );
DAMLClass animal = m.getDAMLClass( ns + "Animal" );
assertNotNull( "Class Animal should not be null", animal );
DAMLClass person = m.getDAMLClass( ns + "Person" );
assertNotNull( "Class Person should not be null", person );
// range of hasMother includes female
assertTrue( "Mother should have Female as range", hasMother.prop_range().hasValue( female ) );
assertTrue( "Mother should not have Animal as local domain (prop_domain)", !hasMother.prop_domain().hasValue( animal ) );
/* test removed - depends on reasoner configuration
boolean found = false;
for (Iterator i = hasMother.getDomainClasses(); !found && i.hasNext(); ) {
Object cls = i.next();
found = found || cls.equals( animal );
}
assertTrue( "Mother should have Animal as domain (getDomainClasses)", found );
*/
// ancestor is transitive
DAMLObjectProperty hasAncestor = (DAMLObjectProperty) m.getDAMLProperty( ns + "hasAncestor" ).as( DAMLObjectProperty.class );
assertNotNull( "hasAncestor should not be null", hasAncestor );
assertTrue( "hasAncestor should be transitive", hasAncestor.isTransitive() );
// bug report by Michael Sintek: getNext() does not terminate on getAll(false)
DAMLInstance peter = m.getDAMLInstance( ns + "Peter" );
assertNotNull( "Instance Peter should not be null", peter );
DAMLProperty shoesize = m.getDAMLProperty( ns + "shoesize" );
assertNotNull( "Property shoesize should not be null", shoesize );
PropertyAccessor paShoesize = peter.accessProperty( shoesize );
Iterator iShoes = paShoesize.getAll( );
assertEquals( "iShoes iterator should have at least one value", true, iShoes.hasNext() );
Object size = iShoes.next();
assertNotNull( "size returned from property accessor iterator should not be null", size );
assertTrue( "size object should be a literal", size instanceof Literal );
boolean nse = false;
try {
iShoes.next();
}
catch (NoSuchElementException ignore) {
nse = true;
}
assertEquals( "Accessing past end of property iterator should throw no such element exception", true, nse );
// try the same bug test with a multi-valued property
Iterator iSubClassOf = person.prop_subClassOf().getAll( );
assertNotNull( "Iterator over subClassOf values should not be null", iSubClassOf );
assertTrue( "Iteration of subClassOf should have at least one value", iSubClassOf.hasNext() );
int nSupers = countIteration( iSubClassOf, true, "direct super-class of Person = " );
assertEquals( "Should be 10 super-classes of Person", 10, nSupers );
// another bug report from Michael Sintek - get() on single-valued property does not terminate
DAMLClass male = m.getDAMLClass( ns + "Male" );
assertNotNull( "Class Male should not be null", male );
DAMLCommon femaleDisjoint = (DAMLCommon) female.prop_disjointWith().get();
assertNotNull( "Value for female.disjointWith should not be null", femaleDisjoint );
assertTrue( "female.disjointWith should be male", male.equals( femaleDisjoint ) );
// another property accessor check
m.getLoader().setLoadImportedOntologies( false );
m.read( "file:testing/ontology/daml/test-cases.daml", "http://dickinson-i-4/daml/tests/test-cases.daml", null );
assertTrue( "loadStatus should be true for successful load", m.getLoadSuccessful() );
ns = "http://dickinson-i-4/daml/tests/test-cases.daml#";
DAMLClass subClassCheck3 = (DAMLClass) m.getDAMLValue( ns + "subClassCheck3" ).as( DAMLClass.class );
assertNotNull( "Class subClassCheck3 should not be null", subClassCheck3 );
Iterator iSubClassOf3 = subClassCheck3.getSuperClasses( false ); // not closed
assertNotNull( "Iterator over subClassOf values should not be null", iSubClassOf );
assertTrue( "Iteration of subClassOf should have at least one value", iSubClassOf3.hasNext() );
nSupers = countIteration( iSubClassOf3, true, "property access on subClassCheck3" );
assertEquals( "Should be 1 non-closed super-classes of subClassCheck3", 1, nSupers );
iSubClassOf3 = subClassCheck3.getSuperClasses( true ); // closed
assertNotNull( "Iterator over subClassOf values should not be null", iSubClassOf );
assertTrue( "Iteration of subClassOf should have at least one value", iSubClassOf3.hasNext() );
nSupers = countIteration( iSubClassOf3, true, "property access on subClassCheck3 with closed = true " );
assertEquals( "Should be 3 closed super-classes of subClassCheck3", 3, nSupers );
// bug submitted by Michael Sintek: setUseEquivalence(false) does not work with property accessors
DAMLProperty q = m.getDAMLProperty( ns + "q" );
assertNotNull( "Property q should not be null", q );
DAMLInstance qX = m.getDAMLInstance( ns + "qX" );
assertNotNull( "Instance qX should not be null", qX );
// with equivalence turned on, there should be four values for q of qX
int nQ = qX.accessProperty( q ).count();
// daml equivalance not currently implemented assertEquals( "There should be 4 values for q of qX (equivalence on)", 4, nQ );
// turn off equivalence, should only be one value
assertEquals( "There should be 1 values for q of qX (equivalence off)", 1, nQ );
// Bug report by Thorsten Liebig
DAMLProperty tlPropTest = (DAMLObjectProperty) m.getDAMLProperty( ns + "TL_PropertyTest" ).as( DAMLObjectProperty.class );
assertNotNull( "Property should not be null", tlPropTest );
Iterator tl_domains = tlPropTest.prop_domain().getAll();
assertEquals( "Property TL_PropertyTest should have a domain of two classes", 2, countIteration( tl_domains, false, null ) );
Iterator tl_ranges = tlPropTest.prop_range().getAll();
assertEquals( "Property TL_PropertyTest should have a range of two classes", 2, countIteration( tl_ranges, false, null ) );
// bug reported by Wesley Bille
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -