diff options
Diffstat (limited to 'src/data/composite/things/content')
| -rw-r--r-- | src/data/composite/things/content/contentArtists.js | 40 | ||||
| -rw-r--r-- | src/data/composite/things/content/hasAnnotationPart.js | 20 | ||||
| -rw-r--r-- | src/data/composite/things/content/index.js | 7 | ||||
| -rw-r--r-- | src/data/composite/things/content/withAnnotationPartNodeLists.js | 28 | ||||
| -rw-r--r-- | src/data/composite/things/content/withAnnotationParts.js | 94 | ||||
| -rw-r--r-- | src/data/composite/things/content/withExpressedOrImplicitArtistReferences.js (renamed from src/data/composite/things/content/helpers/withExpressedOrImplicitArtistReferences.js) | 30 | ||||
| -rw-r--r-- | src/data/composite/things/content/withHasAnnotationPart.js | 43 | ||||
| -rw-r--r-- | src/data/composite/things/content/withSourceText.js | 54 | ||||
| -rw-r--r-- | src/data/composite/things/content/withSourceURLs.js | 63 | ||||
| -rw-r--r-- | src/data/composite/things/content/withWebArchiveDate.js | 9 |
10 files changed, 65 insertions, 323 deletions
diff --git a/src/data/composite/things/content/contentArtists.js b/src/data/composite/things/content/contentArtists.js deleted file mode 100644 index 8d5db5a5..00000000 --- a/src/data/composite/things/content/contentArtists.js +++ /dev/null @@ -1,40 +0,0 @@ -import {input, templateCompositeFrom} from '#composite'; -import {validateReferenceList} from '#validators'; - -import {exitWithoutDependency, exposeDependency} - from '#composite/control-flow'; -import {withResolvedReferenceList} from '#composite/wiki-data'; -import {soupyFind} from '#composite/wiki-properties'; - -import withExpressedOrImplicitArtistReferences - from './helpers/withExpressedOrImplicitArtistReferences.js'; - -export default templateCompositeFrom({ - annotation: `contentArtists`, - - compose: false, - - update: { - validate: validateReferenceList('artist'), - }, - - steps: () => [ - withExpressedOrImplicitArtistReferences({ - from: input.updateValue(), - }), - - exitWithoutDependency({ - dependency: '#artistReferences', - value: input.value([]), - }), - - withResolvedReferenceList({ - list: '#artistReferences', - find: soupyFind.input('artist'), - }), - - exposeDependency({ - dependency: '#resolvedReferenceList', - }), - ], -}); 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..27bf7c53 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 withExpressedOrImplicitArtistReferences} from './withExpressedOrImplicitArtistReferences.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 5eb8e3d5..00000000 --- a/src/data/composite/things/content/withAnnotationParts.js +++ /dev/null @@ -1,94 +0,0 @@ -import {input, templateCompositeFrom} from '#composite'; -import {parseContentNodes} from '#replacer'; -import {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', 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/helpers/withExpressedOrImplicitArtistReferences.js b/src/data/composite/things/content/withExpressedOrImplicitArtistReferences.js index 62799d43..a6200ee8 100644 --- a/src/data/composite/things/content/helpers/withExpressedOrImplicitArtistReferences.js +++ b/src/data/composite/things/content/withExpressedOrImplicitArtistReferences.js @@ -8,16 +8,19 @@ export default templateCompositeFrom({ annotation: `withExpressedOrImplicitArtistReferences`, inputs: { - from: input({type: 'array', acceptsNull: true}), + fromExpressed: input({type: 'array', acceptsNull: true}), + fromContent: input({type: 'string', acceptsNull: true}), + + filterArtistTags: input({type: 'function', defaultValue: () => true}), }, outputs: ['#artistReferences'], steps: () => [ { - dependencies: [input('from')], + dependencies: [input('fromExpressed')], compute: (continuation, { - [input('from')]: expressedArtistReferences, + [input('fromExpressed')]: expressedArtistReferences, }) => (expressedArtistReferences ? continuation.raiseOutput({'#artistReferences': expressedArtistReferences}) @@ -25,12 +28,12 @@ export default templateCompositeFrom({ }, raiseOutputWithoutDependency({ - dependency: 'artistText', - output: input.value({'#artistReferences': null}), + dependency: input('fromContent'), + output: input.value({'#artistReferences': []}), }), withContentNodes({ - from: 'artistText', + from: input('fromContent'), }), withMappedList({ @@ -42,16 +45,23 @@ export default templateCompositeFrom({ '#mappedList': '#artistTagFilter', }), - withFilteredList({ - list: '#contentNodes', - filter: '#artistTagFilter', + withFilteredList('#contentNodes', '#artistTagFilter') + .outputs({'#filteredList': '#artistTags'}), + + withMappedList({ + list: '#artistTags', + map: input('filterArtistTags'), }).outputs({ - '#filteredList': '#artistTags', + '#mappedList': '#customFilter', }), + withFilteredList({list: '#artistTags', filter: '#customFilter'}) + .outputs({'#filteredList': '#artistTags'}), + withMappedList({ list: '#artistTags', map: input.value(node => + 'artist:' + node.data.replacerValue[0].data), }).outputs({ '#mappedList': '#artistReferences', 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 d310e8ea..00000000 --- a/src/data/composite/things/content/withSourceText.js +++ /dev/null @@ -1,54 +0,0 @@ -import {input, templateCompositeFrom} from '#composite'; -import {parseContentNodes} from '#replacer'; - -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 f1e8dbc0..00000000 --- a/src/data/composite/things/content/withSourceURLs.js +++ /dev/null @@ -1,63 +0,0 @@ -import {input, templateCompositeFrom} from '#composite'; -import {parseContentNodes} from '#replacer'; - -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', - }), - ], -}); diff --git a/src/data/composite/things/content/withWebArchiveDate.js b/src/data/composite/things/content/withWebArchiveDate.js index 3aaa4f64..08cebd7f 100644 --- a/src/data/composite/things/content/withWebArchiveDate.js +++ b/src/data/composite/things/content/withWebArchiveDate.js @@ -9,13 +9,14 @@ export default templateCompositeFrom({ steps: () => [ { - dependencies: ['annotation'], + dependencies: ['sourceURLs'], - compute: (continuation, {annotation}) => + compute: (continuation, {sourceURLs}) => continuation({ ['#dateText']: - annotation - ?.match(/https?:\/\/web.archive.org\/web\/([0-9]{8,8})[0-9]*\//) + sourceURLs + .find(url => url.match(/https?:\/\/web\.archive\.org/)) + ?.match(/\/web\/([0-9]{8,8})[0-9]*\//) ?.[1] ?? null, }), |