A glossary built before translation starts saves you from fixing inconsistencies after it ends. Term extraction gives you the first draft.

Most clients do not have a glossary. They have a product, a few thousand strings and a deadline. If three translators work on it, “pressure relief valve” can come back three different ways, and finding that out in review is the expensive way. So, before translation, I extract the term candidates from the source, someone who knows the domain picks the real terms, and the glossary goes into the CAT tool with everything else.

Two ideas from natural language processing do most of the work: stop words and n-gram counts.

Stop words: what to ignore

Stop words are the words that appear everywhere and say nothing about the content: the, and, of, with. In term extraction they matter for a simple reason: a real term rarely starts or ends with one. “Valve of the” is not a term; “pressure relief valve” is.

Every language needs its own list. The stop-words repository has lists for many languages, and I always adapt them: words like click, select or please are noise in a software manual even though no generic list includes them. CAT tools use the same idea; this is memoQ’s stop word list editor:

Stop word list settings in memoQ

How statistical extraction works

The simplest method, and the one Okapi uses, is purely statistical:

  1. Split the text into sentences or phrases, so no candidate crosses a full stop.
  2. Collect every sequence of one to four words (n-grams).
  3. Discard the sequences that start or end with a stop word.
  4. Keep the ones that appear at least a minimum number of times.
  5. Remove the candidates that only exist inside longer ones: if “relief valve” never appears without “pressure”, the term is “pressure relief valve”.

There is no grammar involved, so it works with any language that separates words with spaces, and you can explain every result. This is the whole thing in Python:

term_candidates.py
import re
from collections import Counter

def count_ngrams(text, stop_words, max_words=4):
    """Counts word sequences that neither start nor end with a stop word."""
    counts = Counter()
    for chunk in re.split(r"[.,;:!?()\[\]\n]+", text.lower()):
        words = re.findall(r"[^\W\d_]+(?:[-'][^\W\d_]+)*", chunk)
        for n in range(1, max_words + 1):
            for i in range(len(words) - n + 1):
                gram = words[i:i + n]
                if gram[0] not in stop_words and gram[-1] not in stop_words:
                    counts[" ".join(gram)] += 1
    return counts

def drop_substrings(counts):
    """Removes candidates that only appear inside longer ones, as Okapi does."""
    kept = {}
    for term in sorted(counts, key=lambda t: len(t.split()), reverse=True):
        inside = sum(c for longer, c in kept.items() if f" {term} " in f" {longer} ")
        if counts[term] - inside > 0:
            kept[term] = counts[term] - inside
    return kept

def term_candidates(text, stop_words, max_words=4, min_count=2):
    counts = count_ngrams(text, stop_words, max_words)
    frequent = Counter({t: c for t, c in counts.items() if c >= min_count})
    return sorted(drop_substrings(frequent).items(), key=lambda tc: -tc[1])

On a short maintenance text about a hydraulic pump, with a small English stop word list, it returns:

term_candidates.py
3	pressure relief valve
2	hydraulic pump pressure
2	hydraulic pump
2	engine
1	hydraulic

The lone “hydraulic” at the end is the kind of leftover a person removes in two seconds. And the counts after the sub-string step are standalone occurrences: “hydraulic pump” appears four times in the text, but two of them belong to “hydraulic pump pressure”.

drop_substrings follows the rule in Okapi’s documentation, and it gives the same result as their example: from gnu free (6), gnu free document (6) and gnu free document license (5), it keeps gnu free document license (5) and gnu free document (1), and drops gnu free, which never appears on its own.

The same without code: Okapi Rainbow

Rainbow, from the free Okapi Framework, has a Term Extraction step that does all of the above and a bit more.

  1. Get Okapi. It needs Java and no installation: unzip it and run the applications.

The Okapi Framework folder

  1. Open Rainbow and add your files to the input list by dragging them in. My example is a Word document with mechanical content:

Rainbow's main window

The sample text

  1. Check the filter configuration. For Office files it is the OpenXML filter. With XML and XLIFF, the filter can also read terminology marked in the file itself (ITS terminology annotations), which is the most precise source of terms you can get:

OpenXML filter configuration

  1. Open Utilities > Term Extraction…

Rainbow's Utilities menu

  1. Set the parameters. These are the ones I always touch:

Term Extraction parameters

  • Minimum and maximum number of words per term. One to four or five words covers almost every real term; longer sequences are usually phrases.
  • Minimum number of occurrences per term. Two or three for a small project; higher for a big one, or the list becomes unreadable.
  • Preserve case differences. Off, unless the product has terms that only differ in case.
  • Remove entries that seem to be sub-strings of longer entries. On. This is the step I reproduced in Python, and Okapi’s documentation itself warns that it can occasionally drop a valid term that only appears inside a longer, less useful one.
  • Stop words, not-start words and not-end words. Three text files, one word per line. Leave them empty and Okapi uses its English defaults; for any other language, point them to your own lists. Not-start words can appear inside or at the end of a term but never at its start, and not-end words the other way round.
  • Use Terminology annotations. On if your files carry ITS terminology markup.
  • Output path and sorting. The result is a UTF-8, tab-delimited file with the number of occurrences and the term; sort it by occurrences.
  1. Execute and open the result:

The resulting list of term candidates with their occurrences

Other approaches

  • RAKE (the rake-nltk package) and scikit-learn’s CountVectorizer work along the same lines: stop words, phrase delimiters and counts. They are handy if you already work in Python.

RAKE extracting keywords

  • Linguistic patterns give cleaner lists: with a tagger such as spaCy you keep only sequences that look like noun phrases (adjectives and nouns ending in a noun), so verbs like replace never make it to the list.
  • Language models can propose candidates and even draft definitions, and they are useful for that. I still run a statistical pass first, because it is reproducible, it tells me how often each term appears, and it does not invent terms that are not in the text.

From candidates to glossary

A candidate list is not a glossary. Go through it with someone who knows the product, keep the terms that matter, add a definition or a note where the meaning is not obvious, and translate them before the project starts. Then import the result into your CAT tool (CSV works everywhere; TBX if your tool supports it) and share it with every translator on the project. Once the translation is done, the same glossary feeds the terminology check in your QA.

The short version

  • Extract before translating: fixing inconsistencies afterwards costs more.
  • Use stop word lists for each language, and adapt them to the domain.
  • Count n-grams, filter by frequency and remove sub-strings: that already gives a good list.
  • Okapi Rainbow does it without code; a few lines of Python do it inside any pipeline.
  • A person decides which candidates are real terms.