How can I use Tika Parsers in Tika Core?

Viewed 91

I use tika-core v.1.25 in my project:

<dependency>
    <groupId>org.apache.tika</groupId>
    <artifactId>tika-core</artifactId>
    <version>1.25</version>
    <type>jar</type>
</dependency>

When I need parse my file, I use AutoDetectParser :

InputStream is = new BufferedInputStream(new FileInputStream("D:\Files\test.txt"));
BodyContentHandler ch = new BodyContentHandler(-1); 
Metadata metadata = new Metadata();
ParseContext pc = new ParseContext(); 

AutoDetectParser parser = new AutoDetectParser();
parser.parse(is, ch, metadata, pc); 

AutoDetectParser located in project tika-core:

Apache Tika Core
  org.apache.tika.parser
    AutoDetectParser .java

But at the same time, this class AutoDetectParser does not interact with classes from the project tika-parsers. But at the same time, I need the capabilities of all the parsers that sit in the tika-passers.

For example:

tika-parsers
  org.apache.tika.parser
    apple
      AppleSingleFileParser.java
    asm
      ClassParser.java
    ...
    xliff
      XLZParser.java
    xml
      XMLParser.java

As far as I understand, these are different projects, and for their work you need to write the binding class itself

At the moment my main thought is to use the desired parser instead of the AutoDetectParser parser. For example, if I have file 12312.txt, I parse it through TXTParser, not AutoDetectParser. Or 1213.pdf, so - PDFParser.

But I wonder if there is a wrapper over these parsers or an abstraction level or a class that can properly organize the work of parsers. So that I do not have to manually understand the extension and select the parser.

Tell me how can I organize the work of tika-core in such a way that parsers from the tika-parsers project can be used?

1 Answers

Apparently your dependency is well configured, if it is in the correct pom (the main one). I'm not sure of really understanding your project structure, but I'd like to share two links that I used when implemented tika in my project:

  1. Apache Tika - Getting Started
  2. Content Analysis with Apache Tika Don't know if it is your case, but mine was using spring, and following these steps was relatively easy.

Hope it helps

Related