-
Notifications
You must be signed in to change notification settings - Fork 1
/
repertoires.py3
178 lines (156 loc) · 7.22 KB
/
repertoires.py3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
import sys
import sys
#from html.parser import HTMLParser
#parser = HTMLParser()
import html
ambiguous=re.compile(r'\<span class\=\"w\".*lemma var.*\n\<\/span\>')
unknown=re.compile(r'<span class="w" stage="-1">[^<]+<span class="lemma">[^<]+</span>')
sentence=re.compile(r'\<span class\=\"sent\"\>([^<]*)\<')
# title=re.compile(ur'\<meta content\=\"([^\"]*)\" name\=\"text\:title\" \/\>|\<meta name\=\"text\:title\" content\=\"([^\"]*)\" \/\>',re.U) # as of daba 0.9.0 dec 2020 meta format order changed!
title=re.compile(r'(?:\<meta content\=\"|\<meta name\=\"text\:title\" content\=\")([^\"]*)(?:\" name\=\"text\:title\" \/\>|\" \/\>)',re.U)
#author=re.compile(ur'\<meta content\=\"([^\"]*)\" name\=\"author\:name\" \/\>|\<meta name\=\"author\:name\" content\=\"([^\"]*)\" \/\>',re.U)
author=re.compile(r'(?:\<meta content\=\"|\<meta name\=\"author\:name\" content\=\")([^\"]*)(?:\" name\=\"author\:name\" \/\>|\" \/\>)',re.U)
#wordssearch=re.compile(ur'\<meta content\=\"([0-9]*)\" name\=\"\_auto\:words\" \/\>|\<meta name\=\"\_auto\:words\" content\=\"([0-9]*)\" \/\>',re.U)
wordssearch=re.compile(r'(?:\<meta content\=\"|\<meta name\=\"\_auto\:words\" content\=\")([0-9]*)(?:\" name\=\"\_auto\:words\" \/\>|\" \/\>)',re.U)
parsedwords=re.compile(r'\<span class\=\"w\"',re.U)
extraittxt=re.compile(r'<body><p>([^£]*)</p></body>',re.U) # ^< ne marche plus ?
searchwords=re.compile(r'([a-zɛɔɲŋA-ZƐƆƝŊ0-9\-́̀̌̂]+)',re.U)
medianame=re.compile(r'^([a-zA-Z\-\_]+)[0-9]*[a-z]*\_',re.U)
medianumber=re.compile(r'^[a-zA-Z\-\_]+([0-9]*[a-z]*)\_',re.U)
#date=re.compile(ur'\<meta content\=\"[0-9]+\.([0-9\.]*)\" name\=\"text\:date\" \/\>|\<meta name\=\"text\:date\" content\=\"[0-9]+\.([0-9\.]*)\" \/\>',re.U)
date=re.compile(r'(?:\<meta content\=\"[0-9]+\.|\<meta name\=\"text\:date\" content\=\"[0-9]+\.)([0-9\.]*)(?:\" name\=\"text\:date\" \/\>|\" \/\>)',re.U)
#datesource=re.compile(ur'\<meta content\=\"[0-9]+\.([0-9\.]*)\" name\=\"source\:date\" \/\>|\<meta name\=\"source\:date\" content\=\"[0-9]+\.([0-9\.]*)\" \/\>',re.U)
datesource=re.compile(r'(?:\<meta content\=\"[0-9]+\.|\<meta name\=\"source\:date\" content\=\"[0-9]+\.)([0-9\.]*)(?:\" name\=\"source\:date\" \/\>|\" \/\>)',re.U)
import os
# log=open("repertoire.log","w")
outf = open ("repertoires.csv","w")
grandtotal=0
nbrep=0
for dirname, dirnames, filenames in sorted(os.walk('.')):
if '.git' in dirnames: dirnames.remove('.git') # don't go into any .git directories.
# print path to all subdirectories first.
#for subdirname in dirnames:
# print(os.path.join(dirname, subdirname))
#break
#if select=="" : break #sys.exit("no relevant file (.dis.html, .pars.html, .html) in current directory")
# filenames=os.listdir(".")
toutout=""
toutwords=0
toutmedianame=""
toutmedianumber=""
toutdate=""
filenames=sorted(filenames) # peut-être pas nécessaire
for filename in filenames :
select=".html"
if '.dis.html' in filename :
select=".dis.html"
elif '.pars.html' in filename :
select=".pars.html"
if select in filename :
print(os.path.join(dirname, filename))
fileIN = open(os.path.join(dirname, filename), "r")
if toutmedianame=="":
mn=medianame.search(filename)
if mn :
toutmedianame=mn.group(1)
ismedianumber=medianumber.search(filename)
if ismedianumber!=[] :
toutmedianumber=ismedianumber.group(1)
#tout=fileIN.readlines()
line = fileIN.readline()
tout=""
while line:
tout=tout+line # py2: .decode("utf-8")
line = fileIN.readline()
fileIN.close()
if toutdate=="":
toutdatesearch=date.search(tout)
if toutdatesearch :
toutdate=toutdatesearch.group(1)
else:
toutdatesearch=datesource.search(tout)
if toutdatesearch :
toutdate=toutdatesearch.group(1)
else:
toutdate="23.09.2016"
titlefound=title.search(tout)
titl=""
if titlefound:
titl=titlefound.group(1)
else: print("no tile")
#print title.search(tout).group(2)
# log.write("\n"+filename+"\ntitle-1: "+titl+"\n")
if titl!="":
titl=re.sub(r"\"","",titl)
titl=re.sub(r"\;",",",titl) # dangereux pour un comma-separated-values
titl=html.unescape(titl)
auth=""
authors=author.search(tout)
if authors :
auth=authors.group(1)
if select==".dis.html" :
word=wordssearch.search(tout).group(1)
words=int(word)
elif select==".pars.html" :
words=len(parsedwords.findall(tout))
word=str(words)
elif select==".html" :
touttxt=tout
touttxt=re.sub(r"<c>.*</c>"," ",touttxt,0,re.U|re.MULTILINE) # enlever les <c>...</c>
touttxt=re.sub(r"<n>.*</n>"," ",touttxt,0,re.U|re.MULTILINE) # enlever les <n>...</n>
touttxt=re.sub(r"<h>|</h>"," ",touttxt,0,re.U|re.MULTILINE) # enlever les <h> ou </h>
touttxt=re.sub(r"<ill>|</ill>"," ",touttxt,0,re.U|re.MULTILINE) # enlever les <ill> ou </ill>
touttxt=re.sub(r"<ls>|</ls>"," ",touttxt,0,re.U|re.MULTILINE) # enlever les <ls> ou </ls>
touttxt=re.sub(r"<br/>"," ",touttxt,0,re.U|re.MULTILINE) # enlever les <br/>
touttxt=re.sub(r"<p>|</p>","",touttxt,0,re.U|re.MULTILINE) # enlever les marques de paragraphes
touttxt=re.sub(r"^ *- ","",touttxt,0,re.U|re.MULTILINE) # enlever les tirets
touttxt=re.sub(r" - ","",touttxt,0,re.U|re.MULTILINE) # enlever les tirets isolés
touttxt=re.sub(r"<head>[^¤]*</head>","",touttxt,0,re.U|re.MULTILINE) # enlever la section header
touttxt=re.sub(r"</*body>|</*html>","",touttxt,0,re.U|re.MULTILINE) # enlever les tags bidy et html
swords=searchwords.findall(touttxt)
# rappel : searchwords=re.compile(ur'([a-zɛɔɲŋA-ZƐƆƝŊ0-9\-́̀̌̂]+)',re.U)
if swords :
words=len(swords)
word=str(words)
#for iword in swords :
# outf.write(": "+iword+"\n")
if select!=".html": # càd : = dis.html ou = pars.html
ambs=len(ambiguous.findall(tout))
unkn=len(unknown.findall(tout))
print("ambs, unkn",ambs, unkn)
nambigus=""
if ambs!=0 : nambigus="ambigus: "+str(ambs)+" "
ninconnus=""
if unkn!=0 : ninconnus="inconnus: "+str(unkn)
toutout=toutout+titl+"; ; "+filename+"; ; "+word+"; "+auth+"; "+nambigus+ninconnus+"\n"
else:
diffauth=""
nauth_fn=0
fileauth=re.search(r"[0-9\-]*\_[0-9]*([a-z\_]*)\-",filename)
if fileauth :
authshort=fileauth.group(1)
nauth_fn=1
if "_" in authshort:
spauthshort=authshort.split("_")
nauth_fn=len(spauthshort)
nauth_meta=0
if auth!="":
nauth_meta=1
if "|" in auth:
spauth=auth.split("|")
nauth_meta=len(spauth)
if nauth_fn!=nauth_meta :
diffauth=" "+str(nauth_fn)+"/"+str(nauth_meta)+" ?"
toutout=toutout+titl+"; ; "+filename+"; ; "+word+"; "+auth+"; "+diffauth+"\n"
toutwords=toutwords+words
if toutout!="" :
toutout=toutmedianame+" "+toutmedianumber+" "+toutdate+"; ; ; ; "+str(toutwords)+"; ;\n" +toutout+"\n\n"
outf.write(toutout)
grandtotal=grandtotal+toutwords
nbrep=nbrep+1
outf.write("TOTAL for "+str(nbrep)+" issues ; ; ; ; "+str(grandtotal)+"; ;\n")
outf.close()