Loading...
Loading...
Compare original and translation side by side
legalize-es.mdBOE-A-1978-31229.mdgrepgit diffgit loggit showgit checkoutlegalize-es.mdBOE-A-1978-31229.mdgrepgit diffgit loggit showgit checkoutundefinedundefined
All law files live in the `spain/` directory.
---
所有法律文件都存放在`spain/`目录下。
---spain/
├── BOE-A-1978-31229.md # Constitución Española
├── BOE-A-1995-25444.md # Código Penal
├── BOE-A-2015-11430.md # Estatuto de los Trabajadores
├── BOE-A-2000-323.md # Ley de Enjuiciamiento Civil
└── ... (8,600+ laws)spain/
├── BOE-A-1978-31229.md # Constitución Española
├── BOE-A-1995-25444.md # Código Penal
├── BOE-A-2015-11430.md # Estatuto de los Trabajadores
├── BOE-A-2000-323.md # Ley de Enjuiciamiento Civil
└── ... (8600+部法律)---
titulo: "Constitución Española"
identificador: "BOE-A-1978-31229"
pais: "es"
rango: "constitucion"
fecha_publicacion: "1978-12-29"
ultima_actualizacion: "2024-02-17"
estado: "vigente"
fuente: "https://www.boe.es/eli/es/c/1978/12/27/(1)"
---rangoconstitucionley-organicaleyreal-decreto-leyreal-decreto-legislativoestadovigentederogado---
titulo: "Constitución Española"
identificador: "BOE-A-1978-31229"
pais: "es"
rango: "constitucion"
fecha_publicacion: "1978-12-29"
ultima_actualizacion: "2024-02-17"
estado: "vigente"
fuente: "https://www.boe.es/eli/es/c/1978/12/27/(1)"
---rangoconstitucionley-organicaleyreal-decreto-leyreal-decreto-legislativoestadovigentederogadoundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefined
---
---undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefined
---
---#!/bin/bash#!/bin/bashundefinedundefined#!/bin/bash#!/bin/bashundefinedundefinedimport os
import yaml
def parse_law(filepath):
"""Parse a law Markdown file and return frontmatter + body."""
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
# Extract YAML frontmatter between --- delimiters
if content.startswith('---'):
parts = content.split('---', 2)
if len(parts) >= 3:
metadata = yaml.safe_load(parts[1])
body = parts[2].strip()
return metadata, body
return {}, contentimport os
import yaml
def parse_law(filepath):
"""解析法律Markdown文件,返回前置元数据和正文。"""
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
# 提取---分隔符之间的YAML前置元数据
if content.startswith('---'):
parts = content.split('---', 2)
if len(parts) >= 3:
metadata = yaml.safe_load(parts[1])
body = parts[2].strip()
return metadata, body
return {}, contentundefinedundefinedimport subprocess
import json
def get_reform_history(boe_id):
"""Get all commits that modified a law file."""
filepath = f"spain/{boe_id}.md"
result = subprocess.run(
['git', 'log', '--format=%H|%ad|%s', '--date=short', '--', filepath],
capture_output=True, text=True
)
reforms = []
for line in result.stdout.strip().split('\n'):
if line:
hash_, date, subject = line.split('|', 2)
reforms.append({'hash': hash_, 'date': date, 'subject': subject})
return reformsimport subprocess
import json
def get_reform_history(boe_id):
"""获取修改某部法律文件的所有commit。"""
filepath = f"spain/{boe_id}.md"
result = subprocess.run(
['git', 'log', '--format=%H|%ad|%s', '--date=short', '--', filepath],
capture_output=True, text=True
)
reforms = []
for line in result.stdout.strip().split('\n'):
if line:
hash_, date, subject = line.split('|', 2)
reforms.append({'hash': hash_, 'date': date, 'subject': subject})
return reformsundefinedundefinedimport subprocess
def diff_law_versions(boe_id, commit_before, commit_after):
"""Get unified diff between two versions of a law."""
filepath = f"spain/{boe_id}.md"
result = subprocess.run(
['git', 'diff', f'{commit_before}..{commit_after}', '--', filepath],
capture_output=True, text=True
)
return result.stdout
def get_law_at_date(boe_id, date_str):
"""Get the text of a law as it was on a given date (YYYY-MM-DD)."""
filepath = f"spain/{boe_id}.md"
# Find the last commit before date
rev = subprocess.run(
['git', 'rev-list', '-1', f'--before={date_str}', 'HEAD'],
capture_output=True, text=True
).stdout.strip()
if not rev:
return None
content = subprocess.run(
['git', 'show', f'{rev}:{filepath}'],
capture_output=True, text=True
).stdout
return contentimport subprocess
def diff_law_versions(boe_id, commit_before, commit_after):
"""获取法律两个版本的统一diff。"""
filepath = f"spain/{boe_id}.md"
result = subprocess.run(
['git', 'diff', f'{commit_before}..{commit_after}', '--', filepath],
capture_output=True, text=True
)
return result.stdout
def get_law_at_date(boe_id, date_str):
"""获取指定日期(YYYY-MM-DD)时的法律文本。"""
filepath = f"spain/{boe_id}.md"
# 查找指定日期前的最后一次commit
rev = subprocess.run(
['git', 'rev-list', '-1', f'--before={date_str}', 'HEAD'],
capture_output=True, text=True
).stdout.strip()
if not rev:
return None
content = subprocess.run(
['git', 'show', f'{rev}:{filepath}'],
capture_output=True, text=True
).stdout
return contentundefinedundefinedimport os
import re
def search_laws(query, laws_dir='spain', rango=None, estado='vigente'):
"""Search for a regex pattern across all laws."""
results = []
pattern = re.compile(query, re.IGNORECASE)
for filename in os.listdir(laws_dir):
if not filename.endswith('.md'):
continue
filepath = os.path.join(laws_dir, filename)
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
# Filter by frontmatter fields
if estado and f'estado: "{estado}"' not in content:
continue
if rango and f'rango: "{rango}"' not in content:
continue
matches = list(pattern.finditer(content))
if matches:
titulo_match = re.search(r'titulo: "([^"]+)"', content)
titulo = titulo_match.group(1) if titulo_match else filename
results.append({
'file': filename,
'titulo': titulo,
'match_count': len(matches),
'first_match_context': content[max(0, matches[0].start()-100):matches[0].end()+100]
})
return sorted(results, key=lambda x: x['match_count'], reverse=True)import os
import re
def search_laws(query, laws_dir='spain', rango=None, estado='vigente'):
"""在所有法律中搜索正则匹配的内容。"""
results = []
pattern = re.compile(query, re.IGNORECASE)
for filename in os.listdir(laws_dir):
if not filename.endswith('.md'):
continue
filepath = os.path.join(laws_dir, filename)
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
# 按前置元数据字段筛选
if estado and f'estado: "{estado}"' not in content:
continue
if rango and f'rango: "{rango}"' not in content:
continue
matches = list(pattern.finditer(content))
if matches:
titulo_match = re.search(r'titulo: "([^"]+)"', content)
titulo = titulo_match.group(1) if titulo_match else filename
results.append({
'file': filename,
'titulo': titulo,
'match_count': len(matches),
'first_match_context': content[max(0, matches[0].start()-100):matches[0].end()+100]
})
return sorted(results, key=lambda x: x['match_count'], reverse=True)
---
---undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedimport os, yaml, json
laws = []
for fname in os.listdir('spain'):
if not fname.endswith('.md'):
continue
with open(f'spain/{fname}', 'r', encoding='utf-8') as f:
content = f.read()
if content.startswith('---'):
parts = content.split('---', 2)
if len(parts) >= 3:
meta = yaml.safe_load(parts[1])
meta['filename'] = fname
laws.append(meta)
with open('laws_index.json', 'w', encoding='utf-8') as f:
json.dump(laws, f, ensure_ascii=False, indent=2, default=str)
print(f"Exported {len(laws)} laws")import os, yaml, json
laws = []
for fname in os.listdir('spain'):
if not fname.endswith('.md'):
continue
with open(f'spain/{fname}', 'r', encoding='utf-8') as f:
content = f.read()
if content.startswith('---'):
parts = content.split('---', 2)
if len(parts) >= 3:
meta = yaml.safe_load(parts[1])
meta['filename'] = fname
laws.append(meta)
with open('laws_index.json', 'w', encoding='utf-8') as f:
json.dump(laws, f, ensure_ascii=False, indent=2, default=str)
print(f"已导出 {len(laws)} 部法律")undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefined
---
---fuente:fuente: