src.dackar.RCA.doc_parsers.mdParser¶
Attributes¶
Functions¶
|
Map a raw section heading to a canonical role name using FIELD_LABEL_MAP. |
|
|
|
|
|
|
|
|
|
Parse headings and build a hierarchical section list. |
|
Adds a hierarchical section_path based on heading nesting. |
|
|
|
Light repair for common corrective-action tables where wrapped lines corrupt |
|
|
|
|
|
|
|
|
|
|
|
|
|
Build a figure list with section assignments. |
|
Build a single section-level TextChunk with canonical role. |
|
Paragraph sub-chunks for a section. Only produced for high-signal roles. |
|
Dispatch to the correct chunking strategy based on doc_type. |
|
Parse a document's extracted Markdown (produced by |
|
|
|
|
|
|
|
Packs paragraphs into chunks up to max_chars. Overlap is applied between consecutive chunks. |
|
Compact textual representation for embedding/indexing. |
Module Contents¶
- 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.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.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.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):
Inline Markdown image references parsed per section (s[“figures”]).
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 persiststructured_output.jsonandchunks.jsonl.- Parameters:
document_index (Dict[str, Any]) – The index dict returned by
pdfParser(must includetext_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 tochunks.jsonl.- Return type:
Dict[str, Any]
- Raises:
ValueError – If
document_indexis not a dict.FileNotFoundError – If
text_md_pathis missing or does not exist on disk.
- 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