KWIC, collocates, n-grams and keywords for your own texts

Corpus Concordancer

Load TXT, DOCX, PDF or EPUB files as a corpus, then search it for concordance lines, collocates with MI, MI3, t-score, log-likelihood and logDice, n-grams with range, and keywords against a reference corpus.

Corpus files

0 files chosen. Up to 8,000,000 tokens in total.

Choose corpus files

TXT, DOCX, PDF text layer, EPUB, MD

Reference corpus (optional, for keywords)

Tokenised with the same settings

Tokenisation

Tokenising runs in the page in 100,000-token steps with progress, so very large corpora are slow. Every figure depends on these settings; they are written into each export.

Results

Build the corpus to see word lists, concordance lines, collocates, n-grams and keywords.

Corpus Concordancer

Operator: Abdulla Al Fahad. How tools are built and checked

Counting how often a word occurs is the easy part of studying a set of texts. The harder questions are what surrounds it, which neighbours it keeps unusually often, and which words your texts use more than ordinary writing does. A concordancer answers those by showing the word in context and by scoring it against what chance would predict.

Add your files as a corpus, optionally add a second set as a reference, and the page builds a word list, searchable concordance lines, collocate tables, n-gram lists and a keyword table.

Key features

  • TXT, DOCX, PDF with a text layer, EPUB and Markdown files in one corpus, and a second optional reference corpus tokenised the same way
  • Two tokenisers: Unicode word segments, which also split Chinese, Japanese and Thai, or letters, digits, apostrophes and hyphens
  • Concordance lines for words, wildcards, phrases of up to eight words and regular expressions, with context of 2 to 30 words, three-level sorting and a dispersion strip for each file
  • Collocates inside a window of up to 20 words each side scored by MI, MI3, t-score, signed log-likelihood and logDice, with frequency filters
  • N-grams of 2 to 6 words with frequency and range, and keywords by log-likelihood, %DIFF, log ratio and BIC
  • CSV and XLSX exports for every table that record the tokeniser, lowercasing, list sizes, token counts and file names
  • A word list with frequency, range across the files and frequency per million, with stop words left out

How words are counted and scored

Every number depends on what counts as a word. With Unicode segments, "well-known" is two words and "don't" is one; with the pattern tokeniser "well-known" is one. Lowercasing merges "The" and "the". A lemma list of form,lemma lines such as "ran,run" replaces each listed form by its lemma before counting, so the word list, collocates and keywords see one type. A stop list removes words from the word list, collocate candidates and keywords, but not from concordance lines or n-grams, so the context you read stays complete.

Sentence breaks are noted wherever a full stop, question mark, exclamation mark, ellipsis or blank line lies between two words. Collocate windows and n-grams can be told to stop at a break. Matching is by whole words: a wildcard * stands for any run of letters, ? for exactly one letter, and a regular expression must match the whole word.

How it works

For a node word that occurs f(n) times in a corpus of N words, with a collocate of total frequency f(c) found O times inside a window of S words, the expected count is f(n) x f(c) x S / N. MI is log2(O/E), MI3 is log2(O^3/E), the t-score is (O - E) / sqrt(O), and logDice is 14 + log2(2O / (f(n) + f(c))). Log-likelihood is computed on the 2 x 2 table of window slots against the collocate, and is given a negative sign when O is below E.

Keywords compare a word's frequency a in a corpus of c words with b in a reference of d words. Log-likelihood is 2 x (a ln(a/E1) + b ln(b/E2)) with E1 = c(a+b)/(c+d) and E2 = d(a+b)/(c+d), as in Rayson and Garside (2000). %DIFF is the relative difference of the two relative frequencies, the log ratio is log2 of their quotient with 0.5 standing in for a zero count, and BIC is LL minus ln(c+d).

The cut-off menu offers the LL values 3.84, 6.63, 10.83 and 15.13 for p below 0.05, 0.01, 0.001 and 0.0001.

Tokenising runs in the page in steps of 100,000 words with a progress line and a Cancel button, and a corpus is capped at 8 million words. N-grams are limited to corpora of 3 million words, and a search keeps at most 200,000 hits.

Common use cases

  • A translator checks how an English source text and its published translation use one key term: she loads each as a corpus, sorts the lines by the first word on the right and sees which verbs follow the term in each.
  • A student comparing 12 speeches against a 500-page reference of parliamentary debate sets the cut-off to p < 0.001 and a minimum log ratio of 1, and exports the keyword table with the settings sheet for the appendix.
  • A language teacher loads two textbooks as separate files, searches "make" and "do" in both, and uses the range column of the n-gram list to see which collocations appear in both books and which in only one.

How to use this tool

  1. Choose the corpus files, add reference files if you want keywords, and set the tokeniser, stop list and lemma list.
  2. Press Build corpus, then search a word on the Concordance tab; the Collocates tab works from the same hits.
  3. Export a table as CSV or XLSX, which carries the settings that produced it.

Example

Load an example: two harbour texts as the corpus, two texts about a garden and a town council as the reference

Stop list of 20 common function words; Unicode word segments, lowercased. Search "ferry", window 4 left and 4 right, minimum 2 co-occurrences.

Counts and scores

The corpus has 154 words and 74 types, the reference 141 words. "ferry" has 6 hits, and "stor*" has 5. Collocates: "sailed" 2 times with MI 1.682, t-score 0.973, log-likelihood 4.721 and logDice 13.000, and "pier" 3 times with MI 0.945. Keywords at p < 0.05 with a minimum frequency of 2 put "ferry" first (6 against 0, LL 7.80, log ratio 3.46), then harbour, pier and storm at LL 6.50.

Tips for best results

  • Sort concordance lines by 1 right, then 1 left: lines with the same following word group together and the common patterns appear as blocks.
  • Raise the minimum co-occurrence count for MI and MI3, which favour rare pairs, and read logDice or log-likelihood next to them.
  • Set Stay inside the sentence when the node is often at a sentence edge, so its window does not borrow words from the next sentence.
  • Search with a wildcard such as "stor*" to see every variant in one table, then sort by the node word to count them separately.

Common pitfalls

A PDF with two columns can interleave lines of text, which puts unrelated words next to each other in the lines and collocates; check a few lines against the page.

Changing lowercasing, the tokeniser or the lemma list changes every count, so numbers from different settings cannot be compared with each other.

The window is not shortened for hits near the start or end of a file in the expected count, which slightly underestimates scores for words at file edges.

Common errors and how to fix them

"name.pdf" has no selectable text
The PDF is probably scanned images. Run OCR on it first, then choose the searchable copy.
N-grams are limited to corpora of 3,000,000 tokens
Split the corpus and run each part, or search a single file by loading only that file.
The pattern repeats a group that itself repeats
Patterns that can backtrack badly, such as (a+)+c or (a|aa)+$, are refused before they run, because one of them can freeze the tab on a long word. Rewrite it without the nested repeat, for example a+c.
That regular expression is not valid
The pattern must be a JavaScript regular expression matched against whole words, for example (colou?r|gr[ae]y).

Choosing a window and a measure

Each measure favours something different. MI rewards pairs that are rare but almost always together, so it ranks unusual words first and needs a minimum co-occurrence count. The t-score rewards pairs seen often enough to be reliable, so it ranks frequent function-word partners first. Log-likelihood sits between them and tells you how sure you can be that a pair is not chance, and logDice is a stable score that does not depend on corpus size.

A window of 4 or 5 words each side finds grammatical neighbours and fixed phrases; 10 or more starts to pick up topic words. The window is counted in words, not characters, and can be limited to one sentence.

Frequently asked questions

How do I know the statistics are computed correctly?

The collocate measures were checked against hand calculation on a 20-word corpus (a node with 4 occurrences, a collocate with 3, all 3 pairs adjacent: expected 0.6, MI 2.322, MI3 5.492, t-score 1.386, logDice 13.778), and log-likelihood against a separate implementation, for example 111.4446 for 30 co-occurrences of words with frequencies 100 and 200 in 100,000 words over a window of 10. The page has not been compared with AntConc or Sketch Engine, whose token and window definitions can differ.

Why does a word that never appears in the reference get a log ratio of 3.46 rather than infinity?

A zero count would make the ratio undefined, so 0.5 occurrences stand in for it, a convention used for log ratio. The %DIFF column still shows inf for such words.