Skip to content

Commit

Permalink
fix: Rimuove inizio e fine del testo, corregge SEZIONE
Browse files Browse the repository at this point in the history
- Rimuove il testo all'inizio e alla fine. Comincia con "Capo" e
termina con l'entrata in vigore del testo.
- Corregge l'errore nella determinazione di una sezione quando
questa appare in maiuscolo (SEZIONE).
  • Loading branch information
alterat committed Nov 23, 2017
1 parent c2d2f50 commit a01d071
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions normattiva2rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,26 @@ def checkNumber(ln):
text = f.read().split('\n')

ctxt = [line.strip().replace(" "*5, " ").replace(" "*4, " ").replace(" "*3, " ").replace(" "*2, " ") for line in text]

# remove beginning and end of text
startLine = next((l for l in ctxt if l.startswith("Vigente al:")), -1)
if startLine!=-1:
startInd = ctxt.index(startLine)
ctxt = ctxt[startInd+1:]

endLine = next((l for l in ctxt if l.startswith("TABELLA DI")), -1)
if endLine==-1:
endLine = next((l for l in ctxt if l.startswith("Il presente decreto,")), -1)
if endLine!=-1:
endInd = ctxt.index(endLine)
ctxt = ctxt[:endInd]


# replace "((...))" with nothing
ctxt = [line.replace("(( ... ))","").replace("((...))","") for line in ctxt]
# replace "((" "))" with nothing
ctxt = [line.replace("(( ","").replace(" ))","").replace("((","").replace("))","") for line in ctxt]
ctxt = [line.replace(" . . .","") for line in ctxt]
# replace line with nothing
ctxt = [removeDash(line) for line in ctxt]

Expand All @@ -92,7 +108,7 @@ def checkNumber(ln):
new_ctxt = []

for (line, ind) in zip(ctxt, range(len(ctxt))):
if ((line[:4]=="Capo") | (line[:4]=="Sezi") | (line[:4]=="Art.")) & (ctxt[ind-1]!=""):
if ((line[:4]=="Capo") | (line[:4]=="SEZI")| (line[:4]=="Sezi") | (line[:4]=="Art.")) & (ctxt[ind-1]!=""):
new_ctxt.append("")
new_ctxt.append(line)

Expand All @@ -116,7 +132,7 @@ def checkNumber(ln):
isSezi=1
isCapo = 0
isArt = 0
seziTitle = line + "."
seziTitle = "Sezione" + line[7:] + "."
elif line.startswith("Art. "):
isLetter = 0
isNumber = 0
Expand Down

0 comments on commit a01d071

Please sign in to comment.