added improved reference parsing, can now find passages across chapters.

This commit is contained in:
jwall@VAPPRCSN015.vap.local 2011-11-04 19:19:29 -04:00
parent 99dec3f4a6
commit 7fd974741a
5 changed files with 796 additions and 551 deletions

78
biblerefparsingtests.html Normal file
View File

@ -0,0 +1,78 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="Jason Wall" />
<meta name="PBO.auth" content="8bff0c5d7a8f61d1e5dfa6c58da67c2b" />
<meta name="geo.country" content="US" />
<meta name="dc.language" content="en" />
<meta name="dc.title" content="walljm.com || AJAX Bible || King James Version with Strong's Dictionary and Cross References" />
<meta name="description" content="An AJAX implimentation of The King James Version Bible with Strong's Dictionary integrated." />
<meta name="keywords" content="AJAX, KJV, King James Version, Strong's Dictionary, Strongs" />
<meta name="blogchalk" content="United States, Missouri, Saint Louis, English, Jason, Male, 21-25, photography, poetry" />
<meta name="copyright" content="All content copyrighted to Jason Wall, and available by permission of the owner." />
<title>The Bible with Strong's Numbers and Cross References</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<!--<script type="text/javascript" src="js/bible_ref_parsing.js"></script>-->
<script type="text/javascript" src="js/bible_ref_parsing.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
var tests = [
["john 1:4 - john 2", "John 1:4 - 2:*"],
["john 1 : 4 - john 2", "John 1:4 - 2:*"],
["1 john 1:4 - 1 john 2", "1 John 1:4 - 2:*"],
["1 john 1 : 4 - john 2", "1 John 1:4 - 2:*"],
["1 john 3 - 1 john 5", "1 John 3:1 - 5:*"],
["1 John 1", "1 John 1:1 - 1:*"],
["John 1", "John 1:1 - 1:*"],
["1 John 1:1", "1 John 1:1 - 1:1"],
[" 1 John 1 : 1 ", "1 John 1:1 - 1:1"],
["John 1:1", "John 1:1 - 1:1"],
[" John 1 : 1 ", "John 1:1 - 1:1"],
[" 1 John 1 : 1 - 2 ", "1 John 1:1 - 1:2"],
["1 John 1:1-2", "1 John 1:1 - 1:2"],
["John 1:1-2", "John 1:1 - 1:2"],
["John 1 : 1 - 2", "John 1:1 - 1:2"],
["1 John 1 : 1 - 1 John 2 : 3 ", "1 John 1:1 - 2:3"],
["1 John 1:1-1 John 2:3", "1 John 1:1 - 2:3"],
["John 1:1-John 2:3", "John 1:1 - 2:3"],
["John 1 : 1 - John 2 : 3 ", "John 1:1 - 2:3"],
["John 1-2", "John 1:1 - 2:*"],
["John 1 - 2", "John 1:1 - 2:*"],
["1 John 1-2", "1 John 1:1 - 2:*"],
["1 John 1 - 2 ", "1 John 1:1 - 2:*"]
];
var b = $("body");
var passed = 0;
var failed = 0;
for (var i = 0; i < tests.length; i++)
{
var t = tests[i];
var ref = new Reference(t[0]);
var r = "<b>Test " + i + ":</b> " + t[0] + "<br />";
var parsed = ref.bookname + " " + ref.startchapter + ":" + ref.startverse + " - " + ref.endchapter + ":" + ref.endverse;
r += "<b>Value:</b> " + parsed + "<br />";
if (parsed == t[1])
{
r += "<span style='color:green'>Passed</span><br /><br />";
passed++;
}
else
{
r += "<span style='color:red'>Failed</span><br /><br />";
failed++;
}
b.append(r);
}
b.prepend(passed + " Passed, " + failed + " Failed<br /><br />");
});
</script>
</head>
<body>
</body>
</html>

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -107,9 +107,9 @@ function Search(sv)
if (q.trim() != "") if (q.trim() != "")
{ {
var myref = new Reference(q.trim()); var myref = new Reference(q.trim());
var r = Bible.GetPassage(myref.book, myref.chapter, myref.startverse, myref.endverse); var r = Bible.GetPassage(myref.book, myref.startchapter, myref.endchapter, myref.startverse, myref.endverse);
Bible.DisplayPassage(r.vs, myref.book, myref.chapter, myref.startverse, myref.endverse, r.testament); Bible.DisplayPassage(r.cs, myref.book, myref.startchapter, myref.endchapter, myref.startverse, myref.endverse, r.testament);
} }
} }
} }
@ -202,28 +202,43 @@ var Util = {
} }
var Bible = { var Bible = {
DisplayPassage: function(vs, b, ch, sv, ev, testament) DisplayPassage: function(cs, b, sch, ech, sv, ev, testament)
{ {
try try
{ {
var r = ""; var r = "";
// make the end verse pretty.
var tvs = cs[cs.length - 1].vs.length;
for (var i = 0; i < vs.length; i++) if (ev == "*" || ev > tvs)
{ {
var v = vs[i]; ev = tvs;
r += "<b>" + $(v).attr("n") + ".</b> ";
for (var j = 0; j < v.childNodes.length; j++)
{
r += Traverse(v.childNodes[j], testament);
}
r += "<br />";
} }
var t = $("<div class='passage result'><a href='javascript:void();' class='removeresult' style='border: 0;'><img style='border: 0px;' src='images/delete.png' width='48' height='48' /></a><span class='resultbody'>" + "<h2>" + bookName(b) + " " + ch + ":" + sv + "-" + ev + "</h2>" + r + "</span><br clear='all' /></div>"); for (var j = 0; j < cs.length; j++)
{
if (sch < ech)
{
r += "<b>Chapter: " + cs[j].ch + "</b><br />";
}
var vs = cs[j].vs;
for (var m = 0; m < vs.length; m++)
{
var v = vs[m];
r += "<b>" + $(v).attr("n") + ".</b> ";
for (var w = 0; w < v.childNodes.length; w++)
{
r += Traverse(v.childNodes[w], testament);
}
r += "<br />";
}
}
var t = $("<div class='passage result'><a href='javascript:void();' class='removeresult' style='border: 0;'><img style='border: 0px;' src='images/delete.png' width='48' height='48' /></a><span class='resultbody'>" + "<h2>" + bookName(b) + " " + sch + ":" + sv + "-" + ech + ":" + ev + "</h2>" + r + "</span><br clear='all' /></div>");
t.find(".hiddenlink").click(function(e) t.find(".hiddenlink").click(function(e)
{ {
@ -240,46 +255,69 @@ var Bible = {
Util.HandleError(err); Util.HandleError(err);
} }
}, },
GetPassage: function(b, ch, sv, ev) GetPassage: function(b, sch, ech, sv, ev)
{ {
try try
{ {
var xml; // the verses from the chapter. var xml = []; // the verses from the chapter.
var vs = new Array(); // the verses requested. var cs = []; // the verses requested.
var r = {}; var r = {};
var url = "xml/" + b + "-" + ch + ".xml" for (var i = sch; i <= ech; i++)
$.ajax({ {
async: false, var url = "xml/" + b + "-" + i + ".xml"
type: "GET", $.ajax({
url: url, async: false,
dataType: "xml", type: "GET",
success: function(d, t, x) url: url,
{ dataType: "xml",
xml = d; success: function(d, t, x)
}, {
error: function(request, status, error) xml.push({ "ch": i, "vs": d });
{ },
Util.HandleError(error, request); error: function(request, status, error)
} {
}); Util.HandleError(error, request);
}
});
}
// get the verses requested. for (var j = 0; j < xml.length; j++)
if (ev == "*")
{ {
vs = $(xml).find("v"); var vs = [];
} var start;
else var end;
{
for (var i = sv; i <= ev; i++) // figure out the start verse.
if (j == 0)
{ start = sv; }
else
{ start = 1; }
if ((j + 1) == xml.length)
{ end = ev; }
else
{ end = "*"; }
var tvs = $(xml[j].vs).find("v").length;
// get the verses requested.
if (end == "*" || end > tvs)
{ {
vs.unshift($(xml).find('v[n="' + i + '"]')[0]) end = tvs;
} }
for (var i = start; i <= end; i++)
{
vs.push($(xml[j].vs).find('v[n="' + i + '"]')[0])
}
cs.push({ "ch": xml[j].ch, "vs": vs });
} }
r.vs = vs;
r.testament = $(xml).find("b").attr("testament"); r.cs = cs;
r.testament = $(xml[0].vs).find("b").attr("testament");
return r; return r;
} }
catch (err) catch (err)
{ {

2
js/common.min.js vendored

File diff suppressed because one or more lines are too long