# cdk 2006-04-29
#
# run with
# python cwm.py http://dig.csail.mit.edu/TAMI/cdk/scenario3/data.n3 http://dig.csail.mit.edu/TAMI/cdk/scenario3/schema.n3 http://dig.csail.mit.edu/TAMI/cdk/scenario3/rules.n3 --think --filter="http://dig.csail.mit.edu/TAMI/cdk/scenario3/filter.n3"

@keywords is, of, a .

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix : <#> .

@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix foaf: <http://xmlns.com/foaf/0.1#> . 
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix string: <http://www.w3.org/2000/10/swap/string#>.

@prefix u: <http://niem.gov/niem/universal/0.1#>.
@prefix s: <http://niem.gov/niem/structures/0.1#>.
@prefix c: <http://niem.gov/niem/common/0.1#>.
@prefix j: <http://www.niem.gov/niem/domains/justice/0.1#>.
@prefix emer: <http://www.niem.gov/niem/domains/emergency-management/0.1#>.
@prefix int: <http://www.niem.gov/niem/domains/intelligence/0.1#>.
@prefix air: <http://www.megginson.com/exp/ns/airports#>.

@prefix log: <http://www.w3.org/2000/10/swap/log#> .

@prefix ts: <http://dig.csail.mit.edu/TAMI/cdk/scenario3/schema.n3#> .
@prefix td: <http://dig.csail.mit.edu/TAMI/cdk/scenario3/data.n3#> .
@prefix tr: <http://dig.csail.mit.edu/TAMI/cdk/scenario3/rules.n3#> .



@forAll D, T.

{<http://dig.csail.mit.edu/TAMI/cdk/scenario3/data.n3> log:semantics D}
=>
{D a tr:TamiData}.

{
 D a tr:TamiData.
 D log:includes { T a ts:Transfer }
}
=>
{T ts:status ts:LegalTransfer}.



############################################ Transitive closure ####################################


tr:star a rdf:Property
	; rdfs:domain rdf:Property
	; rdfs:range rdf:Property
.


{?r tr:star ?rstar.
 ?x ?r [?rstar ?y].
}
=>
{?x ?rstar ?y.
}
.

ts:partOf tr:star tr:partOfStar
.
ts:specializationOf tr:star tr:specializationOfStar
.

# the class information seems to be necessary
{?x a ts:Organization.
 ?r tr:star ?rstar.
}
=>
{?x ?rstar ?x.
}
.

{?x a ts:Activity.
 ?r tr:star ?rstar.
}
=>
{?x ?rstar ?x.
}
.


##################################################### rules #########################################################3


{?d a ts:Database. 
 ?d ts:nature ts:Commercial
}
=>
{td:SFDB ts:allowedSource ?d}
.

# Transfer has to satisfy a RoutineUse of the relevant Sorn
# wrt to recipient organization, purpose
# and other things: person, dataCategory, allowedSource, ... (missing) !!!!!!!!!

{?t1 a ts:Transfer.
 ?s1 a ts:Sorn.
 ?s1 dc:creator ?Owner.
 ?t1 ts:sender ?Owner.
 ?s1 ts:routineUse ?r1.
 ?t1 ts:purpose ?p1.
 ?r1 ts:purpose ?p2.
 ?p1 tr:specializationOfStar ?p2.
 ?t1 ts:recipient ?o1.
 ?r1 ts:recipient ?o2.
 ?o1 tr:partOfStar ?o2.
}
=>
{
 ?t1 ts:status ts:LegalTransfer.
}.



{?tt a ts:Transfer.
 ?tt ts:status ts:LegalTransfer.
 ("Legal transfer\n   on "
	?tt.ts:dateTime
	"\n   from "
	?tt.ts:sender.ts:organizationName
	"\n   to "
	?tt.ts:recipient.ts:organizationName
	"\n\n") string:concatenation ?s.
}
=>
{
 ?tt log:outputString ?s.
}.

