/** * {@inheritDoc} */ @Override public void visit(final AtomDConstant constant) { _term = constant.getValue(); }
/** * {@inheritDoc} */ @Override public void visit(final AtomDConstant constant) { _term = constant.getValue(); }
@Override public String toString() { return ATermUtils.toString(getValue()); }
@Override public String toString() { return ATermUtils.toString(getValue()); }
final ATermAppl literal = constant.getValue(); try
final ATermAppl literal = constant.getValue(); try
@Override public void visit(final AtomDConstant constant) { ATermAppl canonical; final ATermAppl literal = constant.getValue(); try { canonical = _translatorAbox.getKB().getDatatypeReasoner().getCanonicalRepresentation(literal); } catch (final InvalidLiteralException e) { final String msg = format("Invalid literal (%s) in SWRL _data constant: %s", literal, e.getMessage()); if (OpenlletOptions.INVALID_LITERAL_AS_INCONSISTENCY) canonical = literal; else throw new InternalReasonerException(msg, e); } catch (final UnrecognizedDatatypeException e) { final String msg = format("Unrecognized datatype in literal appearing (%s) in SWRL _data constant: %s", literal, e.getMessage()); throw new InternalReasonerException(msg, e); } _result = new ConstantNodeProvider(_translatorAbox.addLiteral(canonical)); }
@Override public void visit(final AtomDConstant constant) { ATermAppl canonical; final ATermAppl literal = constant.getValue(); try { canonical = _translatorAbox.getKB().getDatatypeReasoner().getCanonicalRepresentation(literal); } catch (final InvalidLiteralException e) { final String msg = format("Invalid literal (%s) in SWRL _data constant: %s", literal, e.getMessage()); if (OpenlletOptions.INVALID_LITERAL_AS_INCONSISTENCY) canonical = literal; else throw new InternalReasonerException(msg, e); } catch (final UnrecognizedDatatypeException e) { final String msg = format("Unrecognized datatype in literal appearing (%s) in SWRL _data constant: %s", literal, e.getMessage()); throw new InternalReasonerException(msg, e); } _result = new ConstantNodeProvider(_translatorAbox.addLiteral(canonical)); }
@Test public void testTokenizeSharedFailure() { final KnowledgeBaseImpl kb = new KnowledgeBaseImpl(); final AtomDConstant data = new AtomDConstant(literal("hi;bye;foo;bar")); final AtomDVariable x = new AtomDVariable("x"); final AtomDConstant semicolan = new AtomDConstant(literal(";")); final Collection<AtomVariable> emptyCollection = Collections.emptySet(); final Collection<AtomVariable> xSingleton = Collections.singleton((AtomVariable) x); final BuiltInAtom sharedVarAtom = new BuiltInAtom(Namespaces.SWRLB + "tokenize", x, x, semicolan); final BindingHelper sharedVarHelper = StringOperators.tokenize.createHelper(sharedVarAtom); assertTrue(sharedVarHelper.getBindableVars(emptyCollection).isEmpty()); assertTrue(sharedVarHelper.getBindableVars(xSingleton).isEmpty()); final VariableBinding xdataBinding = new VariableBinding(kb.getABox()); xdataBinding.set(x, data.getValue()); sharedVarHelper.rebind(xdataBinding); assertFalse(sharedVarHelper.selectNextBinding()); }
@Test public void testTokenizeBindingEmpty() { final KnowledgeBaseImpl kb = new KnowledgeBaseImpl(); final AtomDConstant data = new AtomDConstant(literal("hi;bye;foo;bar")); final AtomDVariable x = new AtomDVariable("x"); final AtomDConstant comma = new AtomDConstant(literal(",")); final Collection<AtomVariable> emptyCollection = Collections.emptySet(); final Collection<AtomVariable> xSingleton = Collections.singleton((AtomVariable) x); final BuiltInAtom oneVarAtom = new BuiltInAtom(Namespaces.SWRLB + "tokenize", x, data, comma); final BindingHelper sharedVarHelper = StringOperators.tokenize.createHelper(oneVarAtom); assertTrue(sharedVarHelper.getBindableVars(emptyCollection).equals(xSingleton)); final VariableBinding emptyBinding = new VariableBinding(kb.getABox()); sharedVarHelper.rebind(emptyBinding); final VariableBinding fillBinding = new VariableBinding(kb.getABox()); final List<String> expected = Collections.singletonList(ATermUtils.getLiteralValue(data.getValue())); final List<String> tokens = new ArrayList<>(); while (sharedVarHelper.selectNextBinding()) { sharedVarHelper.setCurrentBinding(fillBinding); final String token = ATermUtils.getLiteralValue(fillBinding.get(x).getTerm()); tokens.add(token); } assertEquals("String tokenizer returned unexpected sequence of tokens", expected, tokens); }
@Test public void testTokenizeSharedSuccess() { final KnowledgeBaseImpl kb = new KnowledgeBaseImpl(); final AtomDConstant data = new AtomDConstant(literal("hi;bye;foo;bar")); final AtomDVariable x = new AtomDVariable("x"); final AtomDConstant comma = new AtomDConstant(literal(",")); final Collection<AtomVariable> emptyCollection = Collections.emptySet(); final Collection<AtomVariable> xSingleton = Collections.singleton((AtomVariable) x); final BuiltInAtom sharedVarAtom = new BuiltInAtom(Namespaces.SWRLB + "tokenize", x, x, comma); final BindingHelper sharedVarHelper = StringOperators.tokenize.createHelper(sharedVarAtom); assertTrue(sharedVarHelper.getBindableVars(emptyCollection).isEmpty()); assertTrue(sharedVarHelper.getBindableVars(xSingleton).isEmpty()); final VariableBinding xdataBinding = new VariableBinding(kb.getABox()); xdataBinding.set(x, data.getValue()); sharedVarHelper.rebind(xdataBinding); assertTrue(sharedVarHelper.selectNextBinding()); assertFalse(sharedVarHelper.selectNextBinding()); }