| ; | |
| Object.defineProperty(exports, "__esModule", { | |
| value: true | |
| }); | |
| exports.TYPE_PRIORITIES = void 0; | |
| exports.getLabel = getLabel; | |
| exports.default = exports.parse = exports.parseProp = parseProp; | |
| exports.parseType = parseType; | |
| var _core = require("@citation-js/core"); | |
| var _name = require("@citation-js/name"); | |
| var _date = require("@citation-js/date"); | |
| var _config = _interopRequireDefault(require("./config.json")); | |
| var _types = _interopRequireDefault(require("./types.json")); | |
| function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | |
| function getNameString({ | |
| value, | |
| qualifiers | |
| }) { | |
| if (Array.isArray(qualifiers.P1932) && typeof qualifiers.P1932[0] === 'string') { | |
| return qualifiers.P1932[0]; | |
| } | |
| if (typeof value === 'object' && value !== null) { | |
| return getLabel(value); | |
| } | |
| if (typeof value === 'string') { | |
| return value; | |
| } | |
| return null; | |
| } | |
| function parseName(claim) { | |
| const nameString = getNameString(claim); | |
| if (nameString === null) { | |
| return { | |
| literal: null | |
| }; | |
| } | |
| const { | |
| value, | |
| qualifiers | |
| } = claim; | |
| const isPerson = typeof value !== 'object' || value && value.claims.P31 && value.claims.P31.some(claim => claim.value === 'Q5'); | |
| const name = isPerson ? (0, _name.parse)(nameString) : { | |
| literal: nameString | |
| }; | |
| const ordinal = qualifiers.P1545 ? parseInt(qualifiers.P1545[0]) : null; | |
| if (ordinal !== null) { | |
| name._ordinal = ordinal; | |
| } | |
| return name; | |
| } | |
| function parseNames(values) { | |
| return values.map(parseName).sort((a, b) => a._ordinal - b._ordinal); | |
| } | |
| function getCountryName(value) { | |
| if (value.claims.P1813) { | |
| const shortNames = value.claims.P1813.filter(({ | |
| qualifiers: { | |
| P31 | |
| } | |
| }) => !P31 || P31[0] !== 'Q28840786'); | |
| if (shortNames.length) { | |
| return shortNames[0].value; | |
| } | |
| } | |
| return getLabel(value); | |
| } | |
| function getPlace(value) { | |
| const place = getLabel(value); | |
| if (value.claims.P17) { | |
| return place + ', ' + getCountryName(value.claims.P17[0].value); | |
| } else { | |
| return place; | |
| } | |
| } | |
| function getTitle(value) { | |
| return value.claims.P1476 ? value.claims.P1476[0].value : getLabel(value); | |
| } | |
| function parseKeywords(values) { | |
| return values.map(({ | |
| value | |
| }) => getLabel(value)).filter(value => typeof value === 'string' && value !== '').join(','); | |
| } | |
| function parseDateRange(dates) { | |
| return { | |
| 'date-parts': dates.map(date => (0, _date.parse)(date.value)).filter(date => date && date['date-parts']).map(date => date['date-parts'][0]) | |
| }; | |
| } | |
| function parseVersion(version) { | |
| const output = { | |
| version: version.value | |
| }; | |
| if (version.qualifiers.P577) { | |
| output.issued = (0, _date.parse)(version.qualifiers.P577[0]); | |
| } | |
| if (version.qualifiers.P356) { | |
| output.DOI = version.qualifiers.P356[0]; | |
| } | |
| if (version.qualifiers.P6138) { | |
| output.SWHID = version.qualifiers.P6138[0]; | |
| } | |
| return output; | |
| } | |
| const TYPE_PRIORITIES = exports.TYPE_PRIORITIES = { | |
| 'review-book': 10, | |
| review: 9, | |
| 'entry-dictionary': 5, | |
| 'entry-encyclopedia': 5, | |
| map: 5, | |
| dataset: 4, | |
| legislation: 1, | |
| 'article-magazine': 0, | |
| bill: 0, | |
| chapter: 0, | |
| classic: 0, | |
| collection: 0, | |
| entry: 0, | |
| figure: 0, | |
| graphic: 0, | |
| hearing: 0, | |
| interview: 0, | |
| legal_case: 0, | |
| manuscript: 0, | |
| motion_picture: 0, | |
| musical_score: 0, | |
| pamphlet: 0, | |
| 'paper-conference': 0, | |
| patent: 0, | |
| personal_communication: 0, | |
| 'post-weblog': 0, | |
| report: 0, | |
| song: 0, | |
| speech: 0, | |
| standard: 0, | |
| thesis: 0, | |
| treaty: 0, | |
| broadcast: -1, | |
| 'article-newspaper': -1, | |
| 'article-journal': -1, | |
| periodical: -2, | |
| regulation: -2, | |
| post: -5, | |
| webpage: -6, | |
| software: -7, | |
| article: -9, | |
| book: -10, | |
| performance: -11, | |
| event: -12, | |
| document: -100 | |
| }; | |
| function parseProp(prop, value, entity) { | |
| switch (prop) { | |
| case 'type': | |
| return parseType(value); | |
| case 'author': | |
| case 'chair': | |
| case 'curator': | |
| case 'container-author': | |
| case 'collection-editor': | |
| case 'composer': | |
| case 'director': | |
| case 'editor': | |
| case 'executive-producer': | |
| case 'guest': | |
| case 'host': | |
| case 'illustrator': | |
| case 'narrator': | |
| case 'organizer': | |
| case 'original-author': | |
| case 'performer': | |
| case 'producer': | |
| case 'recipient': | |
| case 'reviewed-author': | |
| case 'script-writer': | |
| case 'translator': | |
| return parseNames(value); | |
| case 'issued': | |
| case 'original-date': | |
| return (0, _date.parse)(value); | |
| case 'event-date': | |
| return parseDateRange(value); | |
| case 'keyword': | |
| return parseKeywords(value); | |
| case 'container-title': | |
| case 'collection-title': | |
| case 'event-title': | |
| case 'medium': | |
| case 'publisher': | |
| case 'original-publisher': | |
| return getTitle(value); | |
| case 'event-place': | |
| case 'jurisdiction': | |
| case 'original-publisher-place': | |
| case 'publisher-place': | |
| return getPlace(value); | |
| case 'chapter-number': | |
| case 'collection-number': | |
| return parseInt(value[0]); | |
| case 'genre': | |
| return getLabel(value); | |
| case 'number-of-volumes': | |
| return value.length; | |
| case 'versions': | |
| return value.map(parseVersion); | |
| default: | |
| return value; | |
| } | |
| } | |
| function parseType(type) { | |
| const unmapped = Array.isArray(type) ? type : [type]; | |
| const mapped = unmapped.map(type => _types.default[type.value]).filter(Boolean); | |
| if (!mapped.length) { | |
| _core.logger.unmapped('[plugin-wikidata]', 'publication type', type); | |
| return 'document'; | |
| } | |
| mapped.sort((a, b) => TYPE_PRIORITIES[b] - TYPE_PRIORITIES[a]); | |
| return mapped[0]; | |
| } | |
| function getLabel(entity) { | |
| if (!entity) { | |
| return undefined; | |
| } | |
| const lang = _config.default.langs.find(lang => entity.labels[lang]); | |
| return entity.labels[lang]; | |
| } |
Xet Storage Details
- Size:
- 5.71 kB
- Xet hash:
- 152085aea7d7c994be9ea9f2fb4d2ba15ec94f1092774379679fc74820e1459c
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.