/
euwiki.py
65 lines (58 loc) · 2.25 KB
/
euwiki.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
"""
Basque Wikipedia
++++++++++++++++
"""
from revscoring.datasources.meta import filters, mappers
from revscoring.features import wikitext
from revscoring.features.meta import aggregators
from revscoring.features.modifiers import log, max
from revscoring.features.wikitext.datasources import Revision
from revscoring.languages import basque, english, spanish
from . import wikipedia
# Templates
infobox_templates = wikitext.revision.template_names_matching(
r"[\w\s_]*infotaula[ _]automatikoa$",
name="euwiki.revision.infobox_templates")
cn_templates = wikitext.revision.template_names_matching(
r"erref[ _]behar", name="euwiki.revision.cn_templates")
# Links
# Excluding category_links based on https://phabricator.wikimedia.org/T240467
# category_links = wikitext.revision.wikilink_titles_matching(
# r"(Kategoria|Category)\:", name="euwiki.revision.category_links")
image_links = wikitext.revision.wikilink_titles_matching(
r"(File|Image|Fitxategi)\:", name="euwiki.revision.image_links")
# References
revision = Revision(
"euwiki.revision.revision",
wikitext.revision.datasources,
)
paragraphs = mappers.map(
str, revision.paragraphs_sentences_and_whitespace,
name="euwiki.revision.paragraphs"
)
paragraphs_without_refs = filters.regex_matching(
r"^(?!\s*$)((?!<ref>)(.|\n))*$",
paragraphs,
name="euwiki.revision.paragraphs_without_refs"
)
paragraphs_without_refs_total_length = aggregators.sum(
mappers.map(len, paragraphs_without_refs),
name="euwiki.revision.paragraphs_without_refs_total_length"
)
local_wiki = [
image_links,
image_links / max(wikitext.revision.content_chars, 1),
# category_links,
# category_links / max(wikitext.revision.content_chars, 1),
infobox_templates,
cn_templates + 1,
cn_templates / max(wikitext.revision.content_chars, 1),
log(paragraphs_without_refs_total_length + 1),
basque.dictionary.revision.dict_words,
basque.dictionary.revision.dict_words / max(wikitext.revision.words, 1),
english.dictionary.revision.dict_words,
english.dictionary.revision.dict_words / max(wikitext.revision.words, 1),
spanish.dictionary.revision.dict_words,
spanish.dictionary.revision.dict_words / max(wikitext.revision.words, 1),
]
wp10 = wikipedia.article + local_wiki