/** * <p>Answer true if this AllDifferent declaration includes <code>res</code> as one of the distinct individuals.</p> * @param res A resource to test against * @return True if <code>res</code> is declared to be distinct from the other individuals in this declaration. * @exception ProfileException If the {@link Profile#DISTINCT_MEMBERS()} property is not supported in the current language profile. */ @Override public boolean hasDistinctMember( Resource res ) { return getDistinctMembers().contains( res ); }
/** * <p>Answer true if the given literal is one of the enumerated literals that are the permissible values * of this datarange.</p> * @param lit A literal to test * @return True if the given literal is in the permissible values for this class. * @exception ProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile. */ @Override public boolean hasOneOf( Literal lit ) { return getOneOf().contains( lit ); }
/** * <p>Answer true if this AllDifferent declaration includes <code>res</code> as one of the distinct individuals.</p> * @param res A resource to test against * @return True if <code>res</code> is declared to be distinct from the other individuals in this declaration. * @exception ProfileException If the {@link Profile#DISTINCT_MEMBERS()} property is not supported in the current language profile. */ @Override public boolean hasDistinctMember( Resource res ) { return getDistinctMembers().contains( res ); }
/** * <p>Answer true if the given individual is one of the enumerated individuals in the class extension * of this class.</p> * @param res An individual to test * @return True if the given individual is in the class extension for this class. * @exception ProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile. */ @Override public boolean hasOneOf( Resource res ) { return getOneOf().contains( res ); }
/** * <p>Answer true if the given literal is one of the enumerated literals that are the permissible values * of this datarange.</p> * @param lit A literal to test * @return True if the given literal is in the permissible values for this class. * @exception ProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile. */ @Override public boolean hasOneOf( Literal lit ) { return getOneOf().contains( lit ); }
/** * <p>Answer true if this Boolean class expression has the given class as an operand.</p> * @param cls A class to test * @return True if the given class is an operand to this expression. * @exception ProfileException If the operand property is not supported in the current language profile. */ @Override public boolean hasOperand( Resource cls ) { return getOperands().contains( cls ); }
/** * <p>Answer true if this Boolean class expression has the given class as an operand.</p> * @param cls A class to test * @return True if the given class is an operand to this expression. * @exception ProfileException If the operand property is not supported in the current language profile. */ @Override public boolean hasOperand( Resource cls ) { return getOperands().contains( cls ); }
/** * <p>Answer true if the given individual is one of the enumerated individuals in the class extension * of this class.</p> * @param res An individual to test * @return True if the given individual is in the class extension for this class. * @exception ProfileException If the {@link Profile#ONE_OF()} property is not supported in the current language profile. */ @Override public boolean hasOneOf( Resource res ) { return getOneOf().contains( res ); }
/** Add the given value to a list which is the value of the given property */ protected void addListPropertyValue( Property p, String name, RDFNode value ) { checkProfile( p, name ); // get the list value if (hasProperty( p )) { RDFNode cur = getRequiredProperty( p ).getObject(); if (!cur.canAs( RDFList.class )) { throw new OntologyException( "Tried to add a value to a list-valued property " + p + " but the current value is not a list: " + cur ); } RDFList values = cur.as( RDFList.class ); // now add our value to the list if (!values.contains( value )){ RDFList newValues = values.with( value ); // if the previous values was nil, the return value will be a new list if (newValues != values) { removeAll( p ); addProperty( p, newValues ); } } } else { // create a new list to hold the only value we know so far addProperty( p, ((OntModel) getModel()).createList( new RDFNode[] {value} ) ); } }
/** Add the given value to a list which is the value of the given property */ protected void addListPropertyValue( Property p, String name, RDFNode value ) { checkProfile( p, name ); // get the list value if (hasProperty( p )) { RDFNode cur = getRequiredProperty( p ).getObject(); if (!cur.canAs( RDFList.class )) { throw new OntologyException( "Tried to add a value to a list-valued property " + p + " but the current value is not a list: " + cur ); } RDFList values = cur.as( RDFList.class ); // now add our value to the list if (!values.contains( value )){ RDFList newValues = values.with( value ); // if the previous values was nil, the return value will be a new list if (newValues != values) { removeAll( p ); addProperty( p, newValues ); } } } else { // create a new list to hold the only value we know so far addProperty( p, ((OntModel) getModel()).createList( new RDFNode[] {value} ) ); } }
public void testIndex1() { model.read(getFileName("ontology/list5.rdf")); final Resource[] toGet = new Resource[] { model.createResource(TestList.NS + "a"), model.createResource(TestList.NS + "b"), model.createResource(TestList.NS + "c"), model.createResource(TestList.NS + "d"), model.createResource(TestList.NS + "e"), }; final RDFList l1 = getListRoot(model); // check the indexes are correct for (int i = 0; i < toGet.length; i++) { Assert.assertTrue("list should contain element " + i, l1.contains(toGet[i])); Assert.assertEquals("list element " + i + " is not correct", i, l1.indexOf(toGet[i])); } }
public void testIndex1() { model.read(getFileName("ontology/list5.rdf")); final Resource[] toGet = new Resource[] { model.createResource(TestList.NS + "a"), model.createResource(TestList.NS + "b"), model.createResource(TestList.NS + "c"), model.createResource(TestList.NS + "d"), model.createResource(TestList.NS + "e"), }; final RDFList l1 = getListRoot(model); // check the indexes are correct for (int i = 0; i < toGet.length; i++) { Assert.assertTrue("list should contain element " + i, l1.contains(toGet[i])); Assert.assertEquals("list element " + i + " is not correct", i, l1.indexOf(toGet[i])); } }
/** * Bug report from David A Bigwood */ public void test_domainInf() { // create an OntModel OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF, null ); // populate the model with stuff String NS = "http://m3t4.com/ont/#"; OntClass c1 = m.createClass( NS + "c1" ); OntClass c2 = m.createClass( NS + "c2" ); OntClass c3 = m.createClass( NS + "c3" ); OntProperty p1 = m.createObjectProperty( NS + "p1" ); // create a union class to contain the union operands UnionClass uc = m.createUnionClass(null, null); // add an operand uc.addOperand( c1 ); assertEquals( "Size should be 1", 1, uc.getOperands().size() ); assertTrue( "uc should have c1 as union member", uc.getOperands().contains( c1 ) ); // add another operand uc.addOperand( c2 ); assertEquals( "Size should be 2", 2, uc.getOperands().size() ); TestUtil.assertIteratorValues(this, uc.listOperands(), new Object[] { c1, c2 } ); // add a third operand uc.addOperand( c3 ); assertEquals( "Size should be 3", 3, uc.getOperands().size() ); TestUtil.assertIteratorValues(this, uc.listOperands(), new Object[] { c1, c2, c3} ); // add union class as domain of a property p1.addDomain(uc); }
/** * Bug report from David A Bigwood */ public void test_domainInf() { // create an OntModel OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF, null ); // populate the model with stuff String NS = "http://m3t4.com/ont/#"; OntClass c1 = m.createClass( NS + "c1" ); OntClass c2 = m.createClass( NS + "c2" ); OntClass c3 = m.createClass( NS + "c3" ); OntProperty p1 = m.createObjectProperty( NS + "p1" ); // create a union class to contain the union operands UnionClass uc = m.createUnionClass(null, null); // add an operand uc.addOperand( c1 ); assertEquals( "Size should be 1", 1, uc.getOperands().size() ); assertTrue( "uc should have c1 as union member", uc.getOperands().contains( c1 ) ); // add another operand uc.addOperand( c2 ); assertEquals( "Size should be 2", 2, uc.getOperands().size() ); TestUtil.assertIteratorValues(this, uc.listOperands(), new Object[] { c1, c2 } ); // add a third operand uc.addOperand( c3 ); assertEquals( "Size should be 3", 3, uc.getOperands().size() ); TestUtil.assertIteratorValues(this, uc.listOperands(), new Object[] { c1, c2, c3} ); // add union class as domain of a property p1.addDomain(uc); }
@Override public void ontTest( OntModel m ) { Profile prof = m.getProfile(); EnumeratedClass A = m.createEnumeratedClass( NS + "A", null ); OntResource a = m.getResource( NS + "a" ).as( OntResource.class ); OntResource b = m.getResource( NS + "b" ).as( OntResource.class ); A.addOneOf( a ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.ONE_OF() ) ); assertEquals( "Size should be 1", 1, A.getOneOf().size() ); assertTrue( "A should have a as enumerated member", A.getOneOf().contains( a ) ); A.addOneOf( b ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.ONE_OF() ) ); assertEquals( "Size should be 2", 2, A.getOneOf().size() ); iteratorTest( A.listOneOf(), new Object[] {a,b} ); A.setOneOf( m.createList( new RDFNode[] {b} ) ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.ONE_OF() ) ); assertEquals( "Size should be 1", 1, A.getOneOf().size() ); assertTrue( "A should have b in the enum", A.hasOneOf( b ) ); assertTrue( "A should not have a in the enum", !A.hasOneOf( a ) ); A.removeOneOf( a ); assertTrue( "Should have b as an enum value", A.hasOneOf( b ) ); A.removeOneOf( b ); assertTrue( "Should not have b as an enum value", !A.hasOneOf( b ) ); } },
@Override public void ontTest( OntModel m ) { Profile prof = m.getProfile(); EnumeratedClass A = m.createEnumeratedClass( NS + "A", null ); OntResource a = m.getResource( NS + "a" ).as( OntResource.class ); OntResource b = m.getResource( NS + "b" ).as( OntResource.class ); A.addOneOf( a ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.ONE_OF() ) ); assertEquals( "Size should be 1", 1, A.getOneOf().size() ); assertTrue( "A should have a as enumerated member", A.getOneOf().contains( a ) ); A.addOneOf( b ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.ONE_OF() ) ); assertEquals( "Size should be 2", 2, A.getOneOf().size() ); iteratorTest( A.listOneOf(), new Object[] {a,b} ); A.setOneOf( m.createList( new RDFNode[] {b} ) ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.ONE_OF() ) ); assertEquals( "Size should be 1", 1, A.getOneOf().size() ); assertTrue( "A should have b in the enum", A.hasOneOf( b ) ); assertTrue( "A should not have a in the enum", !A.hasOneOf( a ) ); A.removeOneOf( a ); assertTrue( "Should have b as an enum value", A.hasOneOf( b ) ); A.removeOneOf( b ); assertTrue( "Should not have b as an enum value", !A.hasOneOf( b ) ); } },
@Override public void ontTest( OntModel m ) { Profile prof = m.getProfile(); UnionClass A = m.createUnionClass( NS + "A", null ); OntClass B = m.createClass( NS + "B" ); OntClass C = m.createClass( NS + "C" ); A.addOperand( B ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.UNION_OF() ) ); assertEquals( "Size should be 1", 1, A.getOperands().size() ); assertTrue( "A should have a as union member", A.getOperands().contains( B ) ); A.addOperand( C ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.UNION_OF() ) ); assertEquals( "Size should be 2", 2, A.getOperands().size() ); iteratorTest( A.listOperands(), new Object[] {B,C} ); ClosableIterator<? extends Resource> i = A.listOperands(); assertTrue( "Argument should be an OntClass", i.next() instanceof OntClass ); i.close(); A.setOperands( m.createList( new RDFNode[] {C} ) ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.UNION_OF() ) ); assertEquals( "Size should be 1", 1, A.getOperands().size() ); assertTrue( "A should have C in the union", A.hasOperand( C ) ); assertTrue( "A should not have B in the union", !A.hasOperand( B ) ); A.removeOperand( B ); assertTrue( "Should have C as an operand", A.hasOperand( C ) ); A.removeOperand( C ); assertTrue( "Should not have C as an operand", !A.hasOperand( C ) ); } },
@Override public void ontTest( OntModel m ) { Profile prof = m.getProfile(); IntersectionClass A = m.createIntersectionClass( NS + "A", null ); OntClass B = m.createClass( NS + "B" ); OntClass C = m.createClass( NS + "C" ); A.addOperand( B ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.INTERSECTION_OF() ) ); assertEquals( "Size should be 1", 1, A.getOperands().size() ); assertTrue( "A should have a as intersection member", A.getOperands().contains( B ) ); A.addOperand( C ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.INTERSECTION_OF() ) ); assertEquals( "Size should be 2", 2, A.getOperands().size() ); iteratorTest( A.listOperands(), new Object[] {B,C} ); ClosableIterator<? extends Resource> i = A.listOperands(); assertTrue( "Argument should be an OntClass", i.next() instanceof OntClass ); i.close(); A.setOperands( m.createList( new RDFNode[] {C} ) ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.INTERSECTION_OF() ) ); assertEquals( "Size should be 1", 1, A.getOperands().size() ); assertTrue( "A should have C in the intersection", A.hasOperand( C ) ); assertTrue( "A should not have B in the intersection", !A.hasOperand( B ) ); A.removeOperand( B ); assertTrue( "Should have C as an operand", A.hasOperand( C ) ); A.removeOperand( C ); assertTrue( "Should not have C as an operand", !A.hasOperand( C ) ); } },
@Override public void ontTest( OntModel m ) { Profile prof = m.getProfile(); IntersectionClass A = m.createIntersectionClass( NS + "A", null ); OntClass B = m.createClass( NS + "B" ); OntClass C = m.createClass( NS + "C" ); A.addOperand( B ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.INTERSECTION_OF() ) ); assertEquals( "Size should be 1", 1, A.getOperands().size() ); assertTrue( "A should have a as intersection member", A.getOperands().contains( B ) ); A.addOperand( C ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.INTERSECTION_OF() ) ); assertEquals( "Size should be 2", 2, A.getOperands().size() ); iteratorTest( A.listOperands(), new Object[] {B,C} ); ClosableIterator<? extends Resource> i = A.listOperands(); assertTrue( "Argument should be an OntClass", i.next() instanceof OntClass ); i.close(); A.setOperands( m.createList( new RDFNode[] {C} ) ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.INTERSECTION_OF() ) ); assertEquals( "Size should be 1", 1, A.getOperands().size() ); assertTrue( "A should have C in the intersection", A.hasOperand( C ) ); assertTrue( "A should not have B in the intersection", !A.hasOperand( B ) ); A.removeOperand( B ); assertTrue( "Should have C as an operand", A.hasOperand( C ) ); A.removeOperand( C ); assertTrue( "Should not have C as an operand", !A.hasOperand( C ) ); } },
@Override public void ontTest( OntModel m ) { Profile prof = m.getProfile(); UnionClass A = m.createUnionClass( NS + "A", null ); OntClass B = m.createClass( NS + "B" ); OntClass C = m.createClass( NS + "C" ); A.addOperand( B ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.UNION_OF() ) ); assertEquals( "Size should be 1", 1, A.getOperands().size() ); assertTrue( "A should have a as union member", A.getOperands().contains( B ) ); A.addOperand( C ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.UNION_OF() ) ); assertEquals( "Size should be 2", 2, A.getOperands().size() ); iteratorTest( A.listOperands(), new Object[] {B,C} ); ClosableIterator<? extends Resource> i = A.listOperands(); assertTrue( "Argument should be an OntClass", i.next() instanceof OntClass ); i.close(); A.setOperands( m.createList( new RDFNode[] {C} ) ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.UNION_OF() ) ); assertEquals( "Size should be 1", 1, A.getOperands().size() ); assertTrue( "A should have C in the union", A.hasOperand( C ) ); assertTrue( "A should not have B in the union", !A.hasOperand( B ) ); A.removeOperand( B ); assertTrue( "Should have C as an operand", A.hasOperand( C ) ); A.removeOperand( C ); assertTrue( "Should not have C as an operand", !A.hasOperand( C ) ); } },