For the tutorial:
To add this rule, the tutorial says that " To define the :hasAffiliation
relationship, we’ll add a couple of rules to the Knowledge Graph. To add the rules, you simply insert a triple with a reserved stardog:rule:content
predicate. Stardog will detect the rule and apply it to any relevant query that has reasoning enabled."
IF {
?x :hasAddress ?a .
?y :hasAddress ?a .
filter (?x != ?y)
}
THEN {
?x :hasAffiliation ?y .
}
IF {
?x :holds ?holding .
?holding :company ?c .
?holding :share ?share .
filter (?share >= 50)
}
THEN {
?x :hasAffiliation ?c .
?c :hasAffiliation ?x .
}
I have this query typed in the Studio below. How to make the rule above to work for this query in the Studio? How to understand this "stardog:rule:content` predicate". Thanks,
# Fraud score as Money * (Paths Count)^2
select ?org ?name1 ?ben ?name2 ?score {
{
# Count distinct paths
select ?org ?name1 ?ben ?name2 ?s (count(*) as ?c) {
{
# Group by intermediaries
select ?org ?name1 ?ben ?name2 ?t1 ?t2 ?s {
?org :lastName ?lname1 ;
:firstName ?fname1 ;
:hasAffiliation* ?t1 .
?t1 :hasBankAccount ?a1 .
?a1 :originated ?tx .
?tx :beneficiary ?a2 .
?t2 :hasBankAccount ?a2 ;
:hasAffiliation* ?ben .
?ben :lastName ?lname2 ;
:firstName ?fname2 .
{
# Find highest sum of Tx for all paths
# between ?org and ?ben
select ?org ?ben (sum(?m) as ?s) {
?org a :Person ;
:hasAffiliation* ?t1 .
?t1 :hasBankAccount ?a1 .
?a1 :originated ?tx .
?tx :beneficiary ?a2 ;
:amount ?m .
?t2 :hasBankAccount ?a2 ;
:hasAffiliation* ?ben .
?ben a :Person .
}
group by ?org ?ben
order by desc(?s) ?org ?ben
limit 1000
}
bind(concat(?fname1, ' - ', ?lname1) as ?name1)
bind(concat(?fname2, ' - ', ?lname2) as ?name2)
}
group by ?org ?name1 ?ben ?name2 ?t1 ?t2 ?s
}
}
group by ?org ?ben ?name1 ?name2 ?s
order by desc(?s) ?org ?ben
}
# Calculate score as total money transacted times
# the square of unique path count between actors
bind(?s * ?c * ?c as ?score)
}
order by desc(?score) ?org ?ben