@Override public void visit(final BuiltInAtom atom) { final BuiltIn builtIn = BuiltInRegistry.instance.getBuiltIn(atom.getPredicate()); helpers.add(builtIn.createHelper(atom)); }
@Override public void visit(final BuiltInAtom atom) { final BuiltIn builtIn = BuiltInRegistry.instance.getBuiltIn(atom.getPredicate()); helpers.add(builtIn.createHelper(atom)); }
public BuiltInCall(final ABox abox, final BuiltInAtom atom) { _builtInCallAbox = abox; _atom = atom; _builtin = BuiltInRegistry.instance.getBuiltIn(atom.getPredicate()); _helper = _builtin.createHelper(atom); }
public BuiltInCall(final ABox abox, final BuiltInAtom atom) { _builtInCallAbox = abox; _atom = atom; _builtin = BuiltInRegistry.instance.getBuiltIn(atom.getPredicate()); _helper = _builtin.createHelper(atom); }
@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 testTokenizeBinding() { 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 oneVarAtom = new BuiltInAtom(Namespaces.SWRLB + "tokenize", x, data, semicolan); 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 = Arrays.asList(new String[] { "hi", "bye", "foo", "bar" }); 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 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()); }