Validation and Fixing

Introduction

Apache Any23 Is able to detect ill-formed HTML DOM content and apply fixes over it.

This section will show how to write RDFa validation Rule and Fix for RDFa.

It's widely recognized that RDFa is subjected to a plethora of different and common mistakes. These errors may lead to a failures during RDF extraction process from HTML pages but since they are, typically, syntax errors they could be easily detected and fixed with some heuristics.

This pages describes the Apache Any23 rule-based approach, that allows it to detect, fix and correctly extract RDF from those ill-formed RDFa in XHTML pages.

More specifically, Apache Any23 allows you to write a Rule able to detect the errors, a Fix containing the logic to fix the problem and a Validator which acts as a register of rules and fixes. The Validator calls all the registered rules and when one of them is applied it calls the associated Fix.

The following code snipped shows how to programmatically detect and fix a very common data error with Apache Any23.

Fix Missing Prefix Mappings Declaration

Sometimes, web authors forget to declare prefix mappings. For example, you can't just use something like dcterms:title without first declaring the dcterms prefix mapping. If a prefix mapping isn't declared, the RDFa parser won't understand the prefix when it is used in your document. This may lead Apache Any23 to don't extract such embedded RDF triples.

This:

<div>
The title of this document is <span property="dcterms:title">Why RDFa is Awesome</span>.
</div>

Should be:

<div xmlns:dcterms="http://purl.org/dc/terms/">
The title of this document is <span property="dcterms:title">Why RDFa is Awesome</span>.
</div>

With the Apache Any23Validator classes it's possible to solve this problem simply implementing the Rule interface as described below:

The MissingOpenGraphNamespaceRule inspects the DOM structure of the HTML page and if it finds some META tags with some RDFa property (of the OpenGraph Protocol vocabulary, in this case) it looks for the declaration of that name space. If there is no declaration it return true, that means that an error has been detected within the document.