#!/usr/bin/perl -Tw
#
# parse.pl - Redland RDF Parsing demo
#
# $Id: parse.pl 10590 2006-03-05 08:13:09Z cmdjb $
#
# Copyright (C) 2005-2006 David Beckett - http://purl.org/net/dajobe/
# Copyright (C) 2005 University of Bristol - http://www.bristol.ac.uk/
#
# This package is Free Software or Open Source available under the
# following licenses (these are alternatives):
# 1. GNU Lesser General Public License (LGPL)
# 2. GNU General Public License (GPL)
# 3. Mozilla Public License (MPL)
#
# See LICENSE.html or LICENSE.txt at the top of this package for the
# full license terms.
#
#
#
use strict;
# Helps with broken web requests (missing headers)
$ENV{'Content-Length'}||=0;
# Tainting, dontcha know
$ENV{'HTTP_HOST'}='librdf.org';
$ENV{'PATH'}="/bin:/usr/bin";
# Standard perl modules
use CGI;
use LWP::Simple;
use URI::URL;
# Configuration
my(@parser_syntaxes)=qw(rdfxml ntriples turtle rss-tag-soup grddl guess),
my(%parser_syntax_labels)=('rdfxml' =>'RDF/XML',
'ntriples' =>'N-Triples',
'turtle' =>'Turtle',
'rss-tag-soup' =>'RSS Tag Soup',
'grddl' => 'GRDDL',
'guess' => 'Guess via MIME type and URI'
);
my $default_parser_syntax='rdfxml';
my(%parser_blurbs)=(
'rdfxml' => <RDF/XML is defined in the RDF/XML (Revised) W3C Recommendation
EOT
,
'ntriples' => <N-Triples is defined in the
RDF Test Cases W3C Recommendation
EOT
,
'turtle' => <Turtle is the Terse RDF Triple Language
EOT
,
'rss-tag-soup' => <RSS Tag Soup reads any RSS syntax including Atom.
EOT
,
'grddl' => <Gleaning Resource Descriptions from Dialects of Languages (GRDDL) from XHTML documents.
EOT
);
my $log_file="/home/dajobe/demo.librdf.org/logs/parser.log";
# see FIXMEs below
my $max_stream_size=200;
my $max_result_size=200;
my(%namespaces)=(
'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
'dc' => 'http://purl.org/dc/elements/1.1/',
'owl' => 'http://www.w3.org/2002/07/owl#',
# 'xsd' => 'http://www.w3.org/2001/XMLSchema#',
'foaf' => 'http://xmlns.com/foaf/0.1/',
'dcterms' => 'http://purl.org/dc/terms/',
'bot' => 'http://www.w3.org/2001/sw/Europe/200401/bot/terms\#',
);
# Redland perl modules
use RDF::Redland;
# $RDF::Debug=1;
######################################################################
# Subroutines
sub log_action ($$$;$) {
my($host, $db, $message, $now)=@_;
$now ||= time;
return unless open (LOG, ">>$log_file");
my($sec,$min,$hour,$mday,$mon,$year)=gmtime $now;
my $date=sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",1900+$year,$mon+1,$mday,$hour,$min,$sec);
$message =~ s/[\n\s]+/ /gs
if $message;
print LOG "$host $date $db $message\n";
close(LOG);
}
sub end_page($) {
my $q=shift;
print <<'EOT';
The source code of this demonstration is available in the Redland
bindings distribution as demos/parse.pl or from the
Redland website
EOT
print qq{
\n\nDave Beckett
\n\n