GenAI
Generative artificial intelligence (GenAI) can create certain types of images, text, videos, and other media in response to prompts ..

Start Pentaho Data Integration:
HTML Parser
The HTML Parser is a utility plugin for Pentaho Data Integration (PDI) that extracts desired text from HTML or XML files. Useful for cleaning data for natural language processing tasks like sentiment analysis and SEO keyword analysis.
Accepts input from both data streams and files
Supports parsing using Xpath expressions or CSS selectors
Can process single files or multiple inputs from a stream
Compatible with local and virtual file systems
The plugin utilizes jsoup, a Java library, that simplifies working with real-world HTML and XML. It offers an easy-to-use API for URL fetching, data parsing, extraction, and manipulation using DOM API methods, CSS, and Xpath selectors.
The step is located in the Input folder.
Select XPath or CSS Selectors as the parsing method:
XPath
XPath (XML Path Language) is a query language for selecting nodes from an XML or HTML document. While Jsoup doesn't natively support XPath, we can use a combination of Jsoup and Java's built-in XPath capabilities to achieve this.
Here's an overview of some common XPath syntax:
/ - Selects from the root node
// - Selects nodes anywhere in the document
. - Selects the current node
.. - Selects the parent of the current node
@ - Selects attributes
[] -Used for predicates (conditions)
Some examples:
//div- Selects all div elements in the document//div[@class='content']- Selects all div elements with class 'content'//h1/text()- Selects the text content of all h1 elements//div[@class='content']/p- Selects all p elements that are direct children of div elements with class 'content'
HTML Data Source
Select HTML source:

Open the following transformation.
Filepath
Linux
~/Projects/genai/html/HTML Parser - Xpath.ktr
Double-click on the hp: html and configure with the following settings:

3. RUN and preview the results.

Select the main title:
Select all navigation links:
Select all article titles (h3 elements within articles):
Select all paragraph content within articles:
Select all author names:
Select the latest news items:
Select the footer text:
Select all section titles (h2 elements that are direct children of section elements):
Select the second article:
Select all elements with a class attribute:
Enable the hop between: dg: filepath from stream -> hp: parse html xpath.
Disable the hop between: Data Grid -> hp: parse html xpath
dg: html from stream -> hp: parse html xpath

Double-click on the hp: html and configure with the following settings:

RUN and preview the results.

x
x
x
HTML from stream
The data source is referenced as <html> in a data stream field.
Pentaho's data streams often use binary fields to handle various types of data, including large text objects like HTML. By using binary datum, you ensure that the entire HTML content is treated as a single, uninterpreted chunk of data within the Pentaho pipeline - represented as 0 or 1.
Storing the HTML as binary datum allows you to pass the raw content through various steps in your Pentaho transformation without Pentaho trying to interpret or modify the HTML prematurely.
Enable the hop between: dg: html from stream -> hp: parse html xpath.
Disable the hop between: dg: filepath from stream -> hp: parse html xpath
Data Grid -> hp: parse html xpath

Double-click on the hp: html and configure with the following settings:

RUN and preview the results.





Open the following transformation.

Windows
C:/Projects/genai/base64/Base64 Encode.ktr
Linux
~/Projects/genai/base64/Base64.ktr.
Double-click on the Base64 Encoder step and configure with the following settings:

Check the Select values step.

RUN and preview the results.

RAW Text
Enable the hop between: Data grid - Raw Text Input -> Base64 Encoder.
Disable the hop between: Data grid -> Base64 Encoder
Get file names images -> Base64 Encoder

Double-click on the Data grid -Raw Input Text step - Data tab

Check the Select values.

RUN and preview the results

Multiple Files
Enable the hop between: Get file names - Images -> Base64 Encoder
Disable the hop between: Data grid - Raw Text Input -> Base64 Encoder.
Data grid -> Base64 Encoder

Double-click on the Get File names - Images step.

Double-click on the Base64 Encoder and configure with the following settings:

Check the Select values.

RUN and preview the results.

Resources
Pentaho Data Integration

Enter Prompt
Enable the hop between: Data Grid -> AI Chat.
Disable the hop bewteen: User Input -> AI Chat.

Open the following transformation:
Windows
C:/Projects/genai/ai chat/.ktr
Linux
~/Projects/genai/html/HTML Parser - Xpath.ktr
Double-click on the hp: html and configure with the following settings:
Double-click on the AI Chat step and configure with the following settings:

Click on the Model tab.


RUN and preview the result.

Prompt from Data Stream fields

Disable the hop between: Data Grid -> AI Chat.
Enable the hop bewteen: User Input -> AI Chat.
Double-click on the User Input step and the Data tab.

Double-click on the AI Chat step and configure with the following settings:

RUN and preview result.

Configure Model with your own account details
Double-click anywhere on the canvas to configure the Parameters.

Enter your own OpenAI Key.
Double-click on the AI Chat step and configure with the following settings.

RUN and preview the result. Should be the same as the previous scenario ..!!
Non-persistant RAG
Enable the hop between: Data Grid -> AI Chat.

Double-click on the AI Chat step and configure with the following settings:

Click on the Embedding tab.

RUN and preview the result.

Embedding - Write
Double-click on the AI Chat step and then on the Embedding tab.
Configure with the following settings.

RUN & check that the embedding has been stored.
Embedding - READ
Double-click on the AI Chat step and configure with the following settings:

Ensure you select the Attach Document(s) option - enables the embedding options.
Click on the Embedding tab and confiure with the following settings:

RUN and preview the result.

Double-click anywhere on the canvas to set the parameters.

Double-click on the Chat AI step and configure with the following settings:

RUN and preview the result.

Prompt - Template
Double-click on the Chat AI step and configure with the following settings:

RUN and preview the result.

Open the following transformation:
Windows
C:/Projects/genai/aichat/Usecase - Log Analysis.ktr
Linux
~/Projects/genai/aichat/Usecase - Log Analysis.ktr
Double-click on the hp: html and configure with the following settings:

Double-click on the AI Chat step to view the settings.

Message / Prompt
Document
Model
Click on the Model tab.

Embedding
Click on the Embedding tab.

Response
Click on the Response tab.

Double-click on the Process generated JSON result step.

Click on the Fields tab.

JSON Notation
$
Root object
$ returns the whole JSON structure
.
Child operator; it's used to access different levels of the JSON structure
$..Issue returns the Issue
RUN and preview result - Output - log-analysis.csv


Double-click on the AI Chat step.

RUN and preview result - Text file output.


Review the main steps of the
The previous step - Get file names returns the paths to the PDFs.

Double-click on the Read Unstructured Document step to view settings.

Double-click on the AI Chat step to view the settings.

Click on the Model tab.

Click on Embedding tab.

Click on the Response tab.

generated_response
Double-click on the Select values step.

RUN and preview the result.

Double-click on Write the Sales Forecast to Excel.

Click on the Content tab.

RUN and open the file:
~/Projects/genai/Use Case - Analyzing Financial Reports/data/Sales Report AI Generated.xlsx

x
x
x
Basic Selectors
a) Element Selector:
b) Class Selector:
c) ID Selector:
d) Universal Selector:
Combinators
a) Descendant Selector (space):
b) Child Selector (>):
c) Adjacent Sibling Selector (+):
d) General Sibling Selector (~):
Attribute Selectors
a) [attribute]:
b) [attribute="value"]:
c) [attribute~="value"]:
d) [attribute^="value"]:
e) [attribute$="value"]:
f) [attribute*="value"]:
Pseudo-classes
Combining Selectors
HTML Data Source
x
x
x
Transformation

Filepath
Open the following transformation:
Windows
C:/Projects/genai/html/HTML Parser - CSS.ktr
Linux
~/Projects/genai/html/HTML Parser - CSS.ktr
Double-click on the hp: html and configure with the following settings:

RUN preview the results.

Select the main title:
Select all navigation links:
Select all product titles:
Select all product descriptions:
Select all product prices:
Select the "About Us" section:
Select the newsletter form:
Select all section titles (h2 elements):
Select the footer text:
Select all elements with a class of "product":
x
x
Filepath from stream
Enable the hop between: dg: filepath from stream -> hp: parse html xpath.
Disable the hop between: Data grid -> hp: parse html css
dg: html from stream -> hp: parse html css

Double-click on the hp: html and configure with the following settings:

RUN preview results.

HTML from stream
Enable the hop between: dg: html from stream -> hp: parse html css.
Disable the hop between: dg: filepath from stream -> hp: parse html css
Data grid -> hp: parse html css

Double-click on the hp: html and configure with the following settings:

RUN preview results.

Word Document
Open the following transformation:

Windows
C:/Projects/genai/tika/Read Unstructured Document- Word Doc.ktr
Linux
~/Projects/genai/tika/Read Unstructured Document- Word Doc.ktr
Double-click on the Read Unstructured Document step and configure with the following settings:

RUN and preview the results.

Open the following transformation:

Windows
C:/Projects/genai/tika/Read Unstructured Document- Password PDF.ktr
Linux
~/Projects/genai/tika/Read Unstructured Document- Password PDF.ktr.
Double-click on the Read Unstructured Document step and configure with the following settings:

RUN and preview the results.

Open the following transformation:

Windows
C:/Projects/genai/tika/Read Unstructured Document- Stream Multiple Files.ktr
Linux
~/Projects/genai/tika/Read Unstructured Document- Stream Multiple Files.ktr.
Double-click on the Javascript: Add password column.

Double-click on the Read Unstructured Document step and configure with the following settings:

RUN and preview the results.

Last updated
Was this helpful?




