tweaked json text conversion to make smaller. switched out text parsing from xml to json.

This commit is contained in:
walljm 2013-01-02 16:50:24 -05:00
parent 1af5989ac1
commit 7d0482cbb1
4 changed files with 84 additions and 69 deletions

View File

@ -7,23 +7,22 @@ namespace DynamicBibleUtility
{ {
public class Book public class Book
{ {
public string bk = ""; public int bk = -1;
public List<Chapter> chs = new List<Chapter>(); public List<Chapter> chs = new List<Chapter>();
} }
public class Chapter public class Chapter
{ {
public string ch = ""; public int ch = -1;
public List<Verse> vss = new List<Verse>(); public List<Verse> vss = new List<Verse>();
} }
public class Verse public class Verse
{ {
public string vs = ""; public int v = -1;
public List<object> words = new List<object>(); public List<object> w = new List<object>();
} }
public class Text public class Text
{ {
public string txt = ""; public string t = "";
public string str = ""; public string s = "";
public int i = -1;
} }
} }

View File

@ -273,32 +273,25 @@ namespace DynamicBibleUtility
if (el.Name == "BIBLEBOOK") if (el.Name == "BIBLEBOOK")
{ {
Book bk = new Book(); Book bk = new Book();
bk.bk = el.FirstAttribute.Value.ToString(); bk.bk = Convert.ToInt32(el.FirstAttribute.Value.ToString());
foreach (XElement chn in el.Nodes()) foreach (XElement chn in el.Nodes())
{ {
Chapter ch = new Chapter(); Chapter ch = new Chapter();
ch.ch = chn.FirstAttribute.Value; ch.ch = Convert.ToInt32(chn.FirstAttribute.Value);
foreach (XElement vs in chn.Nodes()) foreach (XElement vs in chn.Nodes())
{ {
Verse v = new Verse(); Verse v = new Verse();
v.vs = vs.FirstAttribute.Value; v.v = Convert.ToInt32(vs.FirstAttribute.Value);
int i = 0; int i = 0;
foreach (object o in vs.Nodes()) foreach (object o in vs.Nodes())
{ {
Text t = new Text(); Text t = new Text();
if (o.GetType() == typeof(XElement)) if (o.GetType() == typeof(XElement))
{ {
t.txt = ((XElement)o).Value; t.t = ((XElement)o).Value;
if (((XElement)o).Name == "gr") if (((XElement)o).Name == "gr")
{ {
if (Convert.ToInt32(bk.bk) >= 40) t.s = ((XElement)o).FirstAttribute.Value;
{
t.str = "G" + ((XElement)o).FirstAttribute.Value;
}
else
{
t.str = "H" + ((XElement)o).FirstAttribute.Value;
}
} }
else if ((((XElement)o).Name.ToString().ToLower() == "style")) else if ((((XElement)o).Name.ToString().ToLower() == "style"))
{ {
@ -308,24 +301,24 @@ namespace DynamicBibleUtility
{ {
throw new Exception("Unknown Element"); throw new Exception("Unknown Element");
} }
t.i = i++; //t.i = i++;
} }
else if (o.GetType() == typeof(XText)) else if (o.GetType() == typeof(XText))
{ {
t.txt = ((XText)o).Value; t.t = ((XText)o).Value;
t.i = i++; //t.i = i++;
} }
else else
{ {
throw new Exception("Unknown Element"); throw new Exception("Unknown Element");
} }
v.words.Add(t); v.w.Add(t);
} }
ch.vss.Add(v); ch.vss.Add(v);
} }
bk.chs.Add(ch); bk.chs.Add(ch);
System.IO.File.WriteAllText(bk.bk.ToString() + "-"+ch.ch+".json", Serialize(ch)); System.IO.File.WriteAllText(bk.bk.ToString() + "-" + ch.ch + ".json", Serialize(ch).Replace(",\"s\":\"\"", ""));
} }
bbl.Add(bk); bbl.Add(bk);

View File

@ -3,19 +3,18 @@ function SortNumeric(x, y)
return x - y return x - y
} }
String.prototype.trim = function() String.prototype.trim = function()
{ {
return this.replace(/^\s+|\s+$/g, ""); return this.replace(/^\s+|\s+$/g, "");
} }
String.prototype.ltrim = function() String.prototype.ltrim = function()
{ {
return this.replace(/^\s+/, ""); return this.replace(/^\s+/, "");
} }
String.prototype.rtrim = function() String.prototype.rtrim = function()
{ {
return this.replace(/\s+$/, ""); return this.replace(/\s+$/, "");
} }
function Traverse(node, testament) function Traverse(node, testament)
{ {
try try
@ -127,7 +126,10 @@ function Search(sv)
} }
} }
$( "#result" ).sortable({ axis: "x", handle: ".handle" }); $( "#result" ).sortable({
axis: "x",
handle: ".handle"
});
} }
catch (err) catch (err)
{ {
@ -267,7 +269,7 @@ var Bible = {
{ {
var r = ""; var r = "";
// make the end verse pretty. // make the end verse pretty.
var tvs = cs[cs.length - 1].vs.length; var tvs = cs[cs.length - 1].vss.length;
if (ev == "*" || ev > tvs) if (ev == "*" || ev > tvs)
{ {
@ -280,20 +282,30 @@ var Bible = {
{ {
r += "<b>Chapter: " + cs[j].ch + "</b><br />"; r += "<b>Chapter: " + cs[j].ch + "</b><br />";
} }
var vs = cs[j].vs; var vss = cs[j].vss;
for (var m = 0; m < vs.length; m++) for (var m = 0; m < vss.length; m++)
{ {
var v = vs[m]; var v = vss[m];
r += "<b>" + $(v).attr("n") + ".</b> "; r += "<b>" + v.v + ".</b> ";
for (var w = 0; w < v.childNodes.length; w++) for (var w = 0; w < v.w.length; w++)
{ {
r += Traverse(v.childNodes[w], testament); if (v.w[w].s != undefined)
{
var strongs_pre = "";
if (testament == "old") { strongs_pre = "H"; }
if (testament == "new") {strongs_pre = "G"; }
var sp = "";
if (v.w[w].t.substr(v.w[w].t.length-1) == " ") { sp = " "; }
r += "<a href='javascript:void();' class='hiddenlink' title='Strongs #: " + v.w[w].s + "'><span class='searchvalue' style='display:none'>" + strongs_pre + v.w[w].s + "</span>" + v.w[w].t.trim() + "</a>"+sp;
}
else
{
r += v.w[w].t;
}
} }
r += "<br />"; r += "<br />";
} }
} }
@ -318,24 +330,21 @@ var Bible = {
{ {
try try
{ {
var xml = []; // the verses from the chapter. var chapters = []; // the verses from the chapter.
var cs = []; // the verses requested. var cs = []; // the verses requested.
var r = {}; var r = {};
for (var i = sch; i <= ech; i++) for (var i = sch; i <= ech; i++)
{ {
var url = "xml/" + b + "-" + i + ".xml" var url = "bibles/kjv_strongs/" + b + "-" + i + ".json"
$.ajax({ $.ajax({
async: false, async: false,
type: "GET", type: "GET",
url: url, url: url,
dataType: "xml", dataType: "json",
success: function(d, t, x) success: function(d, t, x)
{ {
xml.push({ chapters.push(d);
"ch": i,
"vs": d
});
}, },
error: function(request, status, error) error: function(request, status, error)
{ {
@ -344,9 +353,9 @@ var Bible = {
}); });
} }
for (var j = 0; j < xml.length; j++) for (var j = 0; j < chapters.length; j++)
{ {
var vs = []; var vss = [];
var start; var start;
var end; var end;
@ -360,7 +369,8 @@ var Bible = {
start = 1; start = 1;
} }
if ((j + 1) == xml.length) // figure out the end verse
if ((j + 1) == chapters.length)
{ {
end = ev; end = ev;
} }
@ -369,27 +379,34 @@ var Bible = {
end = "*"; end = "*";
} }
var tvs = $(xml[j].vs).find("v").length;
// get the verses requested. // get the verses requested.
var tvs = chapters[j].vss.length;
if (end == "*" || end > tvs) if (end == "*" || end > tvs)
{ {
end = tvs; end = tvs;
} }
for (var i = start; i <= end; i++) for (i = start; i <= end; i++)
{ {
vs.push($(xml[j].vs).find('v[n="' + i + '"]')[0]) // we're using c based indexes here, so the index is 1 less than the verse #.
vss.push(chapters[j].vss[i-1]);
} }
cs.push({ cs.push({
"ch": xml[j].ch, "ch": chapters[j].ch,
"vs": vs "vss": vss
}); });
} }
r.cs = cs; r.cs = cs;
r.testament = $(xml[0].vs).find("b").attr("testament"); if (b >= 40)
{
r.testament = "new";
}
else
{
r.testament = "old";
}
return r; return r;
} }
catch (err) catch (err)
@ -581,12 +598,18 @@ var Strongs = {
var t = Strongs.BuildStrongs(r); var t = Strongs.BuildStrongs(r);
var d = $("<div></div>").append(t); var d = $("<div></div>").append(t);
d.dialog({draggable:true, width: 600, height: 500, resizable: true, title: "Strongs Definition", d.dialog({
draggable:true,
width: 600,
height: 500,
resizable: true,
title: "Strongs Definition",
buttons: { buttons: {
"Close": function() { "Close": function() {
$( this ).dialog( "close" ); $( this ).dialog( "close" );
}
} }
}}); });
return false; return false;
} }
catch (err) catch (err)