Skip to content

Commit

Permalink
Adds indexing of labels. (#115)
Browse files Browse the repository at this point in the history
Adds indexing of labels.
  • Loading branch information
mjgiarlo authored Nov 21, 2019
2 parents 0b1a869 + ecebbe8 commit fe34bd0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
16 changes: 12 additions & 4 deletions __tests__/Indexer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ describe('Indexer', () => {
'mainTitle': { '@value': 'Hamlet' },
'subtitle': { '@value': 'A Tragic Tale about a Prince of Denmark' },
'someText': { '@value': 'There is nothing either good or bad, but thinking makes it so.' },
'hasResourceTemplate': 'ld4p:RT:bf2:Title:AbbrTitle'
}, {
'hasResourceTemplate': 'ld4p:RT:bf2:Title:AbbrTitle',
'issuance': 'http://id.loc.gov/vocabulary/issuance/mono',
},
{
'@id': 'http://id.loc.gov/vocabulary/issuance/mono',
'label': 'single unit'
},
{
'@id': '_:b0',
'@type': ['as:Update', 'prov:Activity'],
'atTime': '2019-10-18T16:11:33.772Z',
Expand Down Expand Up @@ -86,7 +92,8 @@ describe('Indexer', () => {
text: [
'Hamlet',
'A Tragic Tale about a Prince of Denmark',
'There is nothing either good or bad, but thinking makes it so.'
'There is nothing either good or bad, but thinking makes it so.',
'single unit',
],
subtitle: ['A Tragic Tale about a Prince of Denmark'],
title: ['Hamlet'],
Expand Down Expand Up @@ -348,7 +355,8 @@ describe('Indexer', () => {
text: [
'Hamlet',
'A Tragic Tale about a Prince of Denmark',
'There is nothing either good or bad, but thinking makes it so.'
'There is nothing either good or bad, but thinking makes it so.',
'single unit'
],
subtitle: ['A Tragic Tale about a Prince of Denmark'],
title: ['Hamlet'],
Expand Down
24 changes: 21 additions & 3 deletions src/ResourceIndexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@ export default class {
this.buildFromPath('title', '$..[mainTitle,P10223,P20315,P40085,P30156]') //BIBFRAME and RDA
this.buildFromPath('subtitle', '$..subtitle')
this.buildLabel()
this.buildFromPath('text', '$..*')
this.buildAllText()
this.buildActivityStreamField('created', ['Create'])
this.buildActivityStreamField('modified', ['Create', 'Update'])
this.buildRDFTypes()

if (!this.indexObject.uri || !this.indexObject.label) {
throw `${this.uri} requires a uri and label: ${this.indexObject}`
}

return this.indexObject
}

buildFromPath(fieldName, path) {
const fieldValues = JSONPath({
json: this.json,
json: this.json['@graph'],
path: path,
flatten: true
})
Expand All @@ -47,6 +46,25 @@ export default class {

}

buildAllText() {
const fieldValues = JSONPath({
json: this.json['@graph'],
path: '$..*',
flatten: true
})
.filter(obj => obj['@value']) // Filter out fields without values or labels
.map(obj => obj['@value']) // Extract the value or label
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

this.indexObject['text'] = [...fieldValues, ...labelValues]
}

buildLabel() {
const labelValues = []
const fieldNames = ['title', 'subtitle']
Expand Down

0 comments on commit fe34bd0

Please sign in to comment.