View Source

| *Title* | _The Tika Characterisation Tool_ |
| *Detailed description* | _Tika have been chosen as a useful tool for the PC CC workpackage. This site details the information we have acquired about the tool_ |
| *[Solution Champion|SP:Responsibilities of the roles described on these pages]* \\ | _Asger Askov Blekinge, Markus Raditsch?, Peter May (BL)_ |
| *Corresponding Issue(s)* \\ | _A bulletted list of links to Issues to which this provides a Solution_ \\ |
| *myExperiment Link* | [Basic Apache TIKA 1.0 workflow|]\\
[Simple Tika RESTful web service workflow|] |
| *Tool Registry Link* \\ | _[]_ \\ |
| *Evaluation* \\ | _Any notes or links on how the solution performed. This will be developed and formalised by the Testbed SP._ \\
Some initial evaluation of identification tools can be found here: [SP:SO3 Comparing identification tools] |

h2. Status

h4. Instability, and its effect on performance

Tika does have the ability to run on multiple input files, as one process. Given the startup-cost of the JVM, this seems like an important performance boost. However, for this to be usable, Tika needs to be stable enough to run through the entire list, even if some of the files are unparsable. 

This is not the case, at present. TODO, FINISH THIS

h4. Tika Crashes

Some experimentation with large TIFF files results in Tika crashing when parsing due to lack of heap space. Simply adding \-Xmx1024m (or even 512m) to the Java command line when running Tika solves this problem. Identification only should not be affected as this only reads in a small (8K) buffer from the file.

This does not rule out the case that other files may cause other (possibly parsing) issues that crash Tika.

h4. Tika RESTful service and Taverna Workflow

The SCAPE github repository provides a toolspec for creating a Tika web service ([]).  This service can currently be used with Taverna Workflows however Tika control is via the Command Line Interface (CLI) and requires a local Tika installation.  Instead, a RESTful web service could be hosted externally (to their local machine, e.g. on the web) to provide an accessible and scalable service for use in Taverna workflows, something like:

* GET Tika/rest/mime?file=<path_to_file>
* GET Tika/rest/parse?file=<path_to_file>

Source code can currently be found at&nbsp;[|]&nbsp; This wraps the&nbsp;OpenPlanets Tika fork ([]) in a RESTful web service built using Jersey ([])

# Formulate and document API

h4. Can Tika support extended/fine-grained mime types?

Updated the Tika signature file with additional mime-type XML fragments specifying PDF version in the ‘type’ attribute and the version number in the magic match value. &nbsp;This new fragment was also specified as a sub-class-of the generic PDF:
<mime-type type="application/pdf; version=1.0">
  <acronym>PDF 1.0</acronym>
  <_comment>Portable Document Format - Version 1.0</_comment>
  <sub-class-of type="application/pdf"/>
  <magic priority="50">
    <match value="%PDF-1.0" type="string" offset="0"/>
Minor updates were also required to the unit tests to account for the version being reported in the mime-type.&nbsp;

Currently only supports PDF versioning, so further work is needed to add versions to other mime-types.

h4. Can Tika be extended to support regexp like Fido?

Prototype of Tika ([|]) up and running that used regular expressions for identification.&nbsp; The <match> element for PDF-1.4 was modified to use the regular expression from Fido’s signature file, although this required a slight modification (‘\’ have to be escaped):
<mime-type type="application/pdf; version=1.0">
  <acronym>PDF 1.0</acronym>
  <_comment>Portable Document Format - Version 1.0</_comment>
  <sub-class-of type="application/pdf"/>
  <magic priority="55">
    <match value="(?s)\\A.{0,144}%PDF-1\\.0" type="regex" offset="0"/>
The Tika signature file is based on the Freedesktop MIME-info format ([|]).&nbsp; The <match> element’s ‘type’ attribute was extended to “regex”.

h4. Processing order of Mime-types in the Tika Signature file

Magic patterns are stored in a [TreeSet|], sorted in *descending* order according to the following four rules (in precedence order):

# Magic Priority
# Maximum total length of the Magic pattern value (and all nested patterns)
# String comparison of MIME type
# String comparison based on the constructed string “\[“+priority+”/”\+_String_representation_of_the_matching_clauses_\+”\]”

_String_representation_of_the_matching_clauses_ is a String made up of the MIME type, pattern length, pattern and any mask:

"Magic Detection for " + type.toString() +
" looking for " + pattern.length +
" bytes = " + this.pattern +
" mask = " + this.mask;
(nested clauses are AND’d and OR’d together where nested patterns are involved)

h6. Conclusions:

* Ordering of XML mime-type fragments in the signature file has no effect (because the TreeSet orders the patterns)
* Higher priority fragments are matched first
* Equal priority fragments match against the longer "match value" first (e.g. against “%PDF-1.4” match value first rather than “%PDF-”)
* Equal priority, equal “match value” length fragments match against the lexicographically *greater* MIME type first (e.g. “application/rtf” before “application/pdf”)