From 3e579167d0b8c52aa31b1136aaa22aa64f11d12b Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 27 Nov 2025 15:56:40 -0400 Subject: data: Content: chop almost everything --- .../composite/things/content/hasAnnotationPart.js | 20 ++-- src/data/composite/things/content/index.js | 5 +- .../things/content/withAnnotationPartNodeLists.js | 28 ++++++ .../things/content/withAnnotationParts.js | 103 --------------------- .../things/content/withHasAnnotationPart.js | 43 --------- .../composite/things/content/withSourceText.js | 53 ----------- .../composite/things/content/withSourceURLs.js | 62 ------------- 7 files changed, 39 insertions(+), 275 deletions(-) create mode 100644 src/data/composite/things/content/withAnnotationPartNodeLists.js delete mode 100644 src/data/composite/things/content/withAnnotationParts.js delete mode 100644 src/data/composite/things/content/withHasAnnotationPart.js delete mode 100644 src/data/composite/things/content/withSourceText.js delete mode 100644 src/data/composite/things/content/withSourceURLs.js (limited to 'src/data/composite/things') diff --git a/src/data/composite/things/content/hasAnnotationPart.js b/src/data/composite/things/content/hasAnnotationPart.js index 83d175e3..93aaf5e5 100644 --- a/src/data/composite/things/content/hasAnnotationPart.js +++ b/src/data/composite/things/content/hasAnnotationPart.js @@ -1,9 +1,5 @@ import {input, templateCompositeFrom} from '#composite'; -import {exposeDependency} from '#composite/control-flow'; - -import withHasAnnotationPart from './withHasAnnotationPart.js'; - export default templateCompositeFrom({ annotation: `hasAnnotationPart`, @@ -14,12 +10,16 @@ export default templateCompositeFrom({ }, steps: () => [ - withHasAnnotationPart({ - part: input('part'), - }), + { + dependencies: [input('part'), 'annotationParts'], - exposeDependency({ - dependency: '#hasAnnotationPart', - }), + compute: ({ + [input('part')]: search, + ['annotationParts']: parts, + }) => + parts.some(part => + part.toLowerCase() === + search.toLowerCase()), + }, ], }); diff --git a/src/data/composite/things/content/index.js b/src/data/composite/things/content/index.js index 4176337d..37d6fdc5 100644 --- a/src/data/composite/things/content/index.js +++ b/src/data/composite/things/content/index.js @@ -1,7 +1,4 @@ export {default as contentArtists} from './contentArtists.js'; export {default as hasAnnotationPart} from './hasAnnotationPart.js'; -export {default as withAnnotationParts} from './withAnnotationParts.js'; -export {default as withHasAnnotationPart} from './withHasAnnotationPart.js'; -export {default as withSourceText} from './withSourceText.js'; -export {default as withSourceURLs} from './withSourceURLs.js'; +export {default as withAnnotationPartNodeLists} from './withAnnotationPartNodeLists.js'; export {default as withWebArchiveDate} from './withWebArchiveDate.js'; diff --git a/src/data/composite/things/content/withAnnotationPartNodeLists.js b/src/data/composite/things/content/withAnnotationPartNodeLists.js new file mode 100644 index 00000000..fc304594 --- /dev/null +++ b/src/data/composite/things/content/withAnnotationPartNodeLists.js @@ -0,0 +1,28 @@ +import {input, templateCompositeFrom} from '#composite'; + +import {raiseOutputWithoutDependency} from '#composite/control-flow'; +import {splitContentNodesAround, withContentNodes} from '#composite/wiki-data'; + +export default templateCompositeFrom({ + annotation: `withAnnotationPartNodeLists`, + + outputs: ['#annotationPartNodeLists'], + + steps: () => [ + raiseOutputWithoutDependency({ + dependency: 'annotation', + output: input.value({'#annotationPartNodeLists': []}), + }), + + withContentNodes({ + from: 'annotation', + }), + + splitContentNodesAround({ + nodes: '#contentNodes', + around: input.value(/, */g), + }).outputs({ + '#contentNodeLists': '#annotationPartNodeLists', + }), + ], +}); diff --git a/src/data/composite/things/content/withAnnotationParts.js b/src/data/composite/things/content/withAnnotationParts.js deleted file mode 100644 index 15eb74a5..00000000 --- a/src/data/composite/things/content/withAnnotationParts.js +++ /dev/null @@ -1,103 +0,0 @@ -import {input, templateCompositeFrom} from '#composite'; -import {empty, transposeArrays} from '#sugar'; -import {is} from '#validators'; - -import {raiseOutputWithoutDependency} from '#composite/control-flow'; -import {withPropertyFromList} from '#composite/data'; -import {splitContentNodesAround, withContentNodes} from '#composite/wiki-data'; - -export default templateCompositeFrom({ - annotation: `withAnnotationParts`, - - inputs: { - mode: input({ - validate: is('strings', 'nodes'), - }), - }, - - outputs: ['#annotationParts'], - - steps: () => [ - raiseOutputWithoutDependency({ - dependency: '_annotation', - output: input.value({'#annotationParts': []}), - }), - - withContentNodes({ - from: '_annotation', - }), - - splitContentNodesAround({ - nodes: '#contentNodes', - around: input.value(/, */g), - }), - - { - dependencies: ['#contentNodeLists'], - compute: (continuation, { - ['#contentNodeLists']: nodeLists, - }) => continuation({ - ['#contentNodeLists']: - nodeLists.filter(list => !empty(list)), - }), - }, - - { - dependencies: ['#contentNodeLists', input('mode')], - compute: (continuation, { - ['#contentNodeLists']: nodeLists, - [input('mode')]: mode, - }) => - (mode === 'nodes' - ? continuation.raiseOutput({'#annotationParts': nodeLists}) - : continuation()), - }, - - { - dependencies: ['#contentNodeLists'], - - compute: (continuation, { - ['#contentNodeLists']: nodeLists, - }) => continuation({ - ['#firstNodes']: - nodeLists.map(list => list.at(0)), - - ['#lastNodes']: - nodeLists.map(list => list.at(-1)), - }), - }, - - withPropertyFromList({ - list: '#firstNodes', - property: input.value('i'), - }).outputs({ - '#firstNodes.i': '#startIndices', - }), - - withPropertyFromList({ - list: '#lastNodes', - property: input.value('iEnd'), - }).outputs({ - '#lastNodes.iEnd': '#endIndices', - }), - - { - dependencies: [ - 'annotation', - '#startIndices', - '#endIndices', - ], - - compute: (continuation, { - ['annotation']: annotation, - ['#startIndices']: startIndices, - ['#endIndices']: endIndices, - }) => continuation({ - ['#annotationParts']: - transposeArrays([startIndices, endIndices]) - .map(([start, end]) => - annotation.slice(start, end)), - }), - }, - ], -}); diff --git a/src/data/composite/things/content/withHasAnnotationPart.js b/src/data/composite/things/content/withHasAnnotationPart.js deleted file mode 100644 index 4af554f3..00000000 --- a/src/data/composite/things/content/withHasAnnotationPart.js +++ /dev/null @@ -1,43 +0,0 @@ -import {input, templateCompositeFrom} from '#composite'; - -import {raiseOutputWithoutDependency} from '#composite/control-flow'; - -import withAnnotationParts from './withAnnotationParts.js'; - -export default templateCompositeFrom({ - annotation: `withHasAnnotationPart`, - - inputs: { - part: input({type: 'string'}), - }, - - outputs: ['#hasAnnotationPart'], - - steps: () => [ - withAnnotationParts({ - mode: input.value('strings'), - }), - - raiseOutputWithoutDependency({ - dependency: '#annotationParts', - output: input.value({'#hasAnnotationPart': false}), - }), - - { - dependencies: [ - input('part'), - '#annotationParts', - ], - - compute: (continuation, { - [input('part')]: search, - ['#annotationParts']: parts, - }) => continuation({ - ['#hasAnnotationPart']: - parts.some(part => - part.toLowerCase() === - search.toLowerCase()), - }), - }, - ], -}); diff --git a/src/data/composite/things/content/withSourceText.js b/src/data/composite/things/content/withSourceText.js deleted file mode 100644 index 292306b7..00000000 --- a/src/data/composite/things/content/withSourceText.js +++ /dev/null @@ -1,53 +0,0 @@ -import {input, templateCompositeFrom} from '#composite'; - -import {raiseOutputWithoutDependency} from '#composite/control-flow'; - -import withAnnotationParts from './withAnnotationParts.js'; - -export default templateCompositeFrom({ - annotation: `withSourceText`, - - outputs: ['#sourceText'], - - steps: () => [ - withAnnotationParts({ - mode: input.value('nodes'), - }), - - raiseOutputWithoutDependency({ - dependency: '#annotationParts', - output: input.value({'#sourceText': null}), - }), - - { - dependencies: ['#annotationParts'], - compute: (continuation, { - ['#annotationParts']: annotationParts, - }) => continuation({ - ['#firstPartWithExternalLink']: - annotationParts - .find(nodes => nodes - .some(node => node.type === 'external-link')) ?? - null, - }), - }, - - raiseOutputWithoutDependency({ - dependency: '#firstPartWithExternalLink', - output: input.value({'#sourceText': null}), - }), - - { - dependencies: ['annotation', '#firstPartWithExternalLink'], - compute: (continuation, { - ['annotation']: annotation, - ['#firstPartWithExternalLink']: nodes, - }) => continuation({ - ['#sourceText']: - annotation.slice( - nodes.at(0).i, - nodes.at(-1).iEnd), - }), - }, - ], -}); diff --git a/src/data/composite/things/content/withSourceURLs.js b/src/data/composite/things/content/withSourceURLs.js deleted file mode 100644 index f85ff9ea..00000000 --- a/src/data/composite/things/content/withSourceURLs.js +++ /dev/null @@ -1,62 +0,0 @@ -import {input, templateCompositeFrom} from '#composite'; - -import {raiseOutputWithoutDependency} from '#composite/control-flow'; -import {withFilteredList, withMappedList} from '#composite/data'; - -import withAnnotationParts from './withAnnotationParts.js'; - -export default templateCompositeFrom({ - annotation: `withSourceURLs`, - - outputs: ['#sourceURLs'], - - steps: () => [ - withAnnotationParts({ - mode: input.value('nodes'), - }), - - raiseOutputWithoutDependency({ - dependency: '#annotationParts', - output: input.value({'#sourceURLs': []}), - }), - - { - dependencies: ['#annotationParts'], - compute: (continuation, { - ['#annotationParts']: annotationParts, - }) => continuation({ - ['#firstPartWithExternalLink']: - annotationParts - .find(nodes => nodes - .some(node => node.type === 'external-link')) ?? - null, - }), - }, - - raiseOutputWithoutDependency({ - dependency: '#firstPartWithExternalLink', - output: input.value({'#sourceURLs': []}), - }), - - withMappedList({ - list: '#firstPartWithExternalLink', - map: input.value(node => node.type === 'external-link'), - }).outputs({ - '#mappedList': '#externalLinkFilter', - }), - - withFilteredList({ - list: '#firstPartWithExternalLink', - filter: '#externalLinkFilter', - }).outputs({ - '#filteredList': '#externalLinks', - }), - - withMappedList({ - list: '#externalLinks', - map: input.value(node => node.data.href), - }).outputs({ - '#mappedList': '#sourceURLs', - }), - ], -}); -- cgit 1.3.0-6-gf8a5