# Auto-generated AIR exclusion policy, history aware.

@prefix air: <http://dig.csail.mit.edu/TAMI/2007/amord/air#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix math: <http://www.w3.org/2000/10/swap/math#> .
@prefix s: <http://dig.csail.mit.edu/2009/IARPA-PIR/sparql#> .
@prefix : <> .

# User-defined namespaces:
@prefix example: <http://www.example.com/#> .

@forAll :CURRENT, :H, :HISTORY.
@forAll :P0, :Q0, :T0, :U0, :V0, :W0. # Variables for example:name
@forAll :P1, :Q1, :T1, :U1, :V1, :W1. # Variables for example:age
@forAll :P2, :Q2, :T2, :U2, :V2, :W2. # Variables for example:dob
@forAll :P3, :Q3, :T3, :U3, :V3, :W3. # Variables for example:ssn

:sample-exclusion-history a air:Policy;
    air:label "A sample auto-generated history aware exclusion policy.";
    air:rule :sample-exclusion-history-check.
        
:sample-exclusion-history-check a air:BeliefRule;
    air:label "sample-exclusion-history query check";
    air:pattern {
        :CURRENT a s:ComplianceQuery;
                 s:Query   :Q;
                 s:History :HISTORY.
    };
    air:description ("Make sure this is a query.");
    # Goes to the first rule. If there are no attributes,
    # simply go to the default rule.
    air:rule :sample-exclusion-history-noncompliance-rule.

:sample-exclusion-history-noncompliance-rule a air:BeliefRule;
    air:label "sample-exclusion-history, a default deny policy.";
    air:pattern {
        :HISTORY log:semantics :H .
        # Catch RETRIEVE of example:name
        :H log:includes {
            :Q0 a s:SPARQLQuery;
                s:retrieve :P0;
                s:clause :W0.
            :P0 s:var :V0.
            :W0 s:triplePattern :T0. } .
        :T0 log:includes { [] example:name :V0 } .
        # Catch USE of example:age
        :H log:includes {
            :Q1 a s:SPARQLQuery;
                s:retrieve :P1;
                s:clause :W1.
            :W1 s:triplePattern :T1.
            :W1 s:triplePattern :U1. } .
        :U1 log:includes { :V1 [] [] } .
        :T1 log:includes { [] example:age :V1 }.
        # Catch RETRIEVE of example:dob
        :H log:includes {
            :Q2 a s:SPARQLQuery;
                s:retrieve :P2;
                s:clause :W2.
            :P2 s:var :V2.
            :W2 s:triplePattern :T2. } .
        :T2 log:includes { [] example:dob :V2 } .
        # Catch USE of example:ssn
        :H log:includes {
            :Q3 a s:SPARQLQuery;
                s:retrieve :P3;
                s:clause :W3.
            :W3 s:triplePattern :T3.
            :W3 s:triplePattern :U3. } .
        :U3 log:includes { :V3 [] [] } .
        :T3 log:includes { [] example:ssn :V3 }.
        };
    air:description ("You may see up to 3 of 4 of these attributes: example:name example:age example:dob example:ssn . The query history finds that this new query is incompliant: " :Q );
    air:assert{ :Q air:non-compliant-with :sample-exclusion-history } ;
    # No more policies, go to the base case.
    air:alt [ air:rule :sample-exclusion-history-default ] .


:sample-exclusion-history-default a air:BeliefRule;
    air:label "sample-exclusion-history default rule";
    air:pattern { # Empty search.
        };
    air:description ("No regulated attributes found by this history-aware exclusion policy. Asserting compliance by default.");
    air:assert{ :Q air:compliant-with :sample-exclusion-history } .
        
#ends
