Tutorial >Concordance and Key-Word-In-Context


In publishing, a concordance is an alphabetical list of the words used in a book or body of work, listing each instance of each word with its immediate surrounding context1. In the precomputing era, when search was unavailable, a concordance offered the reader an easy way to search for words they might want to look up.

In programming, when we mention a concordance, we usually refer to an object that stores the words, and corresponding counts, for a given text. For example, if my text is

Summer is hot. It is hot today.

the corresponding concordance would be:

  . 2
hot 2
is 2
it 1
summer 1
today 1

In RiTa, we can generate the above concordance with the RiTa.concordance() function.

  
  let args = { ignoreCase: true };

  let c = RiTa.concordance("Summer is hot. It is hot today.", args);
        

Here is nice example from Dan Shiffman where you can see how a concordance would look for your own text.


Key Words In Context

A common format for a concordance is Key-Word-In-Context or KWIC model. It sorts and aligns the words in a way that allows each to be searchable in the index. The search result for the word 'window' in an example KWIC model looks like this:


 

In RiTa, we can achieve this with the RiTa.kwic() function, as follows:

  let args = {
    ignoreCase: false,
    ignorePunctuation: true,
    wordCount: 6
  };
  let lines = RiTa.kwic(text, keyword, args);

Here is an interactive example of a KWIC model in RiTa.