@prefix s: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix owl: <http://www.w3.org/2002/07/owl#>.
@keywords is, of, a.

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

@prefix grddl: <http://www.w3.org/2003/g/data-view#>.

# hmm... move some of this to a UML diagram?

#####
# webarch stuff
@prefix w: <http://www.w3.org/2004/01/rdxh/grddl-rules#>. #@@


w:reading s:label "reading";
  s:domain :InformationResource; s:range :Message;
  s:comment """we say ?RES has :reading ?M when
   ?M is a message that conveys a representation of
   ?RES; e.g. a 200 OK response to an HTTP GET, or
   an HTTP PUT request.""".

w:Text s:isDefinedBy <http://www.w3.org/TR/charmod>;
  s:comment "a sequence of characters".

w:bodyText s:label "body text";
  s:domain :Message; s:range w:Text;
  s:comment """e.g. take the octets from an HTTP response,
  and the charset from the Content-Type: field and get the characters out.""";
  s:comment """all the same conclusions follow if we abstract
  a bit to include byte sequences, though it gets a little
  harder to explain.""".

####
# XML stuff

@prefix xml: <http://www.w3.org/2004/01/rdxh/grddl-rules#>. #@@
@prefix infoset: <http://www.w3.org/2001/04/infoset-daml#>.

# we assume
# { ?E infoset:attributes ?ATTRS.
#   ?A a ?ATTRS } => { ?E :attribute ?A }.

@prefix xsd: <http://www.w3.org/2004/01/rdxh/grddl-rules#>. #@@

:XMLMessage s:subClassOf :Message;
  s:comment "a message that is written in XML",
   """i.e. whose sender agrees to the XML specification""".

{ ?RESP w:mediaType "application/xml" } => { ?RESP a :XMLMessage }.
{ ?RESP w:mediaType [ str:endsWith "+xml"] } => { ?RESP a :XMLMessage }.

# some messages labelled text/html are XMLMessages to, though it's
# tricky to say which ones.

{ ?D grddl:transformation ?TX; w:representation [ w:bodyText ?TXT ].
  ?TXT ?TX ?G
} => { ?D grddl:result ?G }.

{ ?D grddl:result ?G1, ?G2.
  (?G1 ?G2) log:conjunction ?G
} => { ?D grddl:result ?G }.


# base case: grddl:transformation attribute
{ ?INFORES log:uri ?BASE; w:representation ?M.
  ?M a w:XMLMessage; w:bodyText ?TXT.
  ?TXT xml:infoset [
    infoset:documentElement [
      infoset:attribute [
       infoset:namespaceName "http://www.w3.org/2003/g/data-view#";
       infoset:localName "transformation";
       infoset:normalizedValue [ xsd:stringListParse [ is list:in of ?TXref ] ]
      ]
    ]
  ].
  (?TXref ?BASE) w:urijoin [ is log:uri of ?TX ].
} =>  { ?INFORES grddl:transformation ?TX }.


# abstract to namespace level

{ ?INFORES w:representation ?M.
  ?M a w:XMLMessage; w:bodyText ?TXT.
  ?TXT xml:infoset [
    infoset:documentElement [ infoset:namespaceName [ is log:uri of ?NSDOC ] ]
  ].

  ?NSDOC grddl:result ?G.
} =>  { ?INFORES grddl:result ?G }.

@forAll NSDOC, TX.

{
 ?INFORES grddl:result ?G;
  w:representation [ w:bodyText [
    xml:infoset [
      infoset:documentElement [ infoset:namespaceName [ is log:uri of NSDOC ] ]
  ] ] ].

  ?G log:includes { NSDOC grddl:namespaceTransformation TX }
} => { ?INFORES grddl:transformation TX }.

# $Log: grddl-rules.n3,v $
# Revision 1.1  2007/09/10 14:17:46  connolly
# copied from PR-grddl-20070716
#
# Revision 1.1  2007/07/16 18:39:55  jean-gui
# from /2004/01/rdxh/spec
#
# Revision 1.6  2006/10/17 23:01:20  connolly
# integrate with real infoset schema (which should be updated
# from DAML to OWL)
#
# Revision 1.5  2006/10/17 22:09:54  connolly
# namespace qualify w:XMLMessage
#
# Revision 1.4  2006/10/17 21:48:41  connolly
# test works:
# connolly@dirk:~/w3ccvs/WWW/2004/01/rdxh$ python $swap/cwm.py grddl-rule-tests.n3 grddl-rules.n3  --think
#
# yields
#
# g:doc1     grddl:result {g:doc1     g:rights g:shareAlike .
#         };
#
# Revision 1.3  2006/10/17 21:44:01  connolly
# tests starting to work
#
# Revision 1.2  2006/10/17 21:16:56  connolly
# declare prefixes; fix N3 punctuation
#
# Revision 1.1  2006/10/17 20:10:20  connolly
# thinking out loud in N3 while working on formal bits of spec.html
# hope to back-port this to MathML in the spec and then
# transform it to RIF rules
#
