private static Collection<ATermAppl> getSatisfiableDecimalRanges() { final ATermAppl dt1 = restrict(DECIMAL, minInclusive(literal("1.0", DECIMAL)), maxInclusive(literal("3.0", DECIMAL))); final ATermAppl dt2 = restrict(DECIMAL, minInclusive(literal("2.0", DECIMAL)), maxInclusive(literal("4.0", DECIMAL))); final Collection<ATermAppl> dataranges = Arrays.asList(dt1, dt2); return dataranges; }
private static Collection<ATermAppl> getUnsatisfiableDecimalRanges() { final ATermAppl dt1 = restrict(DECIMAL, minInclusive(literal("1.0", DECIMAL)), maxInclusive(literal("3.0", DECIMAL))); final ATermAppl dt2 = restrict(DECIMAL, minInclusive(literal("4.0", DECIMAL)), maxInclusive(literal("6.0", DECIMAL))); final Collection<ATermAppl> dataranges = Arrays.asList(dt1, dt2); return dataranges; }
@Test public void unionWithEmptyDatatype() throws InvalidConstrainingFacetException, InvalidLiteralException, UnrecognizedDatatypeException { final ATermAppl dt1 = restrict(INTEGER, minInclusive(literal(1)), maxInclusive(literal(3))); final ATermAppl dt2 = restrict(INTEGER, minInclusive(literal(4)), maxInclusive(literal(6))); final ATermAppl dt3 = and(NEGATIVE_INTEGER, POSITIVE_INTEGER); final ATermAppl datarange = or(dt1, dt2, dt3); assertTrue(reasoner.isSatisfiable(Collections.singleton(datarange))); assertTrue(reasoner.containsAtLeast(6, Collections.singleton(datarange))); assertFalse(reasoner.containsAtLeast(7, Collections.singleton(datarange))); }
@Test public void intersectNegatedIntegerInterval() throws InvalidConstrainingFacetException, InvalidLiteralException, UnrecognizedDatatypeException { final ATermAppl intInterval1 = restrict(INTEGER, minInclusive(literal(0)), maxInclusive(literal(1))); final ATermAppl intInterval2 = restrict(INTEGER, minInclusive(literal(2)), maxInclusive(literal(3))); assertSatisfiable(intInterval1, not(intInterval2)); }
@Test public void intersectNegatedDoubleInterval() throws InvalidConstrainingFacetException, InvalidLiteralException, UnrecognizedDatatypeException { final ATermAppl doubleInterval1 = restrict(DOUBLE, minInclusive(literal(0.0)), maxInclusive(literal(1.0))); final ATermAppl doubleInterval2 = restrict(DOUBLE, minInclusive(literal(2.0)), maxInclusive(literal(3.0))); assertSatisfiable(doubleInterval1, not(doubleInterval2)); }
@Test public void intersectNegatedFloatInterval() throws InvalidConstrainingFacetException, InvalidLiteralException, UnrecognizedDatatypeException { final ATermAppl floatInterval1 = restrict(FLOAT, minInclusive(literal(0.0f)), maxInclusive(literal(1.0f))); final ATermAppl floatInterval2 = restrict(FLOAT, minInclusive(literal(2.0f)), maxInclusive(literal(3.0f))); assertSatisfiable(floatInterval1, not(floatInterval2)); }
@Test public void intersectFloatAndFloatInterval() throws InvalidConstrainingFacetException, InvalidLiteralException, UnrecognizedDatatypeException { final ATermAppl floatInterval = restrict(FLOAT, minInclusive(literal(0.0f)), maxInclusive(literal(1.0f))); assertSatisfiable(floatInterval, FLOAT, LITERAL); }
@Test public void intersectIntegerIntervalNotInteger() throws InvalidConstrainingFacetException, InvalidLiteralException, UnrecognizedDatatypeException { final ATermAppl integerInterval = restrict(INTEGER, minInclusive(literal(0)), maxInclusive(literal(1))); assertUnsatisfiable(integerInterval, not(INTEGER)); }
@Test public void intersectFloatIntervalNotFloat() throws InvalidConstrainingFacetException, InvalidLiteralException, UnrecognizedDatatypeException { final ATermAppl floatInterval = restrict(FLOAT, minInclusive(literal(0.0f)), maxInclusive(literal(1.0f))); assertUnsatisfiable(floatInterval, not(FLOAT)); }
@Test public void intersectIntegerNegatedEmptyIntegerRange() throws InvalidConstrainingFacetException, InvalidLiteralException, UnrecognizedDatatypeException { final ATermAppl type = not(restrict(INTEGER, minInclusive(literal("2", INTEGER)), maxInclusive(literal("1", INTEGER)))); final Collection<ATermAppl> types = Arrays.asList(INTEGER, type); assertTrue(reasoner.isSatisfiable(types)); assertTrue(reasoner.containsAtLeast(2, types)); }
@Test public void intersectDoubleIntervalNotDouble() throws InvalidConstrainingFacetException, InvalidLiteralException, UnrecognizedDatatypeException { final ATermAppl doubleInterval = restrict(DOUBLE, minInclusive(literal(0.0)), maxInclusive(literal(1.0))); assertUnsatisfiable(doubleInterval, not(DOUBLE)); }
@Ignore("Equal but not identical semantics is very counter-intuitive and currently Pellet treats equals values as identical") @Test public void equalbutNotIdenticalDateTime() throws InvalidConstrainingFacetException, InvalidLiteralException, UnrecognizedDatatypeException { final ATermAppl d = restrict(DATE_TIME, minInclusive(literal("1956-06-25T04:00:00-05:00", DATE_TIME)), maxInclusive(literal("1956-06-25T04:00:00-05:00", DATE_TIME))); assertTrue(reasoner.isSatisfiable(Collections.singleton(d))); assertTrue(reasoner.isSatisfiable(Collections.singleton(d), reasoner.getValue(literal("1956-06-25T04:00:00-05:00", DATE_TIME)))); assertFalse(reasoner.isSatisfiable(Collections.singleton(d), reasoner.getValue(literal("1956-06-25T10:00:00+01:00", DATE_TIME)))); }
/** * Verify that a decimal range contains correct constants * * @throws UnrecognizedDatatypeException * @throws InvalidLiteralException * @throws InvalidConstrainingFacetException */ @Test public void unaryValuesInDecimalRange() throws InvalidConstrainingFacetException, InvalidLiteralException, UnrecognizedDatatypeException { final ATermAppl type = restrict(DECIMAL, minInclusive(literal("1.0", DECIMAL)), maxInclusive(literal("2.5", DECIMAL))); final Collection<ATermAppl> types = singleton(type); assertFalse(reasoner.isSatisfiable(types, decimal("0.99"))); assertTrue(reasoner.isSatisfiable(types, 1)); assertTrue(reasoner.isSatisfiable(types, 2)); assertTrue(reasoner.isSatisfiable(types, decimal("2.5"))); assertFalse(reasoner.isSatisfiable(types, decimal("2.51"))); }
/** * Verify that a named decimal range contains correct constants * * @throws UnrecognizedDatatypeException * @throws InvalidLiteralException * @throws InvalidConstrainingFacetException */ @Test public void unaryValuesInNamedDecimalRange() throws InvalidConstrainingFacetException, InvalidLiteralException, UnrecognizedDatatypeException { final ATermAppl rdt = restrict(DECIMAL, minInclusive(literal("1.0", DECIMAL)), maxInclusive(literal("2.5", DECIMAL))); final ATermAppl name = term("newDt"); final Collection<ATermAppl> types = singleton(name); assertTrue(reasoner.define(name, rdt)); assertFalse(reasoner.isSatisfiable(types, decimal("0.99"))); assertTrue(reasoner.isSatisfiable(types, 1)); assertTrue(reasoner.isSatisfiable(types, 2)); assertTrue(reasoner.isSatisfiable(types, decimal("2.5"))); assertFalse(reasoner.isSatisfiable(types, decimal("2.51"))); }
@Test public void nestedRestriction() { classes(_C); dataProperties(_p); individuals(_a, _b); _kb.addDatatypeDefinition(_E, restrict(INTEGER, maxInclusive(literal(2)))); _kb.addDatatypeDefinition(_D, restrict(_E, minInclusive(literal(1)))); _kb.addEquivalentClass(_C, some(_p, _D)); _kb.addPropertyValue(_p, _a, literal(2)); _kb.addPropertyValue(_p, _b, literal(3)); assertTrue(_kb.isType(_a, _C)); assertFalse(_kb.isType(_b, _C)); }
@Test public void testQualifiedCardinalityDataProperty() { final KnowledgeBase kb = new KnowledgeBaseImpl(); final ATermAppl c = restrict(Datatypes.INTEGER, minInclusive(literal(10))); final ATermAppl d = restrict(Datatypes.INTEGER, maxInclusive(literal(20))); final ATermAppl p = term("p"); final ATermAppl f = term("f"); final ATermAppl sub = Datatypes.SHORT; final ATermAppl sup = Datatypes.INTEGER; kb.addDatatype(sub); kb.addDatatype(sup); kb.addDatatypeProperty(p); kb.addDatatypeProperty(f); kb.addFunctionalProperty(f); assertSatisfiable(kb, and(min(p, 2, and(c, d)), max(p, 2, c), some(p, or(and(c, not(d)), c)))); assertSubClass(kb, min(p, 4, TOP_LIT), min(p, 2, TOP_LIT)); assertNotSubClass(kb, min(p, 1, TOP_LIT), min(p, 2, TOP_LIT)); assertNotSubClass(kb, min(p, 1, c), min(p, 1, d)); assertNotSubClass(kb, and(some(p, c), some(p, not(c))), min(p, 2, d)); assertSubClass(kb, min(p, 3, c), min(p, 2, c)); assertSubClass(kb, min(p, 3, c), min(p, 2, TOP_LIT)); assertSubClass(kb, min(p, 2, c), min(p, 2, TOP_LIT)); assertNotSubClass(kb, min(p, 2, c), min(p, 2, d)); assertSubClass(kb, min(p, 2, and(c, d)), some(p, c)); assertSubClass(kb, max(p, 1, sup), max(p, 2, sub)); assertSubClass(kb, and(max(f, 1, TOP_LIT), all(f, c)), max(f, 1, c)); assertSubClass(kb, and(min(p, 2, c), min(p, 2, not(c))), min(p, 4, TOP_LIT)); }