import java.applet.*;
import java.awt.*;
import java.net.*;
import java.io.*;
public class hitomi extends Applet {
// ascii to gematria value matrix starting with $20 SPACE
// michigan claremont style
// ABGDHVZX+YKLMN$OPCQRSTkmnpc
// special shins no special value: s = 300, # = 300
private final int[][] gematrix = {{
// lettermatrix A
0,0,0,300,50,0,0,0, 0,0,0,9,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,1,2,90,4,0,0,3, 5,0,0,20,30,40,50,70,
80,100,200,300,400,0,6,0, 8,10,7,0,0,0,0,0,
0,0,0,90,0,0,0,0, 0,0,0,20,0,40,50,0,
80,0,0,300,0,0,0,0, 0,0,0,0,0,0,0,0
}, {
// lettermatrix B, end letters have high values
0,0,0,300,60,0,0,0, 0,0,0,9,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,1,2,90,4,0,0,3, 5,0,0,20,30,40,50,70,
80,100,200,300,400,0,6,0, 8,10,7,0,0,0,0,0,
0,0,0,900,0,0,0,0, 0,0,0,500,0,600,700,0,
800,0,0,300,0,0,0,0, 0,0,0,0,0,0,0,0
}};
//private Hashtable texts = new Hashtable();
//verse object
private class verse {
private class word {
public int[] sum = new int[1];//sums by gematrix A and B
public String w;//the word
//public int nr;//word number in the verse by index
//public word(String w, int sumA, int sumB) {
// this.w = w;
// this.sum[0] = sumA;
// this.sum[1] = sumB;
//}
}
public int chap, rel; //relative verse number
public String id; //e.g. 'GEN' or 'EXO' etc
public word[] w;//words
//constructor
//public verse() {
//this.nr = nr;//by index
//this.id = id;
//}
}
public void init() {
setBackground(Color.white);
//later read once at first user plot request or display 666 as default
//with vector: isEmpty(); flush with removeAll();
//with hastable can store multiple parsed texts in mem, each is an array of
//verse objects, for hashtable see [url]http://www.rgagnon.com/howto.html[/url]
static verse[] thisbook = parse("tanach.txt");
}
public void paint(Graphics g) {
// Get the width and height of the Applet
int aw = this.getSize().width;
int ah = this.getSize().height;
int as; // pixel diameter of the full wheel
if (aw<ah) {as = aw;} else {as = ah;}
// set up hitomi function parameters
g.setColor(Color.orange);
g.drawOval(0,0,as,as);
g.drawString("Value: " + thisbook[0].w[0].sumA, 10,10);
}
private verse[] parse(String f){
// claremont textfile by filename and parse
verse[] book;
try {
URL u = new URL(getCodeBase(), f);
//later try FileReader in place of InputStreamReader
BufferedReader br = new BufferedReader (new InputStreamReader(u.openStream()));
int v=0, m=0;
String l = "";
l = br.readLine();
if (l.startsWith("INIT")) {
//read number of verses
m = Integer.parseInt(l.substring(4,6));//max words in verse
v = Integer.parseInt(l.substring(6,10));//verses in text
//create the book array
book = new verse[v-1];
} /*else {noinit = true; search size and go back to file start
or even save checked file}*/
v=0;
int w=0, i, j, c;//word number, index in line, j index of next space or end
String wd;
byte[] b;
while(null != (l = br.readLine())) {
//calc and store this verse values
book[v].id = l.substring(0, 3);//store tag GEN or EXO etc
book[v].chap = Integer.parseInt(l.substring(4,7));//chapter number
book[v].rel = Integer.parseInt(l.substring(8,11));//verse number
i=12;//verse words start at index 12 in the line of text
book[v].w = new word[m]
//word loop
while (i<l.length()) {
if (-1 == (j = l.indexOf(" ",i))) {
j = l.indexOf(".",i);
}
wd = l.substring(i,j);
book[v].w[w].w = wd;
b = getBytes(wd);
for (c = 0; i<j; {c++; i++}) {
//use ascii code
book[v].w[w].sumA += gematrix[0][b[c]-32];
book[v].w[w].sumB += gematrix[1][b[c]-32];
}
i++; w++;
}
}
br.close();
}
catch(IOException e) {
//Graphics g = this.getGraphics();
//g.drawString(e.getMessage, 0, 0);
}
return book;
}
}
//end