-
Notifications
You must be signed in to change notification settings - Fork 99
Update mediawiki database schema + python version #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,69 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Description of the process | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## Parsing of the tables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ### links.txt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `pl_from` -> Id of the "from" page of this link | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - (`pl_namespace`) -> We keep only if equals 0 (= namespace of the "from" page of this link) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `pl_target_id` -> Target of this link (foreign key to `linktarget`) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ### targets.txt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `lt_id` -> Id of this link (index) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - (`lt_ns`) -> We keep only if equals 0 (= namespace of the targeted page) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `lt_title` -> Title of the targeted page | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ### pages.txt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `page_id` -> Id of the page | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - (`page_namespace`) -> We keep only if equals 0 (= namespace of this page) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `page_title` -> Title of this page | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `page_is_redirect` -> Boolean wether this page is a redirect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - Ignore the eight following | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ### redirects.txt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `rd_from` -> Id of the page from which we are redirected | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - (`rd_namespace`) -> We keep only if equals 0 (= namespace of the page we are redirected to) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `rd_title` -> Title of the page we are redirected to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - Ignore the two following | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## Joining the tables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ### redirects.with_ids.txt (replace_titles_in_redirects_file.py) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Replaces for each redirection, `rd_title` with the targetted `page_id` by matching on `page_title`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| The targetted page_id is then computed as a redirect recursively, until we get on a "final" page. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `rd_from` -> The id of the page we are redirected from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `page_id` -> The id of the page we get to following redirections recursively | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ### targets.with_ids.txt (replace_titles_and_redirects_in_targets_file.py) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Replaces, for each linktarget, `lt_title` with the targetted `page_id` by matching on `page_title`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| We then compute the "final" page obtained from this page following redirection, with the file `redirects.with_ids.txt`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `lt_id` -> Id of this link | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `page_id` -> The id of the page this link is pointing to, after having followed all redirections | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ### links.with_ids.txt (replace_titles_and_redirects_in_links_file.py) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Replaces, for each pagelink, `lt_id` with the targetted `page_id` by joining with `links.with_ids.txt`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+31
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix spelling errors. Lines 31, 32, 37, and 43: "targetted" should be "targeted". Apply this diff: -Replaces for each redirection, `rd_title` with the targetted `page_id` by matching on `page_title`.
-The targetted page_id is then computed as a redirect recursively, until we get on a "final" page.
+Replaces for each redirection, `rd_title` with the targeted `page_id` by matching on `page_title`.
+The targeted page_id is then computed as a redirect recursively, until we get on a "final" page.
- `rd_from` -> The id of the page we are redirected from
- `page_id` -> The id of the page we get to following redirections recursively
### targets.with_ids.txt (replace_titles_and_redirects_in_targets_file.py)
-Replaces, for each linktarget, `lt_title` with the targetted `page_id` by matching on `page_title`.
+Replaces, for each linktarget, `lt_title` with the targeted `page_id` by matching on `page_title`.And on line 43: -Replaces, for each pagelink, `lt_id` with the targetted `page_id` by joining with `links.with_ids.txt`.
+Replaces, for each pagelink, `lt_id` with the targeted `page_id` by joining with `links.with_ids.txt`.📝 Committable suggestion
Suggested change
🧰 Tools🪛 LanguageTool[grammar] ~31-~31: Ensure spelling is correct (QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1) [grammar] ~32-~32: Ensure spelling is correct (QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1) [grammar] ~37-~37: Ensure spelling is correct (QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1) [grammar] ~43-~43: Ensure spelling is correct (QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `pl_from` -> Id of the "from" page, after having followed all redirections | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `page_id` -> Id of the "to" page, after having followed all redirections | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ### page.pruned.txt (prune_pages_file.py) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Prunes the pages file by removing pages which are marked as redirects but have no corresponding redirect in the redirects file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## Sorting, grouping, and counting the links | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ### links.sorted_by_XXX_id.txt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Then we sorts the `links.with_ids.txt` according to the first "source" id, into | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| the file `links.sorted_by_source_id.txt`, and according to the second "target" id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| into the file `links.sorted_by_target_id.txt`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ### links.grouped_by_XXX_id.txt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Then, we use those two files to *GROUP BY* the links by source and by target. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| The file `links.grouped_by_source_id.txt` is like this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `pl_from` -> Id of the "from" page | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `targets` -> A `|`-separated string of the ids the "from" page targets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| The file `links.grouped_by_target_id.txt` is like this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `froms` -> A `|`-separated string of the ids of the pages targeting the "target" page | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `pl_target` -> Id of the "target" page | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ### links.with_counts.txt (combine_grouped_links_files.py) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## Making the database | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,14 +28,14 @@ | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Create a dictionary of redirects. | ||||||||||||||||||||||||||
| REDIRECTS = {} | ||||||||||||||||||||||||||
| for line in io.BufferedReader(gzip.open(REDIRECTS_FILE, 'r')): | ||||||||||||||||||||||||||
| [source_page_id, _] = line.rstrip('\n').split('\t') | ||||||||||||||||||||||||||
| for line in io.BufferedReader(gzip.open(REDIRECTS_FILE, 'rb')): | ||||||||||||||||||||||||||
| [source_page_id, _] = line.rstrip(b'\n').split(b'\t') | ||||||||||||||||||||||||||
| REDIRECTS[source_page_id] = True | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Loop through the pages file, ignoring pages which are marked as redirects but which do not have a | ||||||||||||||||||||||||||
| # corresponding redirect in the redirects dictionary, printing the remaining pages to stdout. | ||||||||||||||||||||||||||
| for line in io.BufferedReader(gzip.open(PAGES_FILE, 'r')): | ||||||||||||||||||||||||||
| [page_id, page_title, is_redirect] = line.rstrip('\n').split('\t') | ||||||||||||||||||||||||||
| for line in io.BufferedReader(gzip.open(PAGES_FILE, 'rb')): | ||||||||||||||||||||||||||
| [page_id, page_title, is_redirect] = line.rstrip(b'\n').split(b'\t') | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if is_redirect == '0' or page_id in REDIRECTS: | ||||||||||||||||||||||||||
| print('\t'.join([page_id, page_title, is_redirect])) | ||||||||||||||||||||||||||
| if True or is_redirect == '0' or page_id in REDIRECTS: | ||||||||||||||||||||||||||
| print(b'\t'.join([page_id, page_title, is_redirect]).decode()) | ||||||||||||||||||||||||||
|
Comment on lines
+37
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Filtering logic is completely disabled. The condition on line 40 will always evaluate to This bug could directly contribute to issue #149, as the pruning step would output incorrect data. Apply this diff to fix the logic: - if True or is_redirect == '0' or page_id in REDIRECTS:
+ if is_redirect == b'0' or page_id in REDIRECTS:
print(b'\t'.join([page_id, page_title, is_redirect]).decode())📝 Committable suggestion
Suggested change
🧰 Tools🪛 Pylint (4.0.2)[refactor] 40-40: Boolean condition 'True or is_redirect == '0' or page_id in REDIRECTS' will always evaluate to 'True' (R1727) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix spelling error.
Line 19: "wether" should be "whether".
Apply this diff:
📝 Committable suggestion
🧰 Tools
🪛 LanguageTool
[grammar] ~19-~19: Ensure spelling is correct
Context: ...is page -
page_is_redirect-> Boolean wether this page is a redirect - Ignore the ei...(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
🤖 Prompt for AI Agents