src.dackar.RCA.doc_parsers.mdParser

Attributes

LOGGER

ch

FIELD_LABEL_MAP

HIGH_SIGNAL_ROLES

STOPWORDS

HEADING_RE

IMAGE_RE

STANDARD_PATTERNS

TAG_PATTERNS

DOC_REF_PREFIXES

HTML_TAG_RE

MD_IMAGE_RE

MD_LINK_RE

MD_EMPH_RE

doc_index_path

Functions

canonicalize_section_role(title, doc_type)

Map a raw section heading to a canonical role name using FIELD_LABEL_MAP.

_now_iso()

read_text(path)

write_json(path, obj)

write_jsonl(path, records)

parse_markdown_sections(md_text)

Parse headings and build a hierarchical section list.

build_section_paths(sections)

Adds a hierarchical section_path based on heading nesting.

load_tables_from_json(paths)

_clean_table_cell(x)

clean_table_object(t)

_repair_wrapped_action_rows(columns, rows)

Light repair for common corrective-action tables where wrapped lines corrupt

detect_mbse_mentions(text, mbse_entities)

detect_equipment_tags(text)

detect_document_refs(text)

detect_standard_refs(text)

extract_keywords(text[, top_k])

assign_tables_to_sections(tables, sections, doc_index)

assign_figures_to_sections(figures_in_text, sections)

Build a figure list with section assignments.

_section_to_chunk(s, idx, doc_id, doc_type, doc_name, ...)

Build a single section-level TextChunk with canonical role.

_paragraph_subchunks(s, sec_idx, doc_id, doc_type, ...)

Paragraph sub-chunks for a section. Only produced for high-signal roles.

build_chunks_for_doc_type(sections, doc_id, doc_type, ...)

Dispatch to the correct chunking strategy based on doc_type.

md_parser(document_index, destination_folder[, ...])

Parse a document's extracted Markdown (produced by pdfParser) into

strip_markup_noise(text)

normalize_raw_text(text)

split_into_paragraphs(text)

chunk_paragraphs(paragraphs[, max_chars, overlap_chars])

Packs paragraphs into chunks up to max_chars. Overlap is applied between consecutive chunks.

textify_table(caption, headers, rows[, head_rows, ...])

Compact textual representation for embedding/indexing.

Module Contents

src.dackar.RCA.doc_parsers.mdParser.LOGGER[source]
src.dackar.RCA.doc_parsers.mdParser.ch[source]
src.dackar.RCA.doc_parsers.mdParser.FIELD_LABEL_MAP: dict[str, dict[str, str]][source]
src.dackar.RCA.doc_parsers.mdParser.HIGH_SIGNAL_ROLES[source]
src.dackar.RCA.doc_parsers.mdParser.canonicalize_section_role(title, doc_type)[source]

Map a raw section heading to a canonical role name using FIELD_LABEL_MAP. Falls back to ‘body’ if no pattern matches.

Parameters:
  • title (str)

  • doc_type (str)

Return type:

str

src.dackar.RCA.doc_parsers.mdParser.STOPWORDS[source]
src.dackar.RCA.doc_parsers.mdParser._now_iso()[source]
Return type:

str

src.dackar.RCA.doc_parsers.mdParser.read_text(path)[source]
Parameters:

path (str)

Return type:

str

src.dackar.RCA.doc_parsers.mdParser.write_json(path, obj)[source]
Parameters:
  • path (str)

  • obj (Any)

Return type:

None

src.dackar.RCA.doc_parsers.mdParser.write_jsonl(path, records)[source]
Parameters:
  • path (str)

  • records (List[Dict[str, Any]])

Return type:

None

src.dackar.RCA.doc_parsers.mdParser.HEADING_RE[source]
src.dackar.RCA.doc_parsers.mdParser.IMAGE_RE[source]
src.dackar.RCA.doc_parsers.mdParser.parse_markdown_sections(md_text)[source]

Parse headings and build a hierarchical section list. Each element: {“title”, “level”, “text”, “figures”: […], “tables”: […]}

Parameters:

md_text (str)

Return type:

List[Dict[str, Any]]

src.dackar.RCA.doc_parsers.mdParser.build_section_paths(sections)[source]

Adds a hierarchical section_path based on heading nesting.

Parameters:

sections (List[Dict[str, Any]])

Return type:

List[Dict[str, Any]]

src.dackar.RCA.doc_parsers.mdParser.load_tables_from_json(paths)[source]
Parameters:

paths (List[str])

Return type:

List[Dict[str, Any]]

src.dackar.RCA.doc_parsers.mdParser._clean_table_cell(x)[source]
Parameters:

x (Any)

Return type:

str

src.dackar.RCA.doc_parsers.mdParser.clean_table_object(t)[source]
Parameters:

t (Dict[str, Any])

Return type:

Dict[str, Any]

src.dackar.RCA.doc_parsers.mdParser._repair_wrapped_action_rows(columns, rows)[source]

Light repair for common corrective-action tables where wrapped lines corrupt owner/status columns. Only applies when columns look action-like.

Parameters:
  • columns (List[str])

  • rows (List[List[str]])

Return type:

List[List[str]]

src.dackar.RCA.doc_parsers.mdParser.detect_mbse_mentions(text, mbse_entities)[source]
Parameters:
  • text (str)

  • mbse_entities (Optional[List[Dict[str, Any]]])

Return type:

Tuple[List[str], float]

src.dackar.RCA.doc_parsers.mdParser.STANDARD_PATTERNS = ['\\bASME\\b.*\\bBPVC\\b.*\\b(Section|Sec\\.?|III|NCA|NC|NB|NH)\\b',...[source]
src.dackar.RCA.doc_parsers.mdParser.TAG_PATTERNS = ['\\b[A-Z]{1,4}-\\d{2,5}[A-Z]?\\b', '\\b[A-Z]{2,6}\\d{2,5}[A-Z]?\\b'][source]
src.dackar.RCA.doc_parsers.mdParser.DOC_REF_PREFIXES[source]
src.dackar.RCA.doc_parsers.mdParser.detect_equipment_tags(text)[source]
Parameters:

text (str)

Return type:

List[str]

src.dackar.RCA.doc_parsers.mdParser.detect_document_refs(text)[source]
Parameters:

text (str)

Return type:

List[str]

src.dackar.RCA.doc_parsers.mdParser.detect_standard_refs(text)[source]
Parameters:

text (str)

Return type:

Tuple[List[str], float]

src.dackar.RCA.doc_parsers.mdParser.extract_keywords(text, top_k=12)[source]
Parameters:
  • text (str)

  • top_k (int)

Return type:

List[str]

src.dackar.RCA.doc_parsers.mdParser.assign_tables_to_sections(tables, sections, doc_index)[source]
Parameters:
  • tables (List[Dict[str, Any]])

  • sections (List[Dict[str, Any]])

  • doc_index (Dict[str, Any])

Return type:

List[Dict[str, Any]]

src.dackar.RCA.doc_parsers.mdParser.assign_figures_to_sections(figures_in_text, sections, doc_figures=None)[source]

Build a figure list with section assignments.

Sources (merged, deduplicated by path):
  1. Inline Markdown image references parsed per section (s[“figures”]).

  2. doc_figures: figures list from document_index (Marker path-indexed).

Parameters:
  • figures_in_text (List[Dict[str, Any]])

  • sections (List[Dict[str, Any]])

  • doc_figures (Optional[List[Dict[str, Any]]])

Return type:

List[Dict[str, Any]]

src.dackar.RCA.doc_parsers.mdParser._section_to_chunk(s, idx, doc_id, doc_type, doc_name, source_path, ingest_id, classification, content_hash)[source]

Build a single section-level TextChunk with canonical role.

Parameters:
  • s (dict)

  • idx (int)

  • doc_id (str)

  • doc_type (str)

  • doc_name (str)

  • source_path (str)

  • classification (str)

Return type:

dict

src.dackar.RCA.doc_parsers.mdParser._paragraph_subchunks(s, sec_idx, doc_id, doc_type, doc_name, source_path, ingest_id, classification, content_hash, mbse_entities)[source]

Paragraph sub-chunks for a section. Only produced for high-signal roles.

Parameters:
  • s (dict)

  • sec_idx (int)

  • doc_id (str)

  • doc_type (str)

  • doc_name (str)

  • source_path (str)

  • classification (str)

Return type:

list[dict]

src.dackar.RCA.doc_parsers.mdParser.build_chunks_for_doc_type(sections, doc_id, doc_type, doc_name, source_path, ingest_id, classification, content_hash, mbse_entities)[source]

Dispatch to the correct chunking strategy based on doc_type. All strategies produce section-level chunks with canonical roles. SOP additionally produces one chunk per step group.

Parameters:
  • sections (list[dict])

  • doc_id (str)

  • doc_type (str)

  • doc_name (str)

  • source_path (str)

  • classification (str)

Return type:

list[dict]

src.dackar.RCA.doc_parsers.mdParser.md_parser(document_index, destination_folder, mbse_entities=None, nureg_section_ids=None)[source]

Parse a document’s extracted Markdown (produced by pdfParser) into hierarchical sections/chunks enriched with MBSE mentions, standards/document references, and keywords, then persist structured_output.json and chunks.jsonl.

Parameters:
  • document_index (Dict[str, Any]) – The index dict returned by pdfParser (must include text_md_path).

  • destination_folder (Optional[str]) – Root destination for parsed outputs. If None, it is inferred from the parent of the Markdown text file’s directory.

  • mbse_entities (Optional[List[Dict[str, Any]]]) – Optional MBSE entity dictionary used for dictionary-based NER of component mentions.

  • nureg_section_ids (Optional[List[str]]) – Optional NUREG section identifiers to attach to every section.

Returns:

The structured output dict (also written to structured_output.json), mirroring the section/table/figure chunks emitted to chunks.jsonl.

Return type:

Dict[str, Any]

Raises:
  • ValueError – If document_index is not a dict.

  • FileNotFoundError – If text_md_path is missing or does not exist on disk.

src.dackar.RCA.doc_parsers.mdParser.HTML_TAG_RE[source]
src.dackar.RCA.doc_parsers.mdParser.MD_IMAGE_RE[source]
src.dackar.RCA.doc_parsers.mdParser.MD_EMPH_RE[source]
src.dackar.RCA.doc_parsers.mdParser.strip_markup_noise(text)[source]
Parameters:

text (str)

Return type:

str

src.dackar.RCA.doc_parsers.mdParser.normalize_raw_text(text)[source]
Parameters:

text (str)

Return type:

str

src.dackar.RCA.doc_parsers.mdParser.split_into_paragraphs(text)[source]
Parameters:

text (str)

Return type:

List[str]

src.dackar.RCA.doc_parsers.mdParser.chunk_paragraphs(paragraphs, max_chars=1400, overlap_chars=200)[source]

Packs paragraphs into chunks up to max_chars. Overlap is applied between consecutive chunks. Char-based is OK since you’re storing raw text and embedding later.

Parameters:
  • paragraphs (List[str])

  • max_chars (int)

  • overlap_chars (int)

Return type:

List[str]

src.dackar.RCA.doc_parsers.mdParser.textify_table(caption, headers, rows, head_rows=4, tail_rows=2)[source]

Compact textual representation for embedding/indexing.

Always includes:
  • caption

  • column headers

  • first head_rows rows (typical parameter definitions)

  • last tail_rows rows (often contain limit/summary values)

  • a note when rows are omitted

Parameters:
  • caption (Optional[str])

  • headers (List[str])

  • rows (List[List[Any]])

  • head_rows (int)

  • tail_rows (int)

Return type:

str

src.dackar.RCA.doc_parsers.mdParser.doc_index_path[source]