@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 ) ); } },
/** * 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 List<VClass> getUnionComponents() { List<VClass> unionComponents = new ArrayList<VClass>(); if (isUnion()) { UnionClass union = this.cls.as(UnionClass.class); Iterator<? extends OntClass> opIt = union.listOperands(); while(opIt.hasNext()) { OntClass component = opIt.next(); if (!component.isAnon()) { unionComponents.add(new VClassJena(component, this.webappDaoFactory)); } } } return unionComponents; }
TestUtil.assertIteratorValues(this, classU.listInstances(), ind);
@Override protected void ontTest(OntModel m) { String ns = "http://example.com/foo#"; OntClass a = m.createClass(ns + "A"); OntClass b = m.createClass(ns + "B"); long old = m.size(); RDFList members = m.createList(new RDFNode[] { a, b }); UnionClass unionClass = m.createUnionClass(null, members); unionClass.remove(); assertEquals( old, m.size() ); } }
/** * 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); }
for (OntClass operand : u.listOperands().toList()) { VClass vc = new VClassJena(operand, getWebappDaoFactory()); ents.addAll(getIndividualsByVClass(vc));
TestUtil.assertIteratorValues(this, classU.listInstances(), ind);
@Override protected void ontTest(OntModel m) { String ns = "http://example.com/foo#"; OntClass a = m.createClass(ns + "A"); OntClass b = m.createClass(ns + "B"); long old = m.size(); RDFList members = m.createList(new RDFNode[] { a, b }); UnionClass unionClass = m.createUnionClass(null, members); unionClass.remove(); assertEquals( old, m.size() ); } }
@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 ) ); } },
UnionClass icls = cls.as(UnionClass.class); for (Iterator<? extends OntClass> operandIt = icls.listOperands(); operandIt.hasNext();) { OntClass operand = operandIt.next(); labelStr.append(getLabelForClass(operand, withPrefix, forPickList));
assertIteratorValues(class4.listInstances(), new Resource[] { inds[0], inds[1], inds[2], inds[3], inds[4], inds[5] }); assertIteratorValues(class4.listInstances(), new Resource[] { inds[0], inds[1], inds[2], inds[3], inds[4], inds[5], newind });
for (OntClass operand : u.listOperands().toList()) { VClass vc = new VClassJena(operand, getWebappDaoFactory()); ents.addAll(getIndividualsByVClass(vc));
@Test public void testAnonClasses() { final OntModel ontmodel = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); final String nc = "urn:test:"; final OntClass class1 = ontmodel.createClass(nc + "C1"); final OntClass class2 = ontmodel.createClass(nc + "C2"); final Individual[] inds = new Individual[6]; for (int j = 0; j < 6; j++) inds[j] = ontmodel.createIndividual(nc + "Ind" + j, OWL.Thing); inds[0].addRDFType(class1); inds[1].addRDFType(class1); inds[2].addRDFType(class1); inds[3].addRDFType(class1); inds[2].addRDFType(class2); inds[3].addRDFType(class2); inds[4].addRDFType(class2); inds[5].addRDFType(class2); assertIteratorValues(class1.listInstances(), new Resource[] { inds[0], inds[1], inds[2], inds[3] }); assertIteratorValues(class2.listInstances(), new Resource[] { inds[2], inds[3], inds[4], inds[5] }); final RDFList list = ontmodel.createList(new RDFNode[] { class1, class2 }); final IntersectionClass class3 = ontmodel.createIntersectionClass(null, list); final UnionClass class4 = ontmodel.createUnionClass(null, list); assertIteratorValues(class3.listInstances(), new Resource[] { inds[2], inds[3] }); assertIteratorValues(class4.listInstances(), new Resource[] { inds[0], inds[1], inds[2], inds[3], inds[4], inds[5] }); }
for (Iterator operandIt = icls.listOperands(); operandIt.hasNext();) { OntClass operand = (OntClass) operandIt.next(); labelStr.append(getLabelForClass(operand, withPrefix, forPickList, wadf));