Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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]
CommandWhat it does
downloadFetches the dumps, the clickstream and Wikidata categories
decompressUnpacks the .gz files
provisionLoads the .sql dumps into MariaDB
buildReads MariaDB and writes the .wgrf graph
infoSummarizes a graph and checks it against the spec
exploreShows the pages reachable from one page
pathFinds a path between two pages: most followed, shortest, popular or niche
strategiesDescribes each path strategy

Every command has --help.

download

Downloads the Wikipedia table dumps, the clickstream and the Wikidata categories.

WikipediaPath.GraphBuilder download [options]
OptionDefaultDescription
-o, --outputdumpsDirectory for the files
--wikifrwikiWiki database name
--datelatestDump run as yyyyMMdd, or latest
--clickstreamlatestMonth as yyyy-MM, latest, or none to skip it
--mirrorhttps://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 what dumpstatus.json says.
  • An interrupted .part file 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]
OptionDefaultDescription
-i, --inputdumpsDirectory with the .gz files
-o, --outputsame as --inputDirectory for the decompressed files
-j, --parallelismnumber of CPU coresFiles 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]
OptionDefaultDescription
-i, --inputdumpsDirectory with the .sql files
-d, --database$WPATH_DB_NAME, else wikipediaTarget database. It must exist
--socket$MYSQL_UNIX_PORTMariaDB unix socket
--clientmariadbMariaDB command-line client
--keep-row-formatoffKeep ROW_FORMAT=COMPRESSED from the dumps
-j, --parallelism4Tables 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]
OptionDefaultDescription
-o, --outputdumps/graph.wgrfFile to write
-d, --database$WPATH_DB_NAME, else wikipediaDatabase with the tables
--socket$MYSQL_UNIX_PORTMariaDB unix socket
--clientmariadbMariaDB command-line client
--categoriesdumps/frwiki-wikidata-categories.tsvCategories file from download
--clickstreamnewest dumps/clickstream-frwiki-*.tsvDecompressed clickstream for the click_count and view_count columns
-v, --verboseoffProgress every few seconds, queries, memory, what was dropped

What it needs

  • The tables page, redirect, linktarget, pagelinks and page_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 newest clickstream-frwiki-*.tsv in dumps/. If there is none, the graph has no click_count and view_count columns. If you give --clickstream and the file is missing, the command stops.

Steps

  1. Read every main-namespace page from page.
  2. Read redirects from redirect, then resolve each one to an article.
  3. Read page_props to give each article its Wikidata category.
  4. Read the clickstream, if any: every row adds to the views of the page it ends on, and each link row with both titles resolved to articles gives clicks to that pair.
  5. Read linktarget to map each link target to an article.
  6. Read pagelinks in 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.
  7. 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]
OptionDefaultDescription
-i, --inputdumps/graph.wgrfFile to read
--top10Entries 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]
OptionDefaultDescription
titlePage to start from
-i, --inputdumps/graph.wgrfFile to read
--nodeStart from this node id instead of a title
-d, --max-depth2Clicks away from the start page, 0 to 32
-n, --max-children10Pages shown under each page. The rest are counted
--orderClicksOrder of child pages: Clicks (most clicked link first), Links (most links first), Title or Id
-s, --strategyfollowedParent of each page: followed (most clicked link from the level above) or first-found
-f, --formattreetree for text, dot for Graphviz
--exclude-date-pageoffNever walk into a date page
--exclude-countryoffNever 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]
OptionDefaultDescription
fromPage to start from
toPage to reach
-i, --inputdumps/graph.wgrfFile to read
-s, --strategyfollowedfollowed, shortest, popular, niche, niche-clicks or niche-views, see below
--exclude-date-pageoffNever go through a date page (day, year, century, …)
--exclude-countryoffNever go through a country page

Strategies

StrategyFindsEach page shows
followedThe links readers click mostclicks on the link to it
shortestThe fewest clicksnothing
popularA way through pages readers click into mostclicks on links into it
nicheA way through pages few others link toin-links
niche-clicksA way through pages readers rarely click intoclicks on links into it
niche-viewsA way through pages readers rarely visitviews

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:

  1. The text as you typed it.
  2. With underscores replaced by spaces (Tour_Eiffel).
  3. With a capital first letter (tour Eiffel).
  4. 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]
OptionDefaultDescription
nameStrategy 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.