Package com.tnsai.rag
Class StructuralPath
java.lang.Object
com.tnsai.rag.StructuralPath
Builds and selects
structural paths.
A path starts at a format root and adds one step per level. An object
key is .name when it is an identifier ([A-Za-z_][A-Za-z0-9_]*)
and ['name'] otherwise, with \\, \', \b,
\f, \n, \r, \t and \uXXXX
escapes; an array element is [n], counted from 0.
The roots the built-in extractors use, with the counts they start from:
- JSON:
$, as in$.products[0].nameor$['a b']. - JSON Lines:
$line[n]per record, from 1. - YAML:
$document[n]per document, from 1. - Markdown:
$frontmatter;$section[n]per heading, from 1 ($section[0]is the text before the first heading), with.heading, and.paragraph[l]and.code[l]at the line they start on. - XML:
/name[k]per element, from 1 among same-named siblings, as in/catalog[1]/book[2], and/$text[k]for text. - HTML:
$html.tag[k]. - CSV and TSV:
$row[n]per data row, from 1. - Plain text:
$text. Source code:$source, and$symbol['name']per symbol. - Office documents:
$heading[n],$paragraph[n],$table[n].
A selector keeps the blocks at and below it: a path is selected when it
equals the selector or continues it with ., [ or /.
$.products selects $.products[4].name but not
$.productsArchive.
- Since:
- 0.18.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic Stringindex(int index) The step for an array element.static StringThe step for an object key.static voidrequireBlankForEmpty(String selector, String documentId) Fails a non-blank selector over an empty document, which has no block to select.static ExtractedDocumentselect(ExtractedDocument document, String selector) Keeps the blocksselectorselects.static booleanWhetherselectorselectspath.
-
Method Details
-
property
The step for an object key.- Parameters:
name- the key- Returns:
.name, or['name']with escapes
-
index
The step for an array element.- Parameters:
index- the element index- Returns:
[index]
-
selects
Whetherselectorselectspath.- Parameters:
selector- the selector; blank selects every pathpath- a structural path- Returns:
- true when the path equals the selector or continues it with
.,[or/
-
select
Keeps the blocksselectorselects. The kept document's content is their contents, one block per line run, in order.- Parameters:
document- an extracted documentselector- the selector; blank keeps the document as it is- Returns:
- the selected document
- Throws:
IllegalArgumentException- when the selector selects no block
-
requireBlankForEmpty
Fails a non-blank selector over an empty document, which has no block to select. A blank selector keeps the empty document.- Parameters:
selector- the selectordocumentId- the empty document's id- Throws:
IllegalArgumentException- when the selector is not blank
-