Discussion Forum

Issues defining rules

Hi there,

When trying to implement the following rules:

rule product-recommendation:

when {

$p isa person;

$pr isa product;

$w isa web-page;

$sess isa session; 

$dev_sess (active-session: $sess, active-device: $dev, active-person: $p) isa device-session; 

$web_visit (visiting: $sess, visited-website: $w) isa website-visit;

$web_promo (promoting-page: $w, promoted: $pr) isa website-promotion;

$post isa post;

$sp (promoting-post: $post, promoted: $pr) isa social-promotion;

$com isa comment;

$reply (replied-to: $post, replied-by: $p, reply-content: $com) isa reply;

$liking (reacted-to: $post, reacted-by: $p) isa liking; 

} then {

(recommended-product: $pr, recommended-to: $p) isa recommendation;


rule mortgage-marriage-recommendation:

when {

$p1 isa person; p2 isa person;

$marriage (husband: $p1, wife: $p2) isa marriage;

$rp isa mortage;

$recommendation (recommended-product: $rp, recommended-to: $p2) isa recommendation;

} then {

(recommended-product: $rp, recommended-to: $p) isa recommendation;


into this schema:


email sub attribute, value string;
name sub attribute, value string;
product-name sub attribute, value string;
account-balance sub attribute, value double;
website-title sub attribute, value string;
post-title sub attribute, value string;
text sub attribute, value string;
visit-date sub attribute, value string;
opens sub attribute, value double;
link-clicks sub attribute, value double;
withdraw-amount sub attribute, value double;
promotion-name sub attribute, value string;
gender sub attribute, value string;
phone sub attribute, value string;
age sub attribute, value string;
title sub attribute, value string;
application-status sub attribute, value string;
application-filed sub attribute, value string;
amount sub attribute, value string;
ticket-title sub attribute, value string;
device-type sub attribute, value string;
session-duration sub attribute, value string;
timestamp sub attribute, value string;
session-id sub attribute, value string;

person sub entity, 
	owns email, 
	owns name,
	owns phone,
	owns age,
	owns gender,
	owns title,
	plays support-ticket-submission:submitted,
	plays device-session:active-person,
	plays debit-transaction:transacting,
	plays application:applying, 
	plays marriage:husband, 
	plays marriage:wife,
	plays employment:employed, 
	plays product-ownership:product-holder, 
	plays branch-visit:visiting,
	plays promotion:receiving, 
	plays liking:reacted-by, 
	plays reply:replied-by,
	plays recommendation:recommended-to,
	plays negative-recommendation:negative-recommended-to,
	plays withdraw:withdrawing; 
company sub entity,
	owns name,
	plays employment:employer;
bank-branch sub entity,
	plays branch-visit:visited-branch,
	plays location:located;
atm sub entity, 
	plays withdraw:withdrawing-atm;
product sub entity, 
	owns product-name, 
	plays recommendation:recommended-product,
	plays negative-recommendation:negative-recommended-product,
	plays support-ticket-submission:ticketed-product,
	plays product-ownership:owned-product,
	plays debit-transaction:account-transaction,
	plays search:searched-product,
	plays promotion:promoted;
current-account sub product,
	owns account-balance; 
mortgage sub product; 
credit-card sub product;
web-page sub entity,
	owns website-title, 
	plays promotion:promoting-page,
	plays website-visit:visited-website; 
post sub entity, 
	owns post-title, 
	owns text, 
	plays reply:replied-to, 
	plays liking:reacted-to,
	plays promotion:promoting-post; 
comment sub post, 
	plays reply:reply-content;
mortgage-application sub entity, 
	owns application-status, 
	owns application-filed, 
	plays application:applied;
data-source sub entity, 
	owns name,
	plays ownership:owned,
	plays source:sourcing; 
bank sub company;
subsidiary sub bank,
	plays ownership:owner;
city sub entity, 
	owns name,
	plays location:locating; 
transaction sub entity, 
	owns amount,
	plays debit-transaction:transacted, 
	plays location:located; 
support-ticket sub entity, 
	owns ticket-title,
	plays support-ticket-submission:ticketing; 
device sub entity,
	owns device-type, 
	plays device-session:active-device;
session sub entity,
	owns session-duration, 
	owns timestamp,
	owns session-id,
	plays website-visit:visiting,
	plays device-session:active-session,
	plays search:active-search-session;

employment sub relation, 
	relates employed,
	relates employer;
visit sub relation, 
	relates visiting;
branch-visit sub visit,
	relates visited-branch,
	owns visit-date;
website-visit sub visit,
	relates visited-website,
	owns visit-date;
source sub relation, 
	relates sourced, 
	relates sourcing; 
ownership sub relation, 
	relates owned, 
	relates owner; 
application sub relation, 
	relates applied, 
	relates applying; 
product-ownership sub relation, 
	relates product-holder,
	relates owned-product;
promotion sub relation,
	relates receiving,
	relates promoted,
	relates promoting-post,
	relates promoting-page, 
	owns link-clicks,
	owns promotion-name,
	owns opens;
website-promotion sub promotion;
email-promotion sub promotion;
social-promotion sub promotion;
reply sub relation,
	relates replied-to,
	relates reply-content,
	relates replied-by;
withdraw sub relation,
	relates withdrawing-atm,
	relates withdrawing,
	owns withdraw-amount;
liking sub relation, 
	relates reacted-to,
	relates reacted-by;
marriage sub relation, 
	plays source:sourced,
	relates husband,
	relates wife;
recommendation sub relation, 
	relates recommended-product,
	relates recommended-to;
negative-recommendation sub relation, 
	relates negative-recommended-product,
	relates negative-recommended-to;
device-session sub relation, 
	relates active-session,
	relates active-device,
	relates active-person;
search sub relation, 
	relates active-search-session, 
	relates searched-product;
support-ticket-submission sub relation, 
	relates ticketing, 
	relates ticketed-product,
	relates submitted;
debit-transaction sub relation, 
	relates account-transaction,
	relates transacting, 
	relates transacted;
location sub relation,
	relates located,
	relates locating; 

I’m receiving a lot of errors and I’m not sure how to fix them. There are massive big stacks of errors that I can’t quite figure out! Any help would be greatly appreciated.

I’d recommend first defining your schema without the rules. Ensure that it commits smoothly and without errors. Then you if you have errors you can start defining your rules one by one and work out the error in them individually, that way you don’t be overwhelmed!

Hope that will help you solve most of your issues :slight_smile: