Skip to content

Commit

Permalink
Merge pull request #120 from LD4P/t119-mapper_parsing_exception
Browse files Browse the repository at this point in the history
Guarantees that only strings are indexed.
  • Loading branch information
jcoyne authored Nov 22, 2019
2 parents fe34bd0 + 19c5b1c commit 049a914
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 10 additions & 0 deletions __tests__/Indexer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ describe('Indexer', () => {
'@id': 'http://id.loc.gov/vocabulary/issuance/mono',
'label': 'single unit'
},
{
'@id': '_:b1',
'@type': 'http://id.loc.gov/ontologies/bibframe/AccessPolicy',
'label': {
'@language': 'en',
'@value': 'Open access'
}
},
{
'@id': '_:b0',
'@type': ['as:Update', 'prov:Activity'],
Expand Down Expand Up @@ -93,6 +101,7 @@ describe('Indexer', () => {
'Hamlet',
'A Tragic Tale about a Prince of Denmark',
'There is nothing either good or bad, but thinking makes it so.',
'Open access',
'single unit',
],
subtitle: ['A Tragic Tale about a Prince of Denmark'],
Expand Down Expand Up @@ -356,6 +365,7 @@ describe('Indexer', () => {
'Hamlet',
'A Tragic Tale about a Prince of Denmark',
'There is nothing either good or bad, but thinking makes it so.',
'Open access',
'single unit'
],
subtitle: ['A Tragic Tale about a Prince of Denmark'],
Expand Down
13 changes: 8 additions & 5 deletions src/ResourceIndexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default class {
})
.filter(obj => obj['@value']) // Filter out fields without values, e.g., from the @context object
.map(obj => obj['@value']) // Extract the value and ignore the @language for now (this is currently coupled to how titles are modeled)
.filter(obj => typeof obj === 'string') // Remove anything not a string
if (fieldValues.length > 0) this.indexObject[fieldName] = fieldValues

}
Expand All @@ -52,16 +53,18 @@ export default class {
path: '$..*',
flatten: true
})
.filter(obj => obj['@value']) // Filter out fields without values or labels
.map(obj => obj['@value']) // Extract the value or label
.filter(obj => obj['@value']) // Filter out fields without values
.map(obj => obj['@value']) // Extract the value
.filter(obj => typeof obj === 'string') // Remove anything not a string

const labelValues = JSONPath({
json: this.json['@graph'],
path: '$..*',
flatten: false
})
.filter(obj => obj['label']) // Filter out fields without values or labels
.map(obj => obj['label']) // Extract the value or label

.filter(obj => obj['label']) // Filter out fields without labels
.map(obj => obj['label']) // Extract label
.filter(obj => typeof obj === 'string') // Remove anything not a string
this.indexObject['text'] = [...fieldValues, ...labelValues]
}

Expand Down

0 comments on commit 049a914

Please sign in to comment.