# An RDF Schema to XHTML Convertor

@prefix : <#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix daml: <http://www.daml.org/2001/03/daml+oil#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix string: <http://www.w3.org/2000/10/swap/string#> . 
@prefix os: <http://www.w3.org/2000/10/swap/os#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix doc: <http://www.w3.org/2000/10/swap/pim/doc#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .

this log:forAll :a , :b , :c , :F , :p , :q , :r , :s , :x , :y , :z .

<> dc:title "An RDF Schema to XHTML Convertor"; 
   dc:description """Converts a properly made RDF Schema file into 
XHTML using a bit of CWM magic. To run it, use:- 

TARGET=targetdoc.n3; cwm rdfstoxhtml.n3 --think --strings > out.html
"""; 
   dc:creator [ foaf:name "Sean B. Palmer"; 
     foaf:mbox <mailto:sean@mysterylights.com>; 
     foaf:homepage <http://purl.org/net/sbp/> ] .

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# 
# Configurable Stuff
# 

# Pass the TARGET environment variable through, and parse the semantics 
# into a target context

{ :x log:uri [ is os:environ of "TARGET" ] } 
   log:implies { :x a :TargetDocument } .

# or if TARGET doesn't work, simply de-comment one of the following:-

# <myn3.n3> a :TargetDocument .
# <0.95-think.n3> a :TargetDocument .
# <rdfs-think.n3> a :TargetDocument .

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# 
# Less Configurable Stuff
# 

# Get the semantics of the TargetDocument

{ :x a :TargetDocument; log:semantics :F } log:implies { :F a :Target } .

# Put out the header

:Result_a0 log:outputString """<html xmlns="http://www.w3.org/1999/xhtml" 
   xml:lang="en" >
<head>
<!-- Transformed by: rdfstoxhtml.n3 -->
<title>RDF Schema to XHTML Result</title>
<style type="text/css">
<!--
body { margin: 1.35em; font-family: Arial, sans-serif; }
h1 { font-family: Tahoma, sans-serif; font-size: 1.8em; }
-->
</style>
</head>
<body>""" .

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# 
# Get the document information
# 

# Get the title of the document

# Old hack:- 
# 
# { :F a :Target; log:includes { :x dc:title :y } . 
#   ("<h1>" :y "</h1>") string:concatenation :z } 
#    log:implies { :Result_a1 log:outputString :z } .

:Result_a1a log:outputString "<h1>RDFS to XHTML Result" .

{ :F a :Target; log:includes { :x dc:title :y } . :x a :TargetDocument . 
   (" for: " :y) string:concatenation :z } 
   log:implies { :Result_a1b log:outputString :z } .

:Result_a1c log:outputString "</h1>" .

# Fix this bit
# 
# If we can't get the title, use any old heading
# 
# { :F a :Target; log:notIncludes { :x dc:title :y } . 
#   :x a :TargetDocument . :x log:uri :z . 
#   ("<h1>" :z "<h1>") string:concatenation :q } 
#    log:implies { :Result_a2 log:outputString :q } .
# 
# { :F a :Target; log:notIncludes { :x dc:title :y } } log:implies 
#    { :Result_a2a log:outputString "<h1>RDFS to XHTML Result</h1>" } .
# 
# This isn't quite right: sniffs dc:title anywhere. Gmprpgrpgrgh: it 
# doesn't work anyway; it = log:notIncludes

# Get description and comments

{ :F a :Target; log:includes { :x dc:description :y } . :x a :TargetDocument . 
   ("<p>Description: " :y "</p>") string:concatenation :z } 
   log:implies { :Result_a2b log:outputString :z } .

{ :F a :Target; log:includes { :x rdfs:comment :y } . :x a :TargetDocument . 
   ("<p>Comment: " :y "</p>") string:concatenation :z } 
   log:implies { :Result_a2c log:outputString :z } .

# What other stuff is relevent? Use rdfs:seeAlso

# Sniff for rdfs:seeAlso

{ :F a :Target; log:includes { :x rdfs:seeAlso :y } . :x a :TargetDocument } 
   log:implies { :Result_a2d log:outputString "<p>See also:-</p>\n<ul>" } .

{ :F a :Target; log:includes { :x rdfs:seeAlso :y } . :x a :TargetDocument . 
  :y log:uri :z . 
  ("<li><a href=\"" :z "\">" :z "</a></li>") string:concatenation :p } 
   log:implies { :Result_a2e log:outputString :p } .

{ :F a :Target; log:includes { :x rdfs:seeAlso :y } . :x a :TargetDocument } 
   log:implies { :Result_a2f log:outputString "</ul>" } .

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# 
# Get the Classes, and their labels
# 

:Result_a3 log:outputString """<h2 id="classes">Classes</h2>
<p>The schema contains the following RDFS classes:-</p>""" .

:Result_a4 log:outputString "<ul>" .

# Get classes with labels and comments

{ :F a :Target; log:includes 
   { :x a rdfs:Class; rdfs:label :y; rdfs:comment :z } .
   :x log:uri :p .
   ("<li><a href=\"" :p "\">" :y "</a> - " :z) string:concatenation :q } 
   log:implies { :Result_a5 log:outputString :q } .

# Get classes with comments

{ :F a :Target; log:includes { :x a rdfs:Class; rdfs:comment :z }; 
   log:notIncludes { :x rdfs:label :r } .
   :x log:uri :p .
   ("<li><a href=\"" :p "\">" :p "</a> - " :z) string:concatenation :q } 
   log:implies { :Result_a6 log:outputString :q } .

# Get classes

{ :F a :Target; log:includes { :x a rdfs:Class } . :x log:uri :p .
  ("<li><a href=\"" :p "\">" :p "</a>") string:concatenation :q } 
  log:implies { :Result_a7 log:outputString :q } .

:Result_a8 log:outputString "</ul>" .

# I need daml:oneOf as a built in... well, rather something a bit 
# like daml:oneOf; log:in

# { :F a :Target; log:includes { :x a rdfs:Class; :y :z } } log:implies
# { :x :y :z . 
#    { :x rdfs:comment :p . ("blargh: " :p) log:concatenation :q } 
#    log:implies { :Result_a7 log:outputString :q }
# } .

# Could get other properties...

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# 
# Get the Properties, and their labels
# 

:Result_a9 log:outputString """<h2 id="properties">Properties</h2>
<p>The schema contains the following RDF properties:-</p>""" .

:Result_b1 log:outputString "<ul>" .

# Get properties with labels and comments

{ :F a :Target; log:includes 
   { :x a rdf:Property; rdfs:label :y; rdfs:comment :z } .
   :x log:uri :p .
   ("<li><a href=\"" :p "\">" :y "</a> - " :z) string:concatenation :q } 
   log:implies { :Result_b2 log:outputString :q } .

# Get properties with comments

{ :F a :Target; log:includes { :x a rdf:Property; rdfs:comment :z }; 
   log:notIncludes { :x rdfs:label :z } .
   :x log:uri :p .
   ("<li><a href=\"" :p "\">" :p "</a> - " :z) string:concatenation :q } 
   log:implies { :Result_b3 log:outputString :q } .

# Get properties

{ :F a :Target; log:includes { :x a rdf:Property } . :x log:uri :p .
   ("<li><a href=\"" :p "\">" :p "</a>") string:concatenation :q } 
   log:implies { :Result_b4 log:outputString :q } .

:Result_b5 log:outputString "</ul>" .

:Result_b6 log:outputString "<hr />" .

# Junk

# { :F a :Target; log:includes { :x rdfs:label :y } .  } 
#    log:implies { ("label: " :y) string:concatenation :Blargh } .
# { ("x" "y") string:concatenation :x } log:implies 
#    { :Result6 log:outputString :x } .
# { :x string:concatenation :Blargh } log:implies { :Blargh a :Deeley } .
# { :Result6 :blargh :x } log:implies { :Result6 log:outputString :x } .
# { :F :title :g . ("<h1>" :g "</h1>") string:concatenation :x  } 
#    log:implies { :Result3 log:outputString :x } .

# I want log:fragment or something...

#  Trailer:

:Result_y log:outputString """<address>Converted using <a 
href="http://www.w3.org/2001/03/earl/rdfstoxhtml.n3">rdfstoxhtml.n3</a>, 
<a href="http://purl.org/net/sbp/">SBP</a></address>""" .

:Result_z log:outputString "</body>\n</html>" .

# Cleanup:

log:implies a log:Chaff . # Not that this matters
 
# EOF