This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest-pfh.py
144 lines (111 loc) · 4.5 KB
/
test-pfh.py
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
from klasa import *
import pywikibot
import collections
def licz_jezyki():
lista_stron2 = ['bīhi sà bòlo', 'ʘna̰e']
statList = collections.defaultdict()
statList["język !Xóõ"] = LangStats("język !Xóõ", "!Xóõ")
i = 1
#templatesToDelete = deletedTemplates()
for a in lista_stron2:
#if (i<1000):
try: haslo = Haslo(a)
except sectionsNotFound:
pass
except WrongHeader:
pass
else:
if haslo.type != 5:
for b in haslo.listLangs:
if b.type != 2 and b.type != 3:
print(b.langLong)
if b.langLong == 'termin obcy w języku polskim':
b.langLong = 'język polski'
if b.langLong in statList:
b.pola()
if not b.inflectedOnly:
statList['%s' % b.langLong].addWord()
#statList[u'%s' % b.langLong].addLength(countLength(b.content, templatesToDelete))
#audiotmp = countAudio(b.content)
#graphtmp = countGraph(b.content)
#if audiotmp:
# statList[u'%s' % b.langLong].addAudio()
# statList[u'%s' % b.langLong].addAudioAll(audiotmp)
#if graphtmp:
# statList[u'%s' % b.langLong].addGraph()
# statList[u'%s' % b.langLong].addGraphAll(graphtmp)
if b.type == 1:
print(meanings(b.znaczeniaDetail))
print('here')
statList['%s' % b.langLong].addMeans(meanings(b.znaczeniaDetail))
#statList[u'%s' % b.langLong].addRef(refs(b.subSections[u'źródła'].text, templatesToDelete))
else:
print(b.type)
#statList[u"język !Xóõ"].countAvgMean()
print(statList["język !Xóõ"].countWords)
print(statList["język !Xóõ"].countMeans)
class LangStats():
def __init__(self, longName, shortName):
self.longName = longName
self.shortName = shortName
self.countWords = 0
self.countMeans = 0
self.countLen = 0
self.countAudio = 0 # words with at least one audio file
self.countGraph = 0 # words with at least one image
self.countAudioAll = 0 # the number of audio files in each word
self.countGraphAll = 0 # the number of images in each word
self.countRef = 0
self.avgLen = 0.0
self.avgMean = 0.0
self.percAudio = 0.0
self.percGraph = 0.0
self.percRef = 0.0
self.rank = {'countWords': 0, 'countMeans': 0, 'countLen': 0, 'avgLen': 0, 'percAudio': 0, 'percGraph': 0, 'percRef': 0}
def addLength(self, length):
self.countLen += length
def addMeans(self, means):
self.countMeans += means
def addAudio(self):
self.countAudio += 1.0
def addGraph(self):
self.countGraph += 1.0
def addAudioAll(self, count):
self.countAudioAll += count
def addGraphAll(self, count):
self.countGraphAll += count
def addRef(self, ref):
self.countRef += ref
def addWord(self):
self.countWords += 1
def countAvgLen(self):
if self.countWords:
self.avgLen = self.countLen/self.countWords
def countAvgMean(self):
if self.countWords:
self.avgMean = self.countMeans/self.countWords
def countPercAudio(self):
if self.countWords:
self.percAudio = self.countAudio/self.countWords*100
def countPercGraph(self):
if self.countWords:
self.percGraph = self.countGraph/self.countWords*100
def countPercRef(self):
if self.countWords:
self.percRef = self.countRef/self.countWords*100
def meanings(input):
"""counting different meanings in each page
"""
re_count = re.compile('(\: \([0-9]\.[0-9]\))')
counter = 0.0
if input:
for elem in input:
if '{{forma' in elem[0]:
continue
else:
s_count = re.findall(re_count, elem[1])
counter += len(s_count)*1.0
return counter
licz_jezyki()