Qur'an | Word by Word | Audio | Prayer Times
__ Sign In
 
__

Java API - Token Search Example

__

This example shows how to use the search API to find substrings in the Quranic text. The program below performs two searches. The first search looks for occurrences of the the Sun, and the second search looks for occurrences of the the Moon. The TokenSearch class is used, which is initiated through calls to findSubstring() and findToken(). These methods specify search criteria. The getResults() method is used to perform the search, and returns the results as an analysis table.

Java Example

public class TokenSearchExample {

    public static void main() {

        // Search #1: The Sun.
        searchSun();

        // Search #2: The Moon.
        searchMoon();
    }

    private static void searchSun() {

        // Search for substring "$~amos" or exact token "$amosFA"
        TokenSearch search = new TokenSearch(EncodingType.Buckwalter);
        search.findSubstring("$~amos");
        search.findToken("$amosFA");

        // Display the results.
        AnalysisTable table = search.getResults();
        System.out.println(table);
        System.out.println("Matches: " + table.getRowCount() + "\r\n");
    }

    private static void searchMoon() {

        // Search for substring "qamar" or exact token "lo>ahil~api"
        TokenSearch search = new TokenSearch(EncodingType.Buckwalter);
        search.findSubstring("qamar");
        search.findToken("{lo>ahil~api");

        // Display the results.
        AnalysisTable table = search.getResults();
        System.out.println(table);
        System.out.println("Matches: " + table.getRowCount() + "\r\n");
    }
}

Program Output

ChapterNumber VerseNumber TokenNumber Token
------------- ----------- ----------- -----
2             258         29          bi{l$~amosi
6             78          3           {l$~amosa
6             96          6           wa{l$~amosa
7             54          20          wa{l$~amosa
10            5           4           {l$~amosa
12            4           11          wa{l$~amosa
13            2           13          {l$~amosa
14            33          3           {l$~amosa
16            12          5           wa{l$~amosa
17            78          4           {l$~amosi
18            17          2           {l$~amosa
18            86          5           {l$~amosi
18            90          5           {l$~amosi
20            130         10          {l$~amosi
21            33          6           wa{l$~amosa
22            18          13          wa{l$~amosu
25            45          14          {l$~amosa
27            24          4           lil$~amosi
29            61          8           {l$~amosa
31            29          14          {l$~amosa
35            13          10          {l$~amosa
36            38          1           wa{l$~amosu
36            40          2           {l$~amosu
39            5           14          {l$~amosa
41            37          5           wa{l$~amosu
41            37          9           lil$~amosi
50            39          10          {l$~amosi
55            5           1           {l$~amosu
71            16          6           {l$~amosa
75            9           2           {l$~amosu
76            13          8           $amosFA
81            1           2           {l$~amosu
91            1           1           wa{l$~amosi

Matches: 33

ChapterNumber VerseNumber TokenNumber Token
------------- ----------- ----------- -----
2             189         3           {lo>ahil~api
6             77          3           {loqamara
6             96          7           wa{loqamara
7             54          21          wa{loqamara
10            5           6           wa{loqamara
12            4           12          wa{loqamara
13            2           14          wa{loqamara
14            33          4           wa{loqamara
16            12          6           wa{loqamara
21            33          7           wa{loqamara
22            18          14          wa{loqamaru
25            61          10          waqamarFA
29            61          9           wa{loqamara
31            29          15          wa{loqamara
35            13          11          wa{loqamara
36            39          1           wa{loqamara
36            40          7           {loqamara
39            5           15          wa{loqamara
41            37          6           wa{loqamaru
41            37          11          liloqamari
54            1           4           {loqamaru
55            5           2           wa{loqamaru
71            16          2           {loqamara
74            32          2           wa{loqamari
75            8           2           {loqamaru
75            9           3           wa{loqamaru
84            18          1           wa{loqamari
91            2           1           wa{loqamari

Matches: 28

Discussion

Given the different morphological and lexical forms possible for the Sun and the Moon, a straightforward string comparison would not return the correct results. The above program uses the following search criteria:

- For the sun search, using Buckwalter transliteration we search for the substring "$~amos" (sun) or the exact token "$amosFA" (a sun).

- For the moon search, we search look for the substring "qamar" (moon) or the exact token "lo>ahil~api" (crescents).

The program output above shows that under these search conditions, there are 28 results for the moon search, and 33 results for the sun search.

See Also

Language Research Group
University of Leeds
__