class BookSellerAgentCapabilities extends SemanticCapabilities { protected KBase setupKbase() { FilterKBase kb = (FilterKBase) super.setupKbase(); // 1. Assertion filter to handle the not_for_sale predicate kb.addKBAssertFilter(new KBAssertFilterAdapter("(B ??myself (not (for_sale ??isbn ??seller)))") { public Formula doApply(Formula formula, MatchResult match) { Term isbn = match.term("isbn"); myKBase.retractFormula(ISBN_FORMULA.instantiate("isbn", isbn)); myKBase.retractFormula(TITLE_FORMULA.instantiate("isbn", isbn)); myKBase.retractFormula(SELLING_PRICE_FORMULA.instantiate("isbn", isbn)); myKBase.retractFormula(SELLING_DELAY_FORMULA.instantiate("isbn", isbn)); ... return new TrueNode(); } }); // 2. Assertion filter to handle the selling_price predicate kb.addKBAssertFilter(new KBAssertFilterAdapter("(B ??myself (selling_price ??isbn ??price ??seller))") { public Formula doApply(Formula formula, MatchResult match) { Term isbn = match.term("isbn"); myKBase.retractFormula(SELLING_PRICE_FORMULA.instantiate("isbn", isbn)); return formula; } }); // 3. Query filter to check if a string is a substring of another one kb.addKBQueryFilter(new KBQueryFilterAdapter("(B ??myself (zsubstr ??str ??substr))") { public MatchResult doApply(Formula formula, MatchResult match) { // The parameters of the zsubstr predicate must be instantiated String str = ((Constant)match.term("str")).stringValue(); String substr = ((Constant)match.term("substr")).stringValue(); return ( str.indexOf(substr) != -1 ) ? match : null; } }); return kb; } }