% \iffalse meta-comment
% An Infrastructure for marking up Dublin Core Metadata in LaTeX documents
% $URL: https://svn.kwarc.info/repos/stex/trunk/sty/owl2onto/owl2onto.dtx $ 
% $Rev: 1671 $; last modified by $Author: kohlhase $ 
% $Date: 2010-11-06 08:05:15 +0100 (Sat, 06 Nov 2010) $
% Copyright (c) 2007 Michael Kohlhase, all rights reserved
%               this file is released under the
%               LaTeX Project Public License (LPPL)
% \fi
% 
% \iffalse
%<*package>
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{owl2onto}[2010/06/24 v0.2 OWL2 Ontologies in sTeX]
%</package>
%<*driver>
\documentclass{ltxdoc}
\usepackage{stex-logo,url,array,float}
\usepackage[show]{ed}
\usepackage[hyperref=auto,style=alphabetic]{biblatex}
\bibliography{kwarc}
\usepackage{listings}
\usepackage{modules,presentation,owl2onto}
\usepackage{../ctansvn}
\usepackage[eso-foot,today]{svninfo}
\svnInfo $Id: owl2onto.dtx 1671 2010-11-06 07:05:15Z kohlhase $
\svnKeyword $HeadURL: https://svn.kwarc.info/repos/stex/trunk/sty/owl2onto/owl2onto.dtx $
\usepackage{hyperref}
\makeindex
\floatstyle{boxed}
\newfloat{exfig}{thp}{lop}
\floatname{exfig}{Example}
\lstdefinelanguage{owl2onto}[LaTeX]{TeX}
  {comment=[l]\%,morekeywords={class}}
\lstdefinelanguage{OWL}[]{XML}
  {keywordsprefix={rdf:,rdfs:,owl:}}
\lstset{basicstyle=\scriptsize\tt,columns=flexible}
\lstset{frame=none,numbers=none,lineskip=-.7ex}%,aboveskip=-1em,belowskip=-2em}
\def\tracissue#1{\cite{sTeX:online}, \hyperlink{http://trac.kwarc.info/sTeX/ticket/#1}{issue #1}}
\begin{document}\DocInput{owl2onto.dtx}\end{document}
%</driver>
% \fi
%
%\iffalse\CheckSum{1}\fi
%
% \changes{v0.1}{2010/03/05}{new}
% \changes{v0.2}{2010/06/05}{adapting to OWL/XML syntax}
% 
% \GetFileInfo{owl2onto.cls}
% 
% \MakeShortVerb{\|}
% \def\latexml{{\LaTeX}ML}
%
% \title{\texttt{owl2onto.cls}: Marking up OWL2 Ontologies in
%   \protect\stex.\thanks{Version {\fileversion} (last revised {\filedate})}}
% \author{Michael Kohlhase \\
%   Jacobs University, Bremen\\
%   \url{http://kwarc.info/kohlhase}}
% \maketitle
% \begin{abstract}
%   The |owl2onto| class allows mark up OWL2 Ontologies in \stex and generate OWL2-XML
%   from them via the {\latexml} system.
% \end{abstract}
%
% \setcounter{tocdepth}{2}\tableofcontents\newpage
%\begin{center}\bf\Huge
%  Experimental!\\
%  do not use!
%\end{center}
%
% \section{The User Interface}\label{sec:user}
%
% The |owl2onto| package allows mark up ontology-based Metadata in {\LaTeX} documents that
% can be harvested by automated tools or exported to PDF.\ednote{continue}
% 
% The main idea behind the |owl2onto| class and package is to think of (documented)
% ontologies as documents, which present the knowledge behind ontology informally to the
% (human) reader and at the same time contain enough (hidden) information so that a formal
% ontology can be generated from them.
%
% \subsection{Package Options}\label{sec:user:options}
% 
% The |owl2onto| package takes a single option: \DescribeMacro{showmeta}|showmeta|. If
% this is set, then the metadata keys are shown (see~\cite{Kohlhase:metakeys:ctan} for details
% and customization options).
%
% \subsection{Ontologies}\label{sec:user:ontologies}
% 
% The |owl2onto| class provides the \DescribeEnv{ontology}|ontology| environment
% environment to declare OWL classes; it takes the place of the usual |document|
% environment\footnote{Admittedly, it is somewhat unconventional to use the document
% environment for this, but this is the best way to ensure that we an OWL/XML document
% with a single document root.}, but its optional argument provides |KeyVal| attributes
% that allow to mark up the semantic aspects of the class, see
% Figure~\ref{fig:ontology}. In this example, we only have a single class declaration.
% 
% \begin{exfig}[ht]
% \lstinputlisting[language=owl2onto]{ex1}\hrule
% \srefaddidkey{ontology}
% \addmetakey{ontology}{baseURI}
% \metasetkeys{ontology}{id=foaf,baseURI=http://xmlns.com/foaf/0.1/}
% \makeatletter\def\mod@id{foaf}\makeatother
% \declaration[type=Class,name=Agent,cseq=agent]
% {An agent (eg. person, group, software or physical artifact).}
% \caption{A simple Ontology in {\LaTeX} and its presentation}\label{fig:ontology}
% \end{exfig}
% 
% \subsection{Declarations}\label{sec:user:declarations}
% 
% In general the \DescribeMacro{\declaration}|\declaration| macro can be used to declare
% the objects of various types in an ontology. The \DescribeMacro{type}|type| key is used
% to specify this, its values range over the set\ednote{give a list of all of them.}. The
% \DescribeMacro{name}|name| attribute specifies the name of the declared object. This
% information is used in the XML generation; see Figure~\ref{fig:ontology-owl} for the
% result of generating XML from Figure~\ref{fig:ontology}. Finally, the
% \DescribeMacro{cseq}|cseq| key allows to specify a command sequence for the object,
% which an be used in properties. 
% 
% \begin{exfig}[ht]
% \lstinputlisting[language=OWL]{ex1.owl2}
% \caption{The OWL/XML generated from Figure~\ref{fig:ontology}}\label{fig:ontology-owl}
% \end{exfig}
% 
% \subsection{Properties}\label{sec:user:properties}
% 
% The properties of the declared objects can be stated via the
% \DescribeMacro{\axiom}|\axiom| macro. Its first argument is an OWL formula marked up in
% prefix notation\ednote{explain this better}, and the second one a natural language
% explanation.
% 
% \begin{exfig}[ht]
% \lstinputlisting[language=owl2onto,firstline=3,lastline=3]{ex2}\hrule
% \srefaddidkey{ontology}
% \addmetakey{ontology}{baseURI}
% \metasetkeys{ontology}{id=foaf,baseURI=http://xmlns.com/foaf/0.1/}
% \makeatletter\def\mod@id{foaf}\makeatother\def\doc{document}\def\agent{agent}
% \axiom{$\agent\|\doc$}{Agents are not Documents}\hrule
% \lstinputlisting[language=owl2onto,firstline=4,lastline=11]{ex2.owl2}
% \caption{An Axiom}\label{fig:ontology}
% \end{exfig}
%
% \section{Limitations}\label{sec:limitations}
% 
% In this section we document known limitations. If you want to help alleviate them,
% please feel free to contact the package author. Some of them are currently discussed in
% the \sTeX TRAC~\cite{sTeX:online}. 
% \begin{compactenum}
% \item none reported yet
% \end{compactenum}
% 
% \StopEventually{\printbibliography}
% 
% \section{The Implementation}\label{sec:impl}
% 
% The functionality is spread over the |owl2onto| class and package. The class provides
% the |document| environment and the |ontology| element corresponds to it, whereas the
% package provides the concrete functionality.
% 
% |owl2onto.dtx| generates four files: |owl2onto.cls| (all the code between
% {\textsf{$\langle$*cls$\rangle$}} and {\textsf{$\langle$/cls$\rangle$}}), |owl2onto.sty|
% (between {\textsf{$\langle$*package$\rangle$}} and
% {\textsf{$\langle$/package$\rangle$}}) and their {\latexml} bindings (between
% {\textsf{$\langle$*ltxml.cls$\rangle$}} and {\textsf{$\langle$/ltxml.cls$\rangle$}} and
% {\textsf{$\langle$*ltxml.sty$\rangle$}} and {\textsf{$\langle$/ltxml.sty$\rangle$
% respetively}}). We keep the corresponding code fragments together, since the
% documentation applies to both of them and to prevent them from getting out of sync.
%
% \subsection{The \texttt{owl2onto} Class}
% 
% We first define the |owl2onto| class, which on the {\LaTeX} side just calls the article
% class. 
%    \begin{macrocode}
%<*cls>
\DeclareOption{showmeta}{\PassOptionsToPackage{\CurrentOption}{metakeys}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions
\LoadClass{article}
\RequirePackage{modules}
\RequirePackage{owl2onto}
%</cls>
%<*cltxml>
# -*- CPERL -*-
package LaTeXML::Package::Pool;
use strict;
use LaTeXML::Global;
use LaTeXML::Package;
DeclareOption(undef,sub {PassOptions('article','cls',ToString(Digest(T_CS('\CurrentOption')))); });
ProcessOptions();
LoadClass('article');
RequirePackage('modules');
RequirePackage('owl2onto');
%</cltxml>
%    \end{macrocode}
% 
% Now, we also need to register the namespace prefixes for {\latexml} to use. 
% 
%    \begin{macrocode}
%<*cltxml>
RegisterNamespace('owl'=>"http://www.w3.org/2002/07/owl#");
RegisterNamespace('stex'=>"http://kwarc.info/ns/sTeX");
RegisterNamespace('ltx'=>"http://dlmf.nist.gov/LaTeXML");
RegisterNamespace('omdoc'=>"http://omdoc.org/ns");
%</cltxml>
%    \end{macrocode}
% 
% Since we are dealing with a class, we need to set up the document type in the {\latexml}
% bindings.
% 
%    \begin{macrocode}
%<*cltxml>
RelaxNGSchema('owl2+ltxml',
        '#default'=>"http://www.w3.org/2002/07/owl#",
        'omdoc'=>"http://omdoc.org/ns",
        'ltx'=>"http://dlmf.nist.gov/LaTeXML",
        'stex'=>"http://kwarc.info/ns/sTeX");
%</cltxml>
%    \end{macrocode}
% 
% The |owl2onto| class also supplies the top-level |document| environment, which we
% redefined so that we can provide KeyVal arguments.
% 
% \begin{environment}{document}
%   The |document| environment is redefined to allow a baseURI\ednote{@Deyan, need to
%   remember the baseURI in a keyword, so that we can use it in the class and property
%   environments}
%    \begin{macrocode}
%<*cls>
\srefaddidkey{ontology}
\addmetakey{ontology}{baseURI}
\newcommand{\ontology}[1][]{\document\metasetkeys{ontology}{#1}%
\importmodule[owl2]{OWL2}%
\ifx\sref@id\@empty\begin{module}\else\begin{module}[id=\sref@id]\fi}
\newcommand{\endontology}{\end{module}\enddocument}
%</cls>
%<*cltxml>
DefEnvironment('{ontology} OptionalKeyVals:omdoc',
	       "<owl:Ontology "
	      .    "?&KeyVal(#1,'id')(xml:id='&KeyVal(#1,'id')')() "
              .    "?&KeyVal(#1,'baseURI')(xml:base='&KeyVal(#1,'baseURI')/')() "
              .    "?&KeyVal(#1,'baseURI')(ontologyIRI='&KeyVal(#1,'baseURI')')() "
	      .    "?#locator(stex:srcref='#locator')()>"
              .   "#body"
	      ."</owl:Ontology>",
	       beforeDigest=> sub { AssignValue(inPreamble=>0); },
	       afterDigest=> sub { $_[0]->getGullet->flush; return; });#$
%</cltxml>
%    \end{macrocode}
% \end{environment}
% 
% \subsection{Classes and Properties}\label{sec:impl:classes}
% 
% Before we provide the core functionality, we need to ensure that the |modules| and
% |presentation| packages are loaded. For {\latexml} we also initialize the package
% inclusions.
%
%    \begin{macrocode}
%<*package>
\RequirePackage{amstext}
\RequirePackage{presentation}
%</package>
%<*sltxml>
# -*- CPERL -*-
package LaTeXML::Package::Pool;
use strict;
use LaTeXML::Global;
use LaTeXML::Package;
%</sltxml>
%    \end{macrocode}
%
% We first ste up a utility macro that allows us to export values
% \begin{macro}{\exportvalue}
%    \begin{macrocode}
%<*package>
\def\exportvalue#1#2{%
\expandafter\def\csname\declaration@cseq #2\expandafter\endcsname\expandafter{#1}
\expandafter\g@addto@macro\csname module@defs@\mod@id\expandafter\endcsname\expandafter%
{\expandafter\def\csname\declaration@cseq #2\expandafter\endcsname\expandafter{#1}}}
%</package>
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\declaration}
%    \begin{macrocode}
%<*package>
\addmetakey{declaration}{id}
\addmetakey{declaration}{cseq}
\addmetakey{declaration}{type}
\addmetakey{declaration}{name}
\newcommand{\declaration}[2][]{\metasetkeys{declaration}{#1}%
\ifx\declaration@cseq\@empty\else
\expandafter\exportvalue{\ontology@baseURI\declaration@name}{@URI}
\expandafter\exportvalue{\expandafter\text\declaration@name}{}
\fi
\noindent\textbf{\declaration@type: \declaration@name}\par\noindent #2\par\noindent}
%</package>
%<*sltxml>
DefMacro('\declaration OptionalKeyVals:declaration {}', sub {
 my ($self,@args)=@_;
 my $name = ToString(KeyVal($args[0],'name')) if $args[0];
 my $cseq = ToString(KeyVal($args[0],'cseq')) if $args[0];
 DefConstructor("\\".$cseq,"<XMTok name='$name'/>",
		properties=>{mode=>'math',requiremath=>1}) 
                if ($cseq && $name);
 (Invocation(T_CS('\@declaration'),@args)->unlist);
});
DefConstructor('\@declaration OptionalKeyVals:declaration {}', sub {
  my ($document, $keyval, $arg, %properties) = @_;
  my $type = ToString(KeyVal($keyval,'type'));
  my $name = ToString(KeyVal($keyval,'name'));
  $document->openElement('owl:Declaration','stex:srcref'=>$properties{'locator'});
  $document->insertElement('owl:'.$type,undef,(IRI=>$name)) if $type;
  $document->closeElement('owl:Declaration');
  if (defined $arg) {
    $document->openElement('owl:AnnotationAssertion');
    $document->insertElement('owl:AnnotationProperty',undef,(IRI=>'http://www.w3.org/2000/01/rdf-schema#comment'));
    $document->insertElement('owl:IRI',$name);
    $document->insertElement('owl:Literal',$arg);
    $document->closeElement('owl:AnnotationAssertion');
  }
});#$
%</sltxml>
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\axiom}
%    \begin{macrocode}
%<*package>
\addmetakey{axiom}{id}
\addmetakey{axiom}{cseq}
\addmetakey{axiom}{type}
\addmetakey{axiom}{name}
\newcommand{\axiom}[3][]{\metasetkeys{axiom}{#1}%
\noindent\textbf{Axiom:} #2\par\noindent #3\par\noindent}
%</package>
%<*sltxml>
DefConstructor('\axiom OptionalKeyVals:axiom {}{}',
           "<owl:Axiom>#2"
          ."?#3(<owl:Annotation>"
          .      "<owl:AnnotationProperty IRI='http://www.w3.org/2000/01/rdf-schema#comment'/>"
          .      "<owl:Literal>#3</owl:Literal>"
          .    "</owl:Annotation>)()"
          ."</owl:Axiom>");
%</sltxml>
%    \end{macrocode}
% \end{macro}
% 
% \subsection{Using Ontologies}\label{sec:impl:using}
%
% % \begin{macro}{useontology}
%    \begin{macrocode}
%<*package>
\def\useontology#1#2{\input}
%</package>
%    \end{macrocode}
% \end{macro}
% 
% \subsection{Finale}
%
% Finally, we need to terminate the file with a success mark for perl.
%    \begin{macrocode}
%<cltxml|sltxml>1;
%    \end{macrocode}
% \Finale
\endinput
% \iffalse
% LocalWords:  GPL structuresharing STR LaTeX dcm dtx keyval sref CPERL url qw
%%% Local Variables: 
%%% mode: doctex
%%% TeX-master: t
%%% End: 
% \fi



% LocalWords:  RequirePackage birthdate personaltitle academictitle workaddress
% LocalWords:  privaddress worktel privtel workfax privfax worktelfax noDelim
% LocalWords:  privtelfax getKeyValue valuelist ToString getValue affill STDERR
% LocalWords:  ExportMetadata AssignValue DCMperson DefConstructor afterDigest
% LocalWords:  getArg setValue FishOutMetadata keyvals foreach idlist tabline
% LocalWords:  LookupValue insertElement atabline bitabline shorttitle nc args
% LocalWords:  sharealike noderivativeworks DefMacro authorblock subsubsection
% LocalWords:  contribs OptionalKeyVals omgroup omdoc srcref locator xml RawTeX
% LocalWords:  openElement iffalse kohlhase Thu owl2onto.cls latexml texttt cls
% LocalWords:  stex fileversion maketitle setcounter tocdepth tableofcontents
% LocalWords:  newpage ednote DescribeEnv exfig lstinputlisting hrule
% LocalWords:  srefaddidkey foaf makeatletter makeatother cseq impl
% LocalWords:  firstline lastline printbibliography cltxml ltx ltxml Deyan ifx
% LocalWords:  newcommand endontology amstext sltxml exportvalue expandafter
% LocalWords:  csname expandafter endcsname expandafter defs noindent textbf
% LocalWords:  noindent noindent requiremath unlist useontology doctex
