Skip to content

Commit

Permalink
fix: du maudit triage
Browse files Browse the repository at this point in the history
  • Loading branch information
dhdaines committed Jul 25, 2024
1 parent 6ab3f8b commit bae1bfb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
20 changes: 16 additions & 4 deletions alexi/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from pathlib import Path
from typing import Any, Iterable, Optional, TextIO

from natsort import natsorted

from alexi.analyse import Analyseur, Bloc, Document, Element, extract_zonage
from alexi.convert import Converteur
from alexi.format import HtmlFormatter
Expand Down Expand Up @@ -301,17 +303,24 @@ def make_doc_tree(docs: list[Document], outdir: Path) -> dict[str, dict[str, str
</html>
"""
metadata = {}
docs.sort(key=operator.attrgetter("numero"))

def doc_sort_key(doc):
if doc.numero != "":
return f"{doc.numero}: {doc.titre}"
elif doc.fileid.startswith("RUD_T"): # FIXME: Very special case here
return f"843: Règlement d’urbanisme durable: {doc.titre}"
else:
return doc.titre

docs = natsorted(docs, key=doc_sort_key)
with open(outdir / "index.html", "wt") as outfh:
LOGGER.info("Génération de %s", outdir / "index.html")
outfh.write(HTML_HEADER)
for doc in docs:
outfh.write('<li class="Document node"><details>\n')
# Make fragment links to this ID expand the document (as
# we usually do not want to link to the full text)
outfh.write(
f'<summary id="{doc.fileid}">{doc.numero}: {doc.titre}</summary>\n'
)
outfh.write(f'<summary id="{doc.fileid}">{doc_sort_key(doc)}</summary>\n')
make_doc_subtree(doc, outfh)
outfh.write("</details></li>\n")
doc_metadata = {
Expand Down Expand Up @@ -350,6 +359,9 @@ def __init__(
if metadata:
with open(metadata, "rt") as infh:
self.pdfdata = json.load(infh)
for key in list(self.pdfdata.keys()):
if "%20" in key:
self.pdfdata[key.replace("%20", " ")] = self.pdfdata[key]
else:
self.pdfdata = {}
self.metadata = {"pdfs": self.pdfdata}
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies = [
"sklearn-crfsuite",
"lunr[languages]",
"unidecode",
"natsort",
]
[project.optional-dependencies]
dev = [
Expand Down

0 comments on commit bae1bfb

Please sign in to comment.