@Override public HasValueRestriction createHasValueRestriction(String uri, Property prop, RDFNode value) { return inner.createHasValueRestriction(uri, prop, value); }
@Override public OntResource doCreate( OntModel m ) { Property p = m.createDatatypeProperty( NS + "p" ); Literal x = m.createTypedLiteral( new Integer( 42 ) ); return m.createHasValueRestriction( null, p, x ); } @Override
@Override public OntResource doCreate( OntModel m ) { Property p = m.createObjectProperty( NS + "p" ); Resource x = m.createResource( NS + "x" ); return m.createHasValueRestriction( null, p, x ); } @Override
@Override public OntResource doCreate( OntModel m ) { Property p = m.createDatatypeProperty( NS + "p" ); Literal x = m.createTypedLiteral( new Integer( 42 ) ); return m.createHasValueRestriction( null, p, x ); } @Override
@Override public OntResource doCreate( OntModel m ) { Property p = m.createObjectProperty( NS + "p" ); Resource x = m.createResource( NS + "x" ); return m.createHasValueRestriction( null, p, x ); } @Override
Resource valueRes = ontModel.getResource(valueURI); if (valueRes != null) { rest = ontModel.createHasValueRestriction(null, onProperty, valueRes); value = ontModel.createLiteral(valueLexicalForm); rest = ontModel.createHasValueRestriction(null, onProperty, value);
public void testGetHasValueRestriction() { OntModel m = ModelFactory.createOntologyModel(); Property p = m.createProperty( NS + "p" ); OntClass c = m.createClass( NS + "c" ); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createHasValueRestriction( NS + "s", p, c ); assertEquals( "Result of get s", s, m.getHasValueRestriction( NS + "s" ) ); assertNull( "result of get q", m.getHasValueRestriction( NS+"q") ); assertNull( "result of get r", m.getHasValueRestriction( NS+"r")); }
public void testGetHasValueRestriction() { OntModel m = ModelFactory.createOntologyModel(); Property p = m.createProperty( NS + "p" ); OntClass c = m.createClass( NS + "c" ); Resource r = m.getResource( NS + "r" ); m.add( r, RDF.type, r ); Resource s = m.createHasValueRestriction( NS + "s", p, c ); assertEquals( "Result of get s", s, m.getHasValueRestriction( NS + "s" ) ); assertNull( "result of get q", m.getHasValueRestriction( NS+"q") ); assertNull( "result of get r", m.getHasValueRestriction( NS+"r")); }
@Override public void ontTest( OntModel m ) { OntClass b = m.createClass( NS + "B" ); Individual x = m.createIndividual( b ); ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createHasValueRestriction( null, p, x ); assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); assertTrue( "has value test not correct", m_owlLiteLang || a.isHasValueRestriction() ); assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); } },
@Override public void ontTest( OntModel m ) { OntClass b = m.createClass( NS + "B" ); Individual x = m.createIndividual( b ); ObjectProperty p = m.createObjectProperty( NS + "p" ); Restriction a = m.createHasValueRestriction( null, p, x ); assertTrue( "all values from test not correct", !a.isAllValuesFromRestriction() ); assertTrue( "some values from test not correct", !a.isSomeValuesFromRestriction() ); assertTrue( "has value test not correct", m_owlLiteLang || a.isHasValueRestriction() ); assertTrue( "cardinality test not correct", !a.isCardinalityRestriction() ); assertTrue( "min cardinality test not correct", !a.isMinCardinalityRestriction() ); assertTrue( "max cardinality test not correct", !a.isMaxCardinalityRestriction() ); } },
@Test public void testHasValueReasoning() { final String ns = "urn:test:"; final OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM); spec.setReasoner(new PelletReasoner()); final OntModel model = ModelFactory.createOntologyModel(spec, null); final OntClass HomeOwner = model.createClass(ns + "HomeOwner"); final Individual bob = model.createIndividual(ns + "bob", HomeOwner); final ObjectProperty hasNeighbor = model.createObjectProperty(ns + "hasNeighbor"); final OntClass NeighborOfBob = model.createClass(ns + "NeighborOfBob"); NeighborOfBob.addEquivalentClass(model.createHasValueRestriction(null, hasNeighbor, bob)); final Individual susan = model.createIndividual(ns + "susan", HomeOwner); susan.setPropertyValue(hasNeighbor, bob); // model.write(System.out, "RDF/XML-ABBREV"); assertTrue("susan is not a NeighborOfBob", susan.hasRDFType(NeighborOfBob)); }
@Test public void testBuiltinDatatypesWithHasValueRestriction() { final String ns = "urn:test:"; final Object[] datatypes = { XSD.anyURI, "http://www.w3.com", XSD.xboolean, "true", "1", XSD.xbyte, "8", XSD.date, "2004-03-15", XSD.dateTime, "2003-12-25T08:30:00", "2003-12-25T08:30:00.001", "2003-12-25T08:30:00-05:00", "2003-12-25T08:30:00Z", XSD.decimal, "3.1415292", XSD.xdouble, "3.1415292", "INF", "NaN", XSD.duration, "P8M3DT7H33M2S", "P1Y", "P1M", "P1Y2MT2H", XSD.xfloat, "3.1415292", "-1E4", "12.78e-2", "INF", "NaN", XSD.gDay, "---11", XSD.gMonth, "--02", XSD.gMonthDay, "--02-14", XSD.gYear, "0001", "1999", XSD.gYearMonth, "1972-08", XSD.xint, "77", XSD.integer, "77", XSD.xlong, "214", XSD.negativeInteger, "-123", XSD.nonNegativeInteger, "2", XSD.nonPositiveInteger, "0", XSD.positiveInteger, "500", XSD.xshort, "476", XSD.xstring, "Test", XSD.time, "13:02:00", }; for (int i = 0; i < datatypes.length;) { final Resource datatype = (Resource) datatypes[i++]; final OntModel model = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); final OntProperty p = model.createDatatypeProperty(ns + "prop"); p.addRange(datatype); final int start = i; while (i < datatypes.length && datatypes[i] instanceof String) { final Individual ind = model.createIndividual(ns + "testInd" + i, OWL.Thing); final Literal value = model.createTypedLiteral((String) datatypes[i], datatype.getURI()); ind.addProperty(p, value); final OntClass c = model.createClass(ns + "testCls" + i); c.addEquivalentClass(model.createHasValueRestriction(null, p, value)); i++; } model.prepare(); for (int j = start; j < i; j++) assertTrue(datatype.getLocalName() + " " + datatypes[j], model.getIndividual(ns + "testInd" + j).hasRDFType(model.getIndividual(ns + "testCls" + j))); } }
@Override public void ontTest( OntModel m ) { 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( A.getHasValue() instanceof Individual ); 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() )); } },
@Override public void ontTest( OntModel m ) { 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( A.getHasValue() instanceof Individual ); 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() )); } },