2017-01-18 17:51:06 -05:00
|
|
|
|
/// <reference path="../../typings/browser/ambient/jquery/index.d.ts" />
|
2016-09-12 18:13:56 -04:00
|
|
|
|
import { Injectable } from "@angular/core";
|
2016-12-01 10:39:04 -05:00
|
|
|
|
import { Http } from "@angular/http";
|
2016-09-12 18:13:56 -04:00
|
|
|
|
|
|
|
|
|
@Injectable()
|
2017-01-18 17:51:06 -05:00
|
|
|
|
export class StrongsService
|
|
|
|
|
{
|
2016-09-12 18:13:56 -04:00
|
|
|
|
result: StrongsResult;
|
|
|
|
|
count = 0;
|
|
|
|
|
|
2017-01-18 17:51:06 -05:00
|
|
|
|
constructor(private http: Http)
|
|
|
|
|
{
|
2016-09-12 18:13:56 -04:00
|
|
|
|
}
|
2016-12-27 21:10:00 -05:00
|
|
|
|
|
2017-01-18 17:51:06 -05:00
|
|
|
|
getResult(sn: number, dict: string): StrongsResult
|
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
const self = this;
|
|
|
|
|
this.result = {
|
|
|
|
|
prefix: "",
|
|
|
|
|
sn: -1,
|
|
|
|
|
strongs: [],
|
|
|
|
|
def: null,
|
|
|
|
|
rmac: null,
|
|
|
|
|
crossrefs: null,
|
2017-01-03 23:51:25 -05:00
|
|
|
|
rmaccode: "",
|
|
|
|
|
status: 0,
|
|
|
|
|
msg: ":)"
|
2016-12-27 21:10:00 -05:00
|
|
|
|
};
|
|
|
|
|
let url = dict + Math.ceil(sn / 100) + ".json";
|
2017-01-18 17:51:06 -05:00
|
|
|
|
if (dict === "grk")
|
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
self.result.prefix = "G";
|
2017-01-18 17:51:06 -05:00
|
|
|
|
if (sn > 5624 || sn < 1)
|
|
|
|
|
{
|
2017-01-03 23:51:25 -05:00
|
|
|
|
self.result.status = -1;
|
|
|
|
|
self.result.msg = "Strongs Number G" + sn + " is out of range.";
|
|
|
|
|
}
|
2017-01-18 17:51:06 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
self.result.prefix = "H";
|
2017-01-18 17:51:06 -05:00
|
|
|
|
if (sn > 8674 || sn < 1)
|
|
|
|
|
{
|
2017-01-03 23:51:25 -05:00
|
|
|
|
self.result.status = -1;
|
|
|
|
|
self.result.msg = "Strongs Number H" + sn + " is out of range.";
|
|
|
|
|
}
|
2016-12-27 21:10:00 -05:00
|
|
|
|
}
|
|
|
|
|
this.result.sn = sn;
|
|
|
|
|
|
2017-01-03 23:51:25 -05:00
|
|
|
|
if (self.result.status == -1)
|
|
|
|
|
return self.result;
|
|
|
|
|
|
2016-12-27 21:10:00 -05:00
|
|
|
|
$.ajax({
|
|
|
|
|
async: false,
|
|
|
|
|
type: "GET",
|
2017-01-16 21:59:07 -05:00
|
|
|
|
url: "data/strongs/" + url,
|
2016-12-27 21:10:00 -05:00
|
|
|
|
dataType: "json",
|
2017-01-18 17:51:06 -05:00
|
|
|
|
success: function (d: StrongsDefinition[], t, x)
|
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
self.result.strongs = d;
|
|
|
|
|
},
|
2017-01-18 17:51:06 -05:00
|
|
|
|
error: function (request, status, error)
|
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
console.log(error);
|
2017-01-03 23:51:25 -05:00
|
|
|
|
self.result.status = -1;
|
|
|
|
|
self.result.msg = "Unable to retrieve Strongs Data for " + self.result.prefix + self.result.sn;
|
2016-09-12 18:13:56 -04:00
|
|
|
|
}
|
2016-12-27 21:10:00 -05:00
|
|
|
|
});
|
2016-09-12 18:13:56 -04:00
|
|
|
|
|
2017-01-03 23:51:25 -05:00
|
|
|
|
if (self.result.status === -1)
|
|
|
|
|
return self.result;
|
|
|
|
|
|
2016-12-27 21:10:00 -05:00
|
|
|
|
self.result.def = self.result.strongs.find(el => (el.i === this.result.prefix + this.result.sn));
|
|
|
|
|
self.result.strongs = [];
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
async: false,
|
|
|
|
|
type: "GET",
|
2017-01-16 21:59:07 -05:00
|
|
|
|
url: "data/strongscr/cr" + url,
|
2016-12-27 21:10:00 -05:00
|
|
|
|
dataType: "json",
|
2017-01-18 17:51:06 -05:00
|
|
|
|
success: function (d: StrongsCrossReference[], t, x)
|
|
|
|
|
{
|
|
|
|
|
for (let cr of d)
|
|
|
|
|
{
|
|
|
|
|
if (cr.id.toUpperCase() == self.result.prefix + self.result.sn)
|
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
self.result.crossrefs = cr;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-09-12 18:13:56 -04:00
|
|
|
|
}
|
2016-12-27 21:10:00 -05:00
|
|
|
|
},
|
2017-01-18 17:51:06 -05:00
|
|
|
|
error: function (request, status, error)
|
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
console.log(error);
|
2017-01-03 23:51:25 -05:00
|
|
|
|
self.result.status = -1;
|
|
|
|
|
self.result.msg = "Unable to retrieve Strongs Cross References for " + self.result.prefix + self.result.sn;
|
2016-12-27 21:10:00 -05:00
|
|
|
|
}
|
|
|
|
|
});
|
2016-09-12 18:13:56 -04:00
|
|
|
|
|
2017-01-03 23:51:25 -05:00
|
|
|
|
if (self.result.status === -1)
|
|
|
|
|
return self.result;
|
|
|
|
|
|
2017-01-18 17:51:06 -05:00
|
|
|
|
if (dict === "grk")
|
|
|
|
|
{
|
2017-01-16 21:59:07 -05:00
|
|
|
|
url = "data/rmac/rs" + (Math.ceil(sn / 1000)) + ".json";
|
2016-12-27 21:10:00 -05:00
|
|
|
|
let rmac_cross_references: RMACCrossReference[];
|
2016-09-12 18:13:56 -04:00
|
|
|
|
|
2016-12-27 21:10:00 -05:00
|
|
|
|
// rmac is a two get process.
|
2016-09-12 18:13:56 -04:00
|
|
|
|
$.ajax({
|
|
|
|
|
async: false,
|
|
|
|
|
type: "GET",
|
2016-12-27 21:10:00 -05:00
|
|
|
|
url: url,
|
2016-09-12 18:13:56 -04:00
|
|
|
|
dataType: "json",
|
2017-01-18 17:51:06 -05:00
|
|
|
|
success: function (d: RMACCrossReference[], t, x)
|
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
rmac_cross_references = d;
|
2016-09-12 18:13:56 -04:00
|
|
|
|
},
|
2017-01-18 17:51:06 -05:00
|
|
|
|
error: function (request, status, error)
|
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
console.log(error);
|
2016-09-12 18:13:56 -04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-12-27 21:10:00 -05:00
|
|
|
|
// deal with RMAC
|
2017-01-18 17:51:06 -05:00
|
|
|
|
let tmp = $.grep<RMACCrossReference>(rmac_cross_references, (el, i) => { return el.i == sn + "" ? true : false; });
|
2017-01-16 21:59:07 -05:00
|
|
|
|
if (tmp.length == 0)
|
|
|
|
|
return this.result;
|
2017-01-18 17:51:06 -05:00
|
|
|
|
|
2017-01-16 21:59:07 -05:00
|
|
|
|
this.result.rmaccode = tmp[0].r;
|
2017-01-18 17:51:06 -05:00
|
|
|
|
if (this.result.rmaccode != undefined)
|
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
url = `data/rmac/r-${this.result.rmaccode.substring(0, 1)}.json`;
|
2016-09-12 18:13:56 -04:00
|
|
|
|
$.ajax({
|
|
|
|
|
async: false,
|
|
|
|
|
type: "GET",
|
|
|
|
|
url: url,
|
|
|
|
|
dataType: "json",
|
2017-01-18 17:51:06 -05:00
|
|
|
|
success: function (d: RMACDefinition[], t, x)
|
|
|
|
|
{
|
|
|
|
|
for (let rmac of d)
|
|
|
|
|
{
|
|
|
|
|
if (rmac.id.toLowerCase() == self.result.rmaccode)
|
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
self.result.rmac = rmac;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-12 18:13:56 -04:00
|
|
|
|
},
|
2017-01-18 17:51:06 -05:00
|
|
|
|
error: function (request, status, error)
|
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
console.log(error);
|
2016-09-12 18:13:56 -04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-27 21:10:00 -05:00
|
|
|
|
return this.result;
|
2016-09-12 18:13:56 -04:00
|
|
|
|
}
|
2017-01-18 17:51:06 -05:00
|
|
|
|
}
|
|
|
|
|
export type StrongsResult =
|
|
|
|
|
{
|
|
|
|
|
prefix: string,
|
|
|
|
|
sn: number,
|
|
|
|
|
strongs: StrongsDefinition[],
|
|
|
|
|
def: StrongsDefinition,
|
|
|
|
|
rmac: RMACDefinition,
|
|
|
|
|
crossrefs: StrongsCrossReference,
|
|
|
|
|
rmaccode: string,
|
|
|
|
|
status: number,
|
|
|
|
|
msg: string
|
|
|
|
|
};
|
|
|
|
|
|
2017-01-20 18:57:02 -05:00
|
|
|
|
type StrongsDefinition = { n: number, i: string, tr: string, de: StrongsDefinitionPart[], lemma: string, p: string }
|
|
|
|
|
type StrongsDefinitionPart = { sn: string, w: string }
|
2017-01-18 17:51:06 -05:00
|
|
|
|
type StrongsCrossReference =
|
|
|
|
|
{
|
|
|
|
|
id: string, // strongs id H1|G1
|
|
|
|
|
t: string, // strongs testament grk|heb
|
|
|
|
|
d: string, // strongs word/data Aaron {ah-ar-ohn'}
|
|
|
|
|
ss: [
|
|
|
|
|
{
|
|
|
|
|
w: string,
|
|
|
|
|
rs: [
|
|
|
|
|
{ r: string }
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type RMACDefinition = { id: string, d: string[] }
|
|
|
|
|
|
|
|
|
|
type RMACCrossReference = { i: string, r: string }
|