2 February 2022

Non-literal matches: Jaccard distance

In a former entry we started to analyze Paul's non-literal quotations in the Romans. Before continuing the list of such quotations we need to learn how similarity is defined in the non-literal matches.

The technique for comparing texts is well-known from data mining. We combine two ideas – both can be found in the popular book Leskovec-Rajamaran-Ullman: Mining of massive datasets, Cambridge University Press, 2014, p. 77-78. The first idea is to create the 2-shingles of an input passage, and then use the Jaccard similarity for bags (see footnote 2 on page 77).

Let's illustrate the concept on Romans 15:11 – it is a quotation of Psalms 117:1. (This is the last non-literal quotation in the Romans, close to the end of the letter. We temporarily skip a couple of other non-linear quotations to get a clear example of the two ideas.)


Then, issue the following commands:
  1. lookup SBLGNT Romans 15:11
  2. lookup LXX Psalms 117:1
It is quite clear that more parts of the two passages literally match. Indeed, the command getrefs SBLGNT LXX Psalms 117:1 finds two of them: “επαινεσατ” and “αυτον παντες οι λαοι”. Even though, the other literal parts are not detected, because they are not unique in the LXX. These literal matches are “αινειτε”, “τον κυριον” and “παντα τα εθνη”. These short texts, appearing in this order in the LXX (1-2-3), are ordered differently in the Romans (1-3-2). Moreover, there is the word “και” (“and”) inserted in Romans. Finally, Paul uses a variant of the LXX word “επαινεσατε”: “επαινεσατωσαν” (here the first 9 characters are literally the same). Luckily, the two ideas taken from the theory of data mining helps us to conclude that the two passages are still quite similar and they differ only in 19%.

The first step is to create 2-shingles of the passages
  1. lookup2 SBLGNT Romans 15:11+8 15:11
  2. lookup1 LXX Psalms 117:1+9 117:1
The 2-shingles of a passage are any substring of length 2 in the passage. That is, for the quotation in Romans they are ai, in, ne, ei, it, te, …, il, la and ao. Some substrings appear more than once – we will count their appearance accordingly later. For the quoted string in Psalm 117 we find similar 2-shingles, but there are some differences. The following table shows the 2-shingles and the number of their appearances in the two passages:

ai in ne ei it te ep pa an nt ta at ae eu un nh ht to on nk ky yr ri io ka ie es sa tv vs na ay yt np so oi il la ao et he ea
Romans 15:11+8 15:11 3 2 2 1 1 2 2 3 3 2 2 2 1 1 1 1 1 2 3 2 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 2 1 1 1
Psalms 117:1+9 117:1 2 2 2 1 1 3 1 3 2 2 2 2 1 1 1 1 2 3 1 1 1 1 1 2 1 1 1 2 1 2 1 1 1 1 1 1

Next, the sum of the numbers in both rows are computed: 59 and 53, these are actually by 1 less than the lengths of the texts (60 and 54, respectively – you can use the commands length2 and length1 to check this). After then for each 2-shingle we choose the minimal number of appearances from each text:
ai in ne ei it te ep pa an nt ta at ae eu un nh ht to on nk ky yr ri io ka ie es sa tv vs na ay yt np so oi il la ao et he ea
2 2 2 1 1 2 1 3 2 2 2 2 1 1 1 1 2 3 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1

We compute the sum of these numbers, it is 48. After dividing this number by the maximum of 59 and 53 we get a ratio of similarity between the two texts, it is about 81%, so the difference is about 19%.

The same computation can be performed automatically by using the command jaccard12 (after both clipboards are set – they should be, if you followed the previous steps).

A short summary of the above result can be seen in this diagram:


This piece of diagram was created, however, not in a fully automated way.


Entries on topic internal references in the Bible

  1. Web version of bibref (12 January 2022)
  2. Order in chaos (17 January 2022)
  3. Reproducibility and imperfection (20 January 2022)
  4. A student of Gamaliel's (23 January 2022)
  5. Non-literal matches in the Romans (26 January 2022)
  6. Literal matches: minimal uniquity and maximal extension (31 January 2022)
  7. Literal matches: the minunique and getrefs algorithms (1 February 2022)
  8. Non-literal matches: Jaccard distance (2 February 2022)
  9. Non-literal matches in the Romans: Part 2 (3 February 2022)
  10. A summary on the Romans (5 February 2022)
  11. The Psalms (6 February 2022)
  12. The Psalms: Part 2 (7 February 2022)
  13. A classification of structure diagrams (15 February 2022)
  14. Isaiah: Part 1 (19 February 2022)
  15. Isaiah: Part 2 (26 February 2022)
  16. Isaiah: Part 3 (2 March 2022)
  17. Isaiah: Part 4 (7 March 2022)
  18. Isaiah: Part 5 (15 March 2022)
  19. Isaiah: Part 6 (23 March 2022)
  20. Isaiah: Part 7 (30 March 2022)
  21. A summary (7 April 2022)
  22. On the Wuppertal Project, concerning Matthew (17 July 2022)
  23. Matthew, a summary (25 July 2022)
  24. Isaiah, a second summary (31 July 2022)
  25. Long false positives (23 August 2022)
  26. A general visualization (25 August 2022)
  27. Stephen's defense speech (19 September 2022)
  28. Statistical Restoration Greek New Testament (31 July 2023)
  29. Qt version of bibref (11 March 2024)
  30. Statements on Bible references (5 August 2024)

Zoltán Kovács
Linz School of Education
Johannes Kepler University
Altenberger Strasse 69
A-4040 Linz