#!/usr/bin/perl
# $Id: grok434.pl,v 1.3 2003/09/04 20:07:19 connolly Exp $

use strict;



&startDoc();
&grokTestLog();
&endDoc();

sub grokTestLog{
    my($state) = 'start';

    # see http://www.w3.org/2003/08/owl-systems/TestResultsTable.py
    my($test, $test2);
    my($runclass);

    while(<>){
	if($state eq 'start'){
	    if(/^Running approved tests/){
		$state = 'running';
		undef $test, $test2;
	    }
	}elsif($state eq 'running'){
	    # Trying not OWL <http://www.w3.org/2002/03owlt/I3.2/Manifest001#test>
	    # Trying positive entailment <http://www.w3.org/2002/03owlt/AllDifferent/Manifest001#test>
	    if(/^Trying/){
		if($test){
		    reportTest($test, 'PassingRun'); #@@hardcoded
		}elsif($test2){
		    reportSpeciesTest($test2, 'PassingRun');  #@@hardcoded
		}
		undef $test, $test2;

		if(/Trying not OWL <([^>]+)>/){
		    $test = $1;
		}
		elsif(/Trying (positive entailment|negative entailment|OWL for OWL|consistent|inconsistent|import entail) <([^>]+)>/){
		    $test2 = $2;
		}
		else{
		    die "what? $_";
		}
	    }
	}else{
	    die "what state??? $state";
	}
    }
}


sub reportTest{
    my $t = shift;
    my $rc = shift;

    print <<EOF;

  <n3:$rc>
    <rdf:type rdf:resource="http://www.w3.org/2002/03owlt/resultsOntology#TestRun"/>
    <n3:test rdf:resource="$t"/>
    <n3:system rdf:resource="#owlp"/>
    <n3:output rdf:resource="http://lists.w3.org/Archives/Public/public-webont-comments/2003Aug/0019.html"/>
  </n3:$rc>
EOF
}

sub reportSpeciesTest{
    my $t = shift;
    my $rc = shift;

    print <<EOF;

  <n3:$rc>
    <rdf:type rdf:resource="http://www.w3.org/2002/03owlt/resultsOntology#TestRun"/>

    <n3:test rdf:parseType="Resource">
      <n3:syntacticLevelTestFrom rdf:resource="$t"/>
    </n3:test>
    <n3:system rdf:resource="#owlp"/>
    <n3:output rdf:resource="http://lists.w3.org/Archives/Public/public-webont-comments/2003Aug/0019.html"/>
  </n3:$rc>
EOF
}




sub startDoc{

print <<EOF;
<rdf:RDF
   xmlns:n3="http://www.w3.org/2002/03owlt/resultsOntology#"
   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>
      <rdf:Description rdf:about="#owlp">
        <rdfs:label>OWLP</rdfs:label>
        <rdfs:seeAlso rdf:resource="http://lists.w3.org/Archives/Public/public-webont-comments/2003Aug/0019.html" />
        <rdfs:comment>OWLP is currently a parser for the OWL DL language as written in RDF/XML.
It works by
1/ processing an RDF/XML document into an XQuery 1.0 path datamodel;
2/ translating this datamodel into an RDF graph, using the current editor's
   draft of the RDF Syntax document; 
3/ processing imports triples, adding the result to the RDF graph;
4/ translating the final RDF graph into an OWL DL abstract ontology, using
   an inverse of the translation in the OWL Semantics and Abstract Syntax
   document. 
An RDF/XML document is an OWL DL document if and only if this process
succeeds. 
        </rdfs:comment>
      </rdf:Description>
EOF
}

sub endDoc{
    print "</rdf:RDF>\n";
}
