@Override public void visitLiteral(final ATermAppl term) { final ATermAppl lexicalValue = (ATermAppl) term.getArgument(ATermUtils.LIT_VAL_INDEX); final ATermAppl lang = (ATermAppl) term.getArgument(ATermUtils.LIT_LANG_INDEX); final ATermAppl datatypeURI = (ATermAppl) term.getArgument(ATermUtils.LIT_URI_INDEX); if (datatypeURI.equals(XSDInteger.getInstance().getName()) || datatypeURI.equals(XSDDecimal.getInstance().getName())) _out.print(lexicalValue.getName()); else if (datatypeURI.equals(XSDFloat.getInstance().getName())) { _out.print(lexicalValue.getName()); _out.print("f"); } else if (!datatypeURI.equals(ATermUtils.PLAIN_LITERAL_DATATYPE)) { _out.print(lexicalValue.getName()); _out.print("^^"); _out.print(datatypeURI.getName()); } else { _out.print("\"" + lexicalValue.getName() + "\""); if (!lang.equals(ATermUtils.EMPTY)) _out.print("@" + lang); } }
@Override protected Number fromLexicalForm(final String lexicalForm) throws InvalidLiteralException { try { return DatatypeConverter.parseInteger(lexicalForm); } catch (final NumberFormatException e) { throw new InvalidLiteralException(getName(), lexicalForm, e); } } }
@Override protected Number fromLexicalForm(final String lexicalForm) throws InvalidLiteralException { try { return DatatypeConverter.parseInteger(lexicalForm); } catch (final NumberFormatException e) { throw new InvalidLiteralException(getName(), lexicalForm, e); } } }
@Override public void visitLiteral(final ATermAppl term) { final ATermAppl lexicalValue = (ATermAppl) term.getArgument(ATermUtils.LIT_VAL_INDEX); final ATermAppl lang = (ATermAppl) term.getArgument(ATermUtils.LIT_LANG_INDEX); final ATermAppl datatypeURI = (ATermAppl) term.getArgument(ATermUtils.LIT_URI_INDEX); if (datatypeURI.equals(XSDInteger.getInstance().getName()) || datatypeURI.equals(XSDDecimal.getInstance().getName())) _out.print(lexicalValue.getName()); else if (datatypeURI.equals(XSDFloat.getInstance().getName())) { _out.print(lexicalValue.getName()); _out.print("f"); } else if (!datatypeURI.equals(ATermUtils.PLAIN_LITERAL_DATATYPE)) { _out.print(lexicalValue.getName()); _out.print("^^"); _out.print(datatypeURI.getName()); } else { _out.print("\"" + lexicalValue.getName() + "\""); if (!lang.equals(ATermUtils.EMPTY)) _out.print("@" + lang); } }
@Test public void test375() { // test case for issue #375. classes(_A, _B, _C); dataProperties(_p); final ATermAppl dt = restrict(Datatypes.INTEGER, minExclusive(literal(1))); _kb.addRange(_p, XSDInteger.getInstance().getName()); _kb.addSubClass(_A, _C); _kb.addEquivalentClass(_A, some(_p, dt)); _kb.addSubClass(_B, _C); _kb.addEquivalentClass(_B, hasValue(_p, literal(2))); assertTrue(_kb.isConsistent()); assertSubClass(_kb, _B, _A); _kb.classify(); _kb.printClassTree(); assertSubClass(_kb, _B, _A); }
@Test public void testFunctionalDataProp1() { final ATermAppl C = term("C"); final ATermAppl D = XSDInteger.getInstance().getName(); final ATermAppl p = term("p"); final ATermAppl a = term("a"); final ATermAppl b = literal("012345678", Datatypes.INTEGER); _kb.addClass(C); _kb.addClass(D); _kb.addDatatypeProperty(p); _kb.addIndividual(a); _kb.addEquivalentClass(C, all(p, D)); _kb.addFunctionalProperty(p); _kb.addPropertyValue(p, a, b); assertTrue(_kb.isConsistent()); assertTrue(_kb.isType(a, C)); final Set<ATermAppl> explanation = _kb.getExplanationSet(); assertIteratorValues(explanation.iterator(), new Object[] { ATermUtils.makeEqClasses(C, all(p, D)), ATermUtils.makeFunctional(p), ATermUtils.makePropAtom(p, a, b) }); }
@Test public void testLiteralMerge() { // Tests the issue described in #250 final KnowledgeBase kb = new KnowledgeBaseImpl(); final ATermAppl a = term("a"); final ATermAppl b = term("b"); final ATermAppl p = term("p"); kb.addIndividual(a); kb.addIndividual(b); kb.addDatatypeProperty(p); kb.addFunctionalProperty(p); // a has a p-successor which is an integer kb.addType(a, some(p, XSDInteger.getInstance().getName())); // bogus axiom to force full datatype reasoning kb.addType(a, max(p, 2, TOP_LIT)); // b has an asserted p value which is a string kb.addPropertyValue(p, b, literal("b")); // check consistency whihc assertTrue(kb.isConsistent()); // this query will force a and b to be merged which will cause // their p values to be merged assertTrue(kb.isDifferentFrom(a, b)); }
@Test public void testDatatypeSubProperty1b() { // Another variation of testDatatypeSubProperty1 where super // property has a range but not the sub property final KnowledgeBase kb = new KnowledgeBaseImpl(); final ATermAppl C = term("C"); final ATermAppl p = term("p"); final ATermAppl q = term("q"); kb.addClass(C); kb.addDatatypeProperty(p); kb.addDatatypeProperty(q); kb.addDomain(p, C); kb.addRange(q, XSDInteger.getInstance().getName()); kb.addSubClass(C, some(q, TOP_LIT)); assertTrue(kb.isConsistent()); assertFalse(kb.isSubPropertyOf(p, q)); assertFalse(kb.isSubPropertyOf(q, p)); assertFalse(kb.isEquivalentProperty(p, q)); assertFalse(kb.isEquivalentProperty(q, p)); }
@Test public void testDatatypeSubProperty1a() { // Tests the issue described in #250 // The sub/equivalent property query was turned into a satisfiability // test where a fresh datatype is used. If the property in question // has a range the intersection of defined range with the fresh // datatype returned to be empty causing the reasoner to conclude // subproperty relation hols even though it does not final KnowledgeBase kb = new KnowledgeBaseImpl(); final ATermAppl p = term("p"); final ATermAppl q = term("q"); final ATermAppl[] ranges = { null, XSDInteger.getInstance().getName(), XSDString.getInstance().getName() }; for (final ATermAppl rangeP : ranges) for (final ATermAppl rangeQ : ranges) { kb.clear(); kb.addDatatypeProperty(p); kb.addDatatypeProperty(q); if (rangeP != null) kb.addRange(p, rangeP); if (rangeQ != null) kb.addRange(q, rangeQ); assertTrue(kb.isConsistent()); assertFalse(kb.isSubPropertyOf(p, q)); assertFalse(kb.isSubPropertyOf(q, p)); assertFalse(kb.isEquivalentProperty(p, q)); assertFalse(kb.isEquivalentProperty(q, p)); } }
kb.addRange(p, ATermUtils.makeRestrictedDatatype(XSDInteger.getInstance().getName(), new ATermAppl[] { ATermUtils.makeFacetRestriction(Facet.XSD.MIN_INCLUSIVE.getName(), ATermUtils.makeTypedLiteral(Byte.toString(MIN), XSDByte.getInstance().getName())), ATermUtils.makeFacetRestriction(Facet.XSD.MAX_INCLUSIVE.getName(), ATermUtils.makeTypedLiteral(Byte.toString(MAX), XSDByte.getInstance().getName())) })); assertTrue(kb.isSatisfiable(E)); assertTrue(kb.hasPropertyValue(x, p, ATermUtils.makeTypedLiteral("5", XSDInteger.getInstance().getName()))); assertFalse(kb.hasPropertyValue(y, p, ATermUtils.makeTypedLiteral("5", XSDDecimal.getInstance().getName())));