diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-11-16 15:41:31 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-11-17 13:40:01 -0400 |
commit | 6bcbe4f3489bafff4a78f87e030c08db734af021 (patch) | |
tree | 94715c3579636f0aa1ea2756ebe8b98989980745 /src | |
parent | 89cf67d4348d4ac43df158b265fdac4e48cfe03c (diff) |
data: reverseAnnotatedReferenceList
Diffstat (limited to 'src')
4 files changed, 108 insertions, 0 deletions
diff --git a/src/data/composite/wiki-data/index.js b/src/data/composite/wiki-data/index.js index 581dafc8..51d07384 100644 --- a/src/data/composite/wiki-data/index.js +++ b/src/data/composite/wiki-data/index.js @@ -19,6 +19,7 @@ export {default as withResolvedContribs} from './withResolvedContribs.js'; export {default as withResolvedReference} from './withResolvedReference.js'; export {default as withResolvedReferenceList} from './withResolvedReferenceList.js'; export {default as withResolvedSeriesList} from './withResolvedSeriesList.js'; +export {default as withReverseAnnotatedReferenceList} from './withReverseAnnotatedReferenceList.js'; export {default as withReverseContributionList} from './withReverseContributionList.js'; export {default as withReverseReferenceList} from './withReverseReferenceList.js'; export {default as withReverseSingleReferenceList} from './withReverseSingleReferenceList.js'; diff --git a/src/data/composite/wiki-data/withReverseAnnotatedReferenceList.js b/src/data/composite/wiki-data/withReverseAnnotatedReferenceList.js new file mode 100644 index 00000000..168b68c0 --- /dev/null +++ b/src/data/composite/wiki-data/withReverseAnnotatedReferenceList.js @@ -0,0 +1,81 @@ +// Analogous implementation for withReverseReferenceList, for annotated +// references. +// +// Unlike withReverseContributionList, this composition is responsible for +// "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. + +import withReverseList_template from './helpers/withReverseList-template.js'; + +import {input} from '#composite'; +import {stitchArrays} from '#sugar'; + +import { + withFlattenedList, + withMappedList, + withPropertyFromList, + withStretchedList, +} from '#composite/data'; + +export default withReverseList_template({ + annotation: `withReverseAnnotatedReferenceList`, + + propertyInputName: 'list', + outputName: '#reverseAnnotatedReferenceList', + + customCompositionSteps: () => [ + withPropertyFromList({ + list: input('data'), + property: input('list'), + }).outputs({ + '#values': '#referenceLists', + }), + + withPropertyFromList({ + list: '#referenceLists', + property: input.value('length'), + }), + + withFlattenedList({ + list: '#referenceLists', + }).outputs({ + '#flattenedList': '#references', + }), + + withStretchedList({ + list: input('data'), + lengths: '#referenceLists.length', + }).outputs({ + '#stretchedList': '#things', + }), + + withPropertyFromList({ + list: '#references', + property: input.value('annotation'), + }).outputs({ + '#references.annotation': '#annotations', + }), + + { + dependencies: ['#things', '#annotations'], + compute: (continuation, { + ['#things']: things, + ['#annotations']: annotations, + }) => continuation({ + ['#referencingThings']: + stitchArrays({ + thing: things, + annotation: annotations, + }), + }), + }, + + withMappedList({ + list: '#references', + map: input.value(reference => [reference.thing]), + }).outputs({ + '#mappedList': '#referencedThings', + }), + ], +}); diff --git a/src/data/composite/wiki-properties/index.js b/src/data/composite/wiki-properties/index.js index 62d476c6..e98c89fc 100644 --- a/src/data/composite/wiki-properties/index.js +++ b/src/data/composite/wiki-properties/index.js @@ -21,6 +21,7 @@ export {default as flag} from './flag.js'; export {default as name} from './name.js'; export {default as referenceList} from './referenceList.js'; export {default as referencedArtworkList} from './referencedArtworkList.js'; +export {default as reverseAnnotatedReferenceList} from './reverseAnnotatedReferenceList.js'; export {default as reverseContributionList} from './reverseContributionList.js'; export {default as reverseReferenceList} from './reverseReferenceList.js'; export {default as reverseSingleReferenceList} from './reverseSingleReferenceList.js'; diff --git a/src/data/composite/wiki-properties/reverseAnnotatedReferenceList.js b/src/data/composite/wiki-properties/reverseAnnotatedReferenceList.js new file mode 100644 index 00000000..d18e5357 --- /dev/null +++ b/src/data/composite/wiki-properties/reverseAnnotatedReferenceList.js @@ -0,0 +1,25 @@ +import {input, templateCompositeFrom} from '#composite'; + +import {exposeDependency} from '#composite/control-flow'; +import {inputWikiData, withReverseAnnotatedReferenceList} + from '#composite/wiki-data'; + +export default templateCompositeFrom({ + annotation: `reverseAnnotatedReferenceList`, + + compose: false, + + inputs: { + data: inputWikiData({allowMixedTypes: false}), + list: input({type: 'string'}), + }, + + steps: () => [ + withReverseAnnotatedReferenceList({ + data: input('data'), + list: input('list'), + }), + + exposeDependency({dependency: '#reverseAnnotatedReferenceList'}), + ], +}); |