Skip to content

Commit

Permalink
feat: add referencing string lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmacdonald committed Aug 14, 2019
1 parent fb741a2 commit 6a00296
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
10 changes: 10 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)=>{
Expand Down Expand Up @@ -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
}
9 changes: 5 additions & 4 deletions test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6a00296

Please sign in to comment.