From 6a00296f44befc294fb0107a35b5c2910c746389 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 14 Aug 2019 12:16:46 -0400 Subject: [PATCH] feat: add referencing string lookup --- package.json | 2 +- src/index.js | 10 ++++++++++ test/browser.js | 9 +++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 104e0c0..74a776b 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "test:chrome": "cross-env NODE_ENV=test browserify test/browser.js | browser-run -b chrome | node test/extract-coverage.js | faucet ", "generate-coverage": "nyc report --reporter=lcov", "check-coverage": "nyc check-coverage --statements 90 --branches 90 --functions 90 --lines 90", - "report-coverage": "cat ./.nyc_output/lcov.info | codecov", + "report-coverage": "cat ./.nyc_output/coverage.json | codecov", "travis-deploy-once": "travis-deploy-once" }, "devDependencies": { diff --git a/src/index.js b/src/index.js index 241fade..200fe9d 100644 --- a/src/index.js +++ b/src/index.js @@ -63,6 +63,10 @@ function getTitleLookupURI(queryString) { return getEntitySourceURI(queryString, 'work') } +function getRSLookupURI(queryString) { + return getEntitySourceURI(queryString, 'thing') +} + function callDBPedia(url, queryString, queryClass) { return fetchWithTimeout(url).then((parsedJSON)=>{ @@ -102,13 +106,19 @@ function findTitle(queryString) { return callDBPedia(getTitleLookupURI(queryString), queryString, 'work') } +function findRS(queryString) { + return callDBPedia(getRSLookupURI(queryString), queryString, 'thing') +} + module.exports = { findPerson: findPerson, findPlace: findPlace, findOrganization: findOrganization, findTitle: findTitle, + findRS: findRS, getPersonLookupURI: getPersonLookupURI, getPlaceLookupURI: getPlaceLookupURI, getOrganizationLookupURI: getOrganizationLookupURI, getTitleLookupURI: getTitleLookupURI, + getRSLookupURI: getRSLookupURI } \ No newline at end of file diff --git a/test/browser.js b/test/browser.js index 1a101fb..0199c7e 100644 --- a/test/browser.js +++ b/test/browser.js @@ -25,7 +25,8 @@ var clock; {uriBuilderFn: 'getPersonLookupURI', testFixture:resultsFixture}, {uriBuilderFn: 'getPlaceLookupURI', testFixture:resultsFixture}, {uriBuilderFn: 'getOrganizationLookupURI', testFixture:resultsFixture}, - {uriBuilderFn: 'getTitleLookupURI', testFixture:resultsFixture} + {uriBuilderFn: 'getTitleLookupURI', testFixture:resultsFixture}, + {uriBuilderFn: 'getRSLookupURI', testFixture:resultsFixture} ].forEach(entityLookup=> { let uriBuilderFn = dbpedia[entityLookup.uriBuilderFn]; @@ -65,14 +66,14 @@ function doObjectsHaveSameKeys(...objects){ } test('lookup builders', (assert)=> { - assert.plan(4); - ['getPersonLookupURI', 'getPlaceLookupURI', 'getOrganizationLookupURI', 'getTitleLookupURI'].forEach(uriBuilderMethod => { + assert.plan(5); + ['getPersonLookupURI', 'getPlaceLookupURI', 'getOrganizationLookupURI', 'getTitleLookupURI', 'getRSLookupURI'].forEach(uriBuilderMethod => { assert.comment(uriBuilderMethod); assert.ok(dbpedia[uriBuilderMethod](queryString).includes(queryString), 'should contain the query string'); }); }); -['findPerson', 'findPlace', 'findOrganization', 'findTitle'].forEach((nameOfLookupFn)=> { +['findPerson', 'findPlace', 'findOrganization', 'findTitle', 'findRS'].forEach((nameOfLookupFn)=> { test(nameOfLookupFn, async function(assert){ let thisAssert = assert // thisAssert.plan(21);