/* * Check advanced instance checking */ public void testTightLexicographicEntailment7() throws Exception { ProbKnowledgeBase pkb = new KBStandaloneLoader().load(FILE_PREFIX + "test_tlexent_4.xml"); ProntoReasoner reasoner = new BasicLexicographicReasoner(new PSATSolverImpl()); ConditionalConstraint lewisCC = reasoner.membershipEntailment( pkb, ATermUtils.makeTermAppl(URI_PREFIX + "Lewis"), ATermUtils.makeTermAppl(URI_PREFIX + "WingedFlying")); /* ConditionalConstraint awfCC = reasoner.subsumptionEntailment( pkb, ATermUtils .makeTermAppl( URI_PREFIX + "ArcticPenguin" ), ATermUtils.makeTermAppl( URI_PREFIX + "WingedFlying" ) ); */ /* ConditionalConstraint apfCC = reasoner.subsumptionEntailment( pkb, ATermUtils .makeTermAppl( URI_PREFIX + "ArcticPenguin" ), ATermUtils.makeTermAppl( URI_PREFIX + "FlyingObject" ) ); */ /* ConditionalConstraint lewisF = reasoner.membershipEntailment( pkb, ATermUtils .makeTermAppl( URI_PREFIX + "Lewis" ), ATermUtils .makeTermAppl( URI_PREFIX + "FlyingObject" ) ); ConditionalConstraint lewisW = reasoner.membershipEntailment( pkb, ATermUtils .makeTermAppl( URI_PREFIX + "Lewis" ), ATermUtils .makeTermAppl( URI_PREFIX + "WingedObject" ) ); */ assertEquals(0.03, lewisCC.getLowerBound(), 0.0001); assertEquals(0.46, lewisCC.getUpperBound(), 0.0001); }
/* * Check inheritance and overriding simultaneously */ public void testTightLexicographicEntailment5() throws Exception { ProbKnowledgeBase pkb = new KBStandaloneLoader().load(FILE_PREFIX + "test_tlexent_3.xml"); ProntoReasoner reasoner = new BasicLexicographicReasoner(new PSATSolverImpl()); ConditionalConstraint awfCC = reasoner.subsumptionEntailment( pkb, ATermUtils.makeTermAppl(URI_PREFIX + "ArcticPenguin"), ATermUtils.makeTermAppl(URI_PREFIX + "WingedFlying")); assertEquals(0.1, awfCC.getLowerBound(), 0.0001); assertEquals(0.5, awfCC.getUpperBound(), 0.0001); }
/* * Check the case of (D|C)[l_1,u_1] and (E|D)[l_2,u_2] */ public void testTightLexicographicEntailment4() throws Exception { ProbKnowledgeBase pkb = new KBStandaloneLoader().load(FILE_PREFIX + "test_tlexent_2.xml"); BasicLexicographicReasoner reasoner = new BasicLexicographicReasoner(new PSATSolverImpl()); ConditionalConstraint wfCC = reasoner.tightLexicographicEntailment( pkb.getPTBox(), null, ATermUtils.makeTermAppl(URI_PREFIX + "WingedObject"), ATermUtils.makeTermAppl(URI_PREFIX + "FlyingObject")); assertEquals(0.63, wfCC.getLowerBound(), 0.0001); assertEquals(0.965, wfCC.getUpperBound(), 0.0001); }
/* * Check that if KB |= C \in D then KB |=(lex) (C|D)[1,1] */ public void testTightLexicographicEntailment2() throws Exception { ProbKnowledgeBase pkb = new KBStandaloneLoader().load(FILE_PREFIX + "test_tlexent_1.xml"); BasicLexicographicReasoner reasoner = new BasicLexicographicReasoner(new PSATSolverImpl()); ConditionalConstraint apfCC = reasoner.tightLexicographicEntailment( pkb.getPTBox(), null, ATermUtils.makeTermAppl(URI_PREFIX + "ArcticPenguin"), ATermUtils.makeTermAppl(URI_PREFIX + "Bird")); assertEquals(1.0, apfCC.getLowerBound(), 0.0001); assertEquals(1.0, apfCC.getUpperBound(), 0.0001); }
/* * Check simple instance checking */ public void testTightLexicographicEntailment6() throws Exception { ProbKnowledgeBase pkb = new KBStandaloneLoader().load(FILE_PREFIX + "test_tlexent_5.xml"); ProntoReasoner reasoner = new BasicLexicographicReasoner(new PSATSolverImpl()); ConditionalConstraint tweetyCC = reasoner.membershipEntailment( pkb, ATermUtils.makeTermAppl(URI_PREFIX + "Tweety"), ATermUtils.makeTermAppl(URI_PREFIX + "FlyingObject")); assertEquals(0.28, tweetyCC.getLowerBound(), 0.0001); assertEquals(0.72, tweetyCC.getUpperBound(), 0.0001); }
@Override protected void printNode(Set<ATermAppl> set) { super.printNode(set); Set<ATermAppl> instances = TaxonomyUtils.getDirectInstances(taxonomy, set.iterator().next()); if (instances.size() > 0) { out.print(" - ("); boolean printed = false; int anonCount = 0; Iterator<ATermAppl> ins = instances.iterator(); for (int k = 0; ins.hasNext(); k++) { ATermAppl x = ins.next(); if (ATermUtils.isBnode(x)) { anonCount++; } else { if (printed) out.print(", "); else printed = true; printURI(out, x); } } if (anonCount > 0) { if (printed) out.print(", "); out.print(anonCount + " Anonymous Individual"); if (anonCount > 1) out.print("s"); } out.print(")"); } }
/** * Membership entailment is supposed to check PABox consistency for that individual. And it must * fail in this case * * @throws Exception */ public void testNotAConsistent() throws Exception { ProbKnowledgeBase pkb = new KBStandaloneLoader().load(FILE_PREFIX + "test_membership_1.xml"); ProntoReasoner reasoner = new BasicLexicographicReasoner(new PSATSolverImpl()); boolean result = false; try { reasoner.membershipEntailment( pkb, ATermUtils.makeTermAppl(URI_PREFIX + "Lewis"), ATermUtils.makeTermAppl(URI_PREFIX + "Penguin")); } catch (RuntimeException e) { result = true; } assertTrue(result); }
@Override public OWLObjectPropertyExpression map(ATermAppl term) { if (ATermUtils.TOP_OBJECT_PROPERTY.equals(term)) return factory.getOWLTopObjectProperty(); if (ATermUtils.BOTTOM_OBJECT_PROPERTY.equals(term)) return factory.getOWLBottomObjectProperty(); if (ATermUtils.isInv(term)) return factory.getOWLObjectInverseOf(OP_MAPPER.map(term)); return factory.getOWLObjectProperty(iri(term)); }
@Override public OWLNamedIndividual map(ATermAppl term) { if (ATermUtils.isBnode(term)) { return null; } else { return factory.getOWLNamedIndividual(iri(term)); } }
@Override protected void printURI(PrintWriter out, ATermAppl c) { String str = null; if (c.equals(ATermUtils.TOP)) str = "owl:Thing"; else if (c.equals(ATermUtils.BOTTOM)) str = "owl:Nothing"; else if (ATermUtils.isPrimitive(c)) str = qnames.shortForm(c.getName()); else str = c.toString(); out.print(str); }
public NodeSet<OWLClass> getObjectPropertyRanges(OWLObjectPropertyExpression pe, boolean direct) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { refreshCheck(); try { ATermAppl some = ATermUtils.makeSomeValues(ATermUtils.makeInv(term(pe)), ATermUtils.TOP); Set<ATermAppl> equivalents = kb.getEquivalentClasses(some); if (direct && !equivalents.isEmpty()) { return toClassNodeSet(Collections.singleton(equivalents)); } Set<Set<ATermAppl>> result = kb.getSuperClasses(some, direct); if (!equivalents.isEmpty()) { result.add(equivalents); } return toClassNodeSet(result); } catch (PelletRuntimeException e) { throw convert(e); } }
public static UnknownDatatype create(String name) { UnknownDatatype unknown = (UnknownDatatype) instance.derive(instance.values, false); unknown.name = ATermUtils.makeTermAppl(name); return unknown; }
public UnknownDatatype() { super(ATermUtils.makeTermAppl("UnknownDatatype")); }
/** @author kolovski */ public class XSDDay extends BaseXSDAtomicType implements AtomicDatatype, XSDAtomicType { private static XSDatatype dt = null; private static IDateTimeValueType min = null; private static IDateTimeValueType max = null; static { try { dt = DatatypeFactory.getTypeByName("gDay"); min = (IDateTimeValueType) dt.createValue("---01", null); max = (IDateTimeValueType) dt.createValue("---31", null); } catch (DatatypeException e) { e.printStackTrace(); } } private static final ValueSpace DAY_VALUE_SPACE = new DayValueSpace(); private static class DayValueSpace extends AbstractDateTimeValueSpace implements ValueSpace { public DayValueSpace() { super(min, max, dt); } // return the difference in Days public int count(Object start, Object end) { BigDateTimeValueType calendarStart = ((IDateTimeValueType) start).getBigValue(); BigDateTimeValueType calendarEnd = ((IDateTimeValueType) end).getBigValue(); return calendarEnd.getDay().intValue() - calendarStart.getDay().intValue() + 1; } public Object succ(Object value, int n) { BigInteger bigN = new BigInteger(String.valueOf(n)); ITimeDurationValueType nDays = new BigTimeDurationValueType( NumberUtils.INTEGER_ZERO, NumberUtils.INTEGER_ZERO, bigN, NumberUtils.INTEGER_ZERO, NumberUtils.INTEGER_ZERO, NumberUtils.DECIMAL_ZERO); IDateTimeValueType s = ((IDateTimeValueType) value).add(nDays); return s; } } public static XSDDay instance = new XSDDay(ATermUtils.makeTermAppl(Namespaces.XSD + "gDay")); protected XSDDay(ATermAppl name) { super(name, DAY_VALUE_SPACE); } public BaseXSDAtomicType create(GenericIntervalList intervals) { XSDDay type = new XSDDay(null); type.values = intervals; return type; } public AtomicDatatype getPrimitiveType() { return instance; } }