Web::RDF::Checker
RDF syntax checker
SYNOPSIS
use Web::RDF::Checker;
$checker = Web::RDF::Checker->new;
$checker->onerror (sub { ... });
$checker->check_parsed_term ($term);
DESCRIPTION
The Web::RDF::Checker
module has a module to check syntax of an RDF term. Note that the module does not support RDF Schema or any other specific vocabulary describing restrictions or characteristics of RDF triples and/or graphs.
METHODS
Following methods are available:
$checker = Web::RDF::Checker->new
-
Create a new checker.
$checker->check_parsed_term ($term)
-
Check the syntax of the specified parsed term. The argument must be a parsed term data structure. Any syntax error is reported through the
onerror
handler. $code = $checker->onerror
$checker->onerror ($new_code)
-
Get or set the error handler for the checker. Any conformance error, as well as warning and additional processing information, is reported to the handler. See
<https://github.com/manakai/data-errors/blob/master/doc/onerror.txt>
for details of error handling.The value should not be set while the parser is running. If the value is changed, the result is undefined.
$code = $checker->onparentnode
$checker->onparentnode ($new_code)
-
Get or set the code reference that is invoked when a DOM
ParentNode
should be validated. This hook is intended for integrating validation of RDF terms and HTML or XML fragments, especially when an RDF/XML fragment is embedded within an XML document.The code reference is expected to not throw any exception. Any conformance error should be handled by itself.
The value should not be set while the parser is running. If the value is changed, the result is undefined.
$boolean = $checker->scripting
$checker->scripting ($boolean)
-
Get or set the scripting flag for the checker. The scripting flag is used to parse HTML fragments embedded within the term.
PARSED TERM DATA STRUCTURE
A parsed term data structure represents a term (i.e. a URL, a blank node identifier, or a literal) in RDF. It is a hash reference with one or more of following key/value pairs:
- url
-
The URL, used to identify a resource. (This is referred to as "RDF URI reference" in RDF 1.0 or "IRI" in RDF 1.1.) This is a Perl string of zero or more characters. In RDF, it must be an absolute URL. However, in a parsed term data structure, it can be a relative URL to represent a non-conforming term.
- bnodeid
-
The blank node identifier, i.e. a graph-local ID identifying a blank node. This is a Perl string of zero or more characters.
- lexical
-
The lexical form of a literal. This is a Perl string of zero or more characters. In RDF, it must be a Unicode string. However, in a parsed term data structure, it can contain non-Unicode characters and surrogate code points to represent a non-conforming term.
- parent_node
-
The parent node of zero or more DOM nodes contained by an XML literal. It is a DOM
ParentNode
object, implementing manakai's DOM Perl Binding specification (e.g. Web::DOM::ParentNode). The node itself is not part of the literal. - lang
-
The language tag of a language-tagged string. It is a Perl string of zero or more characters. In RDF, it must be a well-formed BCP 47 language tag. However, in a parsed term data structure, it can be any string to represent a non-conforming term.
- datatype_url
-
The datatype URL of a literal. (This is referred to as "datatype URI (RDF URI reference)" in RDF 1.0 or "datatype IRI" in RDF 1.1.) This is a Perl string of zero or more characters. In RDF, it must be an absolute URL. However, in a parsed term data structure, it can be a relative URL to represent a non-conforming term.
An RDF term can be constructed by applying the following steps to a parsed term data structure /value/:
1. If /value/ has non-|undef| |url|, return URL |url| and abort
these steps.
2. If /value/ has non-|undef| |bnodeid|, return blank node whose ID
is |bnodeid| and abort these steps.
3. If /value/ has |parent_node|, return a literal whose lexical form
is |inner_html| of /value/'s |parent_node| and datatype URL (or
"IRI" in RDF 1.1) is /value/'s |datatype_url| (or the empty
string if it is |undef|) and abort these steps.
4. If /value/ has non-|undef| |lang|, return a literal whose lexical
form is /value/'s |lexical|, language tag is /value/'s
|language|, and datatype URL (or "IRI" in RDF 1.1) is
|http://www.w3.org/1999/02/22-rdf-syntax-ns#langString| and abort
these steps.
5. Otherwise, return a literal whose lexical form is /value/'s
|lexical| (or the empty string if it is |undef|) and datatype URL is
/value/'s |datatype_url|, if not |undef|, or
|http://www.w3.org/2001/XMLSchema#string|, otherwise.
This data structure is supported by Web::RDF::Checker and Web::RDF::XML::Parser.
DEPENDENCY
In addition to the dependency described in the README file <https://github.com/manakai/perl-web-markup/blob/master/README.pod#dependency>
, following modules (and modules required by them) are required by this module:
- perl-web-langtag <https://github.com/manakai/perl-web-langtag>
- perl-web-url <https://github.com/manakai/perl-web-url>
SPECIFICATIONS
- RDF
-
RDF 1.1 Concepts and Abstract Syntax
<http://www.w3.org/TR/rdf11-concepts/>
. - RDFXML
-
RDF 1.1 XML Syntax
<http://www.w3.org/TR/rdf-syntax-grammar/>
. - VALLANGS
-
Handling of unknown namespaces in conformance checking
<http://suika.suikawiki.org/www/markup/xml/validation-langs>
.
AUTHOR
Wakaba <wakaba@suikawiki.org>.
LICENSE
Copyright 2014 Wakaba <wakaba@suikawiki.org>.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.