WikipediaPath.GraphBuilder
WikipediaPath.GraphBuilder is the command-line tool of the repository. It builds the WGRF graph
from Wikipedia dumps, then reads it.
WikipediaPath.GraphBuilder <command> [options]
| Command | What it does |
|---|---|
download | Fetches the dumps, the clickstream and Wikidata categories |
decompress | Unpacks the .gz files |
provision | Loads the .sql dumps into MariaDB |
build | Reads MariaDB and writes the .wgrf graph |
info | Summarizes a graph and checks it against the spec |
explore | Shows the pages reachable from one page |
path | Finds a path between two pages: most followed, shortest, popular or niche |
strategies | Describes each path strategy |
Every command has --help.
download
Downloads the Wikipedia table dumps, the clickstream and the Wikidata categories.
WikipediaPath.GraphBuilder download [options]
| Option | Default | Description |
|---|---|---|
-o, --output | dumps | Directory for the files |
--wiki | frwiki | Wiki database name |
--date | latest | Dump run as yyyyMMdd, or latest |
--clickstream | latest | Month as yyyy-MM, latest, or none to skip it |
--mirror | https://dumps.wikimedia.org/ | Base URL of a Wikimedia dumps mirror |
Choosing the dump
With --date latest, the command lists the dump runs on the mirror, newest first, and reads each
run’s dumpstatus.json. It picks the first run where these jobs are done: pagetable,
pagelinkstable, linktargettable, redirecttable and pagepropstable.
With an explicit date, the command fails if one of these jobs is not finished.
Downloading
- Files download one at a time. Wikimedia limits parallel connections per IP.
- Each file goes to
<name>.part, then moves to<name>once its size and SHA-1 match whatdumpstatus.jsonsays. - An interrupted
.partfile resumes with an HTTP range request. - Network errors retry up to 5 times, with a longer wait each time.
- A file already present with the right size is skipped.
Wikidata categories
After the dumps, the command runs one SPARQL query per category on the
Wikidata Query Service and writes
<wiki>-wikidata-categories.tsv:
# Wikidata categories of frwiki articles, queried 2026-09-30T22:25:29Z from https://query.wikidata.org/sparql
Q2151 day
Q2150 day
...
Q750 country
Q16 country
If the file exists, the command does not query again. Delete it to get fresh data.
This data is from the day you run the command, not from the dump date.
decompress
Decompresses every .gz file in a directory.
WikipediaPath.GraphBuilder decompress [options]
| Option | Default | Description |
|---|---|---|
-i, --input | dumps | Directory with the .gz files |
-o, --output | same as --input | Directory for the decompressed files |
-j, --parallelism | number of CPU cores | Files decompressed at the same time |
Gzip decoding can’t be split inside one file, so the work is split by file. The largest files
start first, so the longest job does not start last. With the default dump set, pagelinks takes
most of the time.
Each file is written to <name>.part, then renamed. A file that already exists is skipped. If an
archive is corrupt, its .part file is deleted and the command fails.
The .gz files are kept. Delete them yourself if you need the disk space.
provision
Loads the .sql dumps into MariaDB. Each dump drops its table and creates it again.
WikipediaPath.GraphBuilder provision [options]
| Option | Default | Description |
|---|---|---|
-i, --input | dumps | Directory with the .sql files |
-d, --database | $WPATH_DB_NAME, else wikipedia | Target database. It must exist |
--socket | $MYSQL_UNIX_PORT | MariaDB unix socket |
--client | mariadb | MariaDB command-line client |
--keep-row-format | off | Keep ROW_FORMAT=COMPRESSED from the dumps |
-j, --parallelism | 4 | Tables loaded at the same time |
Start the server first with db-start. See Local database.
How it loads
The command starts one mariadb client per file and streams the file to it. The client parses
the SQL. Progress shows every 10 seconds.
Only files ending in .sql are loaded. The clickstream .tsv is ignored.
Row format
Wikimedia dumps create tables with ROW_FORMAT=COMPRESSED. Compressed pages cost CPU on every
insert, and loading is about twice as slow. By default, the command removes this option from the
CREATE TABLE statements. The tables then use more disk.
Use --keep-row-format if disk space matters more than time.
Time
This step takes hours: the pagelinks dump alone is about 9 GB of SQL. Don’t run it again unless
you have new dumps.
build
Reads the provisioned tables and writes a WGRF graph file.
WikipediaPath.GraphBuilder build [options]
| Option | Default | Description |
|---|---|---|
-o, --output | dumps/graph.wgrf | File to write |
-d, --database | $WPATH_DB_NAME, else wikipedia | Database with the tables |
--socket | $MYSQL_UNIX_PORT | MariaDB unix socket |
--client | mariadb | MariaDB command-line client |
--categories | dumps/frwiki-wikidata-categories.tsv | Categories file from download |
--clickstream | newest dumps/clickstream-frwiki-*.tsv | Decompressed clickstream for the click_count and view_count columns |
-v, --verbose | off | Progress every few seconds, queries, memory, what was dropped |
What it needs
- The tables
page,redirect,linktarget,pagelinksandpage_props. The command stops if one is missing. - The categories file. The command stops if it is missing.
- Optionally, a decompressed clickstream
.tsv. Without--clickstream, the command takes the newestclickstream-frwiki-*.tsvindumps/. If there is none, the graph has noclick_countandview_countcolumns. If you give--clickstreamand the file is missing, the command stops.
Steps
- Read every main-namespace page from
page. - Read redirects from
redirect, then resolve each one to an article. - Read
page_propsto give each article its Wikidata category. - Read the clickstream, if any: every row adds to the views of the page it ends on, and each
linkrow with both titles resolved to articles gives clicks to that pair. - Read
linktargetto map each link target to an article. - Read
pagelinksin primary key order. Rows come grouped by source page, which is node order, so each node’s edges go straight to the file. The edge list is never held in memory. - Write titles, the title index, the click counts and the directories.
From Wikipedia to a graph explains the rules applied in each step.
Output
The file is written to <output>.tmp, then renamed. If the build fails, the .tmp file is
deleted and the old graph stays in place.
The command never writes to the database. See Read-only access from build.
Querying MariaDB
The builder runs each query through the mariadb client with --batch --quick and parses the
tab-separated output. It does not use a .NET database driver.
info
Prints a summary of a WGRF file and checks that it follows the spec.
WikipediaPath.GraphBuilder info [options]
| Option | Default | Description |
|---|---|---|
-i, --input | dumps/graph.wgrf | File to read |
--top | 10 | Entries in the “most links” and “most clicked” rankings |
Output
- Header: version, build date, file size, node, edge and name counts.
- Sections and columns: id, name, offset and size of each region.
- Degrees: mean, median, 99th percentile and maximum of outgoing and incoming links, dead ends and orphans, and how many links go both ways.
- Titles: number of aliases, mean and longest title.
- Categories: articles per Wikidata category.
- Clickstream: edges with clicks, total clicks and total views, when the file has them.
- Rankings: pages with the most outgoing and incoming links, the most viewed pages and the most clicked links.
- Checks: errors and warnings.
Checks
The command reads the whole file (about 15 seconds for French Wikipedia).
- An error means the file breaks the spec, for example an edge that points past the last node. The command exits with code 1.
- A warning means the file breaks a builder rule, for example unsorted or duplicate edges, or self-loops. The command still exits with 0.
When everything is fine, it prints:
Checks (14.6 s)
ok: the file follows the spec and the builder rules.
explore
Shows the pages you can reach from one page, level by level.
WikipediaPath.GraphBuilder explore [title] [options]
| Option | Default | Description |
|---|---|---|
title | Page to start from | |
-i, --input | dumps/graph.wgrf | File to read |
--node | Start from this node id instead of a title | |
-d, --max-depth | 2 | Clicks away from the start page, 0 to 32 |
-n, --max-children | 10 | Pages shown under each page. The rest are counted |
--order | Clicks | Order of child pages: Clicks (most clicked link first), Links (most links first), Title or Id |
-s, --strategy | followed | Parent of each page: followed (most clicked link from the level above) or first-found |
-f, --format | tree | tree for text, dot for Graphviz |
--exclude-date-page | off | Never walk into a date page |
--exclude-country | off | Never walk into a country page |
Example
$ WikipediaPath.GraphBuilder explore Pikachu -d 2 -n 3
Pikachu (node 502244, page_id 1797391)
depth 0: 1 new, 1 reached (0.00 % of the graph)
depth 1: 458 new, 459 reached (0.02 % of the graph)
depth 2: 31,309 new, 31,768 reached (1.14 % of the graph)
Pikachu (458 links, 458 new)
├── Pichu et ses évolutions (104 clicks, 339 links, 7 new)
│ ├── Yōkai (0 clicks, 238 links)
│ ├── Raijū (0 clicks, 164 links)
│ ├── Kami (divinité) (0 clicks, 160 links)
│ └── … 4 more
├── Liste des Pokémon (53 clicks, 193 links, 2 new)
│ ├── Système de gestion d'exceptions (0 clicks, 72 links)
│ └── Dolman (0 clicks, 12 links)
├── Pokémon (45 clicks, 351 links, 84 new)
│ ├── Histoire du jeu vidéo (41 clicks, 498 links)
│ ├── Jeu vidéo de rôle (38 clicks, 220 links)
│ ├── Éponymie (36 clicks, 250 links)
│ └── … 81 more
└── … 455 more
The tree is a shortest-path tree: each page shows once, at its shortest distance from the start.
With --strategy followed, a page sits under the page of the level above whose link to it
readers click most, and “clicks” is the count of that link. A page no link from the level above
was clicked into keeps the first page that reached it, with 0 clicks. --strategy first-found
always keeps the first page, as a plain breadth-first search. On a graph without a clickstream,
both give the same tree and the labels show no clicks. See
Explore with the clickstream.
In Graphviz output, each edge is labeled with its clicks.
Graphviz output
WikipediaPath.GraphBuilder explore Pikachu -d 2 -n 5 -f dot | dot -Tsvg > pikachu.svg
Graphviz is not in the dev shell. Install it yourself if you need it.
The start title follows the same rules as path, see Title matching.
path
Finds a chain of links from one page to another: the one readers follow most, the shortest, or one through popular or little-known pages.
WikipediaPath.GraphBuilder path <from> <to> [options]
| Option | Default | Description |
|---|---|---|
from | Page to start from | |
to | Page to reach | |
-i, --input | dumps/graph.wgrf | File to read |
-s, --strategy | followed | followed, shortest, popular, niche, niche-clicks or niche-views, see below |
--exclude-date-page | off | Never go through a date page (day, year, century, …) |
--exclude-country | off | Never go through a country page |
Strategies
| Strategy | Finds | Each page shows |
|---|---|---|
followed | The links readers click most | clicks on the link to it |
shortest | The fewest clicks | nothing |
popular | A way through pages readers click into most | clicks on links into it |
niche | A way through pages few others link to | in-links |
niche-clicks | A way through pages readers rarely click into | clicks on links into it |
niche-views | A way through pages readers rarely visit | views |
All strategies except shortest and niche need a graph built with a clickstream. Without one,
every count is 0 and the command warns you. Run strategies for how each one
scores a path, and see Path search for the search algorithms.
The path goes to standard output. The search statistics and messages go to standard error.
The command exits with 1 when a title is unknown or when no path exists.
When several best paths exist, the command prints one of them. It is the same one on every run.
Examples
On the 2026-09-01 dump with the 2026-08 clickstream:
$ WikipediaPath.GraphBuilder path "Tour Eiffel" "Pikachu"
Prepared 'followed' in 123 ms.
Searched 181,402 pages in 286 ms.
5 clicks from 'Tour Eiffel' to 'Pikachu':
0. Tour Eiffel
1. Tour métallique de Fourvière (17 clicks on this link)
2. Téléphone mobile (16 clicks on this link)
3. Smartphone (121 clicks on this link)
4. Jeu vidéo (11 clicks on this link)
5. Pikachu (23 clicks on this link)
$ WikipediaPath.GraphBuilder path "Tour Eiffel" "Pikachu" -s shortest
Prepared 'shortest' in 0 ms.
Searched 99,483 pages in 30 ms.
2 clicks from 'Tour Eiffel' to 'Pikachu':
0. Tour Eiffel
1. Jeu vidéo
2. Pikachu
$ WikipediaPath.GraphBuilder path "Tour Eiffel" "Pikachu" -s niche
Prepared 'niche' in 98 ms.
Searched 178,161 pages in 45 ms.
3 clicks from 'Tour Eiffel' to 'Pikachu':
0. Tour Eiffel (2,083 in-links)
1. Légende urbaine (483 in-links)
2. Thème de Lavanville (12 in-links)
3. Pikachu (392 in-links)
followed takes 5 clicks here because nobody clicked Tour Eiffel → Jeu vidéo that month: an
unclicked link costs more than a chain of clicked ones.
niche-clicks and niche-views count a page without clickstream data as 0, the rarest value.
They tend to go through pages the clickstream never measured, such as 1944 en sport.
Title matching
The command tries, in this order:
- The text as you typed it.
- With underscores replaced by spaces (
Tour_Eiffel). - With a capital first letter (
tour Eiffel). - Ignoring case, if every match is the same page.
Redirect names work too. The command tells you when it follows one:
'Paris (France)' redirects to 'Paris'.
If nothing matches, it suggests the closest names.
Excluding pages
--exclude-date-page and --exclude-country need the category column. Graphs built by the
current build always have it. The two pages you give can still be a date or a country.
See Path search for how the search works.
strategies
Describes each path --strategy: what the path goes through, the columns it reads, how it scores
a path and what each printed page shows. It reads no graph.
WikipediaPath.GraphBuilder strategies [name]
| Option | Default | Description |
|---|---|---|
name | Strategy to describe. All of them without it |
$ WikipediaPath.GraphBuilder strategies niche
niche: through pages few others link to.
Reads: links.
Entering a page costs the bit length of its number of in-links, at least 1: 1 for 0 or 1 in-link,
11 for 1,024 to 2,047. The path has the lowest total cost over the pages after the start. Each
page shows its in-links.
The texts come from the strategy definitions in Analyze/Paths/Strategies/PathStrategies.cs,
the same ones path --help summarizes.