diff options
-rw-r--r-- | src/data/composite/wiki-data/withReverseAnnotatedReferenceList.js | 41 | ||||
-rw-r--r-- | src/data/composite/wiki-properties/reverseAnnotatedReferenceList.js | 8 |
2 files changed, 41 insertions, 8 deletions
diff --git a/src/data/composite/wiki-data/withReverseAnnotatedReferenceList.js b/src/data/composite/wiki-data/withReverseAnnotatedReferenceList.js index 168b68c0..debc68e4 100644 --- a/src/data/composite/wiki-data/withReverseAnnotatedReferenceList.js +++ b/src/data/composite/wiki-data/withReverseAnnotatedReferenceList.js @@ -5,6 +5,10 @@ // "flipping" the directionality of references: in a forward reference list, // `thing` points to the thing being referenced, while here, it points to the // referencing thing. +// +// This behavior can be customized to respect reference lists which are shaped +// differently than the default and/or to customize the reversed property and +// provide a less generic label than just "thing". import withReverseList_template from './helpers/withReverseList-template.js'; @@ -24,6 +28,12 @@ export default withReverseList_template({ propertyInputName: 'list', outputName: '#reverseAnnotatedReferenceList', + additionalInputs: { + forward: input({type: 'string', defaultValue: 'thing'}), + backward: input({type: 'string', defaultValue: 'thing'}), + annotation: input({type: 'string', defaultValue: 'annotation'}), + }, + customCompositionSteps: () => [ withPropertyFromList({ list: input('data'), @@ -52,28 +62,43 @@ export default withReverseList_template({ withPropertyFromList({ list: '#references', - property: input.value('annotation'), + property: input('annotation'), }).outputs({ - '#references.annotation': '#annotations', + '#values': '#annotations', }), { - dependencies: ['#things', '#annotations'], + dependencies: [ + input('backward'), + input('annotation'), + '#things', + '#annotations', + ], + compute: (continuation, { + [input('backward')]: thingProperty, + [input('annotation')]: annotationProperty, ['#things']: things, ['#annotations']: annotations, }) => continuation({ - ['#referencingThings']: + '#referencingThings': stitchArrays({ - thing: things, - annotation: annotations, + [thingProperty]: things, + [annotationProperty]: annotations, }), }), }, - withMappedList({ + withPropertyFromList({ list: '#references', - map: input.value(reference => [reference.thing]), + property: input('forward'), + }).outputs({ + '#values': '#individualReferencedThings', + }), + + withMappedList({ + list: '#individualReferencedThings', + map: input.value(thing => [thing]), }).outputs({ '#mappedList': '#referencedThings', }), diff --git a/src/data/composite/wiki-properties/reverseAnnotatedReferenceList.js b/src/data/composite/wiki-properties/reverseAnnotatedReferenceList.js index d18e5357..ba7166b9 100644 --- a/src/data/composite/wiki-properties/reverseAnnotatedReferenceList.js +++ b/src/data/composite/wiki-properties/reverseAnnotatedReferenceList.js @@ -12,12 +12,20 @@ export default templateCompositeFrom({ inputs: { data: inputWikiData({allowMixedTypes: false}), list: input({type: 'string'}), + + forward: input({type: 'string', defaultValue: 'thing'}), + backward: input({type: 'string', defaultValue: 'thing'}), + annotation: input({type: 'string', defaultValue: 'annotation'}), }, steps: () => [ withReverseAnnotatedReferenceList({ data: input('data'), list: input('list'), + + forward: input('forward'), + backward: input('backward'), + annotation: input('annotation'), }), exposeDependency({dependency: '#reverseAnnotatedReferenceList'}), |