DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Document Generation API: How to Automate Personalized Document Creation at Scale
  • Extracting Clean Excel Tables From PDFs Using Python + Docling
  • AI-Powered Knowledge: LlamaIndex and Apache Tika for Enterprises
  • Why Whole-Document Sentiment Analysis Fails and How Section-Level Scoring Fixes It

Trending

  • AWS Managed Database Observability: Monitoring DynamoDB, ElastiCache, and Redshift Beyond CloudWatch
  • Chat with Your Oracle Database: SQLcl MCP + GitHub Copilot
  • We Went Multi-Cloud and Almost Drowned: Lessons From Running Across AWS, GCP, and Azure
  • The Update Problem REST Doesn't Solve

Apache Tika and Apache OpenNLP for Easy PDF Parsing and Munching

Learn how to parse PDFs with ease — and without any code — using the updated Apache Tika and Apache OpenNLP processors for Apache 1.5.

By 
Tim Spann user avatar
Tim Spann
DZone Core CORE ·
Jan. 23, 18 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
15.7K Views

Join the DZone community and get the full member experience.

Join For Free

I have just started working on updated Apache Tika and Apache OpenNLP processors for Apache 1.5 and while testing, I found an interesting workflow that I would like to share.

I am using a few of my processors in this flow:

  • Attribute Cleaner (just updated)
  • Apache OpenNLP Processor
  • Apache Tika Processor (this needs a major version refresh)

Here is the flow that I was working on:

  • Load some PDFs.

  • Use the built-in Apache Tika processor to extract metadata from the files.

  • Pull out the text using your Apache Tika processor.

  • Split this into individual lines.

  • Extract out the text of the line into an attribute (i.e. (^.*$)) into a sentence.

  • Run NLP to analyze names and locations on that sentence.

  • Run Stanford CoreNLP sentiment analysis on the sentence.

  • Run your attribute cleaner to turn those attributes into AVRO safe names.

  • Turn all the attributes into a JSON Flow File.

  • Infer an Avro schema (I only needed this once; then, I'll remove it).

  • Set the name of the Schema to be looked up from the Schema Registry.

  • Run QueryRecord to route positive, neutral, and negative sentiments to different places. Example SQL: SELECT * FROM FLOWFILE WHERE sentiment = 'NEGATIVE'. Thanks, Apache Calcite! We also convert from JSON to Avro to send to Kafka, as well as for easy conversion to Apache ORC for Apache Hive usage.

  • Send records to Kafka 1.0. Some are merged to store as files and some are made into Slack messages.

  • Done!

Here is an example of my generated JSON file.

Here are some of the attributes after the run.

You can see the queries in the QueryRecord processor.

The results of a run showing a sentence, file metadata, and sentiment.

We are now waiting for new PDFs (and other file types) to arrive in the directory for immediate processing.

I have a JSONTreeReader, a Hortonworks Schema Registry, and AvroRecordSetWriter.

We set the properties and the schema registry for the reader and writer. Obviously, we can use other readers and writers as needed for types like CSV.

When I'm done, since it's Apache NiFi 1.5, I commit my changes for versioning.

For the upcoming processor, I will be interfacing with OCR, NER, NLTK, Grobid quantities, MITIE, age detection, vision, deep learning, and image captioning with Apache Tika.

Apache Tika has added some really cool updates, so I can't wait to dive in.

Apache Tika Apache OpenNLP PDF OpenNLP

Opinions expressed by DZone contributors are their own.

Related

  • Document Generation API: How to Automate Personalized Document Creation at Scale
  • Extracting Clean Excel Tables From PDFs Using Python + Docling
  • AI-Powered Knowledge: LlamaIndex and Apache Tika for Enterprises
  • Why Whole-Document Sentiment Analysis Fails and How Section-Level Scoring Fixes It

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook