How etymap works

Some graph theory, some text parsing, and a few tricks to fit it all on a static website.

When you type take, the page looks up its Dutch translation, nemen, and then has to answer a question that sounds simple: where do these two words meet? To answer it, the build turns a dictionary into a graph, asks a lowest-common-ancestor question on that graph, and then searches it for "ghost" relatives. Everything is computed ahead of time, so your browser only downloads a few small files.

1. Building the graph

English Wiktionary writes etymologies as prose, but the prose is built from structured templates. The entry for Dutch nemen reads "From Middle Dutch nēmen, from Old Dutch neman, from Proto-West Germanic *neman…", and underneath it looks like this:

{{inh|nl|dum|nēmen}}, from {{inh|nl|odt|neman}}, from {{inh|nl|gmw-pro|*neman}} …

inh means inherited (the word passed down within a language family), bor means borrowed, der means derived, and so on. The Wiktextract project parses all of Wiktionary into JSON. The build streams the full dump (about 11 million entries in a 3 GB file) and keeps entries in around 50 relevant languages.

Each word becomes a node keyed by language|normalised form (macrons are stripped except in reconstructions, to match how Wiktionary names its pages). Each template becomes a directed edge child → parent. Two details make this harder than it looks:

The result is about 1.8 million nodes and 2.9 million edges.

2. Tracing a word's ancestors

Starting from a word, the build walks parent edges breadth-first. Most of the time this gives a simple chain: water ← Middle English water ← Old English wæter ← Proto-West Germanic *watar ← … But compounds have several parents (Dutch tijdperk is tijd + perk), so the ancestry is a directed acyclic graph. Affixes (-je, be-, *-aną) are drawn but never followed. If they were, almost any two verbs would "share an ancestor" in the Proto-Germanic infinitive ending. Each DAG is capped at 32 nodes, which breadth-first order makes a graceful limit: the nodes that get cut are the most distant ones.

3. Finding the common ancestor

Write A(x) for the set of ancestors of x (including x itself). The common ancestors of an English word e and a Dutch word d are C = A(e) ∩ A(d). Ancestry is a partial order, and the lowest common ancestors are the minimal elements of C: the common ancestors that have no other common ancestor below them.

*watōrProto-Germanic *watarProto-West Germanic · LCA wæterOld English watarOld Dutch waterEnglish waterDutch
Every node above *watar is also a common ancestor, but only *watar is minimal, so it is the LCA. (Middle English and Middle Dutch are left out to keep the picture small.)

In a tree the LCA is unique, and classic algorithms answer LCA queries in constant time after linear preprocessing. In a DAG there can be several minimal common ancestors: a compound and its translation might share two roots that are unrelated to each other. The general problem is much harder. Bender et al., "Lowest common ancestors in trees and directed acyclic graphs" (2005), relate the all-pairs version to fast matrix multiplication. Here each DAG has a median of 12 nodes, so the direct method works fine: compute C, then drop every element that is an ancestor of another element of C. The survivors are ranked by combined distance to the two words.

Two special cases fall out of this for free:

A judgement call: Wiktionary sometimes has several unrelated words with the same spelling ("Etymology 1", "Etymology 2"). When a translation doesn't say which one it means, the build tries each combination and keeps the one that connects. That biases things slightly towards finding a relation.

4. Finding hidden relatives

Often there is no common ancestor: take came from Old Norse, while nemen is native Germanic. But Proto-West Germanic *neman, an ancestor of nemen, also had an English line: Old English niman → Middle English nimen → English nim (archaic: "to steal") and, surprisingly, numb (originally "taken", as in "seized by cold").

Finding these means reversing the edges. For each ancestor of the Dutch word, from nearest to most distant, the build runs a depth-first search downwards through the children index. The search may only enter nodes in the other language's line (Old English, Middle English, English, Scots, plus Proto-West Germanic as a stepping stone). It stops at the first modern English word, so numb appears but numbness doesn't, and it stops at the first ancestor that turns up anything. A branch that never reaches modern English is marked † (died out).

*nemanProto-West Germanic nemanOld Dutch nēmenMiddle Dutch nemenDutch nimanOld English nimenMiddle English numb nim
The ghost search starts at each ancestor of nemen and looks downwards for English-line descendants (dotted).

The graph has a trap. Nodes are keyed by spelling, so homographs merge. For egg, the search correctly finds Old English ǣġ → Middle English ey (the native word that Norse egg replaced). But Middle English ey/ay is also a spelling of other words, and an unrestricted search walks straight into English hay, eye and any. The fix uses the fact that each descendants tree on Wiktionary is internally consistent, because one editor wrote it about one word. Every tree edge remembers which page's tree it came from, and the search first tries to stay inside the tree of the ancestor it started from. Only if that finds nothing does it fall back to the whole graph. The search then gives ey and, delightfully, cockney: a "cock's egg".

Results are ranked so that modern words beat dead ends, common words (ones with translation tables) beat rare ones, and links stated on a word's own page beat inferred ones.

5. Storing the data

There is no server, so everything is precomputed. The build resolves around 95,000 English–Dutch pairs in under a minute, and the browser fetches only what it needs:

6. The timeline, family tree and map labels

The timeline has to span from about 4500 BCE (Proto-Indo-European) to today without squashing the medieval period, where most of the action happens. It uses a logarithmic scale anchored at the present:

u(y) = 1 − ln(1 + (2026 − y)/500) / ln(1 + (2026 − ymin)/500)

Near the present this is roughly linear, and further back it compresses logarithmically. The constant 500 sets where that switch happens. Each word appears when its language stage begins, nudged so that a child never appears before its parent. Arcs grow along a quadratic Bézier curve, cut at fraction t using de Casteljau's algorithm: interpolate twice and you get the control points of the partial curve.

The family tree in the side panel uses the same time scale vertically, so scrubbing the timeline moves a "now" line down the tree. Its one adjustment is a monotone warp: if two words are closer in time than a label is tall, everything below is pushed down a little. The mapping stays strictly increasing, so it can be inverted, and you can drag on the tree to scrub.

Labels. Placing map labels so that none overlap is NP-hard in general (it is the classic point-feature label placement problem). The page uses a simple greedy approximation. Labels are sorted by importance (the two words, then the common ancestor, then the form at the current moment, then everything else). Each is tried in four positions around its dot (the "four-position model"), and skipped if they all collide. Hover any dot to see a skipped label.

Caveats

Data: English Wiktionary via Wiktextract / kaikki.org, CC BY-SA 4.0. Basemap: Natural Earth. Built by Oisín Nolan. Back to etymap →