xiaohongshu
xiaohongshu
legislative-flattener
Converts hierarchical legislative text from Word documents into a flat list of requirements. Use when processing regulatory documents, compliance frameworks, or legal text that needs to be extracted into individual, numbered requirements for analysis or mapping.
Full skill instructions
This skill processes Word documents (DOCX) containing legislative or regulatory text and converts hierarchical structures into a flat, numbered list of discrete requirements or provisions.
Activate this skill when the user wants to:
Install required dependencies:
pip install python-docx openpyxl
Basic usage (outputs formatted XLSX by default):
python flattener_utility.py input.docx output.xlsx
Or specify format explicitly:
python flattener_utility.py input.docx output.xlsx --format xlsx
python flattener_utility.py input.docx output.csv --format csv
python flattener_utility.py input.docx output.json --format json
First, understand the input document structure:
Extract content while preserving context:
Convert hierarchy to flat structure:
Generate a structured flat list with these fields for each requirement:
Flat ID: [Sequential number]
Original Reference: [Original section/subsection identifier]
Context Path: [Full hierarchical path, e.g., "Article 5 > Section 2 > Paragraph b"]
Requirement Type: [Mandate/Prohibition/Permission/Definition]
Normative Level: [SHALL/MUST/SHOULD/MAY/INFORMATIVE]
Text: [Full requirement text]
Keywords: [Extracted key concepts or compliance areas]
---
Use this workflow:
# Install required library if needed
# pip install python-docx
from docx import Document
import re
def flatten_legislative_text(docx_path):
"""
Flattens hierarchical legislative text from DOCX.
Returns a list of flattened requirements.
"""
doc = Document(docx_path)
flattened = []
flat_id = 1
context_stack = []
for paragraph in doc.paragraphs:
# Skip empty paragraphs
if not paragraph.text.strip():
continue
# Detect hierarchy level (by style or numbering)
level = detect_level(paragraph)
original_ref = extract_reference(paragraph)
# Update context stack
update_context(context_stack, level, paragraph.text)
# Extract if it's a requirement (not just a heading)
if is_requirement(paragraph):
item = {
'flat_id': flat_id,
'original_ref': original_ref,
'context_path': ' > '.join(context_stack),
'requirement_type': classify_requirement(paragraph.text),
'normative_level': extract_normative_level(paragraph.text),
'text': clean_text(paragraph.text),
'keywords': extract_keywords(paragraph.text)
}
flattened.append(item)
flat_id += 1
return flattened
Provide results in user's preferred format:
Validate the flattening:
## Flattened Requirements
### Requirement 1
- **Flat ID**: 1
- **Original Reference**: Section 500.02(a)
- **Context Path**: Part 500 > Section 500.02 > Paragraph (a)
- **Requirement Type**: Mandate
- **Normative Level**: SHALL
- **Text**: Each Covered Entity shall maintain a cybersecurity program designed to protect the confidentiality, integrity and availability of the Covered Entity's Information Systems.
- **Keywords**: cybersecurity program, confidentiality, integrity, availability, Information Systems
---
### Requirement 2
- **Flat ID**: 2
- **Original Reference**: Section 500.02(b)
- **Context Path**: Part 500 > Section 500.02 > Paragraph (b)
- **Requirement Type**: Mandate
- **Normative Level**: SHALL
- **Text**: The cybersecurity program shall be based on the Covered Entity's Risk Assessment and designed to perform the following core cybersecurity functions...
- **Keywords**: Risk Assessment, core cybersecurity functions
---
The XLSX export includes:
See examples.md for sample input/output pairs and template.md for customizable output templates.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience