WGRF — Wikipedia-fr Path Graph Binary Format
Status: draft · Version: 1
Read-only, mmap-friendly CSR graph of Wikipedia-fr articles for BFS / shortest-path.
Conventions
- Little-endian.
uint16/uint32/uint64= 2/4/8 bytes. Strings are UTF-8, not terminated. - All offsets are byte offsets from the start of the file.
- Every section and column starts aligned to its element size; the builder pads before it.
Model
Two levels of self-describing tables:
- Section directory — locates the top-level regions (nodes, titles, columns, …). A reader finds every region through this table, never by a hard-coded position.
- Column directory — one section that lists the per-edge / per-node columns. An edge is
not a struct but an index: edge
iistarget_id[i],flags[i], … across parallel columns. Both tables carrybyte_length, so a reader skips any section or column it doesn’t recognize — new data is added without a version bump. Adjacency is CSR:Node[i]marks where nodei’s out-edges start; the sentinelNode[node_count]closes the last node.
Layout
[Header] // 64 bytes, fixed
[Section * section_count] // section directory
[Column * column_count] // one section: the column directory
[Node * (node_count + 1)] // CSR row offsets, id-indexed, + sentinel
[<column data blocks>] // target_id (mandatory) + optional columns, any order
[Title * (node_count + 1)] // id-indexed, + sentinel
[TitleBytes] // packed UTF-8, padded to 4
[ByTitle * by_title_count] // alphabetical search index (canonical + aliases)
Physical order is illustrative; only the directories are authoritative.
Header — 64 bytes
struct Header {
byte[4] magic; // "WGRF"
uint32 version; // 1
uint64 build_date; // Unix seconds, UTC
uint32 node_count;
uint32 reserved0;
uint64 edge_count; // length of edge-domain columns
uint16 section_count;
uint16 reserved1;
uint32 reserved2;
uint64 sections_offset; // -> Section[section_count]
byte[16] reserved;
};
A reader rejects a file whose magic is not WGRF or whose version it does not know: a new
version means existing readers would misread the file. sections_offset is 8-aligned.
Section directory
struct Section { // 24 bytes
uint16 section_id; // see registry
uint16 reserved;
uint32 element_size; // bytes/element; 0 if variable (e.g. title_bytes)
uint64 offset; // start of the section
uint64 byte_length; // total size — enables skipping unknown sections
};
Registry (gaps left for growth):
| id | name | element_size | notes |
|---|---|---|---|
| 0 | columns | 32 | the column directory (see below) |
| 1 | nodes | 4 | Node[node_count + 1] |
| 2 | titles | 4 | Title[node_count + 1] |
| 3 | title_bytes | 0 | packed UTF-8 |
| 4 | by_title | 12 | ByTitle[by_title_count] |
Sections columns, nodes, titles, title_bytes, by_title are all required in v1;
future sections may be optional. count is derived: byte_length / element_size, except the
sentinel arrays which hold node_count + 1.
Column directory (section 0)
struct Column { // 32 bytes
uint16 column_id; // see registry
uint8 domain; // 0 = edge-indexed, 1 = node-indexed
uint8 encoding; // 0 = dense fixed-width
// 1 = sparse pairs (index:uint32, value:uint32)
// 2 = delta+varint (reserved)
uint8 element_size; // bytes/element for dense; 8 (one pair) for sparse;
// 0 if variable
uint8 reserved8;
uint16 reserved16;
uint64 offset;
uint64 byte_length; // enables skipping unknown columns
uint64 count; // element count (dense) or pair count (sparse)
};
Registry:
| id | name | domain | encoding | notes |
|---|---|---|---|---|
| 0 | target_id | edge | dense u32 | mandatory — hot BFS array, stored alone |
| 1 | flags | edge | dense u8 | per-edge bits, meaning TBD |
| 2 | click_count | edge | sparse | clicks from the clickstream; optional |
| 16 | page_id | node | dense u32 | Wikipedia curid; optional |
| 17 | category | node | dense u8 | kind of page, see below; optional |
| 18 | view_count | node | dense u32 | visits from the clickstream; optional |
A reader that cannot find column_id = 0 MUST reject the file. Others are optional. Because
click_count is sparse, an absent edge means “no clickstream data” — no flag needed to tell
that apart from a measured zero.
Sparse columns
A sparse column (encoding = 1) stores only the elements that have a value, as pairs:
struct SparsePair { // 8 bytes
uint32 index; // edge or node index, per the column's domain
uint32 value;
};
element_sizeis 8,countis the number of pairs andbyte_lengthiscount * 8.- Pairs are sorted by strictly ascending
index: no index appears twice. A reader finds one element by binary search. A node’s edges are contiguous, so the pairs of its edges form one contiguous run. indexis belowedge_countfor an edge-domain column, belownode_countfor a node-domain one. Likefirst_edge, it assumes edge indices fit in 2^32.- An index without a pair has no value. That is not the same as a value of 0.
click_count values
Number of times readers followed the link of this edge during one month, from the Wikipedia clickstream. One file uses one month. Only edges the clickstream measured have a pair, so most edges have none. When the column is absent, the file was built without clickstream data.
view_count values
Number of times readers reached the page during the same month, from any referer: another article, a search engine, another site or no referer. It sums every clickstream row that ends on the page. The clickstream leaves out the rarest pairs, so this is a lower bound of the page views, not an exact count. When the column is absent, the file was built without clickstream data.
category values
One byte per node naming what kind of page it is. A page has at most one category.
| value | name | example |
|---|---|---|
| 0 | none | any page not listed below |
| 1 | day | 14 juillet |
| 2 | date | 10 mai 1981 |
| 3 | month | Janvier |
| 4 | month_of_year | Janvier 1913 |
| 5 | year | 1913, 44 av. J.-C. |
| 6 | decade | Années 1910 |
| 7 | century | XIXe siècle |
| 8 | millennium | IIe millénaire |
| 9 | year_in_topic | 1913 en sport |
| 10 | country | France, Écosse |
Values 1 to 8 are date pages. year_in_topic is a chronology of one field for one period,
not a date page. country covers historical states, empires and constituent countries too, so
République démocratique allemande is one. Values 11 to 255 are reserved: a reader treats them
as none. When the column is absent, no page has a known category; that is not the same as
every page being none.
Node / Title / ByTitle
struct Node { uint32 first_edge; }; // index into edge-domain columns
struct Title { uint32 first_byte; }; // offset into title_bytes
struct ByTitle { // 12 B, sorted alphabetically by name
uint32 name_first_byte; // -> title_bytes
uint32 name_length;
uint32 node_id; // canonical node this name resolves to
};
out_degree(i) = Node[i+1].first_edge - Node[i].first_edge.- Title length of node
i=Title[i+1].first_byte - Title[i].first_byte. by_title_count >= node_count(canonical titles + searchable redirect aliases; many entries may share onenode_id). Name→id is a binary search comparing againsttitle_bytes.Titlestays id-ordered for the id→name direction used during traversal.- “Alphabetically” means ordinal comparison of the UTF-8 bytes (no case folding, no collation),
shorter name first when one is a prefix of the other; equal names are ordered by
node_id. - Alias names live in
title_bytesafter the canonical titles, pastTitle[node_count], so theTitlesentinel still closes the last canonical title. uint32widths onfirst_edge/first_byteassume the arrays fit in 2^32; confirm from dump statistics.
Alignment
Header is 64 (8-aligned). Because every region has an explicit offset, the builder pads before
each so it starts aligned to its element: Section table → 8, Column table → 8, nodes → 4,
each dense column → its element_size, each sparse column → 4, titles → 4, title_bytes → padded to 4 before
by_title, by_title → 4. What precedes a region never affects its alignment.
Padding bytes and every reserved* field are zero. A section’s or column’s byte_length covers
its data only, never the padding after it.
Builder responsibilities (not in the file)
-
Nodes: main-namespace (
page_namespace = 0) pages that are not redirects. Node ids follow ascendingpage_id. -
Titles: stored in their displayed form: the underscores of
page_titlebecome spaces (Tour_Eiffel→Tour Eiffel). Aliases use the same form. -
Redirects: resolve each to its canonical target, rewrite edges to canonical ids, drop redirects as nodes — the file holds only real articles. Optionally append a redirect’s title to
title_bytesand add aByTitleentry pointing at the canonical id. The v1 builder adds an alias for every resolved redirect. It follows redirect chains up to 8 hops. A redirect that loops, runs longer, points at a missing page, at another namespace or at another wiki (rd_interwiki) is dropped: no alias, and links to it are dropped like red links. -
Edges: a link becomes an edge when both ends resolve to a node. Each node’s targets are sorted by ascending node id, without duplicates (two links can resolve to one article through redirects) and without self-loops.
-
page_id: if the
page_idcolumn is present, the page_id→node_id lookup is built at load. The v1 builder always writes it. -
category: taken from Wikidata. The article’s item comes from
page_props(pp_propname = 'wikibase_item'), and its category from the item’s “instance of” (P31) statements, matched directly, without following “subclass of” (P279):category the item is an instance of dayQ14795564 (point in time with respect to recurrent timeframe) and is part of (P361) an instance of Q47018901 (calendar month) dateQ47150325 (calendar day of a given year) monthQ47018901 (calendar month) month_of_yearQ47018478 (calendar month of a given year) yearQ3186692 (calendar year), Q577 (year) or Q29964144 (year BC) decadeQ39911 (decade) centuryQ578 (century) millenniumQ36507 (millennium) year_in_topicQ18340514 (events in a specific year or time period) countryQ6256 (country), Q3624078 (sovereign state), Q3024240 (historical country), Q48349 (empire) or Q1520223 (constituent country) An item that matches several rows gets the smallest value. Redirects keep no category of their own. Wikidata is queried live, so its statements can be newer than the dump. The v1 builder always writes the column.
-
click_count: taken from a monthly clickstream file (
clickstream-<wiki>-<yyyy-MM>.tsv, rows ofprev,curr,type,n). Only rows oftype = linkcount.prevandcurrare resolved like link targets: by title, through redirects, to a node. A row whose titles don’t both resolve, or whose two nodes have no edge between them in the file, is dropped. Rows that resolve to the same edge (through different redirects) add up, capped at 2^32 - 1. The clickstream month can differ from the dump date, so some rows name links the dump no longer has. The v1 builder writes the column when a clickstream file is available, and leaves it out otherwise. -
view_count: taken from the same clickstream file as
click_count. Every row counts, whatever itstype.curris resolved like a link target; a row whosecurrdoesn’t resolve is dropped. Rows that resolve to the same node add up, capped at 2^32 - 1. The v1 builder writes the column exactly when it writesclick_count.
Open / deferred
- Reverse (bidirectional) index — not in the file; additive as a new section + columns.
uint32field widths (first_edge,first_byte) pending dump statistics.- Edge compression (
encoding = 2, delta+varint ontarget_id) — reserved, unspecified. flagsbit meanings — TBD.