@Override public void visit(final BuiltInAtom atom) { final BuiltIn builtIn = BuiltInRegistry.instance.getBuiltIn(atom.getPredicate()); helpers.add(builtIn.createHelper(atom)); }
@Override public boolean test(final WME wme, final Token token) { final Literal[] literals = new Literal[_args.length]; for (int i = 0; i < literals.length; i++) literals[i] = (Literal) _args[i].getNode(wme, token); return _builtin.apply(_abox, literals); }
@Override public void visit(final BuiltInAtom atom) { final BuiltIn builtIn = BuiltInRegistry.instance.getBuiltIn(atom.getPredicate()); helpers.add(builtIn.createHelper(atom)); }
@Override public boolean test(final WME wme, final Token token) { final Literal[] literals = new Literal[_args.length]; for (int i = 0; i < literals.length; i++) literals[i] = (Literal) _args[i].getNode(wme, token); return _builtin.apply(_abox, literals); }
public BuiltInCall(final ABox abox, final BuiltInAtom atom) { _builtInCallAbox = abox; _atom = atom; _builtin = BuiltInRegistry.instance.getBuiltIn(atom.getPredicate()); _helper = _builtin.createHelper(atom); }
@Override public void activate(final Token token) { final Literal[] literals = new Literal[_args.length]; for (int i = 0; i < literals.length; i++) literals[i] = _args[i] == null ? null : (Literal) _args[i].getNode(null, token); if (_builtin.apply(_abox, literals)) activateChildren(WME.createBuiltin(literals, DependencySet.INDEPENDENT), token); }
public BuiltInCall(final ABox abox, final BuiltInAtom atom) { _builtInCallAbox = abox; _atom = atom; _builtin = BuiltInRegistry.instance.getBuiltIn(atom.getPredicate()); _helper = _builtin.createHelper(atom); }
@Override public void activate(final Token token) { final Literal[] literals = new Literal[_args.length]; for (int i = 0; i < literals.length; i++) literals[i] = _args[i] == null ? null : (Literal) _args[i].getNode(null, token); if (_builtin.apply(_abox, literals)) activateChildren(WME.createBuiltin(literals, DependencySet.INDEPENDENT), token); }
@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()); }