factbook
Version:
Serves as an independent data scraping module, complete with ontology and full scraping ability for the CIA World Factbook site
42 lines (41 loc) • 2.19 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var funktologies_1 = require("funktologies");
var getUuid = require("uuid-by-string");
var constants_1 = require("../constants/constants");
var globalStore_1 = require("../constants/globalStore");
function getCoastLength(cheerioElem, country, countryId) {
var objectProperties = globalStore_1.store.countries[countryId].objectProperties;
var map = funktologies_1.getRelation(objectProperties, constants_1.consts.ONTOLOGY.HAS_COAST);
var clId = constants_1.consts.ONTOLOGY.INST_COAST + getUuid(country);
var objectProp = {};
var bailOut = true;
cheerioElem('#field-coastline').each(function () {
if (!map) {
if (globalStore_1.store.coasts[clId]) {
objectProp[constants_1.consts.ONTOLOGY.HAS_COAST] = globalStore_1.store.coasts[clId];
}
else {
objectProp = funktologies_1.entityMaker(constants_1.consts.ONTOLOGY.HAS_COAST, constants_1.consts.ONTOLOGY.ONT_COAST, clId, "Coast of " + country);
globalStore_1.store.coasts[clId] = objectProp[constants_1.consts.ONTOLOGY.HAS_COAST];
}
map = objectProp[constants_1.consts.ONTOLOGY.HAS_COAST];
globalStore_1.store.countries[countryId].objectProperties.push(funktologies_1.entityRefMaker(constants_1.consts.ONTOLOGY.HAS_COAST, objectProp));
}
bailOut = false;
});
if (bailOut) {
return;
}
cheerioElem('#field-coastline').each(function (index, element) {
var coastGrd = cheerioElem(element).find('div.category_data.subfield.numeric').text().trim();
if (coastGrd) {
var coastGrdSplit = coastGrd.split('km');
map.datatypeProperties[constants_1.consts.ONTOLOGY.DT_LENGTH] = Number(coastGrdSplit[0].trim()) || null;
map.datatypeProperties[constants_1.consts.ONTOLOGY.DT_LENGTH_MODIFIER] = coastGrdSplit.slice(1).join('km').replace(/\\n/g, '').trim() || null;
}
});
map.datatypeProperties[constants_1.consts.ONTOLOGY.DT_UNIT] = 'km';
}
exports.getCoastLength = getCoastLength;
;
;