📄 testclassexpression.java
字号:
}
},
new OntTestCase( "HasValueRestriction.hasValue", true, false, true, false ) {
public void ontTest( OntModel m ) throws Exception {
Profile prof = m.getProfile();
OntProperty p = m.createObjectProperty( NS + "p" );
OntClass B = m.createClass( NS + "B" );
Individual b = m.createIndividual( B );
OntClass C = m.createClass( NS + "C" );
Individual c = m.createIndividual( C );
HasValueRestriction A = m.createHasValueRestriction( NS + "A", p, b );
assertEquals( "Restriction should be has value b", b, A.getHasValue() );
assertTrue( "Restriction should be to have value b", A.hasValue( b ) );
assertTrue( "Restriction should not be have value c", !A.hasValue( c ) );
assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.HAS_VALUE() ));
A.setHasValue( c );
assertEquals( "Restriction should be has value c", c, A.getHasValue() );
assertTrue( "Restriction should not be to have value b", !A.hasValue( b ) );
assertTrue( "Restriction should not be have value c", A.hasValue( c ) );
assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.HAS_VALUE() ));
A.removeHasValue( c );
assertTrue( "Restriction should not be to have value b", !A.hasValue( b ) );
assertTrue( "Restriction should not be have value c", !A.hasValue( c ) );
assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.HAS_VALUE() ));
}
},
new OntTestCase( "SomeValuesFromRestriction.someValuesFrom", true, true, true, false ) {
public void ontTest( OntModel m ) throws Exception {
Profile prof = m.getProfile();
OntProperty p = m.createObjectProperty( NS + "p" );
OntClass B = m.createClass( NS + "B" );
OntClass C = m.createClass( NS + "C" );
SomeValuesFromRestriction A = m.createSomeValuesFromRestriction( NS + "A", p, B );
assertEquals( "Restriction should be some values from B", B, A.getSomeValuesFrom() );
assertTrue( "Restriction should be some values from B", A.hasSomeValuesFrom( B ) );
assertTrue( "Restriction should not be some values from C", !A.hasSomeValuesFrom( C ) );
assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.SOME_VALUES_FROM() ));
A.setSomeValuesFrom( C );
assertEquals( "Restriction should be some values from C", C, A.getSomeValuesFrom() );
assertTrue( "Restriction should not be some values from B", !A.hasSomeValuesFrom( B ) );
assertTrue( "Restriction should be some values from C", A.hasSomeValuesFrom( C ) );
assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.SOME_VALUES_FROM() ));
A.removeSomeValuesFrom( C );
assertTrue( "Restriction should not be some values from C", !A.hasSomeValuesFrom( C ) );
assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.SOME_VALUES_FROM() ));
}
},
new OntTestCase( "SomeValuesFromRestriction.SomeValuesFrom.datatype", true, true, true, false ) {
public void ontTest( OntModel m ) throws Exception {
Profile prof = m.getProfile();
OntProperty p = m.createObjectProperty( NS + "p" );
SomeValuesFromRestriction A = m.createSomeValuesFromRestriction( NS + "A", p, XSD.gDay );
assertEquals( "Restriction should be some values from gDay", XSD.gDay, A.getSomeValuesFrom() );
assertTrue( "Restriction should be some values from gDay", A.hasSomeValuesFrom( XSD.gDay ) );
assertTrue( "Restriction should not be some values from decimal", !A.hasSomeValuesFrom( XSD.decimal ) );
assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.SOME_VALUES_FROM() ));
A.setSomeValuesFrom( XSD.gMonth );
assertEquals( "Restriction should be some values from gMonth", XSD.gMonth, A.getSomeValuesFrom() );
assertTrue( "Restriction should not be some values from gDay", !A.hasSomeValuesFrom( XSD.gDay ) );
assertTrue( "Restriction should be some values from gMonth", A.hasSomeValuesFrom( XSD.gMonth ) );
assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.SOME_VALUES_FROM() ));
A.removeSomeValuesFrom( XSD.gMonth );
assertTrue( "Restriction should not be some values from gMonth", !A.hasSomeValuesFrom( XSD.gMonth ) );
assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.SOME_VALUES_FROM() ));
}
},
new OntTestCase( "SomeValuesFromRestriction.SomeValuesFrom.literal", true, true, true, false ) {
public void ontTest( OntModel m ) throws Exception {
Profile prof = m.getProfile();
OntProperty p = m.createObjectProperty( NS + "p" );
SomeValuesFromRestriction A = m.createSomeValuesFromRestriction( NS + "A", p, RDFS.Literal );
assertEquals( "Restriction should be some values from literal", RDFS.Literal, A.getSomeValuesFrom() );
assertTrue( "Restriction should be some values from literal", A.hasSomeValuesFrom( RDFS.Literal ) );
assertTrue( "Restriction should not be some values from decimal", !A.hasSomeValuesFrom( XSD.decimal ) );
assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.SOME_VALUES_FROM() ));
}
},
new OntTestCase( "SomeValuesFromRestriction.SomeValuesFrom.datarange", true, false, false, false ) {
public void ontTest( OntModel m ) throws Exception {
Profile prof = m.getProfile();
Literal x = m.createLiteral( 1 );
Literal y = m.createLiteral( 2 );
DataRange dr = m.createDataRange( m.createList( new RDFNode[] {x, y} ) );
OntProperty p = m.createObjectProperty( NS + "p" );
SomeValuesFromRestriction A = m.createSomeValuesFromRestriction( NS + "A", p, dr );
assertEquals( "Restriction should be some values from dr", dr, A.getSomeValuesFrom() );
assertTrue( "value should be a datarange", A.getSomeValuesFrom() instanceof DataRange );
assertTrue( "Restriction should be some values from dr", A.hasSomeValuesFrom( dr ) );
assertTrue( "Restriction should not be some values from decimal", !A.hasSomeValuesFrom( XSD.decimal ) );
assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.SOME_VALUES_FROM() ));
A.removeSomeValuesFrom( dr );
assertTrue( "Restriction should not be some values from gMonth", !A.hasSomeValuesFrom( dr ) );
assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.SOME_VALUES_FROM() ));
}
},
new OntTestCase( "CardinalityRestriction.cardinality", true, true, true, false ) {
public void ontTest( OntModel m ) throws Exception {
Profile prof = m.getProfile();
OntProperty p = m.createObjectProperty( NS + "p" );
CardinalityRestriction A = m.createCardinalityRestriction( NS + "A", p, 3 );
assertEquals( "Restriction should be cardinality 3", 3, A.getCardinality() );
assertTrue( "Restriction should be cardinality 3", A.hasCardinality( 3 ) );
assertTrue( "Restriction should not be cardinality 2", !A.hasCardinality( 2 ) );
assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.CARDINALITY() ));
A.setCardinality( 2 );
assertEquals( "Restriction should be cardinality 2", 2, A.getCardinality() );
assertTrue( "Restriction should not be cardinality 3", !A.hasCardinality( 3 ) );
assertTrue( "Restriction should be cardinality 2", A.hasCardinality( 2 ) );
assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.CARDINALITY() ));
A.removeCardinality( 2 );
assertTrue( "Restriction should not be cardinality 3", !A.hasCardinality( 3 ) );
assertTrue( "Restriction should not be cardinality 2", !A.hasCardinality( 2 ) );
assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.CARDINALITY() ));
}
},
new OntTestCase( "MinCardinalityRestriction.minCardinality", true, true, true, false ) {
public void ontTest( OntModel m ) throws Exception {
Profile prof = m.getProfile();
OntProperty p = m.createObjectProperty( NS + "p" );
MinCardinalityRestriction A = m.createMinCardinalityRestriction( NS + "A", p, 3 );
assertEquals( "Restriction should be min cardinality 3", 3, A.getMinCardinality() );
assertTrue( "Restriction should be min cardinality 3", A.hasMinCardinality( 3 ) );
assertTrue( "Restriction should not be min cardinality 2", !A.hasMinCardinality( 2 ) );
assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.MIN_CARDINALITY() ));
A.setMinCardinality( 2 );
assertEquals( "Restriction should be min cardinality 2", 2, A.getMinCardinality() );
assertTrue( "Restriction should not be min cardinality 3", !A.hasMinCardinality( 3 ) );
assertTrue( "Restriction should be min cardinality 2", A.hasMinCardinality( 2 ) );
assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.MIN_CARDINALITY() ));
A.removeMinCardinality( 2 );
assertTrue( "Restriction should not be cardinality 3", !A.hasMinCardinality( 3 ) );
assertTrue( "Restriction should not be cardinality 2", !A.hasMinCardinality( 2 ) );
assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.MIN_CARDINALITY() ));
}
},
new OntTestCase( "MaxCardinalityRestriction.maxCardinality", true, true, true, false ) {
public void ontTest( OntModel m ) throws Exception {
Profile prof = m.getProfile();
OntProperty p = m.createObjectProperty( NS + "p" );
MaxCardinalityRestriction A = m.createMaxCardinalityRestriction( NS + "A", p, 3 );
assertEquals( "Restriction should be max cardinality 3", 3, A.getMaxCardinality() );
assertTrue( "Restriction should be max cardinality 3", A.hasMaxCardinality( 3 ) );
assertTrue( "Restriction should not be max cardinality 2", !A.hasMaxCardinality( 2 ) );
assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.MAX_CARDINALITY() ));
A.setMaxCardinality( 2 );
assertEquals( "Restriction should be max cardinality 2", 2, A.getMaxCardinality() );
assertTrue( "Restriction should not be max cardinality 3", !A.hasMaxCardinality( 3 ) );
assertTrue( "Restriction should be max cardinality 2", A.hasMaxCardinality( 2 ) );
assertEquals( "cardinality should be 1 ", 1, A.getCardinality( prof.MAX_CARDINALITY() ));
A.removeMaxCardinality( 2 );
assertTrue( "Restriction should not be cardinality 3", !A.hasMaxCardinality( 3 ) );
assertTrue( "Restriction should not be cardinality 2", !A.hasMaxCardinality( 2 ) );
assertEquals( "cardinality should be 0 ", 0, A.getCardinality( prof.MAX_CARDINALITY() ));
}
},
new OntTestCase( "QualifiedRestriction.hasClassQ", false, false, true, false ) {
public void ontTest( OntModel m ) throws Exception {
OntProperty p = m.createObjectProperty( NS + "p" );
OntClass c = m.createClass( NS + "C" );
OntClass d = m.createClass( NS + "D" );
String nameA = "ABCBA";
QualifiedRestriction A = m.createMaxCardinalityQRestriction( NS + nameA, p, 3, c );
assertEquals( "Restriction should hasClassQ c", c, A.getHasClassQ() );
assertTrue( "Restriction should be hasClassQ c", A.hasHasClassQ( c ) );
assertFalse( "Restriction should not be hasClassQ d", A.hasHasClassQ( d ) );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -