@prefix dc: <http://purl.org/dc/elements/1.1/>.  #@@ no #

<> dc:title "Comput cwm/n3 bug status (sigma) from www-archive (delta)";
  dc:description "$Id: bugstatus.n3,v 1.8 2009/02/26 17:08:01 timbl Exp $",
"""
$Log: bugstatus.n3,v $
Revision 1.8  2009/02/26 17:08:01  timbl
fix old this syntax

Revision 1.7  2005/04/04 21:10:32  connolly
updated to icaltzd

Revision 1.6  2004/03/10 22:06:12  timbl
Think fixed completuion date

Revision 1.5  2004/01/31 00:45:19  timbl
Add COMPLETED:

Revision 1.4  2004/01/31 00:10:04  connolly
thread closing support

Revision 1.3  2004/01/29 23:53:45  connolly
use cwm to grab mail headers

Revision 1.2  2004/01/29 21:10:11  timbl
Added DTSTART  to events. iCal needs DTSTART it seems.

Revision 1.1  2004/01/29 15:14:37  connolly
- finding thread roots works, to some extent
- basic conversion from email vocab to ical vocab in place

""".


<> dc:description """
hmm... remote query...
""".

<> dc:description """
@@frap. MASE/RDF doesn't give threading headers:
  in-reply-to, references
""".


@prefix :    <bugstatus#>.
@prefix bst: <bugstatus#>.

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

@prefix email: <http://www.w3.org/2000/10/swap/pim/email#>.
@prefix cal: <http://www.w3.org/2002/12/cal/icaltzd#> .

:cwm :bugListName "www-archive";
  :bugKeyWord "n3bugs";
  :bugCache <../admin/,n3bugs.rdf>.

{
{
  ?PROJECT :bugListName ?LIST;
   :bugKeyWord ?KWORD.

  ( "http://www.w3.org/Search/Mail/Public/advanced_search?keywords=" ?KWORD
      "&resultsperpage=1000&sortby=date&index-grp=Public%2FFULL&index-type=t&type-index=" ?LIST ) str:concatenation ?ADDR.
  ?ADDR is log:uri of ?KB.

  #hmm... does cwm say Accept: application/xml+rdf on its GETs?
  # until it does, we can't get the log:semantics.
}
 => { ?PROJECT :bugMailFolder ?KB }.

{ ?PROJECT :bugMailFolder [ log:semantics ?BUGS ] }
  => { ?PROJECT :bugMail ?BUGS }.
} a :DeadCode.

{ ?PROJECT :bugCache [ log:semantics ?BUGS ] }
  => { ?PROJECT :bugMail ?BUGS }.

@prefix apple: <http://www.w3.org/2002/12/cal/prod/Apple_Comp_628d9d8459c556fa#>.

{ ?PROJECT :bugMail [] } => {
    ?PROJECT :calendar [
	a cal:Vcalendar;
	apple:name "Bug Status";
     ]
 }.

@forAll :MSG, :SUBJ, :DATE.

@prefix req: <http://www.w3.org/2000/10/swap/util/reqThreads#>.

{
  ?PROJECT :calendar ?CAL;
    :bugMail ?BUGSTATUSKB.

  (?BUGSTATUSKB [ is log:semantics of <reqThreads.n3>] ) log:conjunction [
    log:conclusion ?F ].
} => { ?PROJECT :bugThreads ?F }.

{
  ?PROJECT :calendar ?CAL;
    :bugThreads [
      log:includes {
        [] req:threadRoot :MSG.
        :MSG email:subject :SUBJ.
        :MSG email:date_iso :DATE.
      } ].

  :MSG log:uri ?MSGURI.
  (?MSGURI "mid:(.*)") str:scrape ?MID.
  ?MSG_ARCHIVE log:uri [
   is str:concatenation of  ("http://www.w3.org/mid/" ?MID )
  ].

  ?DATET is log:dtlit of (:DATE dt:dateTime).

}
  => {
 :MSG :archive ?MSG_ARCHIVE.

 ?CAL cal:component [
    a cal:Vtodo; #@@ not in the rdf calendar schema; i.e. no TODO tests
    cal:summary :SUBJ;
    cal:url ?MSG_ARCHIVE;
    cal:dtstart ?DATET
 ]
 }.

{
  ?CAL cal:component ?TODO.

  ?TODO cal:url [ is :archive of :MSG ].

  ?PROJECT :calendar ?CAL;
    :bugThreads [
      log:includes {
#        :MSG req:threadTail [];
#	     email:date_iso :DATE.
        :MSG req:threadTail [
	     email:date_iso :DATE]
      } ].

  ?WHEN is log:dtlit of (:DATE dt:dateTime).
}
=> {
  ?TODO cal:status "COMPLETED";
	cal:completed ?WHEN.
}.


