@prefix rec:<http://www.w3.org/2001/02pd/rec54#>.
@prefix contact:<http://www.w3.org/2000/10/swap/pim/contact#>.
@prefix dc:<http://purl.org/dc/elements/1.1/>. 
@prefix doc:<http://www.w3.org/2000/10/swap/pim/doc#>. 
@prefix trd:<http://www.w3.org/2001/10/trdoc-data.xsl>.
@prefix mat:<http://www.w3.org/2002/05/matrix/vocab#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix mtm:<merge-tr-matrix#>.
@prefix :<#>.

<> dc:title "Filter to keep only the relevant data from the merging of tr.rdf and matrix-base.n3 done by merge-tr-matrix.n3".

@forAll :WORK, :DOC, :STATUS, :P, :X, :P2, :Y.

# For any work identified as being part of the matrix (in matrix-base.n3)
# we keep only the interesting properties (as defined
# in merge-tr-matrix.n3)
{
  :WORK a mat:Work;
    :P :X.
  :P a mtm:Interesting.
  :X log:notEqualTo mat:Work.
} log:implies {
  :WORK a mat:Work; :P :X.  
}.

# RFC are special cases, since they don't appear in tr.rdf
{
  :WORK a mat:Work;
    mat:status mat:RFC.
} log:implies {
  :WORK a mat:Work; mat:status mat:RFC.
}.

# From tr.rdf, we keep only those that have a status making them
# good for the Matrix (defined as mtm:Status in merge-tr-matrix)
{ 
  :DOC doc:versionOf :WORK; a :STATUS;
    :P :X.
  :STATUS a mtm:Status.
  :WORK a mat:Work; doc:version :DOC.
  :P a mtm:Interesting.
} log:implies {
  :WORK a mat:Work; :P :X; mat:status :STATUS.
}.

# We keep interesting properties of objects of interesting properties
# not very elegant, but I don't know how to do better
{ :WORK :P :X.
  :X :P2 :Y.
  mtm:Interesting is rdf:type of :P,:P2.
} log:implies{
  :X :P2 :Y.
}.

# if a WD is in LC, we don't care to say it is a WD
{ :WORK mat:status rec:LC, rec:WD.
} log:implies {
  :WORK mat:status rec:LC.
}.
