wiki-entity
Version:
Wiki entity fetcher
33 lines (32 loc) • 1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEntityType = void 0;
const simpleEntity_1 = require("./simpleEntity");
function getEntityType(wikiEntity) {
if (!wikiEntity.claims) {
return null;
}
const type = getTypeByProp(wikiEntity, 'P31');
if (type) {
return type;
}
}
exports.getEntityType = getEntityType;
function getTypeByProp(wikiEntity, prop) {
const instanceOf = wikiEntity.claims[prop];
if (!instanceOf) {
return null;
}
const ENTITY_TYPES = require('../../data/entity_types.json');
const types = simpleEntity_1.SIMPLE_ENTITY_TYPES;
for (let i = 0; i < types.length; i++) {
const type = types[i];
for (let j = 0; j < instanceOf.values.length; j++) {
const value = instanceOf.values[j].value;
if (~ENTITY_TYPES[type].indexOf(value)) {
return type;
}
}
}
return null;
}