public Node convert(final ATerm term, final Node s) { final Node prevSubj = _subj; _subj = s; _obj = null; if (term instanceof ATermAppl) visit((ATermAppl) term); else if (term instanceof ATermInt) _obj = NodeFactory.createLiteral(term.toString(), null, XSDDatatype.XSDnonNegativeInteger); else if (term instanceof ATermList) visitList((ATermList) term); else throw new IllegalArgumentException(term.toString()); _subj = prevSubj; return _obj; }
public Node convert(final ATerm term, final Node s) { final Node prevSubj = _subj; _subj = s; _obj = null; if (term instanceof ATermAppl) visit((ATermAppl) term); else if (term instanceof ATermInt) _obj = NodeFactory.createLiteral(term.toString(), null, XSDDatatype.XSDnonNegativeInteger); else if (term instanceof ATermList) visitList((ATermList) term); else throw new IllegalArgumentException(term.toString()); _subj = prevSubj; return _obj; }
public Node convert(final ATerm term, final Node s) { final Node prevSubj = _subj; _subj = s; _obj = null; if (term instanceof ATermAppl) visit((ATermAppl) term); else if (term instanceof ATermInt) _obj = NodeFactory.createLiteral(term.toString(), null, XSDDatatype.XSDnonNegativeInteger); else if (term instanceof ATermList) visitList((ATermList) term); else throw new IllegalArgumentException(term.toString()); _subj = prevSubj; return _obj; }
@Override public T getValue(final ATermAppl literal) throws InvalidLiteralException { final T value = _range.getDatatype().getValue(literal); if (!_range.contains(value)) throw new InvalidLiteralException(_name, literal.getArgument(ATermUtils.LIT_VAL_INDEX).toString()); return value; }
@Override public T getValue(final ATermAppl literal) throws InvalidLiteralException { final T value = _range.getDatatype().getValue(literal); if (!_range.contains(value)) throw new InvalidLiteralException(_name, literal.getArgument(ATermUtils.LIT_VAL_INDEX).toString()); return value; }
@Test public void testFileParser() // XXX seriously we don't care of parsing files. { try { final File file = new File("testAtermFileParser.txt"); if (file.exists()) file.delete(); try (FileOutputStream output = new FileOutputStream(file)) { output.write(_factory.parse("f(a,g(b))").toString().getBytes()); } try (FileInputStream input = new FileInputStream(file)) { final ATerm result = _factory.readFromTextFile(input); System.out.println("result = " + result); } if (file.exists()) file.delete(); } catch (final FileNotFoundException e1) { System.out.println(e1); // TODO : define a logger. } catch (final IOException e2) { System.out.println(e2); } }
@Override public void visitCard(final ATermAppl term) { visit((ATermAppl) term.getArgument(0)); final OWLPropertyExpression prop = (OWLPropertyExpression) _obj; final int cardinality = Integer.parseInt(term.getArgument(1).toString()); if (prop instanceof OWLObjectPropertyExpression) { final OWLClassExpression c = (OWLClassExpression) convert((ATermAppl) term.getArgument(2)); _obj = _factory.getOWLObjectExactCardinality(cardinality, (OWLObjectPropertyExpression) prop, c); } else { final OWLDataRange d = (OWLDataRange) convert((ATermAppl) term.getArgument(2)); _obj = _factory.getOWLDataExactCardinality(cardinality, (OWLDataProperty) prop, d); } }
@Override public void visitCard(final ATermAppl term) { visit((ATermAppl) term.getArgument(0)); final OWLPropertyExpression prop = (OWLPropertyExpression) _obj; final int cardinality = Integer.parseInt(term.getArgument(1).toString()); if (prop instanceof OWLObjectPropertyExpression) { final OWLClassExpression c = (OWLClassExpression) convert((ATermAppl) term.getArgument(2)); _obj = _factory.getOWLObjectExactCardinality(cardinality, (OWLObjectPropertyExpression) prop, c); } else { final OWLDataRange d = (OWLDataRange) convert((ATermAppl) term.getArgument(2)); _obj = _factory.getOWLDataExactCardinality(cardinality, (OWLDataProperty) prop, d); } }
@Override public void visitMax(final ATermAppl term) { visit((ATermAppl) term.getArgument(0)); final OWLPropertyExpression prop = (OWLPropertyExpression) _obj; final int cardinality = Integer.parseInt(term.getArgument(1).toString()); if (prop instanceof OWLObjectPropertyExpression) { final OWLClassExpression c = (OWLClassExpression) convert((ATermAppl) term.getArgument(2)); _obj = _factory.getOWLObjectMaxCardinality(cardinality, (OWLObjectPropertyExpression) prop, c); } else { final OWLDataRange d = (OWLDataRange) convert((ATermAppl) term.getArgument(2)); _obj = _factory.getOWLDataMaxCardinality(cardinality, (OWLDataProperty) prop, d); } }
@Override public void visitMin(final ATermAppl term) { visit((ATermAppl) term.getArgument(0)); final OWLPropertyExpression prop = (OWLPropertyExpression) _obj; final int cardinality = Integer.parseInt(term.getArgument(1).toString()); if (prop instanceof OWLObjectPropertyExpression) { final OWLClassExpression c = (OWLClassExpression) convert((ATermAppl) term.getArgument(2)); _obj = _factory.getOWLObjectMinCardinality(cardinality, (OWLObjectPropertyExpression) prop, c); } else { final OWLDataRange d = (OWLDataRange) convert((ATermAppl) term.getArgument(2)); _obj = _factory.getOWLDataMinCardinality(cardinality, (OWLDataProperty) prop, d); } }
@Override public void visitCard(final ATermAppl term) { visit((ATermAppl) term.getArgument(0)); final OWLPropertyExpression prop = (OWLPropertyExpression) _obj; final int cardinality = Integer.parseInt(term.getArgument(1).toString()); if (prop instanceof OWLObjectPropertyExpression) { final OWLClassExpression c = (OWLClassExpression) convert((ATermAppl) term.getArgument(2)); _obj = _factory.getOWLObjectExactCardinality(cardinality, (OWLObjectPropertyExpression) prop, c); } else { final OWLDataRange d = (OWLDataRange) convert((ATermAppl) term.getArgument(2)); _obj = _factory.getOWLDataExactCardinality(cardinality, (OWLDataProperty) prop, d); } }
@Override public void visitMin(final ATermAppl term) { visit((ATermAppl) term.getArgument(0)); final OWLPropertyExpression prop = (OWLPropertyExpression) _obj; final int cardinality = Integer.parseInt(term.getArgument(1).toString()); if (prop instanceof OWLObjectPropertyExpression) { final OWLClassExpression c = (OWLClassExpression) convert((ATermAppl) term.getArgument(2)); _obj = _factory.getOWLObjectMinCardinality(cardinality, (OWLObjectPropertyExpression) prop, c); } else { final OWLDataRange d = (OWLDataRange) convert((ATermAppl) term.getArgument(2)); _obj = _factory.getOWLDataMinCardinality(cardinality, (OWLDataProperty) prop, d); } }
@Override public void visitMax(final ATermAppl term) { visit((ATermAppl) term.getArgument(0)); final OWLPropertyExpression prop = (OWLPropertyExpression) _obj; final int cardinality = Integer.parseInt(term.getArgument(1).toString()); if (prop instanceof OWLObjectPropertyExpression) { final OWLClassExpression c = (OWLClassExpression) convert((ATermAppl) term.getArgument(2)); _obj = _factory.getOWLObjectMaxCardinality(cardinality, (OWLObjectPropertyExpression) prop, c); } else { final OWLDataRange d = (OWLDataRange) convert((ATermAppl) term.getArgument(2)); _obj = _factory.getOWLDataMaxCardinality(cardinality, (OWLDataProperty) prop, d); } }
@Override public void visitMax(final ATermAppl term) { visit((ATermAppl) term.getArgument(0)); final OWLPropertyExpression prop = (OWLPropertyExpression) _obj; final int cardinality = Integer.parseInt(term.getArgument(1).toString()); if (prop instanceof OWLObjectPropertyExpression) { final OWLClassExpression c = (OWLClassExpression) convert((ATermAppl) term.getArgument(2)); _obj = _factory.getOWLObjectMaxCardinality(cardinality, (OWLObjectPropertyExpression) prop, c); } else { final OWLDataRange d = (OWLDataRange) convert((ATermAppl) term.getArgument(2)); _obj = _factory.getOWLDataMaxCardinality(cardinality, (OWLDataProperty) prop, d); } }
@Override public void visitMin(final ATermAppl term) { visit((ATermAppl) term.getArgument(0)); final OWLPropertyExpression prop = (OWLPropertyExpression) _obj; final int cardinality = Integer.parseInt(term.getArgument(1).toString()); if (prop instanceof OWLObjectPropertyExpression) { final OWLClassExpression c = (OWLClassExpression) convert((ATermAppl) term.getArgument(2)); _obj = _factory.getOWLObjectMinCardinality(cardinality, (OWLObjectPropertyExpression) prop, c); } else { final OWLDataRange d = (OWLDataRange) convert((ATermAppl) term.getArgument(2)); _obj = _factory.getOWLDataMinCardinality(cardinality, (OWLDataProperty) prop, d); } }
@Override public void visit(final OWLLiteral constant) { if (constant.isRDFPlainLiteral()) { final String lexicalValue = constant.getLiteral(); final String lang = constant.getLang(); if (lang != null) _term = ATermUtils.makePlainLiteral(lexicalValue, lang); else _term = ATermUtils.makePlainLiteral(lexicalValue); } else { final String lexicalValue = constant.getLiteral(); constant.getDatatype().accept(this); final String lang = constant.getLang(); final ATerm datatype = _term; if (lang.isEmpty()) _term = ATermUtils.makeTypedLiteral(lexicalValue, datatype.toString()); else _term = ATermUtils.makeTypedPlainLangLiteral(lexicalValue, lang); } }
@Override public void visit(final OWLLiteral constant) { if (constant.isRDFPlainLiteral()) { final String lexicalValue = constant.getLiteral(); final String lang = constant.getLang(); if (lang != null) _term = ATermUtils.makePlainLiteral(lexicalValue, lang); else _term = ATermUtils.makePlainLiteral(lexicalValue); } else { final String lexicalValue = constant.getLiteral(); constant.getDatatype().accept(this); final String lang = constant.getLang(); final ATerm datatype = _term; if (lang.isEmpty()) _term = ATermUtils.makeTypedLiteral(lexicalValue, datatype.toString()); else _term = ATermUtils.makeTypedPlainLangLiteral(lexicalValue, lang); } }
@Override public void visit(final OWLLiteral constant) { if (constant.isRDFPlainLiteral()) { final String lexicalValue = constant.getLiteral(); final String lang = constant.getLang(); if (lang != null) _term = ATermUtils.makePlainLiteral(lexicalValue, lang); else _term = ATermUtils.makePlainLiteral(lexicalValue); } else { final String lexicalValue = constant.getLiteral(); constant.getDatatype().accept(this); final String lang = constant.getLang(); final ATerm datatype = _term; if (lang.isEmpty()) _term = ATermUtils.makeTypedLiteral(lexicalValue, datatype.toString()); else _term = ATermUtils.makeTypedPlainLangLiteral(lexicalValue, lang); } }
public void testAxiomConverterRules1c() { final KnowledgeBase kb = new KnowledgeBaseImpl(); final AxiomConverter converter = new AxiomConverter(kb, OWL._manager.getOWLDataFactory()); final ATermAppl C = ATermUtils.makeTermAppl("C"); final ATermAppl D = ATermUtils.makeTermAppl("D"); final ATermAppl x = ATermUtils.makeVar("x"); final ATermAppl name = ATermUtils.makeBnode("MyRule"); kb.addClass(C); kb.addClass(D); final ATermAppl[] head = new ATermAppl[] { ATermUtils.makeTypeAtom(x, D) }; final ATermAppl[] body = new ATermAppl[] { ATermUtils.makeTypeAtom(x, C) }; final ATermAppl rule = ATermUtils.makeRule(name, head, body); final OWLAxiom actual = converter.convert(rule); final Set<SWRLAtom> antecedent = new HashSet<>(); final Set<SWRLAtom> consequent = new HashSet<>(); antecedent.add(classAtom(Class("C"), variable("x"))); consequent.add(classAtom(Class("D"), variable("x"))); final OWLAxiom expected = rule(name.getArgument(0).toString(), true, antecedent, consequent); assertEquals(expected, actual); }