#!/usr/local/bin/perl eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}' if 0; # not running under some shell ############################################################################## # Copyright (c) 2000-2006 All rights reserved # Alberto Reggiori # Dirk-Willem van Gulik # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # 3. The end-user documentation included with the redistribution, # if any, must include the following acknowledgment: # "This product includes software developed by # Alberto Reggiori and # Dirk-Willem van Gulik ." # Alternately, this acknowledgment may appear in the software itself, # if and wherever such third-party acknowledgments normally appear. # # 4. All advertising materials mentioning features or use of this software # must display the following acknowledgement: # This product includes software developed by the University of # California, Berkeley and its contributors. # # 5. Neither the name of the University nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # 6. Products derived from this software may not be called "RDFStore" # nor may "RDFStore" appear in their names without prior written # permission. # # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. # # ==================================================================== # # This software consists of work developed by Alberto Reggiori and # Dirk-Willem van Gulik. The RDF specific part is based on public # domain software written at the Stanford University Database Group by # Sergey Melnik. For more information on the RDF API Draft work, # please see # The DBMS TCP/IP server part is based on software originally written # by Dirk-Willem van Gulik for Web Weaving Internet Engineering m/v Arnhem, # The Netherlands. # ############################################################################## use Carp; use RDFStore::Model; use RDFStore::NodeFactory; use RDFStore::Parser::SiRPAC; use RDFStore::Vocabulary::RDF; use RDFStore::Vocabulary::RDFS; my $Usage =< 3, Style => 'RDFStore::Parser::Styles::RDFStore::Model', NodeFactory => $factory, store => { seevalues => $verbose } ); my $m; if($stuff =~ /^-/) { # for STDIN use no-blocking $m = $p->parsestream(*STDIN); } else { $m = $p->parsefile($schema_file); }; if($examples) { my $p1=new RDFStore::Parser::SiRPAC( ErrorContext => 3, Style => 'RDFStore::Parser::Styles::RDFStore::Model', NodeFactory => $factory, store => { seevalues => $verbose } ); my $m_e = $p1->parsefile($examples); my $exs = $m_e->elements; while (my $e = $exs->each ) { $m->add($e); }; }; my @namespaces = $m->namespaces; $name = 'RDFDoc' unless($name); my $date = `date`; chop($date); # toc.html &toc(); sub toc { open(TOC,">$outdir/toc.html"); print TOC < $name - Class Hierarchy

Class Hierarchy for $name Project


    EOFHTML #take top classes my $top_classes=$m->find(undef,$RDFStore::Vocabulary::RDF::type,$RDFStore::Vocabulary::RDFS::Class)->elements; if($top_classes->size <= 0 ) { die "No rdfs:Class(es) found in $schema_file!\n"; }; while ( my $top_class = $top_classes->each_subject ) { my $sc = $m->find($top_class,$RDFStore::Vocabulary::RDFS::subClassOf)->elements; my $ns = $sc->first_object; $ns = $ns->getNamespace if($ns); next unless( $sc->size <=0 or $sc->size==1 and $sc->first_object->equals($RDFStore::Vocabulary::RDFS::Resource) or $sc->size==1 and (! grep /^$ns$/,@namespaces ) ); &visit_class( $top_class, *TOC ) ; }; print TOC <
    Generated on $date EOFHTML close(TOC); }; # example sub example { my ($example,$class_name) = @_; my $example_name = ($example->isbNode) ? $example->toString : $example->getLocalName; open(EXAMPLE,">$outdir/$example_name.html"); print EXAMPLE < Project: $name - Example of $class_name Class - $example_name

    Project: $name
    Example $example_name

    Example of $class_name Class 
           
    EOFHTML my $slots = $m->find($example)->elements; while ( my $s = $slots->each) { next if( $s->predicate->equals( $RDFStore::Vocabulary::RDF::type ) ); my $slot_name = $s->predicate->getLocalName; my $value = $s->object; my $type; my $tt; if($value->isa("RDFStore::Resource")) { $type = $m->find($value, $RDFStore::Vocabulary::RDF::type)->elements->first_object; if( $value->isbNode ) { my $ll = $m->find($value, $RDFStore::Vocabulary::RDFS::label)->elements->first_object; #pick up rdfs:label of it if there $ll = ($ll) ? $ll->toString : 'bNode'; $value = "$ll"; } else { my $ns = $value->getNamespace; if( grep /^$ns$/, @namespaces ) { $value = "".$value->getLocalName.""; } else { $tt = 'Resource
    (controlled list)'; $value = $value->getLocalName; }; }; } else { $value = $value->toString; }; unless($tt) { if($type) { $type = $type->getLocalName; $type = " (of class ".$type.")"; $tt = 'Instance'; } else { $tt = 'String'; }; }; print EXAMPLE < EOFHTML }; print EXAMPLE <

    Return to class hierarchy


    Generated on $date EOFHTML close(EXAMPLE); }; sub visit_class { my ($top_class, $fh, $parent_slots ) = @_; my $class_name = $top_class->getLocalName; print $fh < $class_name EOFHTML my $examples = $m->find(undef,$RDFStore::Vocabulary::RDF::type, $top_class); if($examples->size > 0 ) { $examples = $examples->elements; print $fh < Examples : EOFHTML my $max_examples=3; #avoid a complete messy HTML page... my $ex_i=0; while ( my $ex = $examples->each_subject ) { last if($ex_i == $max_examples); my $ll = $m->find($ex, $RDFStore::Vocabulary::RDFS::label)->elements->first_object; #pick up rdfs:label of it if there my $example_name; if($ex->isbNode) { $example_name = $ex->toString; $ll = ($ll) ? $ll->toString : 'bNode'; } else { $example_name = $ex->getLocalName; $ll = ($ll) ? $ll->toString : $example_name; }; print $fh "$ll "; &example( $ex, $class_name ); $ex_i++; }; print $fh < EOFHTML }; my $slots = $m->find(undef,$RDFStore::Vocabulary::RDFS::domain, $top_class)->elements; $slots = $slots->unite( $parent_slots ) if($parent_slots); my $sc = $m->find(undef, $RDFStore::Vocabulary::RDFS::subClassOf, $top_class)->elements; print $fh '
      ' if($sc->size>0); while( my $es = $sc->each_subject) { &visit_class( $es, $fh, $slots ); }; print $fh '
    ' if($sc->size>0); &class($top_class, $slots); }; # class sub class { my ($class,$slots) = @_; my $class_name = ($class->isbNode) ? $class->toString : $class->getLocalName; my $base_class = $m->find($class,$RDFStore::Vocabulary::RDFS::subClassOf)->elements; if($base_class->size > 0 and ! $base_class->first_object->equals($RDFStore::Vocabulary::RDFS::Resource) ) { $base_class = $base_class->first_object; my $ns = $base_class->getNamespace; if( ! grep /^$ns$/, @namespaces ) { $base_class = $base_class->toString; } else { $base_class = ($base_class->isbNode) ? $base_class->toString : $base_class->getLocalName; $base_class = "$base_class"; }; } else { $base_class = ':THING'; }; open(CLASS,">$outdir/$class_name.html"); print CLASS < Project: $name - Example of $class_name Class - $class_name

    Project: $name
    Class $class_name

    Concrete Class Extends 
            $base_class
     
    Direct Examples:
    EOFHTML my $examples = $m->find(undef,$RDFStore::Vocabulary::RDF::type, $class); if($examples->size > 0 ) { $examples = $examples->elements; while ( my $ex = $examples->each_subject ) { if($ex->isbNode) { my $example_name = $ex->toString; my $ll = $m->find($ex, $RDFStore::Vocabulary::RDFS::label)->elements->first_object; #pick up rdfs:label of it if there $ll = ($ll) ? $ll->toString : 'bNode'; print CLASS "$ll "; } else { my $example_name = $ex->getLocalName; print CLASS "$example_name "; }; }; } else { print CLASS "None"; }; print CLASS <
     
    Direct Subclasses:
    EOFHTML my $sub_classes = $m->find(undef,$RDFStore::Vocabulary::RDFS::subClassOf, $class)->elements; if($sub_classes->size > 0) { print CLASS "
      "; while ( my $sc = $sub_classes->each_subject ) { if($sc->isbNode) { my $sc_name = $sc->toString; my $ll = $m->find($sc, $RDFStore::Vocabulary::RDFS::label)->elements->first_object; #pick up rdfs:label of it if there $ll = ($ll) ? $ll->toString : 'bNode'; print CLASS "
    1. $ll
    2. "; } else { my $sc_name = $sc->getLocalName; print CLASS "
    3. $sc_name
    4. "; }; }; print CLASS "
    "; } else { print CLASS "None"; }; print CLASS <
     

    Own Slots
    Slot name Value  Type
    $slot_name  $value$type  $tt 
    EOFHTML while ( my $s = $slots->each_subject) { my $slot_name = $s->getLocalName; my $comment = $m->find($s,$RDFStore::Vocabulary::RDFS::comment)->elements; if($comment->size>0) { $comment=$comment->first_object->toString; } else { $comment=''; }; my $tt=$m->find($s,$RDFStore::Vocabulary::RDFS::range)->elements; my $ranges; if($tt->size > 0 and ! $tt->first_object->equals($RDFStore::Vocabulary::RDFS::Literal) ) { while(my $rr=$tt->each_object) { if($rr->isbNode) { my $rr_name = $rr->toString; my $ll = $m->find($rr, $RDFStore::Vocabulary::RDFS::label)->elements->first_object; #pick up rdfs:label of it if there $ll = ($ll) ? $ll->toString : 'bNode'; $ranges .= "$ll "; } else { my $rr_name = $rr->getLocalName; if( ($rr->getNamespace eq 'http://www.w3.org/2000/10/XMLSchema#') || ($rr->getNamespace eq 'http://www.w3.org/2001/XMLSchema#') ) { $ranges .= "$rr_name "; } else { $ranges .= "$rr_name "; }; }; }; $tt = 'Instance'; } else { $tt = 'String'; }; my $max = $m->find($s,$factory->createResource('http://www.w3.org/2002/07/owl#maxCardinality'))->elements; if($max->size > 0) { $max = $max->first_object->toString; } else { $max = 'n'; }; my $min = $m->find($s,$factory->createResource('http://www.w3.org/2002/07/owl#minCardinality'))->elements; if($min->size > 0) { $min = $min->first_object->toString; } else { $min = '0'; }; print CLASS < EOFHTML }; print CLASS <

    Return to class hierarchy


    Generated on $date EOFHTML close(CLASS); };
    Template Slots
    Slot name Documentation Type Allowed Values/Classes Cardinality Default
    $slot_name $comment  $tt  $ranges  $min:$max