Help needed on loading table and creating search box to search filter data (Bible)

Can someone help me figure out how to put the code in to load my data table?

Attached is a snapshot of some data, it is just simply two columns, one being verse, and the other being reference. The idea here is I want to be able to search this data, but first trying to get it to load. I would like to add data, such as some more chapters of the bible, so I can do more queries. The bottom line here is essentially my own correlative connections of scriptures database, that I can use to query to see how that word or words connects together with other scriptures…

I went here, and tried replacing the mammals.csv filename with my data.csv filename… and still same error message…

https://processing.org/reference/loadTable_.html
https://processing.org/tutorials/data/

Hi again, :wink:

From your second screenshot, you can see that there’s an error from the red colored message that appeared at the bottom of the window.

In programming, compilers (what translate your code into machine code) will most of the time indicate where your error is located and why.

It says :

mammals.csv does not exist or could not be read
NullPointerException

So the file clearly doesn’t exist! :stuck_out_tongue_winking_eye:

First let’s look at what the loadTable() function takes as arguments :

loadTable(filename)

filename String: name of a file in the data folder or a URL.
options String: may contain “header”, “tsv”, “csv”, or “bin” separated by commas

So the first parameter must be the path of an existing file on your computer (here we want a .csv file). Here “existing” is important because otherwise the program can’t load it.

Now in Processing, when you indicate a path it’s supposed to be in a data folder inside your sketch folder, where your Processing code is located if you saved your project.

So are you sure that you have a mammals.csv file in a data folder in the sketch folder? To see it, you can go in the options Sketch -> Go to sketch folder.

Note : this is the second post, see the first one : Where is the directory to save your .csv data?

Thanks, I got it! I wonder how to play with this, and see some different ways I can output this… can this be outputted to my wampserver via mysql phpadmin? or html file? Thanks,

You got it!

It’s preferable to save your sketch to a known location because if it crashes or close, you are going to loose it! :wink: (for now it’s in a temp folder)

What do you mean by outputted? If you have a wamp server, it’s using HTTP so you can serve static files with it.

You have other options :

  • Use PHP to read the CSV and inject html into a web page.

  • Store your CSV in your SQL database and use it with PHP.

  • If you want to switch on a web version, use p5.js on the frontend to display your data interactively.

  • Use Node.js to host your data and create an API?

@josephh

Thanks for your comment. Yes the output is really what I am focused on, I am trying to do something visual like this, but not necessarily cross references…

https://scimaps.org/mapdetail/visualizing_bible_cr_125

I’d like to just take a couple chapters of the bible, and connect them where they are correlated, so if the phrase “four living creatures” shows in Ezekiel 1, and in Revelation 4, I want to put an arc or a line showing connected with that phrase…

Ok nice!

So then you need to define what a “phrase” is going to be because you need to split the text of a chapter and basically analyze every other chapter and check for similarities.

After you constructed this “data structure” where you have a bunch of nodes (the chapters) and connections (correlations), you need to know how to display them : as a cloud of points, at fixed location, animated?

This is a nice exercise! :wink:

Yes, well phrase is going to be either a word or words, but the idea was to put into the search box say the word “salvation” or “love” or “seven churches” or, etc…

I’ve got a way that will take me a while, but it will work where I can export the data from blueletterbible.org, and put the data into a verse column and a reference column, the snapshot looks like this below: Again, though this is only for 1 particular translation, not all the translations, which isn’t important right now. Essentially, just display these cloud of points of data to better visualize the interconnected ness of the bible…

Maybe you can avoid copying by hand all the chapters of the bible by checking : ? :hugs:

https://hackathon.bible/data/

You know that programmers hate typing!

Thanks yes the problem with that site is you can’t get really all the translations. In fact, I’ve got all the translations that I want to fool with, but they are in my eSword application, and they are in the format .bblx

However, when you go to open up sql lite db browser, you can open up the .bblx file, but the problem is you can’t see the blob…and i think it is encrypted…

The biggest problem is there really isn’t a easy way to have all the data in one place then to work with it from there to figure out what formatting options i have…

I am no programmer, but I can troubleshoot…

Yes you are right, I looked at some forum and looks like it’s encrypted but there’s tools to export the data apparently…

Anyway I think that the Bible is so common in the world that there must be an open data source where you can download the data you want!

See Table::findRows() \ Language (API) \ Processing 3+

And reference | Table | matchRows: Table::matchRows() \ Language (API) \ Processing 3+

See Table::findRows() \ Language (API) \ Processing 3+

1 Like

See Bible Downloads - Bible SuperSearch

There are also data sets with cross references.

A small csv from the link above:

"Verse ID","Book Name","Book Number",Chapter,Verse,Text
1,Genesis,1,1,1,"In the beginning God created the heavens and the earth."
2,Genesis,1,1,2,"And the earth was waste and void; and darkness was upon the face of the deep: and the Spirit of God moved upon the face of the waters."
3,Genesis,1,1,3,"And God said, Let there be light: and there was light."
4,Genesis,1,1,4,"And God saw the light, that it was good: and God divided the light from the darkness."
5,Genesis,1,1,5,"And God called the light Day, and the darkness he called Night. And there was evening and there was morning, one day."
6,Genesis,1,1,6,"And God said, Let there be a firmament in the midst of the waters, and let it divide the waters from the waters."
7,Genesis,1,1,7,"And God made the firmament, and divided the waters which were under the firmament from the waters which were above the firmament: and it was so."
8,Genesis,1,1,8,"And God called the firmament Heaven. And there was evening and there was morning, a second day."
9,Genesis,1,1,9,"And God said, Let the waters under the heavens be gathered together unto one place, and let the dry land appear: and it was so."
10,Genesis,1,1,10,"And God called the dry land Earth; and the gathering together of the waters called he Seas: and God saw that it was good."
11,Genesis,1,1,11,"And God said, Let the earth put forth grass, herbs yielding seed, [and] fruit-trees bearing fruit after their kind, wherein is the seed thereof, upon the earth: and it was so."
12,Genesis,1,1,12,"And the earth brought forth grass, herbs yielding seed after their kind, and trees bearing fruit, wherein is the seed thereof, after their kind: and God saw that it was good."
13,Genesis,1,1,13,"And there was evening and there was morning, a third day."
14,Genesis,1,1,14,"And God said, Let there be lights in the firmament of heaven to divide the day from the night; and let them be for signs, and for seasons, and for days and years:"
15,Genesis,1,1,15,"and let them be for lights in the firmament of heaven to give light upon the earth: and it was so."
16,Genesis,1,1,16,"And God made the two great lights; the greater light to rule the day, and the lesser light to rule the night: [he made] the stars also."
17,Genesis,1,1,17,"And God set them in the firmament of heaven to give light upon the earth,"
18,Genesis,1,1,18,"and to rule over the day and over the night, and to divide the light from the darkness: and God saw that it was good."
19,Genesis,1,1,19,"And there was evening and there was morning, a fourth day."
20,Genesis,1,1,20,"And God said, Let the waters swarm with swarms of living creatures, and let birds fly above the earth in the open firmament of heaven."
21,Genesis,1,1,21,"And God created the great sea-monsters, and every living creature that moveth, wherewith the waters swarmed, after their kind, and every winged bird after its kind: and God saw that it was good."
22,Genesis,1,1,22,"And God blessed them, saying, Be fruitful, and multiply, and fill the waters in the seas, and let birds multiply on the earth."
23,Genesis,1,1,23,"And there was evening and there was morning, a fifth day."
24,Genesis,1,1,24,"And God said, Let the earth bring forth living creatures after their kind, cattle, and creeping things, and beasts of the earth after their kind: and it was so."
25,Genesis,1,1,25,"And God made the beasts of the earth after their kind, and the cattle after their kind, and everything that creepeth upon the ground after its kind: and God saw that it was good."
26,Genesis,1,1,26,"And God said, Let us make man in our image, after our likeness: and let them have dominion over the fish of the sea, and over the birds of the heavens, and over the cattle, and over all the earth, and over every creeping thing that creepeth upon the earth."
27,Genesis,1,1,27,"And God created man in his own image, in the image of God created he him; male and female created he them."
28,Genesis,1,1,28,"And God blessed them: and God said unto them, Be fruitful, and multiply, and replenish the earth, and subdue it; and have dominion over the fish of the sea, and over the birds of the heavens, and over every living thing that moveth upon the earth."
29,Genesis,1,1,29,"And God said, Behold, I have given you every herb yielding seed, which is upon the face of all the earth, and every tree, in which is the fruit of a tree yielding seed; to you it shall be for food:"
30,Genesis,1,1,30,"and to every beast of the earth, and to every bird of the heavens, and to everything that creepeth upon the earth, wherein there is life, [I have given] every green herb for food: and it was so."
31,Genesis,1,1,31,"And God saw everything that he had made, and, behold, it was very good. And there was evening and there was morning, the sixth day."

Sketch

Full Sketch with text Input (with blinking Cursor, Enter to submit, Backspace to delete last letter, Esc to delete last search)

// Bible full text search

// constants
final int borderDistanceMainText  = 22;
final int borderDistanceBibleText = 62; 
final int lineDistance            = 17;

// variables 
Table tableBible; 
String input="", search=""; 
int numberOfFindings = 0;

// --------------------------------------------------------------------------

void setup() {
  size(1400, 860);

  // load and show some data 
  tableBible=loadTable("asv.csv", "header");
  println(tableBible.getColumnCount());  // Prints 6
  println(tableBible.getRowCount());  // Prints 31102

  // show headlines 
  TableRow row = tableBible.getRow(0);
  for (int i=0; i < tableBible.getColumnCount(); i++) {
    print(" | "+row.getColumnTitle(i));  // Prints
  }
  println("");
}//func 

void draw() {
  background(0); 

  // Main text upper left corner 
  fill(255); // white 
  text("Enter your search (submit with Enter, use Backspace): "
    +input
    +caret(), borderDistanceMainText, borderDistanceMainText); 

  // green text upper right corner
  fill(0, 255, 0); // green 
  if (search.equals("")) {
    // search phrase is empty, we show Bible text
    text("Full text. Enter a search phrase and hit Enter ", 
      width-130, borderDistanceMainText, 
      110, 900);
  } else {    
    // The search word has been entered, show the search word in green 
    text("Search:\n"
      + search
      + " \n(Esc to delete).\n"
      + numberOfFindings 
      + " findings.", 
      width-130, borderDistanceMainText, 
      110, 900);
  }//else 

  // Main Bible Output / search results
  showText();
  //
}//func 

//---------------------------------------------------------------------------------
// Input functions 

void keyPressed() {
  if (key==CODED) {
    return;
  } else  if (key==ESC) {
    search=""; 
    numberOfFindings=0; 
    key=0;
  } else if (key==BACKSPACE) {
    if (input.length()>0) {
      input = input.substring( 0, input.length()-1 );
    }
  } else if (key==ENTER||key==RETURN) {
    search=input;
    input="";
  } else if (key=='#') {
    exit();
  } else {
    input+=key;
  }
}//func 

//---------------------------------------------------------------------------------
// Other important functions 

void showText() {

  fill(255);
  if (! search.equals("")) {
    // show search results
    Iterable<TableRow> results = tableBible.matchRows( search, "Text" );
    // println((TableRow)results.getRowCount());
    int i=0; 
    for (TableRow row : results) {
      showRow(row, i); 
      i++;
      // we can quit after 10 findings
      // if (i>10) break;
      // we can quit when screen is full
      // if ( i*lineDistance +borderDistance > width+30) break;
    }//for 
    // Evaluate i: 
    if (i==0) {
      text ("         No findings", borderDistanceMainText, 1*lineDistance +borderDistanceBibleText);
      numberOfFindings=0;
    } else {
      numberOfFindings=i;
    }
  } else {
    // no search - show bible text
    for (int i=0; i < 10; i++) {
      TableRow row = tableBible.getRow(i);
      showRow(row, i);
    }
  }
}//func 

//---------------------------------------------------------------------------------
// Tools 

void showRow(TableRow row_, int lineNumber_) {
  text(
    row_.getString("Book Name") + " "+ 
    row_.getString("Chapter") + ":"+
    row_.getString("Verse") + ": "+
    row_.getString("Text"), 
    borderDistanceMainText, lineNumber_*lineDistance +borderDistanceBibleText);
}

String caret() {
  // Blinking cursor: return | or blank
  if (millis() % 1000 < 500) 
    return "|";
  else 
  return " ";
}
//

Remark 1

Anyway, in the graphic you posted, the x-axis are the chapters of the Bible.
They are not in the csv but you can calculate them.
For example for Leviticus 3 the absolute chapter number is 3 + the sum of all chapters in the books before Leviticus (so result is 3 + Genesis chapters + Exodus chapters).
That’s your screen position.

Remark 2

You can make another Sketch B to write a new csv and let the current Sketch A use the additional new csv. The csv would contain the number of chapters for each biblical book, and also how many chapters there are in the Bible before this book (so when you think of Leviticus, say Genesis has 50 Chapters and Exodus 40 chapters, the entry would be 90. Then for Leviticus 3 you could say 90 + 3).
The screen pos for each biblical chapter is then .

Remark 3

You could make a grid of all biblical books and connect them (instead of using the chapters). Here is an example Sketch.

The Sketch is a bit more difficult because

  • it uses a HashMap (and an ArrayList) to store the books from the csv-Bible and
  • to store the books that occur in the search.

It also uses OOP.
It can be optimized of course. You can also switch between two views with Space Bar.

Please note that because the books are shown in two columns, the cross references within a column are just a vertical line. Bad. That could be improved when we would show the books in a circle.

// Bible full text search - with graphical lines between books

// imports 
import java.util.Map;

// constants
final int borderDistanceMainText   = 22;
final int borderDistanceBibleTextY = 62; 
final int lineDistance             = 17;

// variables 
Table tableBible; 
String input="", search=""; 
int numberOfFindings = 0;
boolean showGraphical = true; // How the search is displayed, toggle with ' ' Space Bar  

// Books data 
ArrayList<BiblicalBook> books = new ArrayList();

HashMap<String, BiblicalBook> hashMapBiblicalBooks =  new HashMap<String, BiblicalBook>();
HashMap<String, Integer> hashMapBiblicalBooksFromSearch =  new HashMap<String, Integer>();

// --------------------------------------------------------------------------

void setup() {
  size(1400, 860);

  // load and show some data 
  tableBible=loadTable("asv.csv", "header");
  println(tableBible.getColumnCount());  // Prints 6
  println(tableBible.getRowCount());  // Prints 31102

  // show headlines 
  TableRow row = tableBible.getRow(0);
  for (int i=0; i < tableBible.getColumnCount(); i++) {
    print(" | "+row.getColumnTitle(i));  // Prints
  }
  println("");

  initHashMap();
}//func 

void draw() {
  background(0); 

  // display book titels as grid 
  if (showGraphical) {
    for (BiblicalBook bb : books) {
      bb.display();
    }
  }

  // Main text upper left corner 
  fill(255); // white 
  text("Enter your search (submit with Enter, use Backspace, toggle results view with Space Bar): "
    +input
    +caret(), borderDistanceMainText, borderDistanceMainText); 

  // green text upper right corner
  fill(0, 255, 0); // green 
  if (search.equals("")) {
    // search phrase is empty, we show Bible text
    text("Full text. Enter a search phrase and hit Enter ", 
      width-130, borderDistanceMainText, 
      110, 900);
  } else {    
    // The search word has been entered, show the search word in green 
    text("Search:\n"
      + search
      + " \n(Esc to delete).\n"
      + numberOfFindings 
      + " findings.", 
      width-130, borderDistanceMainText, 
      110, 900);
  }//else 

  // Main Bible Output / search results
  showTextOrResults();
  //
}//func 

//---------------------------------------------------------------------------------
// Input functions 

void keyPressed() {
  if (key==CODED) {
    return;
  } else  if (key==ESC) {
    search=""; 
    numberOfFindings=0; 
    key=0;
  } else if (key==BACKSPACE) {
    if (input.length()>0) {
      input = input.substring( 0, input.length()-1 );
    }
  } else if (key==ENTER||key==RETURN) {
    // submit 
    search=input;
    // input="";
    // init search
    Iterable<TableRow> results = tableBible.matchRows( search, "Text" );
    hashMapBiblicalBooksFromSearch.clear();
    for (TableRow row2 : results) {
      String bibBook = row2.getString("Book Name");
      // new?
      if (hashMapBiblicalBooksFromSearch.get(bibBook) == null) {
        // add 
        hashMapBiblicalBooksFromSearch.put(bibBook, 1);
      }
    }
  } else if (key=='#') {
    exit(); // leave entire Sketch
  } else if (key==' ') {
    // Space Bar 
    showGraphical = ! showGraphical;// toggle
  } else {
    input+=key;
  }
}//func 

//---------------------------------------------------------------------------------
// Other important functions 

void showTextOrResults() {

  fill(255); // white 
  if (! search.equals("")) {
    // show search results
    // Grapical or textual
    if (showGraphical) {
      showResultsGraphical();
      //showResultsGraphical2(results);
      //
    } else {
      showResultsAsText();
    }
    //
  } else {
    // no search - show bible text
    for (int i=0; i < 10; i++) {
      TableRow row = tableBible.getRow(i);
      showRow(row, i);
    } //for
  } //else
} //func 

void showResultsAsText() {
  // get results from table 
  Iterable<TableRow> results = tableBible.matchRows( search, "Text" );
  int i=0; 
  for (TableRow row : results) {
    showRow(row, i); 
    i++;
    // we can quit after 10 findings
    // if (i>10) break;
    // we can quit when screen is full
    // if ( i*lineDistance +borderDistance > width+30) break;
  }//for 
  // Evaluate i: 
  if (i==0) {
    text ("         No findings", borderDistanceMainText, 1*lineDistance +borderDistanceBibleTextY);
    numberOfFindings=0;
  } else {
    numberOfFindings=i;
  }
}

//void showResultsGraphical2(Iterable<TableRow> results) {
// // This is a bad version and would run MUCH slower  
// // get results from table 
// Iterable<TableRow> results = tableBible.matchRows( search, "Text" );
//  for (TableRow row : results) {
//    for (TableRow row2 : results) {
//      if (row!=row2) {
//        BiblicalBook book1 = hashMapBiblicalBooks.get( row.getString("Book Name") );
//        BiblicalBook book2 = hashMapBiblicalBooks.get( row2.getString("Book Name") );
//        book1.showLine(book2);
//      }//if
//    }//for
//  }//for
//}//func

void showResultsGraphical() {
  // Using an enhanced loop to iterate over each entry
  // This can be optimized 
  for (Map.Entry me : hashMapBiblicalBooksFromSearch.entrySet()) {
    //print(me.getKey() + " is ");
    //println(me.getValue());
    for (Map.Entry me2 : hashMapBiblicalBooksFromSearch.entrySet()) {
      if (me!=me2) {
        BiblicalBook book1 = hashMapBiblicalBooks.get(me.getKey() ) ;
        BiblicalBook book2 = hashMapBiblicalBooks.get(me2.getKey() ) ;
        book1.showLine(book2);
      }
    }
  }//for
}//func

void initHashMap() {
  HashMap<String, Integer> hashMapBiblicalBooksLocal =  new HashMap<String, Integer>();

  int yStart = borderDistanceBibleTextY+220;
  int x=125, y= yStart; 
  int columnCounterForBiblicalBooks=0; 

  for (TableRow row : tableBible.rows()) {
    String bibBook = row.getString("Book Name"); 

    // new?
    if (hashMapBiblicalBooksLocal.get(bibBook) == null) {
      // yes, add 
      hashMapBiblicalBooksLocal.put(bibBook, 1);
      BiblicalBook newBiblicalBook = new BiblicalBook(); 
      newBiblicalBook.name= bibBook;
      newBiblicalBook.pos = new PVector(x, y);

      // set anchor
      if (columnCounterForBiblicalBooks == 0)
        newBiblicalBook.anchor = new PVector(x+119, y);
      else if (columnCounterForBiblicalBooks == 1)
        newBiblicalBook.anchor = new PVector(x-4, y);
      else { 
        println("Error unknown columnCounterForBiblicalBooks +++++++++++++++++++++++"); 
        exit(); 
        return;
      }//else

      // add
      books.add(newBiblicalBook);
      hashMapBiblicalBooks.put(bibBook, newBiblicalBook);
      // inc y pos 
      y+=lineDistance;
      if (y > height-33) {
        // new column 
        columnCounterForBiblicalBooks++;
        x+=190; 
        y = yStart;
      }//if
    }//if
  }//for
}//func 

//---------------------------------------------------------------------------------
// Tools 

void showRow(TableRow row_, int lineNumber_) {
  text(
    row_.getString("Book Name") + " "+ 
    row_.getString("Chapter") + ":"+
    row_.getString("Verse") + ": "+
    row_.getString("Text"), 
    borderDistanceMainText, lineNumber_*lineDistance +borderDistanceBibleTextY);
}

String caret() {
  // Blinking cursor: return | or blank
  if (millis() % 1000 < 500) 
    return "|";
  else 
  return " ";
}

//===============================================================================

class BiblicalBook {

  String name; // name of the book 
  PVector pos;  // text position on the screen 
  PVector anchor;  // anchor for blue line (can be different from pos) 

  void display() {
    fill(255); 
    text(name, 
      pos.x, pos.y);
  }//method

  void showLine (BiblicalBook book_ ) {
    stroke(0, 0, 255);
    line(anchor.x, anchor.y, 
      book_.anchor.x, book_.anchor.y);
    if (dist(mouseX, mouseY, anchor.x, anchor.y ) < 19) {
      // display verse or something
    }//if
  } //method
  //
}//class 
//

Book Names

Here are the book names.

BookName
Genesis
Exodus
Leviticus
Numbers
Deuteronomy
Joshua
Judges
Ruth
1 Samuel
2 Samuel
1 Kings
2 Kings
1 Chronicles
2 Chronicles
Ezra
Nehemiah
Esther
Job
Psalms
Proverbs
Ecclesiastes
Song of Solomon
Isaiah
Jeremiah
Lamentations
Ezekiel
Daniel
Hosea
Joel
Amos
Obadiah
Jonah
Micah
Nahum
Habakkuk
Zephaniah
Haggai
Zechariah
Malachi
Matthew
Mark
Luke
John
Acts
Romans
1 Corinthians
2 Corinthians
Galatians
Ephesians
Philippians
Colossians
1 Thessalonians
2 Thessalonians
1 Timothy
2 Timothy
Titus
Philemon
Hebrews
James
1 Peter
2 Peter
1 John
2 John
3 John
Jude
Revelation

Books with number of chapters

Book,NumberOfChapters
Genesis,50
Exodus,40
Leviticus,27
Numbers,36
Deuteronomy,34
Joshua,24
Judges,21
Ruth,4
1 Samuel,31
2 Samuel,24
1 Kings,22
2 Kings,25
1 Chronicles,29
2 Chronicles,36
Ezra,10
Nehemiah,13
Esther,10
Job,42
Psalms,150
Proverbs,31
Ecclesiastes,12
Song of Solomon,8
Isaiah,66
Jeremiah,52
Lamentations,5
Ezekiel,48
Daniel,12
Hosea,14
Joel,3
Amos,9
Obadiah,1
Jonah,4
Micah,7
Nahum,3
Habakkuk,3
Zephaniah,3
Haggai,2
Zechariah,14
Malachi,4
Matthew,28
Mark,16
Luke,24
John,21
Acts,28
Romans,16
1 Corinthians,16
2 Corinthians,13
Galatians,6
Ephesians,6
Philippians,4
Colossians,4
1 Thessalonians,5
2 Thessalonians,3
1 Timothy,6
2 Timothy,4
Titus,3
Philemon,1
Hebrews,13
James,5
1 Peter,5
2 Peter,3
1 John,5
2 John,1
3 John,1
Jude,1
Revelation,22

Nice project!

Warm regards,

Chrisir