wiki-graph-core 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/data/editor/text_compressor.jinja +17 -13
- package/data/help/commands/archive/next.jinja +7 -2
- package/data/help/commands/gc.jinja +2 -1
- package/data/help/commands/legacy/migrate.jinja +6 -1
- package/data/help/commands/legacy.jinja +3 -2
- package/data/help/commands/library-predicate.jinja +296 -0
- package/data/help/commands/library.jinja +237 -0
- package/data/help/commands/maintenance/chapter/add.jinja +3 -3
- package/data/help/commands/maintenance/chapter/list.jinja +4 -4
- package/data/help/commands/maintenance/chapter/move.jinja +4 -4
- package/data/help/commands/maintenance/chapter/remove.jinja +1 -1
- package/data/help/commands/maintenance/chapter/reset.jinja +1 -1
- package/data/help/commands/maintenance/chapter/set-source.jinja +2 -2
- package/data/help/commands/maintenance/chapter/set-summary.jinja +1 -1
- package/data/help/commands/maintenance/chapter/set-title.jinja +3 -3
- package/data/help/commands/maintenance/chapter/tree.jinja +6 -6
- package/data/help/commands/maintenance/chapter.jinja +10 -10
- package/data/help/commands/maintenance/meta.jinja +7 -7
- package/data/help/commands/maintenance/upgrade.jinja +35 -0
- package/data/help/commands/maintenance.jinja +23 -0
- package/data/help/commands/predicate.jinja +204 -28
- package/data/help/commands/root.jinja +10 -3
- package/data/help/commands/uri.jinja +165 -6
- package/data/help/topics/config.jinja +10 -3
- package/data/help/topics/library.jinja +90 -0
- package/data/help/topics/readiness.jinja +32 -2
- package/data/help/topics/recipe.jinja +42 -17
- package/data/help/topics/runtime.jinja +20 -3
- package/data/help/topics/uri.jinja +53 -25
- package/dist/api/app.d.ts +87 -0
- package/dist/api/app.js +137 -0
- package/dist/api/app.js.map +1 -0
- package/dist/api/chapter/advance.d.ts +36 -0
- package/dist/api/chapter/advance.js +171 -0
- package/dist/api/chapter/advance.js.map +1 -0
- package/dist/api/chapter/details.d.ts +25 -0
- package/dist/api/chapter/details.js +17 -0
- package/dist/api/chapter/details.js.map +1 -0
- package/dist/api/chapter/entries.d.ts +41 -0
- package/dist/api/chapter/entries.js +216 -0
- package/dist/api/chapter/entries.js.map +1 -0
- package/dist/api/chapter/generate.d.ts +42 -0
- package/dist/api/chapter/generate.js +61 -0
- package/dist/api/chapter/generate.js.map +1 -0
- package/dist/api/chapter/index.d.ts +43 -0
- package/dist/api/chapter/index.js +11 -0
- package/dist/api/chapter/index.js.map +1 -0
- package/dist/api/chapter/manage.d.ts +53 -0
- package/dist/api/chapter/manage.js +185 -0
- package/dist/api/chapter/manage.js.map +1 -0
- package/dist/api/chapter/options.d.ts +51 -0
- package/dist/api/chapter/options.js +11 -0
- package/dist/api/chapter/options.js.map +1 -0
- package/dist/api/chapter/parse.d.ts +13 -0
- package/dist/api/chapter/parse.js +16 -0
- package/dist/api/chapter/parse.js.map +1 -0
- package/dist/api/chapter/tree.d.ts +61 -0
- package/dist/api/chapter/tree.js +387 -0
- package/dist/api/chapter/tree.js.map +1 -0
- package/dist/api/chapter/types.d.ts +104 -0
- package/dist/api/chapter/types.js +5 -0
- package/dist/api/chapter/types.js.map +1 -0
- package/dist/api/chapter-build/index.d.ts +42 -0
- package/dist/api/chapter-build/index.js +3 -0
- package/dist/api/chapter-build/index.js.map +1 -0
- package/dist/api/chapter-build/types.d.ts +37 -0
- package/dist/api/digest.d.ts +67 -0
- package/dist/api/digest.js +171 -0
- package/dist/api/digest.js.map +1 -0
- package/dist/api/graph.d.ts +24 -0
- package/dist/api/graph.js +2 -0
- package/dist/api/graph.js.map +1 -0
- package/dist/api/import.d.ts +62 -0
- package/dist/api/import.js +269 -0
- package/dist/api/import.js.map +1 -0
- package/dist/api/index.d.ts +91 -0
- package/dist/api/index.js +189 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/knowledge-graph-build/index.d.ts +40 -0
- package/dist/api/knowledge-graph-build/index.js +2 -0
- package/dist/api/knowledge-graph-build/index.js.map +1 -0
- package/dist/api/knowledge-graph-build/types.d.ts +13 -0
- package/dist/api/llm-sampling.d.ts +11 -0
- package/dist/api/llm-sampling.js +58 -0
- package/dist/api/llm-sampling.js.map +1 -0
- package/dist/api/prompts.d.ts +1 -0
- package/dist/api/prompts.js +2 -0
- package/dist/api/prompts.js.map +1 -0
- package/dist/api/wiki-graph-archive.d.ts +42 -0
- package/dist/api/wiki-graph-archive.js +130 -0
- package/dist/api/wiki-graph-archive.js.map +1 -0
- package/dist/core-Cv8a8viI.d.ts +85 -0
- package/dist/document/chapter/index.d.ts +26 -0
- package/dist/document/chapter/index.js +23 -0
- package/dist/document/chapter/index.js.map +1 -0
- package/dist/document/chapter/path.d.ts +14 -0
- package/dist/document/chapter/path.js +133 -0
- package/dist/document/chapter/path.js.map +1 -0
- package/dist/document/chapter/query.d.ts +33 -0
- package/dist/document/chapter/query.js +83 -0
- package/dist/document/chapter/query.js.map +1 -0
- package/dist/document/chapter/stage.d.ts +28 -0
- package/dist/document/chapter/stage.js +13 -0
- package/dist/document/chapter/stage.js.map +1 -0
- package/dist/document/chapter/toc.d.ts +33 -0
- package/dist/document/chapter/toc.js +213 -0
- package/dist/document/chapter/toc.js.map +1 -0
- package/dist/document/chapter/tree.d.ts +20 -0
- package/dist/document/chapter/tree.js +48 -0
- package/dist/document/chapter/tree.js.map +1 -0
- package/dist/document/chapter/types.d.ts +31 -0
- package/dist/document/chapter/types.js +10 -0
- package/dist/document/chapter/types.js.map +1 -0
- package/dist/document/directory/context.d.ts +25 -0
- package/dist/document/directory/context.js +54 -0
- package/dist/document/directory/context.js.map +1 -0
- package/dist/document/directory/core.d.ts +25 -0
- package/dist/document/directory/core.js +382 -0
- package/dist/document/directory/core.js.map +1 -0
- package/dist/document/directory/file-store.d.ts +27 -0
- package/dist/document/directory/file-store.js +48 -0
- package/dist/document/directory/file-store.js.map +1 -0
- package/dist/document/directory/files.d.ts +53 -0
- package/dist/document/directory/files.js +71 -0
- package/dist/document/directory/files.js.map +1 -0
- package/dist/document/directory/index.d.ts +26 -0
- package/dist/document/directory/index.js +4 -0
- package/dist/document/directory/index.js.map +1 -0
- package/dist/document/directory/search-index.d.ts +32 -0
- package/dist/document/directory/search-index.js +154 -0
- package/dist/document/directory/search-index.js.map +1 -0
- package/dist/document/directory/serial-cleanup.d.ts +47 -0
- package/dist/document/directory/serial-cleanup.js +178 -0
- package/dist/document/directory/serial-cleanup.js.map +1 -0
- package/dist/document/directory/toc.d.ts +6 -0
- package/dist/document/directory/toc.js +14 -0
- package/dist/document/directory/toc.js.map +1 -0
- package/dist/document/directory/types.d.ts +105 -0
- package/dist/document/fragment-backed.d.ts +27 -0
- package/dist/document/fragment-backed.js +26 -0
- package/dist/document/fragment-backed.js.map +1 -0
- package/dist/document/fragments/core.d.ts +18 -0
- package/dist/document/fragments/core.js +68 -0
- package/dist/document/fragments/core.js.map +1 -0
- package/dist/document/fragments/draft.d.ts +16 -0
- package/dist/document/fragments/draft.js +57 -0
- package/dist/document/fragments/draft.js.map +1 -0
- package/dist/document/fragments/file-access.d.ts +7 -0
- package/dist/document/fragments/file-access.js +28 -0
- package/dist/document/fragments/file-access.js.map +1 -0
- package/dist/document/fragments/file.d.ts +7 -0
- package/dist/document/fragments/file.js +55 -0
- package/dist/document/fragments/file.js.map +1 -0
- package/dist/document/fragments/index.d.ts +5 -0
- package/dist/document/fragments/index.js +5 -0
- package/dist/document/fragments/index.js.map +1 -0
- package/dist/document/fragments/sentence.d.ts +5 -0
- package/dist/document/fragments/sentence.js +14 -0
- package/dist/document/fragments/sentence.js.map +1 -0
- package/dist/document/fragments/serial.d.ts +16 -0
- package/dist/document/fragments/serial.js +187 -0
- package/dist/document/fragments/serial.js.map +1 -0
- package/dist/document/fragments/types.d.ts +37 -0
- package/dist/document/fragments/types.js +9 -0
- package/dist/document/fragments/types.js.map +1 -0
- package/dist/document/home-schema-upgrade.d.ts +5 -0
- package/dist/document/home-schema-upgrade.js +529 -0
- package/dist/document/home-schema-upgrade.js.map +1 -0
- package/dist/document/index.d.ts +27 -8
- package/dist/document/index.js +10 -4
- package/dist/document/index.js.map +1 -1
- package/dist/document/schema.d.ts +3 -2
- package/dist/document/schema.js +24 -11
- package/dist/document/schema.js.map +1 -1
- package/dist/document/shared-state-database.js +27 -3
- package/dist/document/shared-state-database.js.map +1 -1
- package/dist/document/stores/chunk.d.ts +21 -0
- package/dist/document/stores/chunk.js +299 -0
- package/dist/document/stores/chunk.js.map +1 -0
- package/dist/document/stores/fragment-group.d.ts +16 -0
- package/dist/document/stores/fragment-group.js +77 -0
- package/dist/document/stores/fragment-group.js.map +1 -0
- package/dist/document/stores/graph-build-parameter.d.ts +17 -0
- package/dist/document/stores/graph-build-parameter.js +62 -0
- package/dist/document/stores/graph-build-parameter.js.map +1 -0
- package/dist/document/stores/helpers.d.ts +22 -0
- package/dist/document/stores/helpers.js +115 -0
- package/dist/document/stores/helpers.js.map +1 -0
- package/dist/document/stores/index.d.ts +15 -0
- package/dist/document/stores/index.js +23 -0
- package/dist/document/stores/index.js.map +1 -0
- package/dist/document/stores/mention-link.d.ts +32 -0
- package/dist/document/stores/mention-link.js +287 -0
- package/dist/document/stores/mention-link.js.map +1 -0
- package/dist/document/stores/mention.d.ts +31 -0
- package/dist/document/stores/mention.js +238 -0
- package/dist/document/stores/mention.js.map +1 -0
- package/dist/document/stores/object-metadata.d.ts +19 -0
- package/dist/document/stores/object-metadata.js +148 -0
- package/dist/document/stores/object-metadata.js.map +1 -0
- package/dist/document/stores/reading-edge.d.ts +17 -0
- package/dist/document/stores/reading-edge.js +80 -0
- package/dist/document/stores/reading-edge.js.map +1 -0
- package/dist/document/stores/serial.d.ts +29 -0
- package/dist/document/stores/serial.js +296 -0
- package/dist/document/stores/serial.js.map +1 -0
- package/dist/document/stores/snake/chunk.d.ts +14 -0
- package/dist/document/stores/snake/chunk.js +48 -0
- package/dist/document/stores/snake/chunk.js.map +1 -0
- package/dist/document/stores/snake/core.d.ts +15 -0
- package/dist/document/stores/snake/core.js +112 -0
- package/dist/document/stores/snake/core.js.map +1 -0
- package/dist/document/stores/snake/edge.d.ts +16 -0
- package/dist/document/stores/snake/edge.js +86 -0
- package/dist/document/stores/snake/edge.js.map +1 -0
- package/dist/document/stores/snake/index.d.ts +7 -0
- package/dist/document/stores/snake/index.js +4 -0
- package/dist/document/stores/snake/index.js.map +1 -0
- package/dist/document/stores/types.d.ts +95 -0
- package/dist/document/text-streams/core.d.ts +17 -0
- package/dist/document/text-streams/core.js +45 -0
- package/dist/document/text-streams/core.js.map +1 -0
- package/dist/document/text-streams/draft.d.ts +20 -0
- package/dist/document/text-streams/draft.js +70 -0
- package/dist/document/text-streams/draft.js.map +1 -0
- package/dist/document/text-streams/file-access.d.ts +6 -0
- package/dist/document/text-streams/file-access.js +31 -0
- package/dist/document/text-streams/file-access.js.map +1 -0
- package/dist/document/text-streams/index.d.ts +7 -0
- package/dist/document/text-streams/index.js +5 -0
- package/dist/document/text-streams/index.js.map +1 -0
- package/dist/document/text-streams/sentence.d.ts +13 -0
- package/dist/document/text-streams/sentence.js +77 -0
- package/dist/document/text-streams/sentence.js.map +1 -0
- package/dist/document/text-streams/serial.d.ts +24 -0
- package/dist/document/text-streams/serial.js +324 -0
- package/dist/document/text-streams/serial.js.map +1 -0
- package/dist/document/text-streams/types.d.ts +55 -0
- package/dist/document/text-streams/types.js +10 -0
- package/dist/document/text-streams/types.js.map +1 -0
- package/dist/external/guaranteed/classifier.js.map +1 -0
- package/dist/external/guaranteed/errors.js.map +1 -0
- package/dist/external/guaranteed/index.js.map +1 -0
- package/dist/external/guaranteed/request.js.map +1 -0
- package/dist/external/guaranteed/response.js.map +1 -0
- package/dist/external/llm/cache.js +35 -0
- package/dist/external/llm/cache.js.map +1 -0
- package/dist/external/llm/client/core.d.ts +26 -0
- package/dist/external/llm/client/core.js +321 -0
- package/dist/external/llm/client/core.js.map +1 -0
- package/dist/external/llm/client/files.d.ts +6 -0
- package/dist/external/llm/client/files.js +29 -0
- package/dist/external/llm/client/files.js.map +1 -0
- package/dist/external/llm/client/generation.d.ts +16 -0
- package/dist/external/llm/client/generation.js +35 -0
- package/dist/external/llm/client/generation.js.map +1 -0
- package/dist/external/llm/client/index.d.ts +5 -0
- package/dist/external/llm/client/index.js +5 -0
- package/dist/external/llm/client/index.js.map +1 -0
- package/dist/external/llm/client/log.d.ts +22 -0
- package/dist/external/llm/client/log.js +106 -0
- package/dist/external/llm/client/log.js.map +1 -0
- package/dist/external/llm/client/model.d.ts +10 -0
- package/dist/external/llm/client/model.js +26 -0
- package/dist/external/llm/client/model.js.map +1 -0
- package/dist/external/llm/client/retry.d.ts +4 -0
- package/dist/external/llm/client/retry.js +91 -0
- package/dist/external/llm/client/retry.js.map +1 -0
- package/dist/external/llm/context.js +78 -0
- package/dist/external/llm/context.js.map +1 -0
- package/dist/external/llm/errors.js.map +1 -0
- package/dist/external/llm/index.d.ts +7 -0
- package/dist/external/llm/index.js +17 -0
- package/dist/external/llm/index.js.map +1 -0
- package/dist/external/llm/request-log.js +35 -0
- package/dist/external/llm/request-log.js.map +1 -0
- package/dist/external/llm/sampling.js.map +1 -0
- package/dist/external/wikimatch/enrichment.d.ts +15 -0
- package/dist/external/wikimatch/enrichment.js +61 -0
- package/dist/external/wikimatch/enrichment.js.map +1 -0
- package/dist/external/wikimatch/index.d.ts +19 -0
- package/dist/external/wikimatch/index.js +66 -0
- package/dist/external/wikimatch/index.js.map +1 -0
- package/dist/external/wikimatch/option-narrowing.d.ts +19 -0
- package/dist/external/wikimatch/option-narrowing.js.map +1 -0
- package/dist/external/wikimatch/options.d.ts +16 -0
- package/dist/external/wikimatch/options.js +154 -0
- package/dist/external/wikimatch/options.js.map +1 -0
- package/dist/external/wikimatch/policy-judge.d.ts +19 -0
- package/dist/external/wikimatch/policy-judge.js +431 -0
- package/dist/external/wikimatch/policy-judge.js.map +1 -0
- package/dist/external/wikimatch/range-suppression.js.map +1 -0
- package/dist/external/wikimatch/surface/index.d.ts +10 -0
- package/dist/external/wikimatch/surface/index.js +3 -0
- package/dist/external/wikimatch/surface/index.js.map +1 -0
- package/dist/external/wikimatch/surface/screening.d.ts +18 -0
- package/dist/external/wikimatch/surface/screening.js +168 -0
- package/dist/external/wikimatch/surface/screening.js.map +1 -0
- package/dist/external/wikimatch/surface/window.d.ts +8 -0
- package/dist/external/wikimatch/surface/window.js +44 -0
- package/dist/external/wikimatch/surface/window.js.map +1 -0
- package/dist/external/wikimatch/types.d.ts +153 -0
- package/dist/external/wikimatch/wikispine.d.ts +45 -0
- package/dist/external/wikimatch/wikispine.js.map +1 -0
- package/dist/external/wikimatch/window.d.ts +8 -0
- package/dist/external/wikimatch/window.js.map +1 -0
- package/dist/external/wikimatch/words.js.map +1 -0
- package/dist/external/wikipage/cache.d.ts +20 -0
- package/dist/external/wikipage/cache.js +442 -0
- package/dist/external/wikipage/cache.js.map +1 -0
- package/dist/external/wikipage/fetch-log.js +146 -0
- package/dist/external/wikipage/fetch-log.js.map +1 -0
- package/dist/external/wikipage/index.d.ts +15 -0
- package/dist/external/wikipage/index.js +17 -0
- package/dist/external/wikipage/index.js.map +1 -0
- package/dist/external/wikipage/normalizer.d.ts +16 -0
- package/dist/external/wikipage/normalizer.js +188 -0
- package/dist/external/wikipage/normalizer.js.map +1 -0
- package/dist/external/wikipage/rate-limiter.js.map +1 -0
- package/dist/external/wikipage/resolver.d.ts +22 -0
- package/dist/external/wikipage/resolver.js +359 -0
- package/dist/external/wikipage/resolver.js.map +1 -0
- package/dist/external/wikipage/types.d.ts +118 -0
- package/dist/external/wikipage/wikimedia-client/core.d.ts +13 -0
- package/dist/external/wikipage/wikimedia-client/core.js +207 -0
- package/dist/external/wikipage/wikimedia-client/core.js.map +1 -0
- package/dist/external/wikipage/wikimedia-client/html.d.ts +7 -0
- package/dist/external/wikipage/wikimedia-client/html.js +136 -0
- package/dist/external/wikipage/wikimedia-client/html.js.map +1 -0
- package/dist/external/wikipage/wikimedia-client/index.d.ts +5 -0
- package/dist/external/wikipage/wikimedia-client/index.js +4 -0
- package/dist/external/wikipage/wikimedia-client/index.js.map +1 -0
- package/dist/external/wikipage/wikimedia-client/json.d.ts +7 -0
- package/dist/external/wikipage/wikimedia-client/json.js +27 -0
- package/dist/external/wikipage/wikimedia-client/json.js.map +1 -0
- package/dist/external/wikipage/wikimedia-client/request.d.ts +12 -0
- package/dist/external/wikipage/wikimedia-client/request.js +51 -0
- package/dist/external/wikipage/wikimedia-client/request.js.map +1 -0
- package/dist/external/wikipage/wikimedia-client/wiki.d.ts +54 -0
- package/dist/external/wikipage/wikimedia-client/wiki.js +28 -0
- package/dist/external/wikipage/wikimedia-client/wiki.js.map +1 -0
- package/dist/gc.cjs +8188 -8373
- package/dist/gc.cjs.map +1 -1
- package/dist/gc.d.cts +23 -3
- package/dist/gc.d.ts +2 -2
- package/dist/gc.js +1 -1
- package/dist/gc.js.map +1 -1
- package/dist/graph/evidence-selection/anchor/index.d.ts +4 -0
- package/dist/graph/evidence-selection/anchor/index.js +3 -0
- package/dist/graph/evidence-selection/anchor/index.js.map +1 -0
- package/dist/graph/evidence-selection/anchor/resolver/index.d.ts +38 -0
- package/dist/graph/evidence-selection/anchor/resolver/index.js +418 -0
- package/dist/graph/evidence-selection/anchor/resolver/index.js.map +1 -0
- package/dist/graph/evidence-selection/anchor/resolver/matcher.d.ts +8 -0
- package/dist/graph/evidence-selection/anchor/resolver/matcher.js +178 -0
- package/dist/graph/evidence-selection/anchor/resolver/matcher.js.map +1 -0
- package/dist/graph/evidence-selection/anchor/resolver/parser.d.ts +7 -0
- package/dist/graph/evidence-selection/anchor/resolver/parser.js +91 -0
- package/dist/graph/evidence-selection/anchor/resolver/parser.js.map +1 -0
- package/dist/graph/evidence-selection/anchor/resolver/scoring.d.ts +20 -0
- package/dist/graph/evidence-selection/anchor/resolver/scoring.js +119 -0
- package/dist/graph/evidence-selection/anchor/resolver/scoring.js.map +1 -0
- package/dist/graph/evidence-selection/anchor/resolver/types.d.ts +15 -0
- package/dist/graph/evidence-selection/anchor/resolver/types.js +17 -0
- package/dist/graph/evidence-selection/anchor/resolver/types.js.map +1 -0
- package/dist/graph/evidence-selection/anchor/types.d.ts +27 -0
- package/dist/graph/evidence-selection/index.d.ts +9 -0
- package/dist/graph/evidence-selection/index.js +32 -0
- package/dist/graph/evidence-selection/index.js.map +1 -0
- package/dist/graph/evidence-selection/prompt.js.map +1 -0
- package/dist/graph/evidence-selection/quote-score.js.map +1 -0
- package/dist/graph/evidence-selection/resolver.js +303 -0
- package/dist/graph/evidence-selection/resolver.js.map +1 -0
- package/dist/graph/evidence-selection/text.js.map +1 -0
- package/dist/graph/knowledge-build/artifact-io.d.ts +12 -0
- package/dist/graph/knowledge-build/artifact-io.js +151 -0
- package/dist/graph/knowledge-build/artifact-io.js.map +1 -0
- package/dist/graph/knowledge-build/artifact.d.ts +17 -0
- package/dist/graph/knowledge-build/artifact.js +66 -0
- package/dist/graph/knowledge-build/artifact.js.map +1 -0
- package/dist/graph/knowledge-build/candidates.d.ts +24 -0
- package/dist/graph/knowledge-build/candidates.js +60 -0
- package/dist/graph/knowledge-build/candidates.js.map +1 -0
- package/dist/graph/knowledge-build/commit.d.ts +39 -0
- package/dist/graph/knowledge-build/commit.js +52 -0
- package/dist/graph/knowledge-build/commit.js.map +1 -0
- package/dist/graph/knowledge-build/constants.d.ts +6 -0
- package/dist/graph/knowledge-build/constants.js +11 -0
- package/dist/graph/knowledge-build/constants.js.map +1 -0
- package/dist/graph/knowledge-build/fragments.d.ts +33 -0
- package/dist/graph/knowledge-build/fragments.js +36 -0
- package/dist/graph/knowledge-build/fragments.js.map +1 -0
- package/dist/graph/knowledge-build/generate.d.ts +39 -0
- package/dist/graph/knowledge-build/generate.js +128 -0
- package/dist/graph/knowledge-build/generate.js.map +1 -0
- package/dist/graph/knowledge-build/grounding-runner.d.ts +23 -0
- package/dist/graph/knowledge-build/grounding-runner.js +90 -0
- package/dist/graph/knowledge-build/grounding-runner.js.map +1 -0
- package/dist/graph/knowledge-build/grounding.d.ts +19 -0
- package/dist/graph/knowledge-build/grounding.js +158 -0
- package/dist/graph/knowledge-build/grounding.js.map +1 -0
- package/dist/graph/knowledge-build/index.d.ts +40 -0
- package/dist/graph/knowledge-build/index.js +8 -0
- package/dist/graph/knowledge-build/index.js.map +1 -0
- package/dist/graph/knowledge-build/mentions.d.ts +25 -0
- package/dist/graph/knowledge-build/mentions.js +66 -0
- package/dist/graph/knowledge-build/mentions.js.map +1 -0
- package/dist/graph/knowledge-build/parameter.d.ts +19 -0
- package/dist/graph/knowledge-build/parameter.js +14 -0
- package/dist/graph/knowledge-build/parameter.js.map +1 -0
- package/dist/graph/knowledge-build/progress.d.ts +8 -0
- package/dist/graph/knowledge-build/progress.js +45 -0
- package/dist/graph/knowledge-build/progress.js.map +1 -0
- package/dist/graph/knowledge-build/relations.d.ts +22 -0
- package/dist/graph/knowledge-build/relations.js +118 -0
- package/dist/graph/knowledge-build/relations.js.map +1 -0
- package/dist/graph/knowledge-build/request.d.ts +8 -0
- package/dist/graph/knowledge-build/request.js +19 -0
- package/dist/graph/knowledge-build/request.js.map +1 -0
- package/dist/graph/knowledge-build/snapshot.d.ts +38 -0
- package/dist/graph/knowledge-build/snapshot.js +18 -0
- package/dist/graph/knowledge-build/snapshot.js.map +1 -0
- package/dist/graph/knowledge-build/types.d.ts +46 -0
- package/dist/graph/reading-build/artifact.d.ts +42 -0
- package/dist/graph/reading-build/artifact.js +162 -0
- package/dist/graph/reading-build/artifact.js.map +1 -0
- package/dist/graph/reading-build/copy.d.ts +28 -0
- package/dist/graph/reading-build/copy.js +65 -0
- package/dist/graph/reading-build/copy.js.map +1 -0
- package/dist/graph/reading-build/index.d.ts +39 -0
- package/dist/graph/reading-build/index.js +4 -0
- package/dist/graph/reading-build/index.js.map +1 -0
- package/dist/graph/reading-build/input.d.ts +32 -0
- package/dist/graph/reading-build/input.js +19 -0
- package/dist/graph/reading-build/input.js.map +1 -0
- package/dist/graph/reading-build/options.d.ts +47 -0
- package/dist/graph/reading-build/options.js +20 -0
- package/dist/graph/reading-build/options.js.map +1 -0
- package/dist/graph/reading-build/source-fragments.d.ts +15 -0
- package/dist/graph/reading-build/source-fragments.js +36 -0
- package/dist/graph/reading-build/source-fragments.js.map +1 -0
- package/dist/graph/reading-build/types.d.ts +57 -0
- package/dist/graph/reading.d.ts +73 -0
- package/dist/graph/reading.js +203 -0
- package/dist/graph/reading.js.map +1 -0
- package/dist/graph/topology/core.d.ts +42 -0
- package/dist/graph/topology/core.js +348 -0
- package/dist/graph/topology/core.js.map +1 -0
- package/dist/graph/topology/grouping.d.ts +13 -0
- package/dist/graph/topology/grouping.js.map +1 -0
- package/dist/graph/topology/index.d.ts +34 -0
- package/dist/graph/topology/index.js +5 -0
- package/dist/graph/topology/index.js.map +1 -0
- package/dist/graph/topology/resource-segmentation.d.ts +11 -0
- package/dist/graph/topology/resource-segmentation.js.map +1 -0
- package/dist/graph/topology/segment-incision.d.ts +16 -0
- package/dist/graph/topology/segment-incision.js.map +1 -0
- package/dist/graph/topology/snake/compare.d.ts +8 -0
- package/dist/graph/topology/snake/compare.js +29 -0
- package/dist/graph/topology/snake/compare.js.map +1 -0
- package/dist/graph/topology/snake/components.d.ts +12 -0
- package/dist/graph/topology/snake/components.js +80 -0
- package/dist/graph/topology/snake/components.js.map +1 -0
- package/dist/graph/topology/snake/constants.d.ts +7 -0
- package/dist/graph/topology/snake/constants.js +13 -0
- package/dist/graph/topology/snake/constants.js.map +1 -0
- package/dist/graph/topology/snake/detect.d.ts +9 -0
- package/dist/graph/topology/snake/detect.js +63 -0
- package/dist/graph/topology/snake/detect.js.map +1 -0
- package/dist/graph/topology/snake/detector.d.ts +3 -0
- package/dist/graph/topology/snake/detector.js +7 -0
- package/dist/graph/topology/snake/detector.js.map +1 -0
- package/dist/graph/topology/snake/fingerprints.d.ts +7 -0
- package/dist/graph/topology/snake/fingerprints.js +86 -0
- package/dist/graph/topology/snake/fingerprints.js.map +1 -0
- package/dist/graph/topology/snake/graph-builder.d.ts +14 -0
- package/dist/graph/topology/snake/graph-builder.js +76 -0
- package/dist/graph/topology/snake/graph-builder.js.map +1 -0
- package/dist/graph/topology/snake/graph.d.ts +7 -0
- package/dist/graph/topology/snake/graph.js +105 -0
- package/dist/graph/topology/snake/graph.js.map +1 -0
- package/dist/graph/topology/snake/index.d.ts +4 -0
- package/dist/graph/topology/snake/index.js +3 -0
- package/dist/graph/topology/snake/index.js.map +1 -0
- package/dist/graph/topology/snake/merge.d.ts +6 -0
- package/dist/graph/topology/snake/merge.js +174 -0
- package/dist/graph/topology/snake/merge.js.map +1 -0
- package/dist/graph/topology/snake/records.d.ts +12 -0
- package/dist/graph/topology/snake/records.js +35 -0
- package/dist/graph/topology/snake/records.js.map +1 -0
- package/dist/graph/topology/snake/types.d.ts +23 -0
- package/dist/graph/topology/snake/types.js +1 -0
- package/dist/graph/topology/snake/weights.d.ts +3 -0
- package/dist/graph/topology/snake/weights.js +17 -0
- package/dist/graph/topology/snake/weights.js.map +1 -0
- package/dist/graph/topology/weights.d.ts +10 -0
- package/dist/graph/topology/weights.js +84 -0
- package/dist/graph/topology/weights.js.map +1 -0
- package/dist/graph/wikilink/index.d.ts +12 -0
- package/dist/graph/wikilink/index.js.map +1 -0
- package/dist/graph/wikilink/relation-discovery.d.ts +33 -0
- package/dist/graph/wikilink/relation-discovery.js +477 -0
- package/dist/graph/wikilink/relation-discovery.js.map +1 -0
- package/dist/graph/wikilink/types.d.ts +25 -0
- package/dist/graph/wikilink/types.js +1 -0
- package/dist/graph/wikilink/window.d.ts +9 -0
- package/dist/graph/wikilink/window.js.map +1 -0
- package/dist/index.cjs +37928 -29156
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1649 -1406
- package/dist/index.d.ts +127 -72
- package/dist/index.js +337 -27
- package/dist/index.js.map +1 -1
- package/dist/library/index.d.ts +38 -0
- package/dist/library/index.js +6 -0
- package/dist/library/index.js.map +1 -0
- package/dist/library/lock.d.ts +9 -0
- package/dist/library/lock.js +121 -0
- package/dist/library/lock.js.map +1 -0
- package/dist/library/membership.d.ts +51 -0
- package/dist/library/membership.js +812 -0
- package/dist/library/membership.js.map +1 -0
- package/dist/library/query-helpers.d.ts +45 -0
- package/dist/library/query-helpers.js +45 -0
- package/dist/library/query-helpers.js.map +1 -0
- package/dist/library/query.d.ts +47 -0
- package/dist/library/query.js +466 -0
- package/dist/library/query.js.map +1 -0
- package/dist/library/registry.d.ts +40 -0
- package/dist/library/registry.js +601 -0
- package/dist/library/registry.js.map +1 -0
- package/dist/library/search-index.d.ts +87 -0
- package/dist/library/search-index.js +473 -0
- package/dist/library/search-index.js.map +1 -0
- package/dist/library/search-query.d.ts +32 -0
- package/dist/library/search-query.js +418 -0
- package/dist/library/search-query.js.map +1 -0
- package/dist/library/segments.d.ts +3 -0
- package/dist/library/segments.js +16 -0
- package/dist/library/segments.js.map +1 -0
- package/dist/maintenance/upgrade.d.ts +54 -0
- package/dist/maintenance/upgrade.js +195 -0
- package/dist/maintenance/upgrade.js.map +1 -0
- package/dist/object-stream.d.ts +170 -0
- package/dist/object-stream.js +732 -0
- package/dist/object-stream.js.map +1 -0
- package/dist/retrieval/query/archive-view/backlinks.d.ts +38 -0
- package/dist/retrieval/query/archive-view/backlinks.js +200 -0
- package/dist/retrieval/query/archive-view/backlinks.js.map +1 -0
- package/dist/retrieval/query/archive-view/collection.d.ts +33 -0
- package/dist/retrieval/query/archive-view/collection.js +327 -0
- package/dist/retrieval/query/archive-view/collection.js.map +1 -0
- package/dist/retrieval/query/archive-view/core.d.ts +44 -0
- package/dist/retrieval/query/archive-view/core.js +165 -0
- package/dist/retrieval/query/archive-view/core.js.map +1 -0
- package/dist/retrieval/query/archive-view/evidence-hydration.d.ts +41 -0
- package/dist/retrieval/query/archive-view/evidence-hydration.js +311 -0
- package/dist/retrieval/query/archive-view/evidence-hydration.js.map +1 -0
- package/dist/retrieval/query/archive-view/evidence.d.ts +31 -0
- package/dist/retrieval/query/archive-view/evidence.js +166 -0
- package/dist/retrieval/query/archive-view/evidence.js.map +1 -0
- package/dist/retrieval/query/archive-view/find.d.ts +41 -0
- package/dist/retrieval/query/archive-view/find.js +289 -0
- package/dist/retrieval/query/archive-view/find.js.map +1 -0
- package/dist/retrieval/query/archive-view/helper/constants.d.ts +15 -0
- package/dist/retrieval/query/archive-view/helper/constants.js +20 -0
- package/dist/retrieval/query/archive-view/helper/constants.js.map +1 -0
- package/dist/retrieval/query/archive-view/helper/index.d.ts +34 -0
- package/dist/retrieval/query/archive-view/helper/index.js +9 -0
- package/dist/retrieval/query/archive-view/helper/index.js.map +1 -0
- package/dist/retrieval/query/archive-view/helper/meta.d.ts +17 -0
- package/dist/retrieval/query/archive-view/helper/meta.js +57 -0
- package/dist/retrieval/query/archive-view/helper/meta.js.map +1 -0
- package/dist/retrieval/query/archive-view/helper/parse.d.ts +38 -0
- package/dist/retrieval/query/archive-view/helper/parse.js +71 -0
- package/dist/retrieval/query/archive-view/helper/parse.js.map +1 -0
- package/dist/retrieval/query/archive-view/helper/position.d.ts +39 -0
- package/dist/retrieval/query/archive-view/helper/position.js +75 -0
- package/dist/retrieval/query/archive-view/helper/position.js.map +1 -0
- package/dist/retrieval/query/archive-view/helper/results.d.ts +45 -0
- package/dist/retrieval/query/archive-view/helper/results.js +153 -0
- package/dist/retrieval/query/archive-view/helper/results.js.map +1 -0
- package/dist/retrieval/query/archive-view/helper/sort.d.ts +35 -0
- package/dist/retrieval/query/archive-view/helper/sort.js +88 -0
- package/dist/retrieval/query/archive-view/helper/sort.js.map +1 -0
- package/dist/retrieval/query/archive-view/helper/text.d.ts +46 -0
- package/dist/retrieval/query/archive-view/helper/text.js +91 -0
- package/dist/retrieval/query/archive-view/helper/text.js.map +1 -0
- package/dist/retrieval/query/archive-view/helper/uri.d.ts +4 -0
- package/dist/retrieval/query/archive-view/helper/uri.js +12 -0
- package/dist/retrieval/query/archive-view/helper/uri.js.map +1 -0
- package/dist/retrieval/query/archive-view/helpers.d.ts +34 -0
- package/dist/retrieval/query/archive-view/helpers.js +2 -0
- package/dist/retrieval/query/archive-view/helpers.js.map +1 -0
- package/dist/retrieval/query/archive-view/index-state.d.ts +35 -0
- package/dist/retrieval/query/archive-view/index-state.js +191 -0
- package/dist/retrieval/query/archive-view/index-state.js.map +1 -0
- package/dist/retrieval/query/archive-view/index.d.ts +41 -0
- package/dist/retrieval/query/archive-view/index.js +51 -0
- package/dist/retrieval/query/archive-view/index.js.map +1 -0
- package/dist/retrieval/query/archive-view/knowledge.d.ts +45 -0
- package/dist/retrieval/query/archive-view/knowledge.js +99 -0
- package/dist/retrieval/query/archive-view/knowledge.js.map +1 -0
- package/dist/retrieval/query/archive-view/pack.d.ts +30 -0
- package/dist/retrieval/query/archive-view/pack.js +49 -0
- package/dist/retrieval/query/archive-view/pack.js.map +1 -0
- package/dist/retrieval/query/archive-view/pages.d.ts +41 -0
- package/dist/retrieval/query/archive-view/pages.js +341 -0
- package/dist/retrieval/query/archive-view/pages.js.map +1 -0
- package/dist/retrieval/query/archive-view/references.d.ts +88 -0
- package/dist/retrieval/query/archive-view/references.js +287 -0
- package/dist/retrieval/query/archive-view/references.js.map +1 -0
- package/dist/retrieval/query/archive-view/related/core.d.ts +37 -0
- package/dist/retrieval/query/archive-view/related/core.js +163 -0
- package/dist/retrieval/query/archive-view/related/core.js.map +1 -0
- package/dist/retrieval/query/archive-view/related/entity.d.ts +33 -0
- package/dist/retrieval/query/archive-view/related/entity.js +93 -0
- package/dist/retrieval/query/archive-view/related/entity.js.map +1 -0
- package/dist/retrieval/query/archive-view/related/index.d.ts +37 -0
- package/dist/retrieval/query/archive-view/related/index.js +7 -0
- package/dist/retrieval/query/archive-view/related/index.js.map +1 -0
- package/dist/retrieval/query/archive-view/related/pagination.d.ts +31 -0
- package/dist/retrieval/query/archive-view/related/pagination.js +90 -0
- package/dist/retrieval/query/archive-view/related/pagination.js.map +1 -0
- package/dist/retrieval/query/archive-view/related/query.d.ts +31 -0
- package/dist/retrieval/query/archive-view/related/query.js +145 -0
- package/dist/retrieval/query/archive-view/related/query.js.map +1 -0
- package/dist/retrieval/query/archive-view/related/sort.d.ts +32 -0
- package/dist/retrieval/query/archive-view/related/sort.js +85 -0
- package/dist/retrieval/query/archive-view/related/sort.js.map +1 -0
- package/dist/retrieval/query/archive-view/related/wikipage.d.ts +37 -0
- package/dist/retrieval/query/archive-view/related/wikipage.js +43 -0
- package/dist/retrieval/query/archive-view/related/wikipage.js.map +1 -0
- package/dist/retrieval/query/archive-view/search/bucket-hydration.d.ts +31 -0
- package/dist/retrieval/query/archive-view/search/bucket-hydration.js +58 -0
- package/dist/retrieval/query/archive-view/search/bucket-hydration.js.map +1 -0
- package/dist/retrieval/query/archive-view/search/bucket-order.d.ts +36 -0
- package/dist/retrieval/query/archive-view/search/bucket-order.js +64 -0
- package/dist/retrieval/query/archive-view/search/bucket-order.js.map +1 -0
- package/dist/retrieval/query/archive-view/search/bucket.d.ts +30 -0
- package/dist/retrieval/query/archive-view/search/bucket.js +3 -0
- package/dist/retrieval/query/archive-view/search/bucket.js.map +1 -0
- package/dist/retrieval/query/archive-view/search/buckets.d.ts +42 -0
- package/dist/retrieval/query/archive-view/search/buckets.js +302 -0
- package/dist/retrieval/query/archive-view/search/buckets.js.map +1 -0
- package/dist/retrieval/query/archive-view/search/cache-input.d.ts +45 -0
- package/dist/retrieval/query/archive-view/search/cache-input.js +255 -0
- package/dist/retrieval/query/archive-view/search/cache-input.js.map +1 -0
- package/dist/retrieval/query/archive-view/search/core.d.ts +31 -0
- package/dist/retrieval/query/archive-view/search/core.js +388 -0
- package/dist/retrieval/query/archive-view/search/core.js.map +1 -0
- package/dist/retrieval/query/archive-view/search/hydration.d.ts +51 -0
- package/dist/retrieval/query/archive-view/search/hydration.js +234 -0
- package/dist/retrieval/query/archive-view/search/hydration.js.map +1 -0
- package/dist/retrieval/query/archive-view/search/index.d.ts +35 -0
- package/dist/retrieval/query/archive-view/search/index.js +7 -0
- package/dist/retrieval/query/archive-view/search/index.js.map +1 -0
- package/dist/retrieval/query/archive-view/source-evidence/core.d.ts +60 -0
- package/dist/retrieval/query/archive-view/source-evidence/core.js +330 -0
- package/dist/retrieval/query/archive-view/source-evidence/core.js.map +1 -0
- package/dist/retrieval/query/archive-view/source-evidence/index.d.ts +30 -0
- package/dist/retrieval/query/archive-view/source-evidence/index.js +5 -0
- package/dist/retrieval/query/archive-view/source-evidence/index.js.map +1 -0
- package/dist/retrieval/query/archive-view/source-evidence/pagination.d.ts +46 -0
- package/dist/retrieval/query/archive-view/source-evidence/pagination.js +82 -0
- package/dist/retrieval/query/archive-view/source-evidence/pagination.js.map +1 -0
- package/dist/retrieval/query/archive-view/source-evidence/ranges.d.ts +47 -0
- package/dist/retrieval/query/archive-view/source-evidence/ranges.js +209 -0
- package/dist/retrieval/query/archive-view/source-evidence/ranges.js.map +1 -0
- package/dist/retrieval/query/archive-view/source-evidence/read.d.ts +31 -0
- package/dist/retrieval/query/archive-view/source-evidence/read.js +49 -0
- package/dist/retrieval/query/archive-view/source-evidence/read.js.map +1 -0
- package/dist/retrieval/query/archive-view/source.d.ts +30 -0
- package/dist/retrieval/query/archive-view/source.js +2 -0
- package/dist/retrieval/query/archive-view/source.js.map +1 -0
- package/dist/retrieval/query/archive-view/text-streams.d.ts +44 -0
- package/dist/retrieval/query/archive-view/text-streams.js +160 -0
- package/dist/retrieval/query/archive-view/text-streams.js.map +1 -0
- package/dist/retrieval/query/archive-view/types.d.ts +363 -0
- package/dist/retrieval/query/archive-view/types.js +1 -0
- package/dist/retrieval/query/continuation-cursor/core.d.ts +6 -0
- package/dist/retrieval/query/continuation-cursor/core.js +82 -0
- package/dist/retrieval/query/continuation-cursor/core.js.map +1 -0
- package/dist/retrieval/query/continuation-cursor/index.d.ts +2 -0
- package/dist/retrieval/query/continuation-cursor/index.js +3 -0
- package/dist/retrieval/query/continuation-cursor/index.js.map +1 -0
- package/dist/retrieval/query/continuation-cursor/payload.d.ts +12 -0
- package/dist/retrieval/query/continuation-cursor/payload.js +285 -0
- package/dist/retrieval/query/continuation-cursor/payload.js.map +1 -0
- package/dist/retrieval/query/continuation-cursor/store.d.ts +10 -0
- package/dist/retrieval/query/continuation-cursor/store.js +65 -0
- package/dist/retrieval/query/continuation-cursor/store.js.map +1 -0
- package/dist/retrieval/query/continuation-cursor/types.d.ts +72 -0
- package/dist/retrieval/query/continuation-cursor/types.js +1 -0
- package/dist/retrieval/query/continuation-cursor/types.js.map +1 -0
- package/dist/retrieval/query/index.d.ts +47 -0
- package/dist/retrieval/query/index.js +63 -0
- package/dist/retrieval/query/index.js.map +1 -0
- package/dist/retrieval/query/lexical-search.js.map +1 -0
- package/dist/retrieval/query/search-cache/buckets.d.ts +32 -0
- package/dist/retrieval/query/search-cache/buckets.js +87 -0
- package/dist/retrieval/query/search-cache/buckets.js.map +1 -0
- package/dist/retrieval/query/search-cache/cursor.d.ts +42 -0
- package/dist/retrieval/query/search-cache/cursor.js +84 -0
- package/dist/retrieval/query/search-cache/cursor.js.map +1 -0
- package/dist/retrieval/query/search-cache/database.d.ts +7 -0
- package/dist/retrieval/query/search-cache/database.js +47 -0
- package/dist/retrieval/query/search-cache/database.js.map +1 -0
- package/dist/retrieval/query/search-cache/gc.d.ts +6 -0
- package/dist/retrieval/query/search-cache/gc.js +110 -0
- package/dist/retrieval/query/search-cache/gc.js.map +1 -0
- package/dist/retrieval/query/search-cache/hits.d.ts +42 -0
- package/dist/retrieval/query/search-cache/hits.js +446 -0
- package/dist/retrieval/query/search-cache/hits.js.map +1 -0
- package/dist/retrieval/query/search-cache/ids.d.ts +32 -0
- package/dist/retrieval/query/search-cache/ids.js +48 -0
- package/dist/retrieval/query/search-cache/ids.js.map +1 -0
- package/dist/retrieval/query/search-cache/index.d.ts +33 -0
- package/dist/retrieval/query/search-cache/index.js +46 -0
- package/dist/retrieval/query/search-cache/index.js.map +1 -0
- package/dist/retrieval/query/search-cache/parsing.d.ts +36 -0
- package/dist/retrieval/query/search-cache/parsing.js +38 -0
- package/dist/retrieval/query/search-cache/parsing.js.map +1 -0
- package/dist/retrieval/query/search-cache/schema.d.ts +7 -0
- package/dist/retrieval/query/search-cache/schema.js +117 -0
- package/dist/retrieval/query/search-cache/schema.js.map +1 -0
- package/dist/retrieval/query/search-cache/scores.d.ts +4 -0
- package/dist/retrieval/query/search-cache/scores.js +12 -0
- package/dist/retrieval/query/search-cache/scores.js.map +1 -0
- package/dist/retrieval/query/search-cache/sessions.d.ts +45 -0
- package/dist/retrieval/query/search-cache/sessions.js +330 -0
- package/dist/retrieval/query/search-cache/sessions.js.map +1 -0
- package/dist/retrieval/query/search-cache/store.d.ts +23 -0
- package/dist/retrieval/query/search-cache/store.js +111 -0
- package/dist/retrieval/query/search-cache/store.js.map +1 -0
- package/dist/retrieval/query/search-cache/types.d.ts +164 -0
- package/dist/retrieval/query/search-cache/types.js +9 -0
- package/dist/retrieval/query/search-cache/types.js.map +1 -0
- package/dist/retrieval/query/view.d.ts +41 -0
- package/dist/retrieval/query/view.js +2 -0
- package/dist/retrieval/query/view.js.map +1 -0
- package/dist/retrieval/search-index/index.d.ts +33 -0
- package/dist/retrieval/search-index/index.js +41 -0
- package/dist/retrieval/search-index/index.js.map +1 -0
- package/dist/retrieval/search-index/search/build.d.ts +39 -0
- package/dist/retrieval/search-index/search/build.js +212 -0
- package/dist/retrieval/search-index/search/build.js.map +1 -0
- package/dist/retrieval/search-index/search/core.d.ts +33 -0
- package/dist/retrieval/search-index/search/core.js +8 -0
- package/dist/retrieval/search-index/search/core.js.map +1 -0
- package/dist/retrieval/search-index/search/dirty.d.ts +30 -0
- package/dist/retrieval/search-index/search/dirty.js +28 -0
- package/dist/retrieval/search-index/search/dirty.js.map +1 -0
- package/dist/retrieval/search-index/search/errors.d.ts +3 -0
- package/dist/retrieval/search-index/search/errors.js +8 -0
- package/dist/retrieval/search-index/search/errors.js.map +1 -0
- package/dist/retrieval/search-index/search/fingerprint.d.ts +8 -0
- package/dist/retrieval/search-index/search/fingerprint.js +51 -0
- package/dist/retrieval/search-index/search/fingerprint.js.map +1 -0
- package/dist/retrieval/search-index/search/helpers.d.ts +44 -0
- package/dist/retrieval/search-index/search/helpers.js +109 -0
- package/dist/retrieval/search-index/search/helpers.js.map +1 -0
- package/dist/retrieval/search-index/search/index.d.ts +34 -0
- package/dist/retrieval/search-index/search/index.js +3 -0
- package/dist/retrieval/search-index/search/index.js.map +1 -0
- package/dist/retrieval/search-index/search/match.d.ts +34 -0
- package/dist/retrieval/search-index/search/match.js +82 -0
- package/dist/retrieval/search-index/search/match.js.map +1 -0
- package/dist/retrieval/search-index/search/query.d.ts +44 -0
- package/dist/retrieval/search-index/search/query.js +219 -0
- package/dist/retrieval/search-index/search/query.js.map +1 -0
- package/dist/retrieval/search-index/search/settings.d.ts +29 -0
- package/dist/retrieval/search-index/search/settings.js +35 -0
- package/dist/retrieval/search-index/search/settings.js.map +1 -0
- package/dist/retrieval/search-index/search/status.d.ts +31 -0
- package/dist/retrieval/search-index/search/status.js +70 -0
- package/dist/retrieval/search-index/search/status.js.map +1 -0
- package/dist/retrieval/search-index/search/tokenizer.js +225 -0
- package/dist/retrieval/search-index/search/tokenizer.js.map +1 -0
- package/dist/retrieval/search-index/search/types.d.ts +79 -0
- package/dist/retrieval/search-index/search/types.js +31 -0
- package/dist/retrieval/search-index/search/types.js.map +1 -0
- package/dist/retrieval/search-index/search/write.d.ts +10 -0
- package/dist/retrieval/search-index/search/write.js +70 -0
- package/dist/retrieval/search-index/search/write.js.map +1 -0
- package/dist/runtime/common/cli-command.js.map +1 -0
- package/dist/runtime/common/data-dir.js +49 -0
- package/dist/runtime/common/data-dir.js.map +1 -0
- package/dist/runtime/common/language.js.map +1 -0
- package/dist/runtime/common/llm-scope.js.map +1 -0
- package/dist/runtime/common/logging.js.map +1 -0
- package/dist/runtime/common/prompts.d.ts +6 -0
- package/dist/runtime/common/prompts.js +25 -0
- package/dist/runtime/common/prompts.js.map +1 -0
- package/dist/runtime/common/template.js.map +1 -0
- package/dist/runtime/common/tinyld-language.js.map +1 -0
- package/dist/runtime/common/wiki-graph/dir.d.ts +19 -0
- package/dist/runtime/common/wiki-graph/dir.js +68 -0
- package/dist/runtime/common/wiki-graph/dir.js.map +1 -0
- package/dist/runtime/common/wiki-graph/index.d.ts +3 -0
- package/dist/runtime/common/wiki-graph/index.js +4 -0
- package/dist/runtime/common/wiki-graph/index.js.map +1 -0
- package/dist/runtime/common/wiki-graph/temp.js +21 -0
- package/dist/runtime/common/wiki-graph/temp.js.map +1 -0
- package/dist/runtime/common/wiki-graph/uri.d.ts +37 -0
- package/dist/runtime/common/wiki-graph/uri.js +288 -0
- package/dist/runtime/common/wiki-graph/uri.js.map +1 -0
- package/dist/runtime/context/index.d.ts +1 -0
- package/dist/runtime/context/index.js +13 -0
- package/dist/runtime/context/index.js.map +1 -0
- package/dist/runtime/context/task.js +111 -0
- package/dist/runtime/context/task.js.map +1 -0
- package/dist/runtime/gc/files.js +141 -0
- package/dist/runtime/gc/files.js.map +1 -0
- package/dist/runtime/gc/index.js.map +1 -0
- package/dist/runtime/gc/lock.js +137 -0
- package/dist/runtime/gc/lock.js.map +1 -0
- package/dist/runtime/gc/runner.js +134 -0
- package/dist/runtime/gc/runner.js.map +1 -0
- package/dist/runtime/gc/temp.js +57 -0
- package/dist/runtime/gc/temp.js.map +1 -0
- package/dist/runtime/gc/types.js +1 -0
- package/dist/runtime/gc/types.js.map +1 -0
- package/dist/runtime/jobs/conflicts.d.ts +16 -0
- package/dist/runtime/jobs/conflicts.js +61 -0
- package/dist/runtime/jobs/conflicts.js.map +1 -0
- package/dist/runtime/jobs/database.d.ts +12 -0
- package/dist/runtime/jobs/database.js +74 -0
- package/dist/runtime/jobs/database.js.map +1 -0
- package/dist/runtime/jobs/events.d.ts +6 -0
- package/dist/runtime/jobs/events.js +29 -0
- package/dist/runtime/jobs/events.js.map +1 -0
- package/dist/runtime/jobs/gc.d.ts +10 -0
- package/dist/runtime/jobs/gc.js +81 -0
- package/dist/runtime/jobs/gc.js.map +1 -0
- package/dist/runtime/jobs/helpers.d.ts +6 -0
- package/dist/runtime/jobs/helpers.js +35 -0
- package/dist/runtime/jobs/helpers.js.map +1 -0
- package/dist/runtime/jobs/index.d.ts +7 -0
- package/dist/runtime/jobs/index.js +42 -0
- package/dist/runtime/jobs/index.js.map +1 -0
- package/dist/runtime/jobs/jobs.d.ts +24 -0
- package/dist/runtime/jobs/jobs.js +416 -0
- package/dist/runtime/jobs/jobs.js.map +1 -0
- package/dist/runtime/jobs/paths.d.ts +9 -0
- package/dist/runtime/jobs/paths.js +48 -0
- package/dist/runtime/jobs/paths.js.map +1 -0
- package/dist/runtime/jobs/progress.d.ts +37 -0
- package/dist/runtime/jobs/progress.js +246 -0
- package/dist/runtime/jobs/progress.js.map +1 -0
- package/dist/runtime/jobs/recovery.d.ts +6 -0
- package/dist/runtime/jobs/recovery.js +40 -0
- package/dist/runtime/jobs/recovery.js.map +1 -0
- package/dist/runtime/jobs/row.d.ts +10 -0
- package/dist/runtime/jobs/row.js +92 -0
- package/dist/runtime/jobs/row.js.map +1 -0
- package/dist/runtime/jobs/schema.d.ts +3 -0
- package/dist/runtime/jobs/schema.js +55 -0
- package/dist/runtime/jobs/schema.js.map +1 -0
- package/dist/runtime/jobs/state.d.ts +13 -0
- package/dist/runtime/jobs/state.js +156 -0
- package/dist/runtime/jobs/state.js.map +1 -0
- package/dist/runtime/jobs/types.d.ts +141 -0
- package/dist/runtime/jobs/types.js +13 -0
- package/dist/runtime/jobs/types.js.map +1 -0
- package/dist/runtime/jobs/worker.d.ts +5 -0
- package/dist/runtime/jobs/worker.js +241 -0
- package/dist/runtime/jobs/worker.js.map +1 -0
- package/dist/runtime/progress/index.js.map +1 -0
- package/dist/runtime/progress/reporter.js.map +1 -0
- package/dist/runtime/progress/tracker.js.map +1 -0
- package/dist/runtime/progress/types.js +1 -0
- package/dist/runtime/progress/types.js.map +1 -0
- package/dist/serial.d.ts +36 -85
- package/dist/serial.js +1 -475
- package/dist/serial.js.map +1 -1
- package/dist/state-lock.d.ts +21 -0
- package/dist/state-lock.js +233 -0
- package/dist/state-lock.js.map +1 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/archive.d.ts +11 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/archive.js +94 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/archive.js.map +1 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/database.d.ts +7 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/database.js +28 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/database.js.map +1 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/extract.d.ts +3 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/extract.js +68 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/extract.js.map +1 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/index.js +47 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/index.js.map +1 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/schema.d.ts +3 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/schema.js +41 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/schema.js.map +1 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/core.d.ts +3 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/core.js +77 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/core.js.map +1 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/fragments.d.ts +10 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/fragments.js +123 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/fragments.js.map +1 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/index.d.ts +1 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/index.js +2 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/index.js.map +1 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/references.d.ts +5 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/references.js +305 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/references.js.map +1 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/source-text.d.ts +11 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/source-text.js +62 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/source-text.js.map +1 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/summaries.d.ts +3 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/summaries.js +45 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/summaries.js.map +1 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/types.d.ts +19 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/types.js +1 -0
- package/dist/storage/migration/legacy-sdpub/upgrade/text-storage/types.js.map +1 -0
- package/dist/storage/schema-upgrade/index.d.ts +13 -0
- package/dist/storage/schema-upgrade/index.js +320 -0
- package/dist/storage/schema-upgrade/index.js.map +1 -0
- package/dist/storage/wikg/archive/constants.d.ts +6 -0
- package/dist/storage/wikg/archive/constants.js +19 -0
- package/dist/storage/wikg/archive/constants.js.map +1 -0
- package/dist/storage/wikg/archive/document-files.d.ts +11 -0
- package/dist/storage/wikg/archive/document-files.js +70 -0
- package/dist/storage/wikg/archive/document-files.js.map +1 -0
- package/dist/storage/wikg/archive/extract.d.ts +3 -0
- package/dist/storage/wikg/archive/extract.js +37 -0
- package/dist/storage/wikg/archive/extract.js.map +1 -0
- package/dist/storage/wikg/archive/index.d.ts +6 -0
- package/dist/storage/wikg/archive/index.js +25 -0
- package/dist/storage/wikg/archive/index.js.map +1 -0
- package/dist/storage/wikg/archive/manifest.d.ts +11 -0
- package/dist/storage/wikg/archive/manifest.js +60 -0
- package/dist/storage/wikg/archive/manifest.js.map +1 -0
- package/dist/storage/wikg/archive/paths.d.ts +9 -0
- package/dist/storage/wikg/archive/paths.js +46 -0
- package/dist/storage/wikg/archive/paths.js.map +1 -0
- package/dist/storage/wikg/archive/reader.d.ts +17 -0
- package/dist/storage/wikg/archive/reader.js +101 -0
- package/dist/storage/wikg/archive/reader.js.map +1 -0
- package/dist/storage/wikg/archive/types.d.ts +10 -0
- package/dist/storage/wikg/archive/types.js +1 -0
- package/dist/storage/wikg/archive/types.js.map +1 -0
- package/dist/storage/wikg/archive/write.d.ts +8 -0
- package/dist/storage/wikg/archive/write.js +155 -0
- package/dist/storage/wikg/archive/write.js.map +1 -0
- package/dist/storage/wikg/archive/zip.d.ts +13 -0
- package/dist/storage/wikg/archive/zip.js +122 -0
- package/dist/storage/wikg/archive/zip.js.map +1 -0
- package/dist/storage/wikg/archive-uri.d.ts +1 -0
- package/dist/storage/wikg/archive-uri.js +39 -0
- package/dist/storage/wikg/archive-uri.js.map +1 -0
- package/dist/storage/wikg/coordinator.d.ts +29 -0
- package/dist/storage/wikg/coordinator.js +2 -0
- package/dist/storage/wikg/coordinator.js.map +1 -0
- package/dist/storage/wikg/index.d.ts +41 -0
- package/dist/storage/wikg/index.js +68 -0
- package/dist/storage/wikg/index.js.map +1 -0
- package/dist/storage/wikg/wikg-coordinator/activity.d.ts +4 -0
- package/dist/storage/wikg/wikg-coordinator/activity.js +48 -0
- package/dist/storage/wikg/wikg-coordinator/activity.js.map +1 -0
- package/dist/storage/wikg/wikg-coordinator/archive-key.d.ts +7 -0
- package/dist/storage/wikg/wikg-coordinator/archive-key.js +38 -0
- package/dist/storage/wikg/wikg-coordinator/archive-key.js.map +1 -0
- package/dist/storage/wikg/wikg-coordinator/constants.d.ts +9 -0
- package/dist/storage/wikg/wikg-coordinator/constants.js +19 -0
- package/dist/storage/wikg/wikg-coordinator/constants.js.map +1 -0
- package/dist/storage/wikg/wikg-coordinator/facade.d.ts +40 -0
- package/dist/storage/wikg/wikg-coordinator/facade.js +43 -0
- package/dist/storage/wikg/wikg-coordinator/facade.js.map +1 -0
- package/dist/storage/wikg/wikg-coordinator/file-store.d.ts +52 -0
- package/dist/storage/wikg/wikg-coordinator/file-store.js +369 -0
- package/dist/storage/wikg/wikg-coordinator/file-store.js.map +1 -0
- package/dist/storage/wikg/wikg-coordinator/flusher.d.ts +4 -0
- package/dist/storage/wikg/wikg-coordinator/flusher.js +115 -0
- package/dist/storage/wikg/wikg-coordinator/flusher.js.map +1 -0
- package/dist/storage/wikg/wikg-coordinator/gc.d.ts +5 -0
- package/dist/storage/wikg/wikg-coordinator/gc.js +197 -0
- package/dist/storage/wikg/wikg-coordinator/gc.js.map +1 -0
- package/dist/storage/wikg/wikg-coordinator/index.d.ts +29 -0
- package/dist/storage/wikg/wikg-coordinator/index.js +11 -0
- package/dist/storage/wikg/wikg-coordinator/index.js.map +1 -0
- package/dist/storage/wikg/wikg-coordinator/locks.d.ts +19 -0
- package/dist/storage/wikg/wikg-coordinator/locks.js +194 -0
- package/dist/storage/wikg/wikg-coordinator/locks.js.map +1 -0
- package/dist/storage/wikg/wikg-coordinator/overlays.d.ts +32 -0
- package/dist/storage/wikg/wikg-coordinator/overlays.js +141 -0
- package/dist/storage/wikg/wikg-coordinator/overlays.js.map +1 -0
- package/dist/storage/wikg/wikg-coordinator/owners.d.ts +15 -0
- package/dist/storage/wikg/wikg-coordinator/owners.js +95 -0
- package/dist/storage/wikg/wikg-coordinator/owners.js.map +1 -0
- package/dist/storage/wikg/wikg-coordinator/search-index-cache.d.ts +9 -0
- package/dist/storage/wikg/wikg-coordinator/search-index-cache.js +164 -0
- package/dist/storage/wikg/wikg-coordinator/search-index-cache.js.map +1 -0
- package/dist/storage/wikg/wikg-coordinator/session.d.ts +43 -0
- package/dist/storage/wikg/wikg-coordinator/session.js +147 -0
- package/dist/storage/wikg/wikg-coordinator/session.js.map +1 -0
- package/dist/storage/wikg/wikg-coordinator/state.d.ts +16 -0
- package/dist/storage/wikg/wikg-coordinator/state.js +258 -0
- package/dist/storage/wikg/wikg-coordinator/state.js.map +1 -0
- package/dist/storage/wikg/wikg-coordinator/types.d.ts +28 -0
- package/dist/storage/wikg/wikg-coordinator/types.js +1 -0
- package/dist/storage/wikg/wikg-coordinator/types.js.map +1 -0
- package/dist/storage/wikg/wikg-coordinator/workspace.d.ts +8 -0
- package/dist/storage/wikg/wikg-coordinator/workspace.js +60 -0
- package/dist/storage/wikg/wikg-coordinator/workspace.js.map +1 -0
- package/dist/storage/wikg/wiki-graph-archive-file.d.ts +45 -0
- package/dist/storage/wikg/wiki-graph-archive-file.js +78 -0
- package/dist/storage/wikg/wiki-graph-archive-file.js.map +1 -0
- package/dist/text/editor/clue.d.ts +40 -0
- package/dist/text/editor/clue.js.map +1 -0
- package/dist/text/editor/compression.d.ts +52 -0
- package/dist/text/editor/compression.js +253 -0
- package/dist/text/editor/compression.js.map +1 -0
- package/dist/text/editor/compressor.d.ts +19 -0
- package/dist/text/editor/compressor.js +123 -0
- package/dist/text/editor/compressor.js.map +1 -0
- package/dist/text/editor/feedback.d.ts +16 -0
- package/dist/text/editor/feedback.js.map +1 -0
- package/dist/text/editor/index.d.ts +30 -0
- package/dist/text/editor/index.js +5 -0
- package/dist/text/editor/index.js.map +1 -0
- package/dist/text/editor/language-review.d.ts +14 -0
- package/dist/text/editor/language-review.js +35 -0
- package/dist/text/editor/language-review.js.map +1 -0
- package/dist/text/editor/log.d.ts +50 -0
- package/dist/text/editor/log.js +202 -0
- package/dist/text/editor/log.js.map +1 -0
- package/dist/text/editor/markup.d.ts +18 -0
- package/dist/text/editor/markup.js +294 -0
- package/dist/text/editor/markup.js.map +1 -0
- package/dist/text/editor/prompt-templates.js.map +1 -0
- package/dist/text/editor/response.js.map +1 -0
- package/dist/text/editor/review.d.ts +47 -0
- package/dist/text/editor/review.js +189 -0
- package/dist/text/editor/review.js.map +1 -0
- package/dist/text/editor/types.js +21 -0
- package/dist/text/editor/types.js.map +1 -0
- package/dist/text/output/epub/archive.js.map +1 -0
- package/dist/text/output/epub/book.d.ts +28 -0
- package/dist/text/output/epub/book.js.map +1 -0
- package/dist/text/output/epub/content.js.map +1 -0
- package/dist/text/output/epub/index.d.ts +33 -0
- package/dist/text/output/epub/index.js.map +1 -0
- package/dist/text/output/epub/model.js.map +1 -0
- package/dist/text/output/epub/navigation.js.map +1 -0
- package/dist/text/output/epub/package.js.map +1 -0
- package/dist/text/output/epub/shared.js.map +1 -0
- package/dist/text/output/epub/templates.js +26 -0
- package/dist/text/output/epub/templates.js.map +1 -0
- package/dist/text/output/index.d.ts +27 -0
- package/dist/text/output/index.js.map +1 -0
- package/dist/text/output/plain-text.d.ts +31 -0
- package/dist/text/output/plain-text.js.map +1 -0
- package/dist/text/reader/attention/core.d.ts +39 -0
- package/dist/text/reader/attention/core.js +123 -0
- package/dist/text/reader/attention/core.js.map +1 -0
- package/dist/text/reader/attention/index.d.ts +9 -0
- package/dist/text/reader/attention/index.js +5 -0
- package/dist/text/reader/attention/index.js.map +1 -0
- package/dist/text/reader/attention/wave-reflection.d.ts +21 -0
- package/dist/text/reader/attention/wave-reflection.js.map +1 -0
- package/dist/text/reader/attention/working-memory.d.ts +28 -0
- package/dist/text/reader/attention/working-memory.js.map +1 -0
- package/dist/text/reader/chunk-batch/extract.d.ts +13 -0
- package/dist/text/reader/chunk-batch/extract.js.map +1 -0
- package/dist/text/reader/chunk-batch/extractor.d.ts +17 -0
- package/dist/text/reader/chunk-batch/extractor.js +337 -0
- package/dist/text/reader/chunk-batch/extractor.js.map +1 -0
- package/dist/text/reader/chunk-batch/fragment-projection.d.ts +34 -0
- package/dist/text/reader/chunk-batch/fragment-projection.js.map +1 -0
- package/dist/text/reader/chunk-batch/index.d.ts +13 -0
- package/dist/text/reader/chunk-batch/index.js +13 -0
- package/dist/text/reader/chunk-batch/index.js.map +1 -0
- package/dist/text/reader/chunk-batch/language.d.ts +9 -0
- package/dist/text/reader/chunk-batch/language.js +23 -0
- package/dist/text/reader/chunk-batch/language.js.map +1 -0
- package/dist/text/reader/chunk-batch/parser/annotations.d.ts +19 -0
- package/dist/text/reader/chunk-batch/parser/annotations.js +34 -0
- package/dist/text/reader/chunk-batch/parser/annotations.js.map +1 -0
- package/dist/text/reader/chunk-batch/parser/core.d.ts +33 -0
- package/dist/text/reader/chunk-batch/parser/core.js +171 -0
- package/dist/text/reader/chunk-batch/parser/core.js.map +1 -0
- package/dist/text/reader/chunk-batch/parser/evidence.d.ts +21 -0
- package/dist/text/reader/chunk-batch/parser/evidence.js +40 -0
- package/dist/text/reader/chunk-batch/parser/evidence.js.map +1 -0
- package/dist/text/reader/chunk-batch/parser/helpers.d.ts +27 -0
- package/dist/text/reader/chunk-batch/parser/helpers.js +98 -0
- package/dist/text/reader/chunk-batch/parser/helpers.js.map +1 -0
- package/dist/text/reader/chunk-batch/parser/index.d.ts +13 -0
- package/dist/text/reader/chunk-batch/parser/index.js +3 -0
- package/dist/text/reader/chunk-batch/parser/index.js.map +1 -0
- package/dist/text/reader/chunk-batch/parser/links.d.ts +17 -0
- package/dist/text/reader/chunk-batch/parser/links.js +44 -0
- package/dist/text/reader/chunk-batch/parser/links.js.map +1 -0
- package/dist/text/reader/chunk-batch/parser/resolver.d.ts +28 -0
- package/dist/text/reader/chunk-batch/parser/resolver.js +267 -0
- package/dist/text/reader/chunk-batch/parser/resolver.js.map +1 -0
- package/dist/text/reader/chunk-batch/parser/schema.d.ts +136 -0
- package/dist/text/reader/chunk-batch/parser/schema.js +71 -0
- package/dist/text/reader/chunk-batch/parser/schema.js.map +1 -0
- package/dist/text/reader/chunk-batch/prompt-templates.js.map +1 -0
- package/dist/text/reader/chunk-batch/types.d.ts +85 -0
- package/dist/text/reader/chunk-batch/types.js +1 -0
- package/dist/text/reader/chunk-batch/types.js.map +1 -0
- package/dist/text/reader/core.d.ts +37 -0
- package/dist/text/reader/core.js +82 -0
- package/dist/text/reader/core.js.map +1 -0
- package/dist/text/reader/index.d.ts +13 -0
- package/dist/text/reader/index.js +7 -0
- package/dist/text/reader/index.js.map +1 -0
- package/dist/text/reader/segment/core.js +9 -0
- package/dist/text/reader/segment/core.js.map +1 -0
- package/dist/text/reader/segment/index.d.ts +2 -0
- package/dist/text/reader/segment/index.js +5 -0
- package/dist/text/reader/segment/index.js.map +1 -0
- package/dist/text/reader/segment/intl-segmenter.js.map +1 -0
- package/dist/text/reader/segment/types.js +1 -0
- package/dist/text/reader/segment/types.js.map +1 -0
- package/dist/text/reader/types.d.ts +29 -0
- package/dist/text/reader/types.js +1 -0
- package/dist/text/reader/types.js.map +1 -0
- package/dist/text/serial/discovery.d.ts +36 -0
- package/dist/text/serial/discovery.js +5 -0
- package/dist/text/serial/discovery.js.map +1 -0
- package/dist/text/serial/fragments.d.ts +67 -0
- package/dist/text/serial/fragments.js +121 -0
- package/dist/text/serial/fragments.js.map +1 -0
- package/dist/text/serial/generation.d.ts +48 -0
- package/dist/text/serial/generation.js +257 -0
- package/dist/text/serial/generation.js.map +1 -0
- package/dist/text/serial/index.d.ts +40 -0
- package/dist/text/serial/index.js +7 -0
- package/dist/text/serial/index.js.map +1 -0
- package/dist/text/serial/options.d.ts +77 -0
- package/dist/text/serial/options.js +17 -0
- package/dist/text/serial/options.js.map +1 -0
- package/dist/text/serial/read.d.ts +28 -0
- package/dist/text/serial/read.js +19 -0
- package/dist/text/serial/read.js.map +1 -0
- package/dist/text/serial/reader-graph.d.ts +39 -0
- package/dist/text/serial/reader-graph.js +27 -0
- package/dist/text/serial/reader-graph.js.map +1 -0
- package/dist/text/serial/record.d.ts +40 -0
- package/dist/text/serial/record.js +21 -0
- package/dist/text/serial/record.js.map +1 -0
- package/dist/text/serial/source.d.ts +39 -0
- package/dist/text/serial/source.js +12 -0
- package/dist/text/serial/source.js.map +1 -0
- package/dist/text/serial/topology.d.ts +43 -0
- package/dist/text/serial/topology.js +64 -0
- package/dist/text/serial/topology.js.map +1 -0
- package/dist/text/source/adapter.js.map +1 -0
- package/dist/text/source/epub/archive.js.map +1 -0
- package/dist/text/source/epub/content.js.map +1 -0
- package/dist/text/source/epub/document.js.map +1 -0
- package/dist/text/source/epub/index.js.map +1 -0
- package/dist/text/source/epub/navigation.js.map +1 -0
- package/dist/text/source/epub/package.js.map +1 -0
- package/dist/text/source/epub/xml.js.map +1 -0
- package/dist/text/source/index.js.map +1 -0
- package/dist/text/source/meta.js.map +1 -0
- package/dist/text/source/plain-text.js.map +1 -0
- package/dist/text/source/toc.d.ts +17 -0
- package/dist/text/source/toc.js +19 -0
- package/dist/text/source/toc.js.map +1 -0
- package/dist/text/source/types.js +1 -0
- package/dist/text/source/types.js.map +1 -0
- package/dist/text/summary-build/artifact.d.ts +44 -0
- package/dist/text/summary-build/artifact.js +157 -0
- package/dist/text/summary-build/artifact.js.map +1 -0
- package/dist/text/summary-build/build.d.ts +37 -0
- package/dist/text/summary-build/build.js +60 -0
- package/dist/text/summary-build/build.js.map +1 -0
- package/dist/text/summary-build/index.d.ts +38 -0
- package/dist/text/summary-build/index.js +4 -0
- package/dist/text/summary-build/index.js.map +1 -0
- package/dist/text/summary-build/schema.d.ts +106 -0
- package/dist/text/summary-build/schema.js +118 -0
- package/dist/text/summary-build/schema.js.map +1 -0
- package/dist/text/summary-build/snapshot/chunk-store.d.ts +17 -0
- package/dist/text/summary-build/snapshot/chunk-store.js +68 -0
- package/dist/text/summary-build/snapshot/chunk-store.js.map +1 -0
- package/dist/text/summary-build/snapshot/empty-stores.d.ts +50 -0
- package/dist/text/summary-build/snapshot/empty-stores.js +60 -0
- package/dist/text/summary-build/snapshot/empty-stores.js.map +1 -0
- package/dist/text/summary-build/snapshot/graph-stores.d.ts +42 -0
- package/dist/text/summary-build/snapshot/graph-stores.js +148 -0
- package/dist/text/summary-build/snapshot/graph-stores.js.map +1 -0
- package/dist/text/summary-build/snapshot/helpers.d.ts +17 -0
- package/dist/text/summary-build/snapshot/helpers.js +65 -0
- package/dist/text/summary-build/snapshot/helpers.js.map +1 -0
- package/dist/text/summary-build/snapshot/index.d.ts +63 -0
- package/dist/text/summary-build/snapshot/index.js +106 -0
- package/dist/text/summary-build/snapshot/index.js.map +1 -0
- package/dist/text/summary-build/snapshot/serial-store.d.ts +29 -0
- package/dist/text/summary-build/snapshot/serial-store.js +92 -0
- package/dist/text/summary-build/snapshot/serial-store.js.map +1 -0
- package/dist/text/summary-build/snapshot-io.d.ts +14 -0
- package/dist/text/summary-build/snapshot-io.js +25 -0
- package/dist/text/summary-build/snapshot-io.js.map +1 -0
- package/dist/text/summary-build/source.d.ts +39 -0
- package/dist/text/summary-build/source.js +30 -0
- package/dist/text/summary-build/source.js.map +1 -0
- package/dist/text/summary-build/types.d.ts +34 -0
- package/dist/text/summary-build/types.js +1 -0
- package/dist/text/summary-build/types.js.map +1 -0
- package/dist/worker-DWasYKWW.d.cts +143 -0
- package/dist/worker.cjs +5560 -2312
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.cts +1 -2
- package/dist/worker.d.ts +2 -2
- package/dist/worker.js +1 -1
- package/dist/worker.js.map +1 -1
- package/package.json +3 -2
- package/dist/archive/query/archive-view.d.ts +0 -26
- package/dist/archive/query/archive-view.js +0 -4540
- package/dist/archive/query/archive-view.js.map +0 -1
- package/dist/archive/query/continuation-cursor.d.ts +0 -61
- package/dist/archive/query/continuation-cursor.js +0 -363
- package/dist/archive/query/continuation-cursor.js.map +0 -1
- package/dist/archive/query/index.d.ts +0 -29
- package/dist/archive/query/index.js +0 -63
- package/dist/archive/query/index.js.map +0 -1
- package/dist/archive/query/lexical-search.js.map +0 -1
- package/dist/archive/query/search-cache.d.ts +0 -192
- package/dist/archive/query/search-cache.js +0 -1248
- package/dist/archive/query/search-cache.js.map +0 -1
- package/dist/archive/search-index/index.d.ts +0 -26
- package/dist/archive/search-index/index.js +0 -29
- package/dist/archive/search-index/index.js.map +0 -1
- package/dist/archive/search-index/search-index.d.ts +0 -26
- package/dist/archive/search-index/search-index.js +0 -555
- package/dist/archive/search-index/search-index.js.map +0 -1
- package/dist/archive/search-index/search-tokenizer.js +0 -225
- package/dist/archive/search-index/search-tokenizer.js.map +0 -1
- package/dist/common/cli-command.js.map +0 -1
- package/dist/common/data-dir.js +0 -48
- package/dist/common/data-dir.js.map +0 -1
- package/dist/common/language.js.map +0 -1
- package/dist/common/llm-scope.js.map +0 -1
- package/dist/common/logging.js.map +0 -1
- package/dist/common/template.js.map +0 -1
- package/dist/common/tinyld-language.js.map +0 -1
- package/dist/common/wiki-graph-dir.d.ts +0 -10
- package/dist/common/wiki-graph-dir.js +0 -41
- package/dist/common/wiki-graph-dir.js.map +0 -1
- package/dist/common/wiki-graph-temp.js +0 -21
- package/dist/common/wiki-graph-temp.js.map +0 -1
- package/dist/common/wiki-graph-uri.d.ts +0 -28
- package/dist/common/wiki-graph-uri.js +0 -171
- package/dist/common/wiki-graph-uri.js.map +0 -1
- package/dist/context/index.d.ts +0 -1
- package/dist/context/index.js +0 -13
- package/dist/context/index.js.map +0 -1
- package/dist/context/task-context.js +0 -111
- package/dist/context/task-context.js.map +0 -1
- package/dist/document/document.d.ts +0 -153
- package/dist/document/document.js +0 -615
- package/dist/document/document.js.map +0 -1
- package/dist/document/fragments.d.ts +0 -63
- package/dist/document/fragments.js +0 -371
- package/dist/document/fragments.js.map +0 -1
- package/dist/document/stores.d.ts +0 -203
- package/dist/document/stores.js +0 -1678
- package/dist/document/stores.js.map +0 -1
- package/dist/document/text-streams.d.ts +0 -86
- package/dist/document/text-streams.js +0 -515
- package/dist/document/text-streams.js.map +0 -1
- package/dist/editor/clue.d.ts +0 -27
- package/dist/editor/clue.js.map +0 -1
- package/dist/editor/compressor.d.ts +0 -18
- package/dist/editor/compressor.js +0 -68
- package/dist/editor/compressor.js.map +0 -1
- package/dist/editor/editor.d.ts +0 -39
- package/dist/editor/editor.js +0 -253
- package/dist/editor/editor.js.map +0 -1
- package/dist/editor/feedback.d.ts +0 -16
- package/dist/editor/feedback.js.map +0 -1
- package/dist/editor/index.d.ts +0 -17
- package/dist/editor/index.js +0 -5
- package/dist/editor/index.js.map +0 -1
- package/dist/editor/language-review.d.ts +0 -14
- package/dist/editor/language-review.js +0 -35
- package/dist/editor/language-review.js.map +0 -1
- package/dist/editor/log.d.ts +0 -37
- package/dist/editor/log.js +0 -202
- package/dist/editor/log.js.map +0 -1
- package/dist/editor/markup.d.ts +0 -20
- package/dist/editor/markup.js +0 -294
- package/dist/editor/markup.js.map +0 -1
- package/dist/editor/prompt-templates.js.map +0 -1
- package/dist/editor/response.js.map +0 -1
- package/dist/editor/review.d.ts +0 -34
- package/dist/editor/review.js +0 -189
- package/dist/editor/review.js.map +0 -1
- package/dist/editor/types.js +0 -21
- package/dist/editor/types.js.map +0 -1
- package/dist/evidence-selection/anchor-resolver.d.ts +0 -43
- package/dist/evidence-selection/anchor-resolver.js +0 -783
- package/dist/evidence-selection/anchor-resolver.js.map +0 -1
- package/dist/evidence-selection/anchor-types.d.ts +0 -27
- package/dist/evidence-selection/anchor-types.js +0 -1
- package/dist/evidence-selection/index.d.ts +0 -8
- package/dist/evidence-selection/index.js +0 -32
- package/dist/evidence-selection/index.js.map +0 -1
- package/dist/evidence-selection/prompt.js.map +0 -1
- package/dist/evidence-selection/quote-score.js.map +0 -1
- package/dist/evidence-selection/selection-resolver.js +0 -303
- package/dist/evidence-selection/selection-resolver.js.map +0 -1
- package/dist/evidence-selection/text.js.map +0 -1
- package/dist/facade/app.d.ts +0 -75
- package/dist/facade/app.js +0 -141
- package/dist/facade/app.js.map +0 -1
- package/dist/facade/build-queue.d.ts +0 -181
- package/dist/facade/build-queue.js +0 -1442
- package/dist/facade/build-queue.js.map +0 -1
- package/dist/facade/chapter-build.d.ts +0 -60
- package/dist/facade/chapter-build.js +0 -1020
- package/dist/facade/chapter-build.js.map +0 -1
- package/dist/facade/chapter.d.ts +0 -168
- package/dist/facade/chapter.js +0 -944
- package/dist/facade/chapter.js.map +0 -1
- package/dist/facade/digest.d.ts +0 -55
- package/dist/facade/digest.js +0 -168
- package/dist/facade/digest.js.map +0 -1
- package/dist/facade/graph.d.ts +0 -60
- package/dist/facade/graph.js +0 -203
- package/dist/facade/graph.js.map +0 -1
- package/dist/facade/import.d.ts +0 -49
- package/dist/facade/import.js +0 -262
- package/dist/facade/import.js.map +0 -1
- package/dist/facade/index.d.ts +0 -39
- package/dist/facade/index.js +0 -171
- package/dist/facade/index.js.map +0 -1
- package/dist/facade/knowledge-graph-build.d.ts +0 -75
- package/dist/facade/knowledge-graph-build.js +0 -897
- package/dist/facade/knowledge-graph-build.js.map +0 -1
- package/dist/facade/llm-sampling.d.ts +0 -11
- package/dist/facade/llm-sampling.js +0 -58
- package/dist/facade/llm-sampling.js.map +0 -1
- package/dist/facade/wiki-graph-archive.d.ts +0 -41
- package/dist/facade/wiki-graph-archive.js +0 -130
- package/dist/facade/wiki-graph-archive.js.map +0 -1
- package/dist/gc/files.js +0 -141
- package/dist/gc/files.js.map +0 -1
- package/dist/gc/index.js.map +0 -1
- package/dist/gc/lock.js +0 -137
- package/dist/gc/lock.js.map +0 -1
- package/dist/gc/runner.js +0 -129
- package/dist/gc/runner.js.map +0 -1
- package/dist/gc/tmp-gc.js +0 -57
- package/dist/gc/tmp-gc.js.map +0 -1
- package/dist/guaranteed/classifier.js.map +0 -1
- package/dist/guaranteed/errors.js.map +0 -1
- package/dist/guaranteed/index.js.map +0 -1
- package/dist/guaranteed/request.js.map +0 -1
- package/dist/guaranteed/response.js.map +0 -1
- package/dist/index-B8NNnQ8P.d.ts +0 -424
- package/dist/legacy-sdpub/upgrade.js +0 -795
- package/dist/legacy-sdpub/upgrade.js.map +0 -1
- package/dist/llm/cache.js +0 -35
- package/dist/llm/cache.js.map +0 -1
- package/dist/llm/client.d.ts +0 -26
- package/dist/llm/client.js +0 -572
- package/dist/llm/client.js.map +0 -1
- package/dist/llm/context.js +0 -78
- package/dist/llm/context.js.map +0 -1
- package/dist/llm/errors.js.map +0 -1
- package/dist/llm/index.d.ts +0 -7
- package/dist/llm/index.js +0 -17
- package/dist/llm/index.js.map +0 -1
- package/dist/llm/request-log.js +0 -35
- package/dist/llm/request-log.js.map +0 -1
- package/dist/llm/sampling.js.map +0 -1
- package/dist/output/epub/archive.js.map +0 -1
- package/dist/output/epub/book.d.ts +0 -15
- package/dist/output/epub/book.js.map +0 -1
- package/dist/output/epub/content.js.map +0 -1
- package/dist/output/epub/index.d.ts +0 -20
- package/dist/output/epub/index.js.map +0 -1
- package/dist/output/epub/navigation.js.map +0 -1
- package/dist/output/epub/package.js.map +0 -1
- package/dist/output/epub/shared.js.map +0 -1
- package/dist/output/epub/templates.js +0 -26
- package/dist/output/epub/templates.js.map +0 -1
- package/dist/output/index.d.ts +0 -14
- package/dist/output/index.js.map +0 -1
- package/dist/output/plain-text.d.ts +0 -18
- package/dist/output/plain-text.js.map +0 -1
- package/dist/progress/index.js.map +0 -1
- package/dist/progress/reporter.js.map +0 -1
- package/dist/progress/tracker.js.map +0 -1
- package/dist/reader/attention/attention.d.ts +0 -39
- package/dist/reader/attention/attention.js +0 -123
- package/dist/reader/attention/attention.js.map +0 -1
- package/dist/reader/attention/index.d.ts +0 -9
- package/dist/reader/attention/index.js +0 -5
- package/dist/reader/attention/index.js.map +0 -1
- package/dist/reader/attention/wave-reflection.d.ts +0 -21
- package/dist/reader/attention/wave-reflection.js.map +0 -1
- package/dist/reader/attention/working-memory.d.ts +0 -28
- package/dist/reader/attention/working-memory.js.map +0 -1
- package/dist/reader/chunk-batch/extract.d.ts +0 -13
- package/dist/reader/chunk-batch/extract.js.map +0 -1
- package/dist/reader/chunk-batch/extractor.d.ts +0 -17
- package/dist/reader/chunk-batch/extractor.js +0 -337
- package/dist/reader/chunk-batch/extractor.js.map +0 -1
- package/dist/reader/chunk-batch/fragment-projection.d.ts +0 -34
- package/dist/reader/chunk-batch/fragment-projection.js.map +0 -1
- package/dist/reader/chunk-batch/index.d.ts +0 -12
- package/dist/reader/chunk-batch/index.js +0 -13
- package/dist/reader/chunk-batch/index.js.map +0 -1
- package/dist/reader/chunk-batch/language.d.ts +0 -9
- package/dist/reader/chunk-batch/language.js +0 -23
- package/dist/reader/chunk-batch/language.js.map +0 -1
- package/dist/reader/chunk-batch/parser.d.ts +0 -94
- package/dist/reader/chunk-batch/parser.js +0 -640
- package/dist/reader/chunk-batch/parser.js.map +0 -1
- package/dist/reader/chunk-batch/prompt-templates.js.map +0 -1
- package/dist/reader/chunk-batch/types.d.ts +0 -85
- package/dist/reader/index.d.ts +0 -13
- package/dist/reader/index.js +0 -7
- package/dist/reader/index.js.map +0 -1
- package/dist/reader/reader.d.ts +0 -37
- package/dist/reader/reader.js +0 -82
- package/dist/reader/reader.js.map +0 -1
- package/dist/reader/segment/index.d.ts +0 -2
- package/dist/reader/segment/index.js +0 -5
- package/dist/reader/segment/index.js.map +0 -1
- package/dist/reader/segment/intl-segmenter.js.map +0 -1
- package/dist/reader/segment/segment.js +0 -9
- package/dist/reader/segment/segment.js.map +0 -1
- package/dist/reader/types.d.ts +0 -29
- package/dist/source/epub/archive.js.map +0 -1
- package/dist/source/epub/content.js.map +0 -1
- package/dist/source/epub/document.js.map +0 -1
- package/dist/source/epub/index.js.map +0 -1
- package/dist/source/epub/navigation.js.map +0 -1
- package/dist/source/epub/package.js.map +0 -1
- package/dist/source/epub/xml.js.map +0 -1
- package/dist/source/index.js.map +0 -1
- package/dist/source/meta.js.map +0 -1
- package/dist/source/plain-text.js.map +0 -1
- package/dist/source/toc.d.ts +0 -16
- package/dist/source/toc.js +0 -17
- package/dist/source/toc.js.map +0 -1
- package/dist/topology/grouping.d.ts +0 -15
- package/dist/topology/grouping.js.map +0 -1
- package/dist/topology/index.d.ts +0 -21
- package/dist/topology/index.js +0 -5
- package/dist/topology/index.js.map +0 -1
- package/dist/topology/resource-segmentation.d.ts +0 -13
- package/dist/topology/resource-segmentation.js.map +0 -1
- package/dist/topology/segment-incision.d.ts +0 -18
- package/dist/topology/segment-incision.js.map +0 -1
- package/dist/topology/snake-detector.d.ts +0 -13
- package/dist/topology/snake-detector.js +0 -520
- package/dist/topology/snake-detector.js.map +0 -1
- package/dist/topology/snake-graph-builder.d.ts +0 -14
- package/dist/topology/snake-graph-builder.js +0 -76
- package/dist/topology/snake-graph-builder.js.map +0 -1
- package/dist/topology/topology.d.ts +0 -29
- package/dist/topology/topology.js +0 -348
- package/dist/topology/topology.js.map +0 -1
- package/dist/topology/weights.d.ts +0 -10
- package/dist/topology/weights.js +0 -84
- package/dist/topology/weights.js.map +0 -1
- package/dist/types-FVIqiLC9.d.cts +0 -24
- package/dist/wikg/archive-uri.d.ts +0 -1
- package/dist/wikg/archive-uri.js +0 -37
- package/dist/wikg/archive-uri.js.map +0 -1
- package/dist/wikg/archive.d.ts +0 -28
- package/dist/wikg/archive.js +0 -496
- package/dist/wikg/archive.js.map +0 -1
- package/dist/wikg/index.d.ts +0 -31
- package/dist/wikg/index.js +0 -60
- package/dist/wikg/index.js.map +0 -1
- package/dist/wikg/wikg-coordinator.d.ts +0 -45
- package/dist/wikg/wikg-coordinator.js +0 -1687
- package/dist/wikg/wikg-coordinator.js.map +0 -1
- package/dist/wikg/wiki-graph-archive-file.d.ts +0 -42
- package/dist/wikg/wiki-graph-archive-file.js +0 -78
- package/dist/wikg/wiki-graph-archive-file.js.map +0 -1
- package/dist/wikilink/index.d.ts +0 -10
- package/dist/wikilink/index.js.map +0 -1
- package/dist/wikilink/relation-discovery.d.ts +0 -31
- package/dist/wikilink/relation-discovery.js +0 -477
- package/dist/wikilink/relation-discovery.js.map +0 -1
- package/dist/wikilink/types.d.ts +0 -23
- package/dist/wikilink/window.d.ts +0 -7
- package/dist/wikilink/window.js.map +0 -1
- package/dist/wikimatch/enrichment.d.ts +0 -10
- package/dist/wikimatch/enrichment.js +0 -55
- package/dist/wikimatch/enrichment.js.map +0 -1
- package/dist/wikimatch/index.d.ts +0 -16
- package/dist/wikimatch/index.js +0 -66
- package/dist/wikimatch/index.js.map +0 -1
- package/dist/wikimatch/option-narrowing.d.ts +0 -17
- package/dist/wikimatch/option-narrowing.js.map +0 -1
- package/dist/wikimatch/options.d.ts +0 -14
- package/dist/wikimatch/options.js +0 -155
- package/dist/wikimatch/options.js.map +0 -1
- package/dist/wikimatch/policy-judge.d.ts +0 -17
- package/dist/wikimatch/policy-judge.js +0 -430
- package/dist/wikimatch/policy-judge.js.map +0 -1
- package/dist/wikimatch/range-suppression.js.map +0 -1
- package/dist/wikimatch/surface-screening.d.ts +0 -16
- package/dist/wikimatch/surface-screening.js +0 -168
- package/dist/wikimatch/surface-screening.js.map +0 -1
- package/dist/wikimatch/surface-window.d.ts +0 -6
- package/dist/wikimatch/surface-window.js +0 -44
- package/dist/wikimatch/surface-window.js.map +0 -1
- package/dist/wikimatch/types.d.ts +0 -151
- package/dist/wikimatch/wikispine.d.ts +0 -43
- package/dist/wikimatch/wikispine.js.map +0 -1
- package/dist/wikimatch/window.d.ts +0 -6
- package/dist/wikimatch/window.js.map +0 -1
- package/dist/wikimatch/words.js.map +0 -1
- package/dist/wikipage/cache.d.ts +0 -18
- package/dist/wikipage/cache.js +0 -404
- package/dist/wikipage/cache.js.map +0 -1
- package/dist/wikipage/fetch-log.js +0 -143
- package/dist/wikipage/fetch-log.js.map +0 -1
- package/dist/wikipage/index.d.ts +0 -14
- package/dist/wikipage/index.js +0 -17
- package/dist/wikipage/index.js.map +0 -1
- package/dist/wikipage/normalizer.d.ts +0 -14
- package/dist/wikipage/normalizer.js +0 -147
- package/dist/wikipage/normalizer.js.map +0 -1
- package/dist/wikipage/rate-limiter.js.map +0 -1
- package/dist/wikipage/resolver.d.ts +0 -26
- package/dist/wikipage/resolver.js +0 -325
- package/dist/wikipage/resolver.js.map +0 -1
- package/dist/wikipage/types.d.ts +0 -96
- package/dist/wikipage/wikimedia-client.d.ts +0 -48
- package/dist/wikipage/wikimedia-client.js +0 -397
- package/dist/wikipage/wikimedia-client.js.map +0 -1
- package/dist/worker-BgQ0Xl8T.d.cts +0 -181
- /package/dist/{evidence-selection → api/chapter-build}/types.js +0 -0
- /package/dist/{evidence-selection → api/chapter-build}/types.js.map +0 -0
- /package/dist/{facade → api/knowledge-graph-build}/types.js +0 -0
- /package/dist/{facade → api/knowledge-graph-build}/types.js.map +0 -0
- /package/dist/{facade → api}/types.d.ts +0 -0
- /package/dist/{gc → api}/types.js +0 -0
- /package/dist/{gc → api}/types.js.map +0 -0
- /package/dist/{guaranteed → document/directory}/types.js +0 -0
- /package/dist/{guaranteed → document/directory}/types.js.map +0 -0
- /package/dist/{llm → document/stores}/types.js +0 -0
- /package/dist/{llm → document/stores}/types.js.map +0 -0
- /package/dist/{guaranteed → external/guaranteed}/classifier.d.ts +0 -0
- /package/dist/{guaranteed → external/guaranteed}/classifier.js +0 -0
- /package/dist/{guaranteed → external/guaranteed}/errors.d.ts +0 -0
- /package/dist/{guaranteed → external/guaranteed}/errors.js +0 -0
- /package/dist/{guaranteed → external/guaranteed}/index.d.ts +0 -0
- /package/dist/{guaranteed → external/guaranteed}/index.js +0 -0
- /package/dist/{guaranteed → external/guaranteed}/request.d.ts +0 -0
- /package/dist/{guaranteed → external/guaranteed}/request.js +0 -0
- /package/dist/{guaranteed → external/guaranteed}/response.d.ts +0 -0
- /package/dist/{guaranteed → external/guaranteed}/response.js +0 -0
- /package/dist/{guaranteed → external/guaranteed}/types.d.ts +0 -0
- /package/dist/{progress → external/guaranteed}/types.js +0 -0
- /package/dist/{progress → external/guaranteed}/types.js.map +0 -0
- /package/dist/{llm → external/llm}/cache.d.ts +0 -0
- /package/dist/{llm → external/llm}/context.d.ts +0 -0
- /package/dist/{llm → external/llm}/errors.d.ts +0 -0
- /package/dist/{llm → external/llm}/errors.js +0 -0
- /package/dist/{llm → external/llm}/request-log.d.ts +0 -0
- /package/dist/{llm → external/llm}/sampling.d.ts +0 -0
- /package/dist/{llm → external/llm}/sampling.js +0 -0
- /package/dist/{llm → external/llm}/types.d.ts +0 -0
- /package/dist/{reader/chunk-batch → external/llm}/types.js +0 -0
- /package/dist/{reader/chunk-batch → external/llm}/types.js.map +0 -0
- /package/dist/{wikimatch → external/wikimatch}/option-narrowing.js +0 -0
- /package/dist/{wikimatch → external/wikimatch}/range-suppression.d.ts +0 -0
- /package/dist/{wikimatch → external/wikimatch}/range-suppression.js +0 -0
- /package/dist/{reader/segment → external/wikimatch}/types.js +0 -0
- /package/dist/{reader/segment → external/wikimatch}/types.js.map +0 -0
- /package/dist/{wikimatch → external/wikimatch}/wikispine.js +0 -0
- /package/dist/{wikimatch → external/wikimatch}/window.js +0 -0
- /package/dist/{wikimatch → external/wikimatch}/words.d.ts +0 -0
- /package/dist/{wikimatch → external/wikimatch}/words.js +0 -0
- /package/dist/{wikipage → external/wikipage}/fetch-log.d.ts +0 -0
- /package/dist/{wikipage → external/wikipage}/rate-limiter.d.ts +0 -0
- /package/dist/{wikipage → external/wikipage}/rate-limiter.js +0 -0
- /package/dist/{reader → external/wikipage}/types.js +0 -0
- /package/dist/{reader → external/wikipage}/types.js.map +0 -0
- /package/dist/{source → graph/evidence-selection/anchor}/types.js +0 -0
- /package/dist/{source → graph/evidence-selection/anchor}/types.js.map +0 -0
- /package/dist/{evidence-selection → graph/evidence-selection}/prompt.d.ts +0 -0
- /package/dist/{evidence-selection → graph/evidence-selection}/prompt.js +0 -0
- /package/dist/{evidence-selection → graph/evidence-selection}/quote-score.d.ts +0 -0
- /package/dist/{evidence-selection → graph/evidence-selection}/quote-score.js +0 -0
- /package/dist/{evidence-selection/selection-resolver.d.ts → graph/evidence-selection/resolver.d.ts} +0 -0
- /package/dist/{evidence-selection → graph/evidence-selection}/text.d.ts +0 -0
- /package/dist/{evidence-selection → graph/evidence-selection}/text.js +0 -0
- /package/dist/{evidence-selection → graph/evidence-selection}/types.d.ts +0 -0
- /package/dist/{wikilink → graph/evidence-selection}/types.js +0 -0
- /package/dist/{wikilink → graph/evidence-selection}/types.js.map +0 -0
- /package/dist/{wikimatch → graph/knowledge-build}/types.js +0 -0
- /package/dist/{wikimatch → graph/knowledge-build}/types.js.map +0 -0
- /package/dist/{wikipage → graph/reading-build}/types.js +0 -0
- /package/dist/{wikipage → graph/reading-build}/types.js.map +0 -0
- /package/dist/{topology → graph/topology}/grouping.js +0 -0
- /package/dist/{topology → graph/topology}/resource-segmentation.js +0 -0
- /package/dist/{topology → graph/topology}/segment-incision.js +0 -0
- /package/dist/{evidence-selection/anchor-types.js.map → graph/topology/snake/types.js.map} +0 -0
- /package/dist/{wikilink → graph/wikilink}/index.js +0 -0
- /package/dist/{output/epub/model.js.map → graph/wikilink/types.js.map} +0 -0
- /package/dist/{wikilink → graph/wikilink}/window.js +0 -0
- /package/dist/{source/adapter.js.map → retrieval/query/archive-view/types.js.map} +0 -0
- /package/dist/{archive → retrieval}/query/lexical-search.d.ts +0 -0
- /package/dist/{archive → retrieval}/query/lexical-search.js +0 -0
- /package/dist/{archive/search-index/search-tokenizer.d.ts → retrieval/search-index/search/tokenizer.d.ts} +0 -0
- /package/dist/{common → runtime/common}/cli-command.d.ts +0 -0
- /package/dist/{common → runtime/common}/cli-command.js +0 -0
- /package/dist/{common → runtime/common}/data-dir.d.ts +0 -0
- /package/dist/{common → runtime/common}/language.d.ts +0 -0
- /package/dist/{common → runtime/common}/language.js +0 -0
- /package/dist/{common → runtime/common}/llm-scope.d.ts +0 -0
- /package/dist/{common → runtime/common}/llm-scope.js +0 -0
- /package/dist/{common → runtime/common}/logging.d.ts +0 -0
- /package/dist/{common → runtime/common}/logging.js +0 -0
- /package/dist/{common → runtime/common}/template.d.ts +0 -0
- /package/dist/{common → runtime/common}/template.js +0 -0
- /package/dist/{common → runtime/common}/tinyld-language.d.ts +0 -0
- /package/dist/{common → runtime/common}/tinyld-language.js +0 -0
- /package/dist/{common/wiki-graph-temp.d.ts → runtime/common/wiki-graph/temp.d.ts} +0 -0
- /package/dist/{context/task-context.d.ts → runtime/context/task.d.ts} +0 -0
- /package/dist/{gc → runtime/gc}/files.d.ts +0 -0
- /package/dist/{gc → runtime/gc}/index.d.ts +0 -0
- /package/dist/{gc → runtime/gc}/index.js +0 -0
- /package/dist/{gc → runtime/gc}/lock.d.ts +0 -0
- /package/dist/{gc → runtime/gc}/runner.d.ts +0 -0
- /package/dist/{gc/tmp-gc.d.ts → runtime/gc/temp.d.ts} +0 -0
- /package/dist/{gc → runtime/gc}/types.d.ts +0 -0
- /package/dist/{progress → runtime/progress}/index.d.ts +0 -0
- /package/dist/{progress → runtime/progress}/index.js +0 -0
- /package/dist/{progress → runtime/progress}/reporter.d.ts +0 -0
- /package/dist/{progress → runtime/progress}/reporter.js +0 -0
- /package/dist/{progress → runtime/progress}/tracker.d.ts +0 -0
- /package/dist/{progress → runtime/progress}/tracker.js +0 -0
- /package/dist/{progress → runtime/progress}/types.d.ts +0 -0
- /package/dist/{legacy-sdpub/upgrade.d.ts → storage/migration/legacy-sdpub/upgrade/index.d.ts} +0 -0
- /package/dist/{editor → text/editor}/clue.js +0 -0
- /package/dist/{editor → text/editor}/feedback.js +0 -0
- /package/dist/{editor → text/editor}/prompt-templates.d.ts +0 -0
- /package/dist/{editor → text/editor}/prompt-templates.js +0 -0
- /package/dist/{editor → text/editor}/response.d.ts +0 -0
- /package/dist/{editor → text/editor}/response.js +0 -0
- /package/dist/{editor → text/editor}/types.d.ts +0 -0
- /package/dist/{output → text/output}/epub/archive.d.ts +0 -0
- /package/dist/{output → text/output}/epub/archive.js +0 -0
- /package/dist/{output → text/output}/epub/book.js +0 -0
- /package/dist/{output → text/output}/epub/content.d.ts +0 -0
- /package/dist/{output → text/output}/epub/content.js +0 -0
- /package/dist/{output → text/output}/epub/index.js +0 -0
- /package/dist/{output → text/output}/epub/model.d.ts +0 -0
- /package/dist/{output → text/output}/epub/model.js +0 -0
- /package/dist/{output → text/output}/epub/navigation.d.ts +0 -0
- /package/dist/{output → text/output}/epub/navigation.js +0 -0
- /package/dist/{output → text/output}/epub/package.d.ts +0 -0
- /package/dist/{output → text/output}/epub/package.js +0 -0
- /package/dist/{output → text/output}/epub/shared.d.ts +0 -0
- /package/dist/{output → text/output}/epub/shared.js +0 -0
- /package/dist/{output → text/output}/epub/templates.d.ts +0 -0
- /package/dist/{output → text/output}/index.js +0 -0
- /package/dist/{output → text/output}/plain-text.js +0 -0
- /package/dist/{reader → text/reader}/attention/wave-reflection.js +0 -0
- /package/dist/{reader → text/reader}/attention/working-memory.js +0 -0
- /package/dist/{reader → text/reader}/chunk-batch/extract.js +0 -0
- /package/dist/{reader → text/reader}/chunk-batch/fragment-projection.js +0 -0
- /package/dist/{reader → text/reader}/chunk-batch/prompt-templates.d.ts +0 -0
- /package/dist/{reader → text/reader}/chunk-batch/prompt-templates.js +0 -0
- /package/dist/{reader/segment/segment.d.ts → text/reader/segment/core.d.ts} +0 -0
- /package/dist/{reader → text/reader}/segment/intl-segmenter.d.ts +0 -0
- /package/dist/{reader → text/reader}/segment/intl-segmenter.js +0 -0
- /package/dist/{reader → text/reader}/segment/types.d.ts +0 -0
- /package/dist/{source → text/source}/adapter.d.ts +0 -0
- /package/dist/{source → text/source}/adapter.js +0 -0
- /package/dist/{source → text/source}/epub/archive.d.ts +0 -0
- /package/dist/{source → text/source}/epub/archive.js +0 -0
- /package/dist/{source → text/source}/epub/content.d.ts +0 -0
- /package/dist/{source → text/source}/epub/content.js +0 -0
- /package/dist/{source → text/source}/epub/document.d.ts +0 -0
- /package/dist/{source → text/source}/epub/document.js +0 -0
- /package/dist/{source → text/source}/epub/index.d.ts +0 -0
- /package/dist/{source → text/source}/epub/index.js +0 -0
- /package/dist/{source → text/source}/epub/navigation.d.ts +0 -0
- /package/dist/{source → text/source}/epub/navigation.js +0 -0
- /package/dist/{source → text/source}/epub/package.d.ts +0 -0
- /package/dist/{source → text/source}/epub/package.js +0 -0
- /package/dist/{source → text/source}/epub/xml.d.ts +0 -0
- /package/dist/{source → text/source}/epub/xml.js +0 -0
- /package/dist/{source → text/source}/index.d.ts +0 -0
- /package/dist/{source → text/source}/index.js +0 -0
- /package/dist/{source → text/source}/meta.d.ts +0 -0
- /package/dist/{source → text/source}/meta.js +0 -0
- /package/dist/{source → text/source}/plain-text.d.ts +0 -0
- /package/dist/{source → text/source}/plain-text.js +0 -0
- /package/dist/{source → text/source}/types.d.ts +0 -0
|
@@ -1,4540 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WikipageResolver
|
|
3
|
-
} from "../../wikipage/index.js";
|
|
4
|
-
import {
|
|
5
|
-
getGraphNode,
|
|
6
|
-
listGraphNeighbors
|
|
7
|
-
} from "../../facade/graph.js";
|
|
8
|
-
import {
|
|
9
|
-
getChapterTree,
|
|
10
|
-
listChapters
|
|
11
|
-
} from "../../facade/chapter.js";
|
|
12
|
-
import {
|
|
13
|
-
createLexicalQuery,
|
|
14
|
-
listLexicalQueryCandidateTerms,
|
|
15
|
-
createMentionLexicalHits,
|
|
16
|
-
scoreLexicalText
|
|
17
|
-
} from "./lexical-search.js";
|
|
18
|
-
import {
|
|
19
|
-
createEntitySearchSession,
|
|
20
|
-
createSearchSession,
|
|
21
|
-
decodeBucketSearchSessionCursor,
|
|
22
|
-
decodeSearchSessionCursor,
|
|
23
|
-
encodeBucketSearchSessionCursor,
|
|
24
|
-
populateSearchSessionObjectCaches,
|
|
25
|
-
readCachedEntitySearchSessionPage,
|
|
26
|
-
readCachedSearchSessionPage,
|
|
27
|
-
readEntitySearchEvidenceMentions,
|
|
28
|
-
readEntitySearchSessionPage,
|
|
29
|
-
readSearchSessionChunkBucketPage,
|
|
30
|
-
readSearchSessionDescriptor,
|
|
31
|
-
readSearchSessionMetadataForCursor,
|
|
32
|
-
readSearchSessionObjectBucketPage,
|
|
33
|
-
readSearchSessionPage,
|
|
34
|
-
SEARCH_EVIDENCE_KIND
|
|
35
|
-
} from "./search-cache.js";
|
|
36
|
-
import {
|
|
37
|
-
createSearchIndexFingerprint,
|
|
38
|
-
ensureSearchIndex,
|
|
39
|
-
querySearchIndex,
|
|
40
|
-
readSearchIndexStatus,
|
|
41
|
-
SEARCH_INDEX_FTS_HIT_LIMIT,
|
|
42
|
-
SEARCH_OBJECT_PROPERTY_KIND,
|
|
43
|
-
SEARCH_OBJECT_PROPERTY_OWNER_KIND,
|
|
44
|
-
TEXT_SENTENCE_KIND
|
|
45
|
-
} from "../search-index/search-index.js";
|
|
46
|
-
import { WIKI_GRAPH_URI_PREFIX } from "../../common/wiki-graph-uri.js";
|
|
47
|
-
const DEFAULT_SOURCE_CONTEXT = 2;
|
|
48
|
-
async function getArchiveIndex(document) {
|
|
49
|
-
const [chapters, meta, nodes, edges] = await Promise.all([
|
|
50
|
-
listChapters(document),
|
|
51
|
-
document.readBookMeta(),
|
|
52
|
-
document.chunks.countAll(),
|
|
53
|
-
document.readingEdges.countAll()
|
|
54
|
-
]);
|
|
55
|
-
return {
|
|
56
|
-
chapters,
|
|
57
|
-
edgeCount: edges,
|
|
58
|
-
meta,
|
|
59
|
-
nodeCount: nodes,
|
|
60
|
-
summaryCount: chapters.filter((chapter) => chapter.stage === "summarized").length
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
async function listArchiveObjects(document, kind) {
|
|
64
|
-
switch (kind) {
|
|
65
|
-
case "chapters":
|
|
66
|
-
return await Promise.all(
|
|
67
|
-
(await listChapters(document)).map(async (chapter) => {
|
|
68
|
-
const state = await createChapterState(document, chapter);
|
|
69
|
-
return {
|
|
70
|
-
id: formatChapterId(chapter.chapterId),
|
|
71
|
-
label: chapter.title ?? "[untitled]",
|
|
72
|
-
state,
|
|
73
|
-
summary: formatChapterStateSummary(state),
|
|
74
|
-
type: "chapter"
|
|
75
|
-
};
|
|
76
|
-
})
|
|
77
|
-
);
|
|
78
|
-
case "edges":
|
|
79
|
-
return (await document.readingEdges.listAll()).map((edge) => ({
|
|
80
|
-
id: formatEdgeId(edge),
|
|
81
|
-
label: `${formatNodeId(edge.fromId)} -> ${formatNodeId(edge.toId)}`,
|
|
82
|
-
summary: `weight ${formatWeight(edge.weight)}`,
|
|
83
|
-
type: "edge"
|
|
84
|
-
}));
|
|
85
|
-
case "meta": {
|
|
86
|
-
const meta = await document.readBookMeta();
|
|
87
|
-
return [
|
|
88
|
-
{
|
|
89
|
-
id: ARCHIVE_ROOT_ID,
|
|
90
|
-
label: formatMetaTitle(meta),
|
|
91
|
-
summary: formatMetaSummary(meta),
|
|
92
|
-
type: "meta"
|
|
93
|
-
}
|
|
94
|
-
];
|
|
95
|
-
}
|
|
96
|
-
case "nodes":
|
|
97
|
-
return (await document.chunks.listAll()).map((node) => ({
|
|
98
|
-
id: formatNodeId(node.id),
|
|
99
|
-
label: node.label,
|
|
100
|
-
summary: node.content,
|
|
101
|
-
type: "node"
|
|
102
|
-
}));
|
|
103
|
-
case "summaries":
|
|
104
|
-
return (await Promise.all(
|
|
105
|
-
(await listChapters(document)).map(async (chapter) => {
|
|
106
|
-
const summary = await document.readSummary(chapter.chapterId);
|
|
107
|
-
if (summary === void 0) {
|
|
108
|
-
return void 0;
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
id: formatSummaryId(chapter.chapterId),
|
|
112
|
-
label: chapter.title ?? `[chapter ${chapter.chapterId}]`,
|
|
113
|
-
summary: createSnippet(summary),
|
|
114
|
-
type: "summary"
|
|
115
|
-
};
|
|
116
|
-
})
|
|
117
|
-
)).filter(isDefined);
|
|
118
|
-
case "fragments":
|
|
119
|
-
return (await Promise.all(
|
|
120
|
-
(await listChapters(document)).map(async (chapter) => {
|
|
121
|
-
const title = chapter.title ?? formatChapterId(chapter.chapterId);
|
|
122
|
-
return listTextStreamSentenceCollection(
|
|
123
|
-
await createTextStreamIndex(
|
|
124
|
-
document,
|
|
125
|
-
chapter.chapterId,
|
|
126
|
-
"source"
|
|
127
|
-
),
|
|
128
|
-
chapter.chapterId,
|
|
129
|
-
"source",
|
|
130
|
-
title,
|
|
131
|
-
chapter.documentOrder
|
|
132
|
-
).map((hit) => ({
|
|
133
|
-
id: hit.id,
|
|
134
|
-
label: title,
|
|
135
|
-
summary: hit.snippet,
|
|
136
|
-
type: "source"
|
|
137
|
-
}));
|
|
138
|
-
})
|
|
139
|
-
)).flat();
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
async function listArchiveCollection(document, options = {}) {
|
|
143
|
-
const items = [];
|
|
144
|
-
const documentOrders = await document.serials.listDocumentOrders();
|
|
145
|
-
const chapterFilter = options.chapters === void 0 ? void 0 : new Set(options.chapters);
|
|
146
|
-
const types = options.types ?? [
|
|
147
|
-
"meta",
|
|
148
|
-
"chapter-title",
|
|
149
|
-
"entity",
|
|
150
|
-
"node",
|
|
151
|
-
"triple"
|
|
152
|
-
];
|
|
153
|
-
if (types.includes("meta")) {
|
|
154
|
-
const meta = await document.readBookMeta();
|
|
155
|
-
if (meta !== void 0) {
|
|
156
|
-
items.push({
|
|
157
|
-
field: "metadata",
|
|
158
|
-
id: ARCHIVE_ROOT_ID,
|
|
159
|
-
snippet: formatMetaSummary(meta),
|
|
160
|
-
title: meta.title ?? "Archive metadata",
|
|
161
|
-
type: "meta"
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (types.includes("chapter") || types.includes("chapter-title")) {
|
|
166
|
-
for (const chapter of filterChapters(
|
|
167
|
-
await listChapters(document),
|
|
168
|
-
chapterFilter
|
|
169
|
-
)) {
|
|
170
|
-
const title = chapter.title ?? `[chapter ${chapter.chapterId}]`;
|
|
171
|
-
if (types.includes("chapter") || types.includes("chapter-title")) {
|
|
172
|
-
items.push({
|
|
173
|
-
chapter: chapter.chapterId,
|
|
174
|
-
field: "title",
|
|
175
|
-
id: formatChapterTitleId(chapter.chapterId),
|
|
176
|
-
position: {
|
|
177
|
-
chapter: chapter.chapterId,
|
|
178
|
-
documentOrder: chapter.documentOrder
|
|
179
|
-
},
|
|
180
|
-
snippet: title,
|
|
181
|
-
title,
|
|
182
|
-
type: "chapter-title"
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
if (types.includes("node")) {
|
|
188
|
-
for (const node of await document.chunks.listAll()) {
|
|
189
|
-
if (!isChapterAllowed(chapterFilter, node.sentenceId[0])) {
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
const position = createNodePosition(node.sentenceIds, documentOrders);
|
|
193
|
-
items.push({
|
|
194
|
-
chapter: node.sentenceId[0],
|
|
195
|
-
field: "content",
|
|
196
|
-
id: formatNodeId(node.id),
|
|
197
|
-
...position === void 0 ? {} : { position },
|
|
198
|
-
snippet: createSnippet(node.content),
|
|
199
|
-
title: node.label,
|
|
200
|
-
type: "node"
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (types.includes("entity")) {
|
|
205
|
-
items.push(
|
|
206
|
-
...listEntityCollection(
|
|
207
|
-
filterMentionsByChapterSet(
|
|
208
|
-
await listAllMentions(document),
|
|
209
|
-
chapterFilter
|
|
210
|
-
),
|
|
211
|
-
documentOrders
|
|
212
|
-
)
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
if (types.includes("triple")) {
|
|
216
|
-
items.push(
|
|
217
|
-
...await listTripleCollection(document, chapterFilter, documentOrders)
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
const result = createCollectionResult(items, options);
|
|
221
|
-
const evidenceItems = await hydrateFindHitEvidence(document, result.items, {
|
|
222
|
-
...options.evidenceLimit === void 0 ? {} : { evidenceLimit: options.evidenceLimit },
|
|
223
|
-
order: options.order ?? "doc-asc",
|
|
224
|
-
...options.sourceContext === void 0 ? {} : { sourceContext: options.sourceContext }
|
|
225
|
-
});
|
|
226
|
-
return {
|
|
227
|
-
...result,
|
|
228
|
-
items: await hydrateFindHitBacklinks(document, evidenceItems, options)
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
function filterChapters(chapters, chapterFilter) {
|
|
232
|
-
return chapterFilter === void 0 ? chapters : chapters.filter((chapter) => chapterFilter.has(chapter.chapterId));
|
|
233
|
-
}
|
|
234
|
-
function isChapterAllowed(chapterFilter, chapterId) {
|
|
235
|
-
return chapterFilter === void 0 || chapterFilter.has(chapterId);
|
|
236
|
-
}
|
|
237
|
-
async function findArchiveObjects(document, query, options = {}) {
|
|
238
|
-
const limit = options.limit ?? DEFAULT_FIND_LIMIT;
|
|
239
|
-
const textOnlySearch = isTextOnlySearch(options);
|
|
240
|
-
if (options.cursor !== void 0 && (!textOnlySearch || !isFindCursor(options.cursor))) {
|
|
241
|
-
const bucketCursor = tryDecodeBucketSearchSessionCursor(options.cursor);
|
|
242
|
-
if (bucketCursor !== void 0) {
|
|
243
|
-
return await readBucketedSearchResultPage(document, bucketCursor, {
|
|
244
|
-
...options,
|
|
245
|
-
limit
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
const cursor = decodeSearchSessionCursor(options.cursor);
|
|
249
|
-
const descriptor = await readSearchSessionDescriptor(
|
|
250
|
-
cursor.sessionId,
|
|
251
|
-
options.archiveKey ?? "archive"
|
|
252
|
-
);
|
|
253
|
-
assertSearchCursorTypesMatch(options.types, descriptor.types);
|
|
254
|
-
const page = isEntitySearchTypes(descriptor.types) ? await readEntitySearchSessionPage(
|
|
255
|
-
cursor.sessionId,
|
|
256
|
-
cursor.offset,
|
|
257
|
-
limit,
|
|
258
|
-
options.archiveKey ?? "archive",
|
|
259
|
-
cursor.createdAt
|
|
260
|
-
) : await readSearchSessionPage(
|
|
261
|
-
cursor.sessionId,
|
|
262
|
-
cursor.offset,
|
|
263
|
-
limit,
|
|
264
|
-
options.archiveKey ?? "archive",
|
|
265
|
-
cursor.createdAt
|
|
266
|
-
);
|
|
267
|
-
return await hydrateFindResultBacklinks(
|
|
268
|
-
document,
|
|
269
|
-
{
|
|
270
|
-
chapters: page.chapters,
|
|
271
|
-
items: await hydrateFindHitEvidence(
|
|
272
|
-
document,
|
|
273
|
-
page.items,
|
|
274
|
-
createFindEvidenceHydrationOptions(options, cursor.sessionId)
|
|
275
|
-
),
|
|
276
|
-
lens: parseFindLens(page.lens),
|
|
277
|
-
lensHint: page.lens === "broad" ? BROAD_FIND_LENS_HINT : null,
|
|
278
|
-
limit,
|
|
279
|
-
match: parseFindMatch(page.match),
|
|
280
|
-
nextCursor: page.nextCursor,
|
|
281
|
-
order: options.order ?? "doc-asc",
|
|
282
|
-
query: page.query,
|
|
283
|
-
terms: page.terms,
|
|
284
|
-
types: parseFindTypes(descriptor.types)
|
|
285
|
-
},
|
|
286
|
-
options
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
const requestedTypes = options.types ?? null;
|
|
290
|
-
const wantsStructuredSearch = requestedTypes === null || requestedTypes.includes("entity") || requestedTypes.includes("triple");
|
|
291
|
-
const search = createLexicalQuery(query);
|
|
292
|
-
if (search === void 0) {
|
|
293
|
-
return createFindResult(query, [], options);
|
|
294
|
-
}
|
|
295
|
-
if (textOnlySearch) {
|
|
296
|
-
return await findTextOnlyArchiveObjectsIndexed(
|
|
297
|
-
document,
|
|
298
|
-
query,
|
|
299
|
-
options,
|
|
300
|
-
search
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
const revisionScope = await createSearchRevisionScope(
|
|
304
|
-
document,
|
|
305
|
-
options.chapters
|
|
306
|
-
);
|
|
307
|
-
const cacheInput = {
|
|
308
|
-
archiveKey: options.archiveKey ?? "archive",
|
|
309
|
-
chapters: options.chapters ?? null,
|
|
310
|
-
lens: options.types === void 0 ? "broad" : "typed",
|
|
311
|
-
match: options.match ?? "any",
|
|
312
|
-
order: options.order ?? "doc-asc",
|
|
313
|
-
query,
|
|
314
|
-
revisionScope,
|
|
315
|
-
terms: search.terms,
|
|
316
|
-
types: options.types ?? null
|
|
317
|
-
};
|
|
318
|
-
const canReadSearchCache = options.triplePattern === void 0;
|
|
319
|
-
const usesBucketedSearch = options.types === void 0 && options.triplePattern === void 0;
|
|
320
|
-
if (canReadSearchCache && isEntityOnlySearch(options)) {
|
|
321
|
-
const cachedPage = await readCachedEntitySearchSessionPage(
|
|
322
|
-
cacheInput,
|
|
323
|
-
0,
|
|
324
|
-
limit
|
|
325
|
-
);
|
|
326
|
-
if (cachedPage !== void 0) {
|
|
327
|
-
return await hydrateFindResultBacklinks(
|
|
328
|
-
document,
|
|
329
|
-
{
|
|
330
|
-
chapters: cachedPage.chapters,
|
|
331
|
-
items: await hydrateFindHitEvidence(
|
|
332
|
-
document,
|
|
333
|
-
cachedPage.items,
|
|
334
|
-
createFindEvidenceHydrationOptions(options, cachedPage.sessionId)
|
|
335
|
-
),
|
|
336
|
-
lens: parseFindLens(cachedPage.lens),
|
|
337
|
-
lensHint: cachedPage.lens === "broad" ? BROAD_FIND_LENS_HINT : null,
|
|
338
|
-
limit,
|
|
339
|
-
match: parseFindMatch(cachedPage.match),
|
|
340
|
-
nextCursor: cachedPage.nextCursor,
|
|
341
|
-
order: options.order ?? "doc-asc",
|
|
342
|
-
query: cachedPage.query,
|
|
343
|
-
terms: cachedPage.terms,
|
|
344
|
-
types: parseFindTypes(cachedPage.types)
|
|
345
|
-
},
|
|
346
|
-
options
|
|
347
|
-
);
|
|
348
|
-
}
|
|
349
|
-
} else if (canReadSearchCache && !usesBucketedSearch) {
|
|
350
|
-
const cachedPage = await readCachedSearchSessionPage(cacheInput, 0, limit);
|
|
351
|
-
if (cachedPage !== void 0) {
|
|
352
|
-
return await hydrateFindResultBacklinks(
|
|
353
|
-
document,
|
|
354
|
-
{
|
|
355
|
-
chapters: cachedPage.chapters,
|
|
356
|
-
items: await hydrateFindHitEvidence(
|
|
357
|
-
document,
|
|
358
|
-
cachedPage.items,
|
|
359
|
-
createFindEvidenceHydrationOptions(options)
|
|
360
|
-
),
|
|
361
|
-
lens: parseFindLens(cachedPage.lens),
|
|
362
|
-
lensHint: cachedPage.lens === "broad" ? BROAD_FIND_LENS_HINT : null,
|
|
363
|
-
limit,
|
|
364
|
-
match: parseFindMatch(cachedPage.match),
|
|
365
|
-
nextCursor: cachedPage.nextCursor,
|
|
366
|
-
order: options.order ?? "doc-asc",
|
|
367
|
-
query: cachedPage.query,
|
|
368
|
-
terms: cachedPage.terms,
|
|
369
|
-
types: parseFindTypes(cachedPage.types)
|
|
370
|
-
},
|
|
371
|
-
options
|
|
372
|
-
);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
if (usesBucketedSearch) {
|
|
376
|
-
if (!await isArchiveSearchIndexCurrent(document)) {
|
|
377
|
-
throw new Error(
|
|
378
|
-
"Wiki Graph search index is missing or outdated. Run `<archive-uri>/index enable` before searching."
|
|
379
|
-
);
|
|
380
|
-
}
|
|
381
|
-
const sessionId2 = await createSearchSession({
|
|
382
|
-
archiveKey: options.archiveKey ?? "archive",
|
|
383
|
-
chapters: options.chapters ?? null,
|
|
384
|
-
lens: "broad",
|
|
385
|
-
match: options.match ?? "any",
|
|
386
|
-
order: options.order ?? "doc-asc",
|
|
387
|
-
query,
|
|
388
|
-
revisionScope,
|
|
389
|
-
terms: search.terms,
|
|
390
|
-
types: null
|
|
391
|
-
});
|
|
392
|
-
const descriptor = await readSearchSessionDescriptor(
|
|
393
|
-
sessionId2,
|
|
394
|
-
options.archiveKey ?? "archive"
|
|
395
|
-
);
|
|
396
|
-
return await readBucketedSearchResultPage(
|
|
397
|
-
document,
|
|
398
|
-
{
|
|
399
|
-
createdAt: descriptor.createdAt,
|
|
400
|
-
cursor: { bucket: 0 },
|
|
401
|
-
sessionId: sessionId2
|
|
402
|
-
},
|
|
403
|
-
{ ...options, limit }
|
|
404
|
-
);
|
|
405
|
-
}
|
|
406
|
-
const allMentions = wantsStructuredSearch ? await document.mentions.listBySurfaceTerms(
|
|
407
|
-
listLexicalQueryCandidateTerms(query)
|
|
408
|
-
) : [];
|
|
409
|
-
const indexed = await findArchiveObjectsIndexed(document, query, options);
|
|
410
|
-
const structuredHits = wantsStructuredSearch ? [
|
|
411
|
-
...findEntities(search, { mentions: allMentions }),
|
|
412
|
-
...await findTriples(document, search, { mentions: allMentions })
|
|
413
|
-
] : [];
|
|
414
|
-
const hits = [...structuredHits, ...indexed?.hits ?? []];
|
|
415
|
-
if (isEntityOnlySearch(options)) {
|
|
416
|
-
const ranked2 = createRankedFindResult(
|
|
417
|
-
query,
|
|
418
|
-
filterLexicalHitsByMatch(hits, search, options.match ?? "any"),
|
|
419
|
-
options,
|
|
420
|
-
search.terms
|
|
421
|
-
);
|
|
422
|
-
const entityCacheInput2 = createEntitySearchCacheInput(
|
|
423
|
-
ranked2.items,
|
|
424
|
-
indexed?.result
|
|
425
|
-
);
|
|
426
|
-
const sentenceCacheInput2 = await createSentenceEvidenceSearchCacheInput(
|
|
427
|
-
document,
|
|
428
|
-
indexed?.result,
|
|
429
|
-
options
|
|
430
|
-
);
|
|
431
|
-
const sessionId2 = await createEntitySearchSession({
|
|
432
|
-
archiveKey: options.archiveKey ?? "archive",
|
|
433
|
-
chapters: ranked2.chapters,
|
|
434
|
-
chunkHits: sentenceCacheInput2.chunkHits,
|
|
435
|
-
entityHits: [
|
|
436
|
-
...entityCacheInput2.entityHits,
|
|
437
|
-
...sentenceCacheInput2.entityHits
|
|
438
|
-
],
|
|
439
|
-
evidenceEvents: [
|
|
440
|
-
...entityCacheInput2.evidenceEvents,
|
|
441
|
-
...sentenceCacheInput2.evidenceEvents
|
|
442
|
-
],
|
|
443
|
-
lens: ranked2.lens,
|
|
444
|
-
match: ranked2.match,
|
|
445
|
-
order: ranked2.order,
|
|
446
|
-
query,
|
|
447
|
-
revisionScope,
|
|
448
|
-
terms: ranked2.terms,
|
|
449
|
-
tripleHits: sentenceCacheInput2.tripleHits,
|
|
450
|
-
types: ranked2.types
|
|
451
|
-
});
|
|
452
|
-
const firstPage2 = await readEntitySearchSessionPage(sessionId2, 0, limit);
|
|
453
|
-
return await hydrateFindResultBacklinks(
|
|
454
|
-
document,
|
|
455
|
-
{
|
|
456
|
-
...ranked2,
|
|
457
|
-
items: await hydrateFindHitEvidence(
|
|
458
|
-
document,
|
|
459
|
-
firstPage2.items,
|
|
460
|
-
createFindEvidenceHydrationOptions(options, sessionId2)
|
|
461
|
-
),
|
|
462
|
-
nextCursor: firstPage2.nextCursor
|
|
463
|
-
},
|
|
464
|
-
options
|
|
465
|
-
);
|
|
466
|
-
}
|
|
467
|
-
const ranked = createRankedFindResult(
|
|
468
|
-
query,
|
|
469
|
-
filterLexicalHitsByMatch(hits, search, options.match ?? "any"),
|
|
470
|
-
options,
|
|
471
|
-
search.terms
|
|
472
|
-
);
|
|
473
|
-
const entityCacheInput = createEntitySearchCacheInput(
|
|
474
|
-
ranked.items,
|
|
475
|
-
indexed?.result
|
|
476
|
-
);
|
|
477
|
-
const sentenceCacheInput = await createSentenceEvidenceSearchCacheInput(
|
|
478
|
-
document,
|
|
479
|
-
indexed?.result,
|
|
480
|
-
options
|
|
481
|
-
);
|
|
482
|
-
const sessionId = await createSearchSession({
|
|
483
|
-
archiveKey: options.archiveKey ?? "archive",
|
|
484
|
-
chapters: ranked.chapters,
|
|
485
|
-
chunkHits: sentenceCacheInput.chunkHits,
|
|
486
|
-
entityHits: [
|
|
487
|
-
...entityCacheInput.entityHits,
|
|
488
|
-
...sentenceCacheInput.entityHits
|
|
489
|
-
],
|
|
490
|
-
evidenceEvents: [
|
|
491
|
-
...entityCacheInput.evidenceEvents,
|
|
492
|
-
...sentenceCacheInput.evidenceEvents
|
|
493
|
-
],
|
|
494
|
-
items: ranked.items,
|
|
495
|
-
lens: ranked.lens,
|
|
496
|
-
match: ranked.match,
|
|
497
|
-
order: ranked.order,
|
|
498
|
-
query,
|
|
499
|
-
revisionScope,
|
|
500
|
-
terms: ranked.terms,
|
|
501
|
-
tripleHits: sentenceCacheInput.tripleHits,
|
|
502
|
-
types: ranked.types
|
|
503
|
-
});
|
|
504
|
-
const firstPage = await readSearchSessionPage(sessionId, 0, limit);
|
|
505
|
-
return await hydrateFindResultBacklinks(
|
|
506
|
-
document,
|
|
507
|
-
{
|
|
508
|
-
...ranked,
|
|
509
|
-
items: await hydrateFindHitEvidence(
|
|
510
|
-
document,
|
|
511
|
-
firstPage.items,
|
|
512
|
-
createFindEvidenceHydrationOptions(options)
|
|
513
|
-
),
|
|
514
|
-
nextCursor: firstPage.nextCursor
|
|
515
|
-
},
|
|
516
|
-
options
|
|
517
|
-
);
|
|
518
|
-
}
|
|
519
|
-
async function findTextOnlyArchiveObjectsIndexed(document, query, options, search) {
|
|
520
|
-
const indexed = await findArchiveObjectsIndexed(document, query, options);
|
|
521
|
-
const hits = indexed?.hits ?? [];
|
|
522
|
-
return createFindResult(
|
|
523
|
-
query,
|
|
524
|
-
filterLexicalHitsByMatch(hits, search, options.match ?? "any"),
|
|
525
|
-
options,
|
|
526
|
-
indexed?.result.terms ?? search.terms
|
|
527
|
-
);
|
|
528
|
-
}
|
|
529
|
-
async function createSearchRevisionScope(document, chapters) {
|
|
530
|
-
if (chapters === void 0 || chapters.length === 0) {
|
|
531
|
-
return JSON.stringify({
|
|
532
|
-
chaptersRevision: await document.serials.getChaptersRevision(),
|
|
533
|
-
scope: "all"
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
const uniqueChapters = [...new Set(chapters)].sort(compareNumbers);
|
|
537
|
-
const revisions = await document.serials.getRevisions(uniqueChapters);
|
|
538
|
-
return JSON.stringify({
|
|
539
|
-
chapters: uniqueChapters.map(
|
|
540
|
-
(chapterId) => [chapterId, revisions.get(chapterId) ?? 0]
|
|
541
|
-
),
|
|
542
|
-
scope: "chapters"
|
|
543
|
-
});
|
|
544
|
-
}
|
|
545
|
-
async function readBucketedSearchResultPage(document, cursor, options) {
|
|
546
|
-
const session = await readSearchSessionMetadataForCursor(
|
|
547
|
-
cursor.sessionId,
|
|
548
|
-
options.archiveKey ?? "archive",
|
|
549
|
-
cursor.createdAt
|
|
550
|
-
);
|
|
551
|
-
assertSearchCursorTypesMatch(options.types, session.types);
|
|
552
|
-
const items = [];
|
|
553
|
-
let bucketCursor = cursor.cursor;
|
|
554
|
-
while (bucketCursor !== void 0 && items.length < options.limit) {
|
|
555
|
-
const remaining = options.limit - items.length;
|
|
556
|
-
const page = await readBucketPage(
|
|
557
|
-
document,
|
|
558
|
-
session,
|
|
559
|
-
bucketCursor,
|
|
560
|
-
remaining
|
|
561
|
-
);
|
|
562
|
-
items.push(...page.items);
|
|
563
|
-
bucketCursor = page.nextCursor;
|
|
564
|
-
}
|
|
565
|
-
return await hydrateFindResultBacklinks(
|
|
566
|
-
document,
|
|
567
|
-
{
|
|
568
|
-
chapters: session.chapters,
|
|
569
|
-
items: await hydrateFindHitEvidence(
|
|
570
|
-
document,
|
|
571
|
-
items,
|
|
572
|
-
createFindEvidenceHydrationOptions(options, cursor.sessionId)
|
|
573
|
-
),
|
|
574
|
-
lens: parseFindLens(session.lens),
|
|
575
|
-
lensHint: session.lens === "broad" ? BROAD_FIND_LENS_HINT : null,
|
|
576
|
-
limit: options.limit,
|
|
577
|
-
match: parseFindMatch(session.match),
|
|
578
|
-
nextCursor: bucketCursor === void 0 ? null : encodeBucketSearchSessionCursor(
|
|
579
|
-
cursor.sessionId,
|
|
580
|
-
bucketCursor,
|
|
581
|
-
session.createdAt
|
|
582
|
-
),
|
|
583
|
-
order: options.order ?? "doc-asc",
|
|
584
|
-
query: session.query,
|
|
585
|
-
terms: session.terms,
|
|
586
|
-
types: parseFindTypes(session.types)
|
|
587
|
-
},
|
|
588
|
-
options
|
|
589
|
-
);
|
|
590
|
-
}
|
|
591
|
-
async function readBucketPage(document, session, cursor, limit) {
|
|
592
|
-
switch (cursor.bucket) {
|
|
593
|
-
case 0:
|
|
594
|
-
return await readChapterTitleBucketPage(
|
|
595
|
-
document,
|
|
596
|
-
session,
|
|
597
|
-
cursor.key,
|
|
598
|
-
limit
|
|
599
|
-
);
|
|
600
|
-
case 1:
|
|
601
|
-
return await readObjectBucketPage(document, session, cursor.key, limit);
|
|
602
|
-
case 2:
|
|
603
|
-
return await readChunkBucketPage(document, session, cursor.key, limit);
|
|
604
|
-
case 3:
|
|
605
|
-
return await readTextBucketPage(document, session, cursor.key, limit);
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
async function readChapterTitleBucketPage(document, session, after, limit) {
|
|
609
|
-
const result = await querySearchIndex(document, session.query, {
|
|
610
|
-
...session.chapters === null ? {} : { chapters: session.chapters },
|
|
611
|
-
match: parseFindMatch(session.match),
|
|
612
|
-
objectHitLimit: SEARCH_INDEX_FTS_HIT_LIMIT,
|
|
613
|
-
textHitLimit: 0,
|
|
614
|
-
types: ["chapter-title"]
|
|
615
|
-
});
|
|
616
|
-
const chapters = new Map(
|
|
617
|
-
(await listChapters(document)).map((chapter) => [
|
|
618
|
-
chapter.chapterId,
|
|
619
|
-
chapter
|
|
620
|
-
])
|
|
621
|
-
);
|
|
622
|
-
const hits = (result?.objectHits ?? []).filter(
|
|
623
|
-
(hit) => hit.ownerKind === SEARCH_OBJECT_PROPERTY_OWNER_KIND.chapter
|
|
624
|
-
).sort(compareChapterTitleIndexHits).filter((hit) => isAfterChapterTitleKey(hit, after));
|
|
625
|
-
const page = hits.slice(0, limit + 1);
|
|
626
|
-
const hydrated = (await Promise.all(
|
|
627
|
-
page.slice(0, limit).map(async (hit) => {
|
|
628
|
-
const item = await hydrateSearchObjectHit(document, chapters, hit);
|
|
629
|
-
return item === void 0 ? void 0 : withSearchTerms(item, session.terms);
|
|
630
|
-
})
|
|
631
|
-
)).filter(isDefined);
|
|
632
|
-
const last = page.at(limit - 1);
|
|
633
|
-
return {
|
|
634
|
-
items: hydrated,
|
|
635
|
-
nextCursor: page.length > limit && last !== void 0 ? {
|
|
636
|
-
bucket: 0,
|
|
637
|
-
key: {
|
|
638
|
-
chapterId: parseSearchPropertyIntegerOwnerId(last.ownerId),
|
|
639
|
-
score: last.score
|
|
640
|
-
}
|
|
641
|
-
} : { bucket: 1 }
|
|
642
|
-
};
|
|
643
|
-
}
|
|
644
|
-
async function readObjectBucketPage(document, session, after, limit) {
|
|
645
|
-
if (!session.objectCachesPopulated) {
|
|
646
|
-
await populateObjectBucketCaches(document, session);
|
|
647
|
-
}
|
|
648
|
-
const page = await readSearchSessionObjectBucketPage(
|
|
649
|
-
session.sessionId,
|
|
650
|
-
1,
|
|
651
|
-
after,
|
|
652
|
-
limit
|
|
653
|
-
);
|
|
654
|
-
const items = page.slice(0, limit);
|
|
655
|
-
const hydrated = await Promise.all(
|
|
656
|
-
items.map(async (hit) => await hydrateCachedObjectBucketHit(document, hit))
|
|
657
|
-
);
|
|
658
|
-
const last = items.at(-1);
|
|
659
|
-
return {
|
|
660
|
-
items: hydrated,
|
|
661
|
-
nextCursor: page.length > limit && last !== void 0 ? {
|
|
662
|
-
bucket: 1,
|
|
663
|
-
key: {
|
|
664
|
-
id: getObjectBucketCursorId(last),
|
|
665
|
-
kind: last.type === "triple" ? "triple" : "entity",
|
|
666
|
-
score: last.score ?? 0
|
|
667
|
-
}
|
|
668
|
-
} : { bucket: 2 }
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
async function populateObjectBucketCaches(document, session) {
|
|
672
|
-
const search = createLexicalQuery(session.query);
|
|
673
|
-
if (search === void 0) {
|
|
674
|
-
return;
|
|
675
|
-
}
|
|
676
|
-
const [allMentions, indexed] = await Promise.all([
|
|
677
|
-
document.mentions.listBySurfaceTerms(
|
|
678
|
-
listLexicalQueryCandidateTerms(session.query)
|
|
679
|
-
),
|
|
680
|
-
querySearchIndex(document, session.query, {
|
|
681
|
-
...session.chapters === null ? {} : { chapters: session.chapters },
|
|
682
|
-
match: parseFindMatch(session.match),
|
|
683
|
-
objectHitLimit: SEARCH_INDEX_FTS_HIT_LIMIT,
|
|
684
|
-
textHitLimit: 0,
|
|
685
|
-
types: null
|
|
686
|
-
})
|
|
687
|
-
]);
|
|
688
|
-
const structuredHits = [
|
|
689
|
-
...findEntities(search, { mentions: allMentions }),
|
|
690
|
-
...await findTriples(document, search, { mentions: allMentions })
|
|
691
|
-
];
|
|
692
|
-
const entityCacheInput = createEntitySearchCacheInput(
|
|
693
|
-
structuredHits,
|
|
694
|
-
indexed
|
|
695
|
-
);
|
|
696
|
-
await populateSearchSessionObjectCaches({
|
|
697
|
-
entityHits: entityCacheInput.entityHits,
|
|
698
|
-
evidenceEvents: entityCacheInput.evidenceEvents,
|
|
699
|
-
sessionId: session.sessionId
|
|
700
|
-
});
|
|
701
|
-
}
|
|
702
|
-
async function readChunkBucketPage(document, session, after, limit) {
|
|
703
|
-
const page = await readSearchSessionChunkBucketPage(
|
|
704
|
-
session.sessionId,
|
|
705
|
-
after,
|
|
706
|
-
limit
|
|
707
|
-
);
|
|
708
|
-
const items = page.slice(0, limit);
|
|
709
|
-
const hydrated = (await Promise.all(
|
|
710
|
-
items.map(
|
|
711
|
-
async (hit) => await hydrateCachedChunkBucketHit(document, hit)
|
|
712
|
-
)
|
|
713
|
-
)).filter(isDefined);
|
|
714
|
-
const last = items.at(-1);
|
|
715
|
-
return {
|
|
716
|
-
items: hydrated,
|
|
717
|
-
nextCursor: page.length > limit && last !== void 0 ? {
|
|
718
|
-
bucket: 2,
|
|
719
|
-
key: {
|
|
720
|
-
chunkId: parseSearchPropertyIntegerOwnerId(
|
|
721
|
-
last.id.slice("wikg://chunk/".length)
|
|
722
|
-
),
|
|
723
|
-
score: last.score ?? 0
|
|
724
|
-
}
|
|
725
|
-
} : { bucket: 3 }
|
|
726
|
-
};
|
|
727
|
-
}
|
|
728
|
-
async function readTextBucketPage(document, session, after, limit) {
|
|
729
|
-
const result = await querySearchIndex(document, session.query, {
|
|
730
|
-
...session.chapters === null ? {} : { chapters: session.chapters },
|
|
731
|
-
match: parseFindMatch(session.match),
|
|
732
|
-
objectHitLimit: 0,
|
|
733
|
-
...after === void 0 ? {} : {
|
|
734
|
-
textAfter: {
|
|
735
|
-
chapterId: after.chapterId,
|
|
736
|
-
kind: after.kind,
|
|
737
|
-
rank: after.rank,
|
|
738
|
-
sentenceIndex: after.sentenceIndex
|
|
739
|
-
}
|
|
740
|
-
},
|
|
741
|
-
textHitLimit: createBucketQueryWindow(limit),
|
|
742
|
-
types: ["source", "summary"]
|
|
743
|
-
});
|
|
744
|
-
const chapters = new Map(
|
|
745
|
-
(await listChapters(document)).map((chapter) => [
|
|
746
|
-
chapter.chapterId,
|
|
747
|
-
chapter
|
|
748
|
-
])
|
|
749
|
-
);
|
|
750
|
-
const hits = [...result?.textHits ?? []].sort(compareTextIndexHits).filter((hit) => isAfterTextKey(hit, after));
|
|
751
|
-
const page = hits.slice(0, limit + 1);
|
|
752
|
-
const hydrated = (await Promise.all(
|
|
753
|
-
page.slice(0, limit).map(async (hit) => {
|
|
754
|
-
const item = await hydrateSearchTextHit(document, chapters, hit);
|
|
755
|
-
return item === void 0 ? void 0 : withSearchTerms(item, session.terms);
|
|
756
|
-
})
|
|
757
|
-
)).filter(isDefined);
|
|
758
|
-
const last = page.at(limit - 1);
|
|
759
|
-
return {
|
|
760
|
-
items: hydrated,
|
|
761
|
-
nextCursor: page.length > limit && last !== void 0 ? {
|
|
762
|
-
bucket: 3,
|
|
763
|
-
key: {
|
|
764
|
-
chapterId: last.chapterId,
|
|
765
|
-
kind: last.kind,
|
|
766
|
-
rank: last.rank,
|
|
767
|
-
sentenceIndex: last.sentenceIndex
|
|
768
|
-
}
|
|
769
|
-
} : void 0
|
|
770
|
-
};
|
|
771
|
-
}
|
|
772
|
-
function createBucketQueryWindow(limit) {
|
|
773
|
-
return Math.max(limit + 1, limit * 3 + 1, 100);
|
|
774
|
-
}
|
|
775
|
-
async function hydrateCachedObjectBucketHit(document, hit) {
|
|
776
|
-
if (hit.type === "entity") {
|
|
777
|
-
const qid = parseEntityQid(hit.id);
|
|
778
|
-
if (qid === void 0) {
|
|
779
|
-
return hit;
|
|
780
|
-
}
|
|
781
|
-
const mentions = await document.mentions.listByQid(qid);
|
|
782
|
-
const [first] = [...mentions].sort(compareMentions);
|
|
783
|
-
if (first === void 0) {
|
|
784
|
-
return hit;
|
|
785
|
-
}
|
|
786
|
-
return {
|
|
787
|
-
...hit,
|
|
788
|
-
chapter: first.chapterId,
|
|
789
|
-
position: {
|
|
790
|
-
chapter: first.chapterId,
|
|
791
|
-
sentence: first.sentenceIndex ?? 0
|
|
792
|
-
},
|
|
793
|
-
snippet: first.note ?? first.surface,
|
|
794
|
-
title: selectEntityLabel(mentions)
|
|
795
|
-
};
|
|
796
|
-
}
|
|
797
|
-
if (hit.type === "triple") {
|
|
798
|
-
return hit;
|
|
799
|
-
}
|
|
800
|
-
return hit;
|
|
801
|
-
}
|
|
802
|
-
async function hydrateCachedChunkBucketHit(document, hit) {
|
|
803
|
-
const chunkId = parseSearchPropertyIntegerOwnerId(
|
|
804
|
-
hit.id.slice("wikg://chunk/".length)
|
|
805
|
-
);
|
|
806
|
-
const node = await document.chunks.getById(chunkId);
|
|
807
|
-
if (node === void 0) {
|
|
808
|
-
return void 0;
|
|
809
|
-
}
|
|
810
|
-
const { position: _position, ...baseHit } = hit;
|
|
811
|
-
const position = createNodePosition(node.sentenceIds);
|
|
812
|
-
return {
|
|
813
|
-
...baseHit,
|
|
814
|
-
chapter: node.sentenceId[0],
|
|
815
|
-
field: "title",
|
|
816
|
-
...position === void 0 ? {} : { position },
|
|
817
|
-
snippet: createSnippet(node.content),
|
|
818
|
-
title: node.label
|
|
819
|
-
};
|
|
820
|
-
}
|
|
821
|
-
function compareChapterTitleIndexHits(left, right) {
|
|
822
|
-
return compareNumbers(right.score, left.score) || compareNumbers(
|
|
823
|
-
parseSearchPropertyIntegerOwnerId(left.ownerId),
|
|
824
|
-
parseSearchPropertyIntegerOwnerId(right.ownerId)
|
|
825
|
-
);
|
|
826
|
-
}
|
|
827
|
-
function compareTextIndexHits(left, right) {
|
|
828
|
-
return compareNumbers(left.rank, right.rank) || compareNumbers(left.chapterId, right.chapterId) || compareNumbers(left.sentenceIndex, right.sentenceIndex) || compareNumbers(left.kind, right.kind);
|
|
829
|
-
}
|
|
830
|
-
function isAfterChapterTitleKey(hit, key) {
|
|
831
|
-
if (key === void 0) {
|
|
832
|
-
return true;
|
|
833
|
-
}
|
|
834
|
-
return compareChapterTitleIndexHits(
|
|
835
|
-
{
|
|
836
|
-
...hit,
|
|
837
|
-
ownerId: String(key.chapterId),
|
|
838
|
-
score: key.score
|
|
839
|
-
},
|
|
840
|
-
hit
|
|
841
|
-
) < 0;
|
|
842
|
-
}
|
|
843
|
-
function isAfterTextKey(hit, key) {
|
|
844
|
-
if (key === void 0) {
|
|
845
|
-
return true;
|
|
846
|
-
}
|
|
847
|
-
return compareTextIndexHits(
|
|
848
|
-
{
|
|
849
|
-
chapterId: key.chapterId,
|
|
850
|
-
kind: key.kind,
|
|
851
|
-
rank: key.rank,
|
|
852
|
-
score: 0,
|
|
853
|
-
sentenceIndex: key.sentenceIndex,
|
|
854
|
-
wordsCount: 0
|
|
855
|
-
},
|
|
856
|
-
hit
|
|
857
|
-
) < 0;
|
|
858
|
-
}
|
|
859
|
-
function getObjectBucketCursorId(hit) {
|
|
860
|
-
if (hit.type !== "triple") {
|
|
861
|
-
return hit.id.replace(/^wikg:\/\/entity\//u, "");
|
|
862
|
-
}
|
|
863
|
-
const triple = parseTripleCursorId(hit.id);
|
|
864
|
-
return triple ?? hit.id;
|
|
865
|
-
}
|
|
866
|
-
function parseTripleCursorId(id) {
|
|
867
|
-
const match = /^wikg:\/\/triple\/([^/]+)\/([^/]+)\/([^/]+)$/u.exec(id);
|
|
868
|
-
if (match?.[1] === void 0 || match[2] === void 0 || match[3] === void 0) {
|
|
869
|
-
return void 0;
|
|
870
|
-
}
|
|
871
|
-
return `${match[1]}${decodeURIComponent(match[2])}${match[3]}`;
|
|
872
|
-
}
|
|
873
|
-
function tryDecodeBucketSearchSessionCursor(cursor) {
|
|
874
|
-
try {
|
|
875
|
-
return decodeBucketSearchSessionCursor(cursor);
|
|
876
|
-
} catch {
|
|
877
|
-
return void 0;
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
async function rebuildArchiveSearchIndex(document, progress) {
|
|
881
|
-
const input = await createSearchIndexRecords(document, progress);
|
|
882
|
-
if (await readSearchIndexStatus(document, input) === "dirty") {
|
|
883
|
-
await document.deleteSearchIndexDatabase();
|
|
884
|
-
}
|
|
885
|
-
await ensureSearchIndex(document, input, progress);
|
|
886
|
-
}
|
|
887
|
-
async function isArchiveSearchIndexCurrent(document) {
|
|
888
|
-
return await readArchiveSearchIndexStatus(document) === "current";
|
|
889
|
-
}
|
|
890
|
-
async function readArchiveSearchIndexStatus(document) {
|
|
891
|
-
return await readSearchIndexStatus(
|
|
892
|
-
document,
|
|
893
|
-
await createSearchIndexRecords(document)
|
|
894
|
-
);
|
|
895
|
-
}
|
|
896
|
-
async function clearDirtyArchiveSearchIndex(document) {
|
|
897
|
-
if (await readArchiveSearchIndexStatus(document) === "dirty") {
|
|
898
|
-
await document.deleteSearchIndexDatabase();
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
async function createArchiveSearchIndexFingerprint(document) {
|
|
902
|
-
return createSearchIndexFingerprint(await createSearchIndexRecords(document));
|
|
903
|
-
}
|
|
904
|
-
async function grepArchiveObjects(document, query, options = {}) {
|
|
905
|
-
const search = createPhraseSearch(query);
|
|
906
|
-
if (search === void 0) {
|
|
907
|
-
return createFindResult(
|
|
908
|
-
query,
|
|
909
|
-
[],
|
|
910
|
-
{ ...options, match: "all" },
|
|
911
|
-
[],
|
|
912
|
-
"exact"
|
|
913
|
-
);
|
|
914
|
-
}
|
|
915
|
-
const hits = [];
|
|
916
|
-
hits.push(...findMeta(await document.readBookMeta(), search));
|
|
917
|
-
hits.push(...await findChapters(document, search));
|
|
918
|
-
hits.push(...await findNodes(document, search));
|
|
919
|
-
return createFindResult(
|
|
920
|
-
query,
|
|
921
|
-
hits,
|
|
922
|
-
{ ...options, match: "all" },
|
|
923
|
-
[query.trim().toLowerCase()],
|
|
924
|
-
"exact"
|
|
925
|
-
);
|
|
926
|
-
}
|
|
927
|
-
async function findArchiveObjectsIndexed(document, query, options) {
|
|
928
|
-
if (!await isArchiveSearchIndexCurrent(document)) {
|
|
929
|
-
throw new Error(
|
|
930
|
-
"Wiki Graph search index is missing or outdated. Run `<archive-uri>/index enable` before searching."
|
|
931
|
-
);
|
|
932
|
-
}
|
|
933
|
-
const result = await querySearchIndex(document, query, {
|
|
934
|
-
...options.chapters === void 0 ? {} : { chapters: options.chapters },
|
|
935
|
-
...options.match === void 0 ? {} : { match: options.match },
|
|
936
|
-
...createSearchIndexQueryLimitOptions(options),
|
|
937
|
-
types: options.types ?? null
|
|
938
|
-
});
|
|
939
|
-
return result === void 0 ? void 0 : {
|
|
940
|
-
hits: await hydrateSearchIndexHits(
|
|
941
|
-
document,
|
|
942
|
-
result,
|
|
943
|
-
createSearchIndexHydrationOptions(options)
|
|
944
|
-
),
|
|
945
|
-
result
|
|
946
|
-
};
|
|
947
|
-
}
|
|
948
|
-
async function queryRequiredSearchIndex(document, query, options) {
|
|
949
|
-
if (!await isArchiveSearchIndexCurrent(document)) {
|
|
950
|
-
throw new Error(
|
|
951
|
-
"Wiki Graph search index is missing or outdated. Run `<archive-uri>/index enable` before searching."
|
|
952
|
-
);
|
|
953
|
-
}
|
|
954
|
-
return await querySearchIndex(document, query, options);
|
|
955
|
-
}
|
|
956
|
-
async function hydrateSearchIndexHits(document, result, options = {}) {
|
|
957
|
-
const chapters = new Map(
|
|
958
|
-
(await listChapters(document)).map((chapter) => [
|
|
959
|
-
chapter.chapterId,
|
|
960
|
-
chapter
|
|
961
|
-
])
|
|
962
|
-
);
|
|
963
|
-
const hits = [];
|
|
964
|
-
for (const hit of result.objectHits) {
|
|
965
|
-
const hydrated = await hydrateSearchObjectHit(document, chapters, hit);
|
|
966
|
-
if (hydrated !== void 0) {
|
|
967
|
-
hits.push(withSearchTerms(hydrated, result.terms));
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
const textHits = options.textHitLimit === void 0 ? result.textHits : result.textHits.slice(0, options.textHitLimit);
|
|
971
|
-
for (const hit of textHits) {
|
|
972
|
-
const hydrated = await hydrateSearchTextHit(document, chapters, hit);
|
|
973
|
-
if (hydrated !== void 0) {
|
|
974
|
-
hits.push(withSearchTerms(hydrated, result.terms));
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
return hits;
|
|
978
|
-
}
|
|
979
|
-
function createSearchIndexHydrationOptions(options) {
|
|
980
|
-
if (!isTextOnlySearch(options) || options.limit === void 0) {
|
|
981
|
-
return {};
|
|
982
|
-
}
|
|
983
|
-
return { textHitLimit: createTextOnlySearchCacheWindow(options.limit) };
|
|
984
|
-
}
|
|
985
|
-
function createSearchIndexQueryLimitOptions(options) {
|
|
986
|
-
if (!isTextOnlySearch(options) || options.limit === void 0) {
|
|
987
|
-
return {};
|
|
988
|
-
}
|
|
989
|
-
return { textHitLimit: createTextOnlySearchCacheWindow(options.limit) };
|
|
990
|
-
}
|
|
991
|
-
function createTextOnlySearchCacheWindow(limit) {
|
|
992
|
-
return Math.max(limit + 1, TEXT_ONLY_SEARCH_CACHE_WINDOW);
|
|
993
|
-
}
|
|
994
|
-
function isTextOnlySearch(options) {
|
|
995
|
-
return options.types !== void 0 && options.types.length > 0 && options.types.every((type) => type === "source" || type === "summary");
|
|
996
|
-
}
|
|
997
|
-
function withSearchTerms(hit, terms) {
|
|
998
|
-
return {
|
|
999
|
-
...hit,
|
|
1000
|
-
matchCount: terms.length,
|
|
1001
|
-
matchedTerms: terms,
|
|
1002
|
-
missingTerms: []
|
|
1003
|
-
};
|
|
1004
|
-
}
|
|
1005
|
-
async function hydrateSearchObjectHit(document, chapters, hit) {
|
|
1006
|
-
switch (hit.ownerKind) {
|
|
1007
|
-
case SEARCH_OBJECT_PROPERTY_OWNER_KIND.chapter: {
|
|
1008
|
-
const chapterId = parseSearchPropertyIntegerOwnerId(hit.ownerId);
|
|
1009
|
-
const chapter = chapters.get(chapterId);
|
|
1010
|
-
if (chapter === void 0) {
|
|
1011
|
-
return void 0;
|
|
1012
|
-
}
|
|
1013
|
-
const title = chapter.title ?? `[chapter ${chapter.chapterId}]`;
|
|
1014
|
-
return {
|
|
1015
|
-
chapter: chapter.chapterId,
|
|
1016
|
-
field: "title",
|
|
1017
|
-
id: formatChapterTitleId(chapter.chapterId),
|
|
1018
|
-
matchCount: 1,
|
|
1019
|
-
position: { chapter: chapter.chapterId },
|
|
1020
|
-
score: hit.score,
|
|
1021
|
-
snippet: title,
|
|
1022
|
-
title,
|
|
1023
|
-
type: "chapter-title"
|
|
1024
|
-
};
|
|
1025
|
-
}
|
|
1026
|
-
case SEARCH_OBJECT_PROPERTY_OWNER_KIND.chunk: {
|
|
1027
|
-
const chunkId = parseSearchPropertyIntegerOwnerId(hit.ownerId);
|
|
1028
|
-
const node = await document.chunks.getById(chunkId);
|
|
1029
|
-
if (node === void 0) {
|
|
1030
|
-
return void 0;
|
|
1031
|
-
}
|
|
1032
|
-
const position = createNodePosition(node.sentenceIds);
|
|
1033
|
-
const isLabel = hit.propertyKind === SEARCH_OBJECT_PROPERTY_KIND.label;
|
|
1034
|
-
return {
|
|
1035
|
-
chapter: node.sentenceId[0],
|
|
1036
|
-
field: isLabel ? "title" : "content",
|
|
1037
|
-
id: formatNodeId(node.id),
|
|
1038
|
-
matchCount: 1,
|
|
1039
|
-
...position === void 0 ? {} : { position },
|
|
1040
|
-
score: hit.score,
|
|
1041
|
-
snippet: isLabel ? node.label : createSnippet(node.content),
|
|
1042
|
-
title: node.label,
|
|
1043
|
-
type: "node"
|
|
1044
|
-
};
|
|
1045
|
-
}
|
|
1046
|
-
case SEARCH_OBJECT_PROPERTY_OWNER_KIND.entity:
|
|
1047
|
-
return void 0;
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
function parseSearchPropertyIntegerOwnerId(ownerId) {
|
|
1051
|
-
const value = Number(ownerId);
|
|
1052
|
-
if (!Number.isSafeInteger(value)) {
|
|
1053
|
-
throw new Error(`Invalid search property owner id: ${ownerId}`);
|
|
1054
|
-
}
|
|
1055
|
-
return value;
|
|
1056
|
-
}
|
|
1057
|
-
async function hydrateSearchTextHit(document, chapters, hit) {
|
|
1058
|
-
const stream = hit.kind === TEXT_SENTENCE_KIND.source ? "source" : "summary";
|
|
1059
|
-
const chapter = chapters.get(hit.chapterId);
|
|
1060
|
-
if (chapter === void 0) {
|
|
1061
|
-
return void 0;
|
|
1062
|
-
}
|
|
1063
|
-
const range = await readTextStreamRange(
|
|
1064
|
-
document,
|
|
1065
|
-
hit.chapterId,
|
|
1066
|
-
stream,
|
|
1067
|
-
hit.sentenceIndex,
|
|
1068
|
-
hit.sentenceIndex
|
|
1069
|
-
);
|
|
1070
|
-
return {
|
|
1071
|
-
chapter: hit.chapterId,
|
|
1072
|
-
field: stream,
|
|
1073
|
-
id: range.id,
|
|
1074
|
-
matchCount: 1,
|
|
1075
|
-
position: {
|
|
1076
|
-
chapter: hit.chapterId,
|
|
1077
|
-
sentence: hit.sentenceIndex
|
|
1078
|
-
},
|
|
1079
|
-
score: hit.score,
|
|
1080
|
-
snippet: createSnippet(range.text),
|
|
1081
|
-
title: chapter.title ?? `[chapter ${hit.chapterId}]`,
|
|
1082
|
-
type: stream
|
|
1083
|
-
};
|
|
1084
|
-
}
|
|
1085
|
-
async function createSearchIndexRecords(document, progress) {
|
|
1086
|
-
const objectProperties = [];
|
|
1087
|
-
const textSentences = [];
|
|
1088
|
-
const chapters = await listChapters(document);
|
|
1089
|
-
let chapterDone = 0;
|
|
1090
|
-
for (const chapter of chapters) {
|
|
1091
|
-
const title = chapter.title ?? `[chapter ${chapter.chapterId}]`;
|
|
1092
|
-
objectProperties.push({
|
|
1093
|
-
chapterId: chapter.chapterId,
|
|
1094
|
-
ownerId: String(chapter.chapterId),
|
|
1095
|
-
ownerKind: SEARCH_OBJECT_PROPERTY_OWNER_KIND.chapter,
|
|
1096
|
-
propertyKind: SEARCH_OBJECT_PROPERTY_KIND.title,
|
|
1097
|
-
text: title
|
|
1098
|
-
});
|
|
1099
|
-
textSentences.push(
|
|
1100
|
-
...await createTextStreamSearchIndexRecords(
|
|
1101
|
-
document,
|
|
1102
|
-
chapter.chapterId,
|
|
1103
|
-
"summary",
|
|
1104
|
-
title
|
|
1105
|
-
)
|
|
1106
|
-
);
|
|
1107
|
-
textSentences.push(
|
|
1108
|
-
...await createTextStreamSearchIndexRecords(
|
|
1109
|
-
document,
|
|
1110
|
-
chapter.chapterId,
|
|
1111
|
-
"source",
|
|
1112
|
-
title
|
|
1113
|
-
)
|
|
1114
|
-
);
|
|
1115
|
-
chapterDone += 1;
|
|
1116
|
-
await progress?.({
|
|
1117
|
-
done: chapterDone,
|
|
1118
|
-
phase: "collecting",
|
|
1119
|
-
total: chapters.length,
|
|
1120
|
-
unit: "chapter"
|
|
1121
|
-
});
|
|
1122
|
-
}
|
|
1123
|
-
for (const node of await document.chunks.listAll()) {
|
|
1124
|
-
objectProperties.push({
|
|
1125
|
-
chapterId: node.sentenceId[0],
|
|
1126
|
-
ownerId: String(node.id),
|
|
1127
|
-
ownerKind: SEARCH_OBJECT_PROPERTY_OWNER_KIND.chunk,
|
|
1128
|
-
propertyKind: SEARCH_OBJECT_PROPERTY_KIND.label,
|
|
1129
|
-
text: node.label
|
|
1130
|
-
});
|
|
1131
|
-
objectProperties.push({
|
|
1132
|
-
chapterId: node.sentenceId[0],
|
|
1133
|
-
ownerId: String(node.id),
|
|
1134
|
-
ownerKind: SEARCH_OBJECT_PROPERTY_OWNER_KIND.chunk,
|
|
1135
|
-
propertyKind: SEARCH_OBJECT_PROPERTY_KIND.content,
|
|
1136
|
-
text: node.content
|
|
1137
|
-
});
|
|
1138
|
-
}
|
|
1139
|
-
for (const mention of await document.mentions.listAll()) {
|
|
1140
|
-
objectProperties.push({
|
|
1141
|
-
chapterId: mention.chapterId,
|
|
1142
|
-
ownerId: mention.qid,
|
|
1143
|
-
ownerKind: SEARCH_OBJECT_PROPERTY_OWNER_KIND.entity,
|
|
1144
|
-
propertyKind: SEARCH_OBJECT_PROPERTY_KIND.surface,
|
|
1145
|
-
text: mention.surface
|
|
1146
|
-
});
|
|
1147
|
-
}
|
|
1148
|
-
return { objectProperties, textSentences };
|
|
1149
|
-
}
|
|
1150
|
-
async function createTextStreamSearchIndexRecords(document, chapterId, stream, _title) {
|
|
1151
|
-
const index = await createTextStreamIndex(document, chapterId, stream);
|
|
1152
|
-
return index.sentences.map((sentence) => ({
|
|
1153
|
-
chapterId,
|
|
1154
|
-
kind: stream === "source" ? TEXT_SENTENCE_KIND.source : TEXT_SENTENCE_KIND.summary,
|
|
1155
|
-
sentenceIndex: sentence.globalIndex,
|
|
1156
|
-
text: sentence.text,
|
|
1157
|
-
wordsCount: sentence.wordsCount
|
|
1158
|
-
}));
|
|
1159
|
-
}
|
|
1160
|
-
async function readArchiveText(document, id) {
|
|
1161
|
-
const reference = parseArchiveReference(id);
|
|
1162
|
-
switch (reference.type) {
|
|
1163
|
-
case "chapter":
|
|
1164
|
-
throw new Error(
|
|
1165
|
-
`Chapter ${formatChapterId(reference.id)} is a scope URI, not a readable object.`
|
|
1166
|
-
);
|
|
1167
|
-
case "chapter-title": {
|
|
1168
|
-
const chapter = await requireChapter(document, reference.id);
|
|
1169
|
-
return chapter.title ?? `[chapter ${reference.id}]`;
|
|
1170
|
-
}
|
|
1171
|
-
case "fragment":
|
|
1172
|
-
return (await readSourceFragment(
|
|
1173
|
-
document,
|
|
1174
|
-
reference.serialId,
|
|
1175
|
-
reference.fragmentId
|
|
1176
|
-
)).text;
|
|
1177
|
-
case "summary": {
|
|
1178
|
-
const summary = await readTextStreamText(
|
|
1179
|
-
document,
|
|
1180
|
-
reference.id,
|
|
1181
|
-
"summary"
|
|
1182
|
-
);
|
|
1183
|
-
if (summary.trim() === "") {
|
|
1184
|
-
throw new Error(`Summary ${formatSummaryId(reference.id)} is missing.`);
|
|
1185
|
-
}
|
|
1186
|
-
return summary;
|
|
1187
|
-
}
|
|
1188
|
-
case "node": {
|
|
1189
|
-
const { node } = await requireNode(document, reference.id);
|
|
1190
|
-
return node.content;
|
|
1191
|
-
}
|
|
1192
|
-
case "meta": {
|
|
1193
|
-
return formatMetaText(await document.readBookMeta());
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
async function readArchivePage(document, id, options = {}) {
|
|
1198
|
-
if (isWikiGraphObjectUri(id)) {
|
|
1199
|
-
return await readWikiGraphPage(
|
|
1200
|
-
document,
|
|
1201
|
-
normalizeWikiGraphObjectUri(id),
|
|
1202
|
-
options
|
|
1203
|
-
);
|
|
1204
|
-
}
|
|
1205
|
-
const reference = parseArchiveReference(id);
|
|
1206
|
-
switch (reference.type) {
|
|
1207
|
-
case "chapter": {
|
|
1208
|
-
throw new Error(
|
|
1209
|
-
`Chapter ${formatChapterId(reference.id)} is a scope URI, not a readable object. Use wikg://chapter/${reference.id}/title or wikg://chapter/${reference.id}/state.`
|
|
1210
|
-
);
|
|
1211
|
-
}
|
|
1212
|
-
case "chapter-title": {
|
|
1213
|
-
const chapter = await requireChapter(document, reference.id);
|
|
1214
|
-
return {
|
|
1215
|
-
id: formatChapterTitleId(reference.id),
|
|
1216
|
-
title: chapter.title ?? `[chapter ${reference.id}]`,
|
|
1217
|
-
type: "chapter-title"
|
|
1218
|
-
};
|
|
1219
|
-
}
|
|
1220
|
-
case "fragment": {
|
|
1221
|
-
const [fragment, relatedNodes, fragmentIds] = await Promise.all([
|
|
1222
|
-
readSourceFragment(document, reference.serialId, reference.fragmentId),
|
|
1223
|
-
listFragmentNodes(document, reference.serialId, reference.fragmentId),
|
|
1224
|
-
document.getSerialFragments(reference.serialId).listFragmentIds()
|
|
1225
|
-
]);
|
|
1226
|
-
const fragmentIndex = fragmentIds.indexOf(reference.fragmentId);
|
|
1227
|
-
const previousFragmentId = fragmentIndex > 0 ? fragmentIds[fragmentIndex - 1] : void 0;
|
|
1228
|
-
const nextFragmentId = fragmentIndex >= 0 && fragmentIndex < fragmentIds.length - 1 ? fragmentIds[fragmentIndex + 1] : void 0;
|
|
1229
|
-
return {
|
|
1230
|
-
fragment,
|
|
1231
|
-
id: fragment.id,
|
|
1232
|
-
nextFragmentId: nextFragmentId === void 0 ? void 0 : formatFragmentId(reference.serialId, nextFragmentId),
|
|
1233
|
-
nodes: relatedNodes,
|
|
1234
|
-
previousFragmentId: previousFragmentId === void 0 ? void 0 : formatFragmentId(reference.serialId, previousFragmentId),
|
|
1235
|
-
title: fragment.id,
|
|
1236
|
-
type: "fragment"
|
|
1237
|
-
};
|
|
1238
|
-
}
|
|
1239
|
-
case "meta":
|
|
1240
|
-
return {
|
|
1241
|
-
...createMetaPage(await document.readBookMeta()),
|
|
1242
|
-
id: ARCHIVE_ROOT_ID,
|
|
1243
|
-
type: "meta"
|
|
1244
|
-
};
|
|
1245
|
-
case "node": {
|
|
1246
|
-
const { chapterId, node } = await requireNode(document, reference.id);
|
|
1247
|
-
const [neighbors, sourceFragments] = await Promise.all([
|
|
1248
|
-
listGraphNeighbors(document, chapterId, reference.id),
|
|
1249
|
-
readNodeSourceFragments(document, node)
|
|
1250
|
-
]);
|
|
1251
|
-
const outgoing = neighbors.filter(
|
|
1252
|
-
(neighbor) => neighbor.direction === "outgoing"
|
|
1253
|
-
);
|
|
1254
|
-
const incoming = neighbors.filter(
|
|
1255
|
-
(neighbor) => neighbor.direction === "incoming"
|
|
1256
|
-
);
|
|
1257
|
-
return {
|
|
1258
|
-
generatedNodeSummary: node.content,
|
|
1259
|
-
id: formatNodeId(node.id),
|
|
1260
|
-
incoming,
|
|
1261
|
-
neighbors,
|
|
1262
|
-
outgoing,
|
|
1263
|
-
position: createNodePosition(node.sentenceIds),
|
|
1264
|
-
sourceFragments,
|
|
1265
|
-
title: node.label,
|
|
1266
|
-
type: "node"
|
|
1267
|
-
};
|
|
1268
|
-
}
|
|
1269
|
-
case "summary": {
|
|
1270
|
-
const chapter = await requireChapter(document, reference.id);
|
|
1271
|
-
const content = await readTextStreamText(
|
|
1272
|
-
document,
|
|
1273
|
-
reference.id,
|
|
1274
|
-
"summary"
|
|
1275
|
-
);
|
|
1276
|
-
if (content.trim() === "") {
|
|
1277
|
-
throw new Error(`Summary ${formatSummaryId(reference.id)} is missing.`);
|
|
1278
|
-
}
|
|
1279
|
-
return {
|
|
1280
|
-
content,
|
|
1281
|
-
id: formatSummaryId(reference.id),
|
|
1282
|
-
title: chapter.title ?? `[chapter ${reference.id}]`,
|
|
1283
|
-
type: "summary"
|
|
1284
|
-
};
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
async function readWikiGraphPage(document, uri, options = {}) {
|
|
1289
|
-
uri = normalizeWikiGraphObjectUri(uri);
|
|
1290
|
-
const reference = parseWikiGraphReference(uri);
|
|
1291
|
-
switch (reference.type) {
|
|
1292
|
-
case "meta":
|
|
1293
|
-
return await readArchivePage(document, ARCHIVE_ROOT_ID, options);
|
|
1294
|
-
case "chapter":
|
|
1295
|
-
throw new Error(
|
|
1296
|
-
`wikg://chapter/${reference.chapterId} is a scope URI, not a readable object. Use wikg://chapter/${reference.chapterId}/title or wikg://chapter/${reference.chapterId}/state.`
|
|
1297
|
-
);
|
|
1298
|
-
case "chapter-title":
|
|
1299
|
-
return await readArchivePage(
|
|
1300
|
-
document,
|
|
1301
|
-
formatChapterTitleId(reference.chapterId),
|
|
1302
|
-
options
|
|
1303
|
-
);
|
|
1304
|
-
case "chapter-state": {
|
|
1305
|
-
const details = await requireChapter(document, reference.chapterId);
|
|
1306
|
-
const targets = await createChapterState(document, details);
|
|
1307
|
-
return {
|
|
1308
|
-
id: reference.target === void 0 ? `wikg://chapter/${reference.chapterId}/state` : `wikg://chapter/${reference.chapterId}/state/${reference.target}`,
|
|
1309
|
-
...reference.target === void 0 ? { state: targets } : { target: reference.target, value: targets[reference.target] },
|
|
1310
|
-
type: "state"
|
|
1311
|
-
};
|
|
1312
|
-
}
|
|
1313
|
-
case "chapter-tree":
|
|
1314
|
-
return {
|
|
1315
|
-
id: "chapter-tree",
|
|
1316
|
-
title: "Chapter tree",
|
|
1317
|
-
tree: await getChapterTree(document),
|
|
1318
|
-
type: "chapter-tree"
|
|
1319
|
-
};
|
|
1320
|
-
case "entity": {
|
|
1321
|
-
const mentions = filterMentionsByChapter(
|
|
1322
|
-
await document.mentions.listByQid(reference.qid),
|
|
1323
|
-
reference.chapterId
|
|
1324
|
-
);
|
|
1325
|
-
if (mentions.length === 0) {
|
|
1326
|
-
throw new Error(`Entity ${uri} was not found in this archive.`);
|
|
1327
|
-
}
|
|
1328
|
-
return {
|
|
1329
|
-
evidence: await createMentionEvidencePreview(
|
|
1330
|
-
document,
|
|
1331
|
-
mentions,
|
|
1332
|
-
options.evidenceLimit,
|
|
1333
|
-
createEvidenceReadContext(),
|
|
1334
|
-
options.sourceContext ?? DEFAULT_SOURCE_CONTEXT,
|
|
1335
|
-
options.order ?? "doc-asc"
|
|
1336
|
-
),
|
|
1337
|
-
id: uri,
|
|
1338
|
-
label: selectEntityLabel(mentions),
|
|
1339
|
-
labels: selectEntityLabels(mentions),
|
|
1340
|
-
mentionCount: mentions.length,
|
|
1341
|
-
qid: reference.qid,
|
|
1342
|
-
type: "entity"
|
|
1343
|
-
};
|
|
1344
|
-
}
|
|
1345
|
-
case "entity-wikipage":
|
|
1346
|
-
return {
|
|
1347
|
-
...await resolveEntityWikipage(reference.qid, options),
|
|
1348
|
-
id: uri,
|
|
1349
|
-
type: "entity-wikipage"
|
|
1350
|
-
};
|
|
1351
|
-
case "triple": {
|
|
1352
|
-
const links = await filterMentionLinksByChapter(
|
|
1353
|
-
document,
|
|
1354
|
-
await document.mentionLinks.listByTriple({
|
|
1355
|
-
objectQid: reference.objectQid,
|
|
1356
|
-
predicate: reference.predicate,
|
|
1357
|
-
subjectQid: reference.subjectQid
|
|
1358
|
-
}),
|
|
1359
|
-
reference.chapterId
|
|
1360
|
-
);
|
|
1361
|
-
if (links.length === 0) {
|
|
1362
|
-
throw new Error(`Triple ${uri} was not found in this archive.`);
|
|
1363
|
-
}
|
|
1364
|
-
return {
|
|
1365
|
-
evidence: await createMentionLinkEvidencePreview(
|
|
1366
|
-
document,
|
|
1367
|
-
links,
|
|
1368
|
-
options.evidenceLimit,
|
|
1369
|
-
createEvidenceReadContext(),
|
|
1370
|
-
options.sourceContext ?? DEFAULT_SOURCE_CONTEXT,
|
|
1371
|
-
options.order ?? "doc-asc"
|
|
1372
|
-
),
|
|
1373
|
-
id: uri,
|
|
1374
|
-
label: await createTriplePageLabel(document, reference),
|
|
1375
|
-
objectQid: reference.objectQid,
|
|
1376
|
-
predicate: reference.predicate,
|
|
1377
|
-
subjectQid: reference.subjectQid,
|
|
1378
|
-
type: "triple"
|
|
1379
|
-
};
|
|
1380
|
-
}
|
|
1381
|
-
case "chunk": {
|
|
1382
|
-
if (reference.chapterId !== void 0) {
|
|
1383
|
-
const { chapterId } = await requireNode(document, reference.id);
|
|
1384
|
-
if (chapterId !== reference.chapterId) {
|
|
1385
|
-
throw new Error(`Chunk ${uri} was not found in this archive.`);
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
return await readArchivePage(
|
|
1389
|
-
document,
|
|
1390
|
-
formatNodeId(reference.id),
|
|
1391
|
-
options
|
|
1392
|
-
);
|
|
1393
|
-
}
|
|
1394
|
-
case "text-stream":
|
|
1395
|
-
return {
|
|
1396
|
-
...options.backlinks === true ? { backlinks: await createTextStreamBacklinks(document, reference) } : {},
|
|
1397
|
-
fragment: await createTextStreamRangeFragment(document, reference),
|
|
1398
|
-
id: uri,
|
|
1399
|
-
nextFragmentId: void 0,
|
|
1400
|
-
nodes: [],
|
|
1401
|
-
previousFragmentId: void 0,
|
|
1402
|
-
title: uri,
|
|
1403
|
-
type: "fragment"
|
|
1404
|
-
};
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
async function listArchiveLinks(document, id, direction) {
|
|
1408
|
-
return (await listAllArchiveLinks(document, id)).filter(
|
|
1409
|
-
(neighbor) => direction === "links" ? neighbor.direction === "outgoing" : neighbor.direction === "incoming"
|
|
1410
|
-
);
|
|
1411
|
-
}
|
|
1412
|
-
async function listAllArchiveLinks(document, id) {
|
|
1413
|
-
if (isWikiGraphObjectUri(id)) {
|
|
1414
|
-
id = normalizeWikiGraphObjectUri(id);
|
|
1415
|
-
const reference2 = parseWikiGraphReference(id);
|
|
1416
|
-
if (reference2.type !== "chunk") {
|
|
1417
|
-
return [];
|
|
1418
|
-
}
|
|
1419
|
-
const { chapterId: chapterId2 } = await requireNode(document, reference2.id);
|
|
1420
|
-
if (reference2.chapterId !== void 0 && reference2.chapterId !== chapterId2) {
|
|
1421
|
-
throw new Error(`Chunk ${id} was not found in this archive.`);
|
|
1422
|
-
}
|
|
1423
|
-
return await listGraphNeighbors(document, chapterId2, reference2.id);
|
|
1424
|
-
}
|
|
1425
|
-
const reference = parseArchiveReference(id);
|
|
1426
|
-
if (reference.type !== "node") {
|
|
1427
|
-
return [];
|
|
1428
|
-
}
|
|
1429
|
-
const { chapterId } = await requireNode(document, reference.id);
|
|
1430
|
-
return await listGraphNeighbors(document, chapterId, reference.id);
|
|
1431
|
-
}
|
|
1432
|
-
async function listRelatedArchiveObjects(document, id, options = {}) {
|
|
1433
|
-
if (isWikiGraphObjectUri(id)) {
|
|
1434
|
-
return await listRelatedWikiGraphObjects(
|
|
1435
|
-
document,
|
|
1436
|
-
normalizeWikiGraphObjectUri(id),
|
|
1437
|
-
options
|
|
1438
|
-
);
|
|
1439
|
-
}
|
|
1440
|
-
const reference = parseArchiveReference(id);
|
|
1441
|
-
if (reference.type !== "node") {
|
|
1442
|
-
rejectRelatedRole(options.role, id);
|
|
1443
|
-
return paginateRelatedItems([], options);
|
|
1444
|
-
}
|
|
1445
|
-
rejectRelatedRole(options.role, id);
|
|
1446
|
-
const documentOrders = await document.serials.listDocumentOrders();
|
|
1447
|
-
const { chapterId } = await requireNode(document, reference.id);
|
|
1448
|
-
const items = sortGraphNeighborsByListMode(
|
|
1449
|
-
await listGraphNeighbors(document, chapterId, reference.id),
|
|
1450
|
-
documentOrders,
|
|
1451
|
-
options.order ?? "doc-asc"
|
|
1452
|
-
).map((neighbor) => ({
|
|
1453
|
-
id: formatNodeId(neighbor.node.id),
|
|
1454
|
-
label: neighbor.node.label,
|
|
1455
|
-
summary: neighbor.node.content,
|
|
1456
|
-
type: "node"
|
|
1457
|
-
}));
|
|
1458
|
-
return await hydrateRelatedItemsEvidence(
|
|
1459
|
-
document,
|
|
1460
|
-
await filterAndSortChunkRelatedItemsByQuery(document, items, options.query),
|
|
1461
|
-
options
|
|
1462
|
-
);
|
|
1463
|
-
}
|
|
1464
|
-
async function listRelatedWikiGraphObjects(document, uri, options) {
|
|
1465
|
-
const reference = parseWikiGraphReference(uri);
|
|
1466
|
-
switch (reference.type) {
|
|
1467
|
-
case "chapter": {
|
|
1468
|
-
throw new Error(`Related is not available for scope URI: ${uri}`);
|
|
1469
|
-
}
|
|
1470
|
-
case "chapter-title":
|
|
1471
|
-
rejectRelatedRole(options.role, uri);
|
|
1472
|
-
return paginateRelatedItems([], options);
|
|
1473
|
-
case "chunk": {
|
|
1474
|
-
rejectRelatedRole(options.role, uri);
|
|
1475
|
-
const { chapterId } = await requireNode(document, reference.id);
|
|
1476
|
-
if (reference.chapterId !== void 0 && reference.chapterId !== chapterId) {
|
|
1477
|
-
throw new Error(`Chunk ${uri} was not found in this archive.`);
|
|
1478
|
-
}
|
|
1479
|
-
const items = sortGraphNeighborsByListMode(
|
|
1480
|
-
await listGraphNeighbors(document, chapterId, reference.id),
|
|
1481
|
-
await document.serials.listDocumentOrders(),
|
|
1482
|
-
options.order ?? "doc-asc"
|
|
1483
|
-
).map((neighbor) => ({
|
|
1484
|
-
id: formatNodeId(neighbor.node.id),
|
|
1485
|
-
label: neighbor.node.label,
|
|
1486
|
-
summary: neighbor.node.content,
|
|
1487
|
-
type: "node"
|
|
1488
|
-
}));
|
|
1489
|
-
return await hydrateRelatedItemsEvidence(
|
|
1490
|
-
document,
|
|
1491
|
-
await filterAndSortChunkRelatedItemsByQuery(
|
|
1492
|
-
document,
|
|
1493
|
-
items,
|
|
1494
|
-
options.query
|
|
1495
|
-
),
|
|
1496
|
-
options
|
|
1497
|
-
);
|
|
1498
|
-
}
|
|
1499
|
-
case "text-stream": {
|
|
1500
|
-
rejectRelatedQuery(options.query, uri);
|
|
1501
|
-
rejectRelatedRole(options.role, uri);
|
|
1502
|
-
const chapter = await requireChapter(document, reference.chapterId);
|
|
1503
|
-
return await hydrateRelatedItemsEvidence(
|
|
1504
|
-
document,
|
|
1505
|
-
[
|
|
1506
|
-
{
|
|
1507
|
-
id: formatChapterId(reference.chapterId),
|
|
1508
|
-
label: chapter.title ?? `[chapter ${reference.chapterId}]`,
|
|
1509
|
-
summary: `${chapter.stage}; ${chapter.fragmentCount} fragments`,
|
|
1510
|
-
type: "chapter"
|
|
1511
|
-
}
|
|
1512
|
-
],
|
|
1513
|
-
options
|
|
1514
|
-
);
|
|
1515
|
-
}
|
|
1516
|
-
case "entity":
|
|
1517
|
-
return await listRelatedEntityObjects(document, reference, options);
|
|
1518
|
-
case "triple":
|
|
1519
|
-
throw new Error(
|
|
1520
|
-
`Related is only available for chunk and entity objects: ${uri}`
|
|
1521
|
-
);
|
|
1522
|
-
case "chapter-tree":
|
|
1523
|
-
case "entity-wikipage":
|
|
1524
|
-
case "meta":
|
|
1525
|
-
case "chapter-state":
|
|
1526
|
-
rejectRelatedQuery(options.query, uri);
|
|
1527
|
-
rejectRelatedRole(options.role, uri);
|
|
1528
|
-
return paginateRelatedItems([], options);
|
|
1529
|
-
}
|
|
1530
|
-
}
|
|
1531
|
-
async function resolveEntityWikipage(qid, options) {
|
|
1532
|
-
const [en, zh] = await Promise.all([
|
|
1533
|
-
resolveEntityWikipageLocale(qid, "en", "enwiki", options),
|
|
1534
|
-
resolveEntityWikipageLocale(qid, "zh", "zhwiki", options)
|
|
1535
|
-
]);
|
|
1536
|
-
return { en, zh };
|
|
1537
|
-
}
|
|
1538
|
-
async function resolveEntityWikipageLocale(qid, language, wiki, options) {
|
|
1539
|
-
const resolver = await WikipageResolver.open({
|
|
1540
|
-
...options.wikipageResolverOptions,
|
|
1541
|
-
language,
|
|
1542
|
-
wiki
|
|
1543
|
-
});
|
|
1544
|
-
try {
|
|
1545
|
-
const [resolution] = await resolver.resolveQids([qid]);
|
|
1546
|
-
if (resolution === void 0) {
|
|
1547
|
-
return null;
|
|
1548
|
-
}
|
|
1549
|
-
return createEntityWikipageLocale(resolution, wiki);
|
|
1550
|
-
} finally {
|
|
1551
|
-
await resolver.close();
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
function createEntityWikipageLocale(resolution, wiki) {
|
|
1555
|
-
const sitelink = resolution.sitelinks?.find((item) => item.wiki === wiki) ?? (resolution.sitelink?.wiki === wiki ? resolution.sitelink : void 0);
|
|
1556
|
-
if (sitelink === void 0) {
|
|
1557
|
-
return null;
|
|
1558
|
-
}
|
|
1559
|
-
return {
|
|
1560
|
-
...resolution.description === void 0 ? {} : { description: resolution.description },
|
|
1561
|
-
title: sitelink.title,
|
|
1562
|
-
url: formatWikipediaPageUrl(sitelink)
|
|
1563
|
-
};
|
|
1564
|
-
}
|
|
1565
|
-
function formatWikipediaPageUrl(sitelink) {
|
|
1566
|
-
const language = sitelink.wiki === "zhwiki" ? "zh" : "en";
|
|
1567
|
-
return `https://${language}.wikipedia.org/wiki/${encodeURIComponent(
|
|
1568
|
-
sitelink.title.replace(/ /gu, "_")
|
|
1569
|
-
)}`;
|
|
1570
|
-
}
|
|
1571
|
-
async function listRelatedEntityObjects(document, reference, options) {
|
|
1572
|
-
const mentions = filterMentionsByChapter(
|
|
1573
|
-
await document.mentions.listByQid(reference.qid),
|
|
1574
|
-
reference.chapterId
|
|
1575
|
-
);
|
|
1576
|
-
if (mentions.length === 0) {
|
|
1577
|
-
throw new Error(
|
|
1578
|
-
`Entity ${formatEntityUri(reference.qid)} was not found in this archive.`
|
|
1579
|
-
);
|
|
1580
|
-
}
|
|
1581
|
-
const chapters = [
|
|
1582
|
-
...new Set(mentions.map((mention) => mention.chapterId))
|
|
1583
|
-
].sort(compareNumbers);
|
|
1584
|
-
const role = options.role ?? "any";
|
|
1585
|
-
const triplesById = /* @__PURE__ */ new Map();
|
|
1586
|
-
for (const chapterId of chapters) {
|
|
1587
|
-
for (const link of await document.mentionLinks.listByChapter(chapterId)) {
|
|
1588
|
-
const [source, target] = await Promise.all([
|
|
1589
|
-
document.mentions.getById(link.sourceMentionId),
|
|
1590
|
-
document.mentions.getById(link.targetMentionId)
|
|
1591
|
-
]);
|
|
1592
|
-
if (source === void 0 || target === void 0) {
|
|
1593
|
-
continue;
|
|
1594
|
-
}
|
|
1595
|
-
if (!matchesRelatedEntityRole(source.qid, target.qid, reference.qid, role)) {
|
|
1596
|
-
continue;
|
|
1597
|
-
}
|
|
1598
|
-
const id = formatTripleUri(source.qid, link.predicate, target.qid);
|
|
1599
|
-
const existing = triplesById.get(id);
|
|
1600
|
-
if (existing !== void 0) {
|
|
1601
|
-
triplesById.set(id, {
|
|
1602
|
-
...existing,
|
|
1603
|
-
evidenceLinks: [...existing.evidenceLinks ?? [], link]
|
|
1604
|
-
});
|
|
1605
|
-
continue;
|
|
1606
|
-
}
|
|
1607
|
-
triplesById.set(id, {
|
|
1608
|
-
evidenceLinks: [link],
|
|
1609
|
-
id,
|
|
1610
|
-
label: `${source.surface} ${link.predicate} ${target.surface}`,
|
|
1611
|
-
objectLabel: target.surface,
|
|
1612
|
-
objectQid: target.qid,
|
|
1613
|
-
predicate: link.predicate,
|
|
1614
|
-
subjectLabel: source.surface,
|
|
1615
|
-
subjectQid: source.qid,
|
|
1616
|
-
summary: `${source.qid} ${link.predicate} ${target.qid}`,
|
|
1617
|
-
type: "triple"
|
|
1618
|
-
});
|
|
1619
|
-
}
|
|
1620
|
-
}
|
|
1621
|
-
return await hydrateRelatedItemsEvidence(
|
|
1622
|
-
document,
|
|
1623
|
-
await filterAndSortEntityRelatedTriplesByQuery(
|
|
1624
|
-
document,
|
|
1625
|
-
sortRelatedItemsByListMode(
|
|
1626
|
-
[...triplesById.values()],
|
|
1627
|
-
options.order ?? "doc-asc",
|
|
1628
|
-
await document.serials.listDocumentOrders()
|
|
1629
|
-
),
|
|
1630
|
-
reference.qid,
|
|
1631
|
-
options.query
|
|
1632
|
-
),
|
|
1633
|
-
options
|
|
1634
|
-
);
|
|
1635
|
-
}
|
|
1636
|
-
async function filterAndSortChunkRelatedItemsByQuery(document, items, query) {
|
|
1637
|
-
if (query === void 0) {
|
|
1638
|
-
return items;
|
|
1639
|
-
}
|
|
1640
|
-
const indexResult = await queryRequiredSearchIndex(document, query, {
|
|
1641
|
-
types: ["node"]
|
|
1642
|
-
});
|
|
1643
|
-
if (indexResult === void 0) {
|
|
1644
|
-
return [];
|
|
1645
|
-
}
|
|
1646
|
-
const scoresByChunkId = /* @__PURE__ */ new Map();
|
|
1647
|
-
const allowedChunkIds = new Set(
|
|
1648
|
-
items.flatMap((item) => {
|
|
1649
|
-
if (item.type !== "node") {
|
|
1650
|
-
return [];
|
|
1651
|
-
}
|
|
1652
|
-
const reference = parseArchiveReference(item.id);
|
|
1653
|
-
return reference.type === "node" ? [reference.id] : [];
|
|
1654
|
-
})
|
|
1655
|
-
);
|
|
1656
|
-
for (const hit of indexResult.objectHits) {
|
|
1657
|
-
if (hit.ownerKind !== SEARCH_OBJECT_PROPERTY_OWNER_KIND.chunk || !allowedChunkIds.has(Number(hit.ownerId))) {
|
|
1658
|
-
continue;
|
|
1659
|
-
}
|
|
1660
|
-
const chunkId = Number(hit.ownerId);
|
|
1661
|
-
const scores = scoresByChunkId.get(chunkId) ?? [];
|
|
1662
|
-
scores.push(hit.score);
|
|
1663
|
-
scoresByChunkId.set(chunkId, scores);
|
|
1664
|
-
}
|
|
1665
|
-
return items.flatMap((item) => {
|
|
1666
|
-
if (item.type !== "node") {
|
|
1667
|
-
return [];
|
|
1668
|
-
}
|
|
1669
|
-
const reference = parseArchiveReference(item.id);
|
|
1670
|
-
if (reference.type !== "node") {
|
|
1671
|
-
return [];
|
|
1672
|
-
}
|
|
1673
|
-
const scores = scoresByChunkId.get(reference.id);
|
|
1674
|
-
return scores === void 0 ? [] : [{ ...item, score: aggregateEvidenceScores(scores) }];
|
|
1675
|
-
}).sort(compareRelatedQueryItems);
|
|
1676
|
-
}
|
|
1677
|
-
async function filterAndSortEntityRelatedTriplesByQuery(document, items, anchorQid, query) {
|
|
1678
|
-
if (query === void 0) {
|
|
1679
|
-
return items;
|
|
1680
|
-
}
|
|
1681
|
-
const scope = await createEntityRelatedQueryScope(document, items, anchorQid);
|
|
1682
|
-
const indexResult = await queryRequiredSearchIndex(document, query, {
|
|
1683
|
-
chapters: [...scope.chapterIds],
|
|
1684
|
-
types: ["entity", "source"]
|
|
1685
|
-
});
|
|
1686
|
-
if (indexResult === void 0) {
|
|
1687
|
-
return [];
|
|
1688
|
-
}
|
|
1689
|
-
const sentenceScores = new Map(
|
|
1690
|
-
indexResult.textHits.filter((hit) => hit.kind === TEXT_SENTENCE_KIND.source).map(
|
|
1691
|
-
(hit) => [
|
|
1692
|
-
createSentenceHitKey(hit.chapterId, hit.sentenceIndex),
|
|
1693
|
-
hit.score
|
|
1694
|
-
]
|
|
1695
|
-
)
|
|
1696
|
-
);
|
|
1697
|
-
const endpointScoresByKey = /* @__PURE__ */ new Map();
|
|
1698
|
-
for (const hit of indexResult.objectHits) {
|
|
1699
|
-
if (hit.ownerKind !== SEARCH_OBJECT_PROPERTY_OWNER_KIND.entity || hit.ownerId === anchorQid || hit.chapterId === void 0) {
|
|
1700
|
-
continue;
|
|
1701
|
-
}
|
|
1702
|
-
const key = createEntityRelatedEndpointKey(hit.ownerId, hit.chapterId);
|
|
1703
|
-
const scores = endpointScoresByKey.get(key) ?? [];
|
|
1704
|
-
scores.push(hit.score);
|
|
1705
|
-
endpointScoresByKey.set(key, scores);
|
|
1706
|
-
}
|
|
1707
|
-
return items.flatMap((item) => {
|
|
1708
|
-
if (item.type !== "triple") {
|
|
1709
|
-
return [];
|
|
1710
|
-
}
|
|
1711
|
-
const scores = [
|
|
1712
|
-
...[...scope.endpointKeysByTripleId.get(item.id) ?? []].flatMap(
|
|
1713
|
-
(key) => endpointScoresByKey.get(key) ?? []
|
|
1714
|
-
),
|
|
1715
|
-
...(item.evidenceLinks ?? []).flatMap(
|
|
1716
|
-
(link) => link.evidenceSentenceIds.flatMap(([chapterId, sentenceIndex]) => {
|
|
1717
|
-
const score = sentenceScores.get(
|
|
1718
|
-
createSentenceHitKey(chapterId, sentenceIndex)
|
|
1719
|
-
);
|
|
1720
|
-
return score === void 0 ? [] : [score];
|
|
1721
|
-
})
|
|
1722
|
-
)
|
|
1723
|
-
];
|
|
1724
|
-
return scores.length === 0 ? [] : [{ ...item, score: aggregateEvidenceScores(scores) }];
|
|
1725
|
-
}).sort(compareRelatedQueryItems);
|
|
1726
|
-
}
|
|
1727
|
-
async function createEntityRelatedQueryScope(document, items, anchorQid) {
|
|
1728
|
-
const chapterIds = /* @__PURE__ */ new Set();
|
|
1729
|
-
const endpointKeysByTripleId = /* @__PURE__ */ new Map();
|
|
1730
|
-
const mentionCache = /* @__PURE__ */ new Map();
|
|
1731
|
-
for (const item of items) {
|
|
1732
|
-
if (item.type !== "triple") {
|
|
1733
|
-
continue;
|
|
1734
|
-
}
|
|
1735
|
-
const endpointKeys = /* @__PURE__ */ new Set();
|
|
1736
|
-
for (const link of item.evidenceLinks ?? []) {
|
|
1737
|
-
for (const [chapterId] of link.evidenceSentenceIds) {
|
|
1738
|
-
chapterIds.add(chapterId);
|
|
1739
|
-
}
|
|
1740
|
-
const [source, target] = await Promise.all([
|
|
1741
|
-
getCachedMention(document, mentionCache, link.sourceMentionId),
|
|
1742
|
-
getCachedMention(document, mentionCache, link.targetMentionId)
|
|
1743
|
-
]);
|
|
1744
|
-
for (const mention of [source, target]) {
|
|
1745
|
-
if (mention === void 0 || mention.qid === anchorQid) {
|
|
1746
|
-
continue;
|
|
1747
|
-
}
|
|
1748
|
-
chapterIds.add(mention.chapterId);
|
|
1749
|
-
endpointKeys.add(
|
|
1750
|
-
createEntityRelatedEndpointKey(mention.qid, mention.chapterId)
|
|
1751
|
-
);
|
|
1752
|
-
}
|
|
1753
|
-
}
|
|
1754
|
-
endpointKeysByTripleId.set(item.id, endpointKeys);
|
|
1755
|
-
}
|
|
1756
|
-
return { chapterIds, endpointKeysByTripleId };
|
|
1757
|
-
}
|
|
1758
|
-
async function getCachedMention(document, cache, mentionId) {
|
|
1759
|
-
if (!cache.has(mentionId)) {
|
|
1760
|
-
cache.set(mentionId, await document.mentions.getById(mentionId));
|
|
1761
|
-
}
|
|
1762
|
-
return cache.get(mentionId);
|
|
1763
|
-
}
|
|
1764
|
-
function createEntityRelatedEndpointKey(qid, chapterId) {
|
|
1765
|
-
return `${qid}:${chapterId}`;
|
|
1766
|
-
}
|
|
1767
|
-
function compareRelatedQueryItems(left, right) {
|
|
1768
|
-
const scoreComparison = (right.score ?? 0) - (left.score ?? 0);
|
|
1769
|
-
if (scoreComparison !== 0) {
|
|
1770
|
-
return scoreComparison;
|
|
1771
|
-
}
|
|
1772
|
-
return compareListHits(
|
|
1773
|
-
createFindHitFromListItem(left),
|
|
1774
|
-
createFindHitFromListItem(right),
|
|
1775
|
-
"doc-asc"
|
|
1776
|
-
);
|
|
1777
|
-
}
|
|
1778
|
-
function sortRelatedItemsByListMode(items, order = "doc-asc", documentOrders) {
|
|
1779
|
-
return [...items].sort(
|
|
1780
|
-
(left, right) => compareListHits(
|
|
1781
|
-
createFindHitFromListItem(left, documentOrders),
|
|
1782
|
-
createFindHitFromListItem(right, documentOrders),
|
|
1783
|
-
order
|
|
1784
|
-
)
|
|
1785
|
-
);
|
|
1786
|
-
}
|
|
1787
|
-
function sortGraphNeighborsByListMode(neighbors, documentOrders, order) {
|
|
1788
|
-
const direction = order === "doc-asc" ? 1 : -1;
|
|
1789
|
-
return [...neighbors].sort(
|
|
1790
|
-
(left, right) => compareSentenceIds(
|
|
1791
|
-
getFirstGraphNodeSentenceId(left.node),
|
|
1792
|
-
getFirstGraphNodeSentenceId(right.node),
|
|
1793
|
-
documentOrders
|
|
1794
|
-
) * direction
|
|
1795
|
-
);
|
|
1796
|
-
}
|
|
1797
|
-
function createFindHitFromListItem(item, documentOrders) {
|
|
1798
|
-
const position = createListItemPosition(item, documentOrders);
|
|
1799
|
-
const score = item.type === "triple" ? item.evidenceLinks?.length ?? 0 : void 0;
|
|
1800
|
-
return {
|
|
1801
|
-
field: "title",
|
|
1802
|
-
id: item.id,
|
|
1803
|
-
...position === void 0 ? {} : { position },
|
|
1804
|
-
...score === void 0 ? {} : { score },
|
|
1805
|
-
snippet: item.summary,
|
|
1806
|
-
title: item.label,
|
|
1807
|
-
type: toFindObjectType(item.type)
|
|
1808
|
-
};
|
|
1809
|
-
}
|
|
1810
|
-
function toFindObjectType(type) {
|
|
1811
|
-
switch (type) {
|
|
1812
|
-
case "edge":
|
|
1813
|
-
case "state":
|
|
1814
|
-
return "meta";
|
|
1815
|
-
default:
|
|
1816
|
-
return type;
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
function createListItemPosition(item, documentOrders) {
|
|
1820
|
-
if (item.type === "triple") {
|
|
1821
|
-
return createFirstMentionLinkPosition(
|
|
1822
|
-
item.evidenceLinks ?? [],
|
|
1823
|
-
documentOrders
|
|
1824
|
-
);
|
|
1825
|
-
}
|
|
1826
|
-
return void 0;
|
|
1827
|
-
}
|
|
1828
|
-
function createFirstMentionLinkPosition(links, documentOrders) {
|
|
1829
|
-
const sentenceIds = links.flatMap((link) => link.evidenceSentenceIds);
|
|
1830
|
-
const [first] = sentenceIds.sort(
|
|
1831
|
-
(left, right) => compareSentenceIds(left, right, documentOrders)
|
|
1832
|
-
);
|
|
1833
|
-
return first === void 0 ? void 0 : createSentencePosition(first, documentOrders);
|
|
1834
|
-
}
|
|
1835
|
-
function getFirstGraphNodeSentenceId(node) {
|
|
1836
|
-
return [...node.sentenceIds].sort(compareSentenceIds)[0] ?? [
|
|
1837
|
-
Number.MAX_SAFE_INTEGER,
|
|
1838
|
-
Number.MAX_SAFE_INTEGER
|
|
1839
|
-
];
|
|
1840
|
-
}
|
|
1841
|
-
function matchesRelatedEntityRole(subjectQid, objectQid, qid, role) {
|
|
1842
|
-
const isSubject = subjectQid === qid;
|
|
1843
|
-
const isObject = objectQid === qid;
|
|
1844
|
-
const isSelf = isSubject && isObject;
|
|
1845
|
-
switch (role) {
|
|
1846
|
-
case "any":
|
|
1847
|
-
return isSubject || isObject;
|
|
1848
|
-
case "subject":
|
|
1849
|
-
return isSubject && !isSelf;
|
|
1850
|
-
case "object":
|
|
1851
|
-
return isObject && !isSelf;
|
|
1852
|
-
case "self":
|
|
1853
|
-
return isSelf;
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
|
-
function rejectRelatedRole(role, id) {
|
|
1857
|
-
if (role !== void 0 && role !== "any") {
|
|
1858
|
-
throw new Error(`--role is only available for entity related: ${id}`);
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
|
-
function rejectRelatedQuery(query, id) {
|
|
1862
|
-
if (query !== void 0) {
|
|
1863
|
-
throw new Error(
|
|
1864
|
-
`Related query is only available for chunk and entity: ${id}`
|
|
1865
|
-
);
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
async function hydrateRelatedItemsEvidence(document, items, options) {
|
|
1869
|
-
const page = paginateRelatedItems(items, options);
|
|
1870
|
-
if (options.evidenceLimit === void 0) {
|
|
1871
|
-
return {
|
|
1872
|
-
...page,
|
|
1873
|
-
items: page.items.map((item) => {
|
|
1874
|
-
if (item.type !== "triple") {
|
|
1875
|
-
return item;
|
|
1876
|
-
}
|
|
1877
|
-
const { evidenceLinks: _evidenceLinks, ...publicItem } = item;
|
|
1878
|
-
return publicItem;
|
|
1879
|
-
})
|
|
1880
|
-
};
|
|
1881
|
-
}
|
|
1882
|
-
const context = createEvidenceReadContext();
|
|
1883
|
-
const evidenceLimit = options.evidenceLimit;
|
|
1884
|
-
return {
|
|
1885
|
-
...page,
|
|
1886
|
-
items: await Promise.all(
|
|
1887
|
-
page.items.map(async (item) => {
|
|
1888
|
-
if (item.evidence !== void 0) {
|
|
1889
|
-
return item;
|
|
1890
|
-
}
|
|
1891
|
-
if (item.type === "triple") {
|
|
1892
|
-
const evidence = await createMentionLinkEvidencePreview(
|
|
1893
|
-
document,
|
|
1894
|
-
item.evidenceLinks ?? [],
|
|
1895
|
-
evidenceLimit,
|
|
1896
|
-
context,
|
|
1897
|
-
options.sourceContext ?? DEFAULT_SOURCE_CONTEXT,
|
|
1898
|
-
options.order ?? "doc-asc"
|
|
1899
|
-
);
|
|
1900
|
-
const { evidenceLinks: _evidenceLinks, ...publicItem } = item;
|
|
1901
|
-
return { ...publicItem, evidence };
|
|
1902
|
-
}
|
|
1903
|
-
if (item.type === "node") {
|
|
1904
|
-
const reference = parseArchiveReference(item.id);
|
|
1905
|
-
if (reference.type !== "node") {
|
|
1906
|
-
return item;
|
|
1907
|
-
}
|
|
1908
|
-
const { node } = await requireNode(document, reference.id);
|
|
1909
|
-
return {
|
|
1910
|
-
...item,
|
|
1911
|
-
evidence: await createSourceEvidencePreview(
|
|
1912
|
-
document,
|
|
1913
|
-
createNodeEvidenceRanges(node),
|
|
1914
|
-
evidenceLimit,
|
|
1915
|
-
context,
|
|
1916
|
-
options.sourceContext ?? DEFAULT_SOURCE_CONTEXT,
|
|
1917
|
-
options.order ?? "doc-asc"
|
|
1918
|
-
)
|
|
1919
|
-
};
|
|
1920
|
-
}
|
|
1921
|
-
return item;
|
|
1922
|
-
})
|
|
1923
|
-
)
|
|
1924
|
-
};
|
|
1925
|
-
}
|
|
1926
|
-
function paginateRelatedItems(items, options) {
|
|
1927
|
-
const limit = options.limit ?? 20;
|
|
1928
|
-
const offset = parseRelatedCursor(options.cursor);
|
|
1929
|
-
const pageItems = items.slice(offset, offset + limit);
|
|
1930
|
-
const nextOffset = offset + pageItems.length;
|
|
1931
|
-
return {
|
|
1932
|
-
items: pageItems,
|
|
1933
|
-
limit,
|
|
1934
|
-
nextCursor: nextOffset >= items.length ? null : String(nextOffset)
|
|
1935
|
-
};
|
|
1936
|
-
}
|
|
1937
|
-
function parseRelatedCursor(cursor) {
|
|
1938
|
-
if (cursor === void 0) {
|
|
1939
|
-
return 0;
|
|
1940
|
-
}
|
|
1941
|
-
if (!/^(0|[1-9][0-9]*)$/u.test(cursor)) {
|
|
1942
|
-
throw new Error(`Invalid related cursor: ${cursor}`);
|
|
1943
|
-
}
|
|
1944
|
-
return Number(cursor);
|
|
1945
|
-
}
|
|
1946
|
-
async function listArchiveEvidence(document, uri, options = {}) {
|
|
1947
|
-
const reference = parseWikiGraphReference(uri);
|
|
1948
|
-
switch (reference.type) {
|
|
1949
|
-
case "chapter":
|
|
1950
|
-
case "chapter-title":
|
|
1951
|
-
case "chapter-state":
|
|
1952
|
-
case "chapter-tree":
|
|
1953
|
-
case "entity-wikipage":
|
|
1954
|
-
case "meta":
|
|
1955
|
-
case "text-stream":
|
|
1956
|
-
throw new Error(`Evidence is not available for ${uri}.`);
|
|
1957
|
-
case "chunk": {
|
|
1958
|
-
const { chapterId, node } = await requireNode(document, reference.id);
|
|
1959
|
-
if (reference.chapterId !== void 0 && reference.chapterId !== chapterId) {
|
|
1960
|
-
throw new Error(`Chunk ${uri} was not found in this archive.`);
|
|
1961
|
-
}
|
|
1962
|
-
return await createSourceEvidencePage(
|
|
1963
|
-
document,
|
|
1964
|
-
createNodeEvidenceRanges(node),
|
|
1965
|
-
options
|
|
1966
|
-
);
|
|
1967
|
-
}
|
|
1968
|
-
case "entity":
|
|
1969
|
-
return await createSourceEvidencePage(
|
|
1970
|
-
document,
|
|
1971
|
-
await createMentionEvidenceRanges(
|
|
1972
|
-
document,
|
|
1973
|
-
filterMentionsByChapter(
|
|
1974
|
-
await document.mentions.listByQid(reference.qid),
|
|
1975
|
-
reference.chapterId
|
|
1976
|
-
)
|
|
1977
|
-
),
|
|
1978
|
-
options
|
|
1979
|
-
);
|
|
1980
|
-
case "triple":
|
|
1981
|
-
return await createSourceEvidencePage(
|
|
1982
|
-
document,
|
|
1983
|
-
createMentionLinkEvidenceRanges(
|
|
1984
|
-
document,
|
|
1985
|
-
await filterMentionLinksByChapter(
|
|
1986
|
-
document,
|
|
1987
|
-
await document.mentionLinks.listByTriple({
|
|
1988
|
-
objectQid: reference.objectQid,
|
|
1989
|
-
predicate: reference.predicate,
|
|
1990
|
-
subjectQid: reference.subjectQid
|
|
1991
|
-
}),
|
|
1992
|
-
reference.chapterId
|
|
1993
|
-
)
|
|
1994
|
-
),
|
|
1995
|
-
options
|
|
1996
|
-
);
|
|
1997
|
-
}
|
|
1998
|
-
}
|
|
1999
|
-
async function packArchiveContext(document, id, budget) {
|
|
2000
|
-
validatePackReference(id);
|
|
2001
|
-
const [anchor, related] = await Promise.all([
|
|
2002
|
-
readArchivePage(document, id, { evidenceLimit: 3 }),
|
|
2003
|
-
listRelatedArchiveObjects(document, id, { evidenceLimit: 3 })
|
|
2004
|
-
]);
|
|
2005
|
-
return {
|
|
2006
|
-
anchor,
|
|
2007
|
-
budget,
|
|
2008
|
-
related: related.items
|
|
2009
|
-
};
|
|
2010
|
-
}
|
|
2011
|
-
function validatePackReference(id) {
|
|
2012
|
-
const reference = parseWikiGraphReference(id);
|
|
2013
|
-
switch (reference.type) {
|
|
2014
|
-
case "chunk":
|
|
2015
|
-
case "entity":
|
|
2016
|
-
return;
|
|
2017
|
-
case "chapter":
|
|
2018
|
-
case "chapter-title":
|
|
2019
|
-
case "chapter-state":
|
|
2020
|
-
case "chapter-tree":
|
|
2021
|
-
case "entity-wikipage":
|
|
2022
|
-
case "meta":
|
|
2023
|
-
case "text-stream":
|
|
2024
|
-
throw new Error(
|
|
2025
|
-
`Pack is only available for chunk and entity objects: ${id}`
|
|
2026
|
-
);
|
|
2027
|
-
}
|
|
2028
|
-
}
|
|
2029
|
-
function formatChapterId(chapterId) {
|
|
2030
|
-
return `chapter:${chapterId}`;
|
|
2031
|
-
}
|
|
2032
|
-
function formatChapterTitleId(chapterId) {
|
|
2033
|
-
return `chapter-title:${chapterId}`;
|
|
2034
|
-
}
|
|
2035
|
-
function formatEdgeId(edge) {
|
|
2036
|
-
return `edge:${edge.fromId}->${edge.toId}`;
|
|
2037
|
-
}
|
|
2038
|
-
function formatNodeId(nodeId) {
|
|
2039
|
-
return `node:${nodeId}`;
|
|
2040
|
-
}
|
|
2041
|
-
function formatSummaryId(chapterId) {
|
|
2042
|
-
return `summary:${chapterId}`;
|
|
2043
|
-
}
|
|
2044
|
-
function formatFragmentId(serialId, fragmentId) {
|
|
2045
|
-
return `fragment:${serialId}:${fragmentId}`;
|
|
2046
|
-
}
|
|
2047
|
-
function findEntities(search, context) {
|
|
2048
|
-
const candidatesByQid = /* @__PURE__ */ new Map();
|
|
2049
|
-
for (const { match, mention } of createMentionLexicalHits(
|
|
2050
|
-
context.mentions,
|
|
2051
|
-
search
|
|
2052
|
-
)) {
|
|
2053
|
-
const candidates = candidatesByQid.get(mention.qid) ?? [];
|
|
2054
|
-
candidates.push({
|
|
2055
|
-
hit: {
|
|
2056
|
-
chapter: mention.chapterId,
|
|
2057
|
-
field: "title",
|
|
2058
|
-
id: `wikg://entity/${mention.qid}`,
|
|
2059
|
-
...createFindMatchFields(match),
|
|
2060
|
-
position: {
|
|
2061
|
-
chapter: mention.chapterId,
|
|
2062
|
-
sentence: mention.sentenceIndex ?? 0
|
|
2063
|
-
},
|
|
2064
|
-
snippet: mention.note ?? mention.surface,
|
|
2065
|
-
title: mention.surface,
|
|
2066
|
-
type: "entity"
|
|
2067
|
-
},
|
|
2068
|
-
mention
|
|
2069
|
-
});
|
|
2070
|
-
candidatesByQid.set(mention.qid, candidates);
|
|
2071
|
-
}
|
|
2072
|
-
return [...candidatesByQid.values()].map((candidates) => {
|
|
2073
|
-
const rankedCandidates = [...candidates].sort((left, right) => {
|
|
2074
|
-
const scoreComparison = (right.hit.score ?? 0) - (left.hit.score ?? 0);
|
|
2075
|
-
if (scoreComparison !== 0) {
|
|
2076
|
-
return scoreComparison;
|
|
2077
|
-
}
|
|
2078
|
-
if (left.hit.position === void 0) {
|
|
2079
|
-
return right.hit.position === void 0 ? 0 : 1;
|
|
2080
|
-
}
|
|
2081
|
-
if (right.hit.position === void 0) {
|
|
2082
|
-
return -1;
|
|
2083
|
-
}
|
|
2084
|
-
return compareArchivePositions(left.hit.position, right.hit.position);
|
|
2085
|
-
});
|
|
2086
|
-
const [best] = rankedCandidates;
|
|
2087
|
-
if (best === void 0) {
|
|
2088
|
-
throw new Error("Internal error: entity search candidate is empty.");
|
|
2089
|
-
}
|
|
2090
|
-
return {
|
|
2091
|
-
...best.hit,
|
|
2092
|
-
score: aggregateEvidenceScores(
|
|
2093
|
-
rankedCandidates.map((candidate) => candidate.hit.score ?? 0)
|
|
2094
|
-
),
|
|
2095
|
-
evidenceMentions: rankedCandidates.map((candidate) => ({
|
|
2096
|
-
match: {
|
|
2097
|
-
matchCount: candidate.hit.matchCount ?? 0,
|
|
2098
|
-
matchedTerms: candidate.hit.matchedTerms ?? [],
|
|
2099
|
-
missingTerms: candidate.hit.missingTerms ?? [],
|
|
2100
|
-
score: candidate.hit.score ?? 0
|
|
2101
|
-
},
|
|
2102
|
-
mention: candidate.mention
|
|
2103
|
-
}))
|
|
2104
|
-
};
|
|
2105
|
-
});
|
|
2106
|
-
}
|
|
2107
|
-
async function findTriples(document, search, context) {
|
|
2108
|
-
const mentionsById = new Map(
|
|
2109
|
-
context.mentions.map((mention) => [mention.id, mention])
|
|
2110
|
-
);
|
|
2111
|
-
const hitsByTriple = /* @__PURE__ */ new Map();
|
|
2112
|
-
for (const chapter of await listChapters(document)) {
|
|
2113
|
-
for (const link of await document.mentionLinks.listByChapter(
|
|
2114
|
-
chapter.chapterId
|
|
2115
|
-
)) {
|
|
2116
|
-
const [source, target] = await Promise.all([
|
|
2117
|
-
getMentionForTripleSearch(document, mentionsById, link.sourceMentionId),
|
|
2118
|
-
getMentionForTripleSearch(document, mentionsById, link.targetMentionId)
|
|
2119
|
-
]);
|
|
2120
|
-
if (source === void 0 || target === void 0) {
|
|
2121
|
-
continue;
|
|
2122
|
-
}
|
|
2123
|
-
const text = `${source.surface} ${link.predicate} ${target.surface}`;
|
|
2124
|
-
const match = scoreLexicalText(text, search);
|
|
2125
|
-
if (match === void 0) {
|
|
2126
|
-
continue;
|
|
2127
|
-
}
|
|
2128
|
-
const id = formatTripleUri(source.qid, link.predicate, target.qid);
|
|
2129
|
-
const next = {
|
|
2130
|
-
chapter: source.chapterId,
|
|
2131
|
-
evidenceLinks: [link],
|
|
2132
|
-
field: "content",
|
|
2133
|
-
id,
|
|
2134
|
-
...createFindMatchFields(match),
|
|
2135
|
-
position: {
|
|
2136
|
-
chapter: source.chapterId,
|
|
2137
|
-
sentence: source.sentenceIndex ?? 0
|
|
2138
|
-
},
|
|
2139
|
-
snippet: link.note ?? text,
|
|
2140
|
-
title: text,
|
|
2141
|
-
triple: {
|
|
2142
|
-
objectLabel: target.surface,
|
|
2143
|
-
predicate: link.predicate,
|
|
2144
|
-
subjectLabel: source.surface
|
|
2145
|
-
},
|
|
2146
|
-
type: "triple"
|
|
2147
|
-
};
|
|
2148
|
-
const values = hitsByTriple.get(id) ?? [];
|
|
2149
|
-
values.push(next);
|
|
2150
|
-
hitsByTriple.set(id, values);
|
|
2151
|
-
}
|
|
2152
|
-
}
|
|
2153
|
-
return [...hitsByTriple.values()].map(groupTripleEvidenceHits);
|
|
2154
|
-
}
|
|
2155
|
-
async function listAllMentions(document) {
|
|
2156
|
-
return await document.mentions.listAll();
|
|
2157
|
-
}
|
|
2158
|
-
function groupTripleEvidenceHits(evidenceHits) {
|
|
2159
|
-
const rankedHits = [...evidenceHits].sort(compareFindEvidenceHits);
|
|
2160
|
-
const [best] = rankedHits;
|
|
2161
|
-
if (best === void 0) {
|
|
2162
|
-
throw new Error("Internal error: triple search candidate is empty.");
|
|
2163
|
-
}
|
|
2164
|
-
return {
|
|
2165
|
-
...best,
|
|
2166
|
-
evidenceLinks: rankedHits.flatMap((hit) => hit.evidenceLinks ?? []),
|
|
2167
|
-
score: aggregateEvidenceScores(rankedHits.map((hit) => hit.score ?? 0))
|
|
2168
|
-
};
|
|
2169
|
-
}
|
|
2170
|
-
function listEntityCollection(mentions, documentOrders) {
|
|
2171
|
-
const mentionsByQid = /* @__PURE__ */ new Map();
|
|
2172
|
-
for (const mention of mentions) {
|
|
2173
|
-
const values = mentionsByQid.get(mention.qid) ?? [];
|
|
2174
|
-
values.push(mention);
|
|
2175
|
-
mentionsByQid.set(mention.qid, values);
|
|
2176
|
-
}
|
|
2177
|
-
return [...mentionsByQid.entries()].map(([qid, qidMentions]) => {
|
|
2178
|
-
const [first] = qidMentions.sort(compareMentions);
|
|
2179
|
-
if (first === void 0) {
|
|
2180
|
-
throw new Error("Internal error: entity collection candidate is empty.");
|
|
2181
|
-
}
|
|
2182
|
-
return {
|
|
2183
|
-
chapter: first.chapterId,
|
|
2184
|
-
evidenceMentions: qidMentions.map(
|
|
2185
|
-
(mention) => createUnscoredEntityEvidenceMention(mention)
|
|
2186
|
-
),
|
|
2187
|
-
field: "title",
|
|
2188
|
-
id: `wikg://entity/${qid}`,
|
|
2189
|
-
position: {
|
|
2190
|
-
chapter: first.chapterId,
|
|
2191
|
-
documentOrder: documentOrders?.get(first.chapterId) ?? first.chapterId,
|
|
2192
|
-
sentence: first.sentenceIndex ?? 0
|
|
2193
|
-
},
|
|
2194
|
-
score: qidMentions.length,
|
|
2195
|
-
snippet: `${qidMentions.length} mentions`,
|
|
2196
|
-
title: selectEntityLabel(qidMentions),
|
|
2197
|
-
type: "entity"
|
|
2198
|
-
};
|
|
2199
|
-
});
|
|
2200
|
-
}
|
|
2201
|
-
function listTextStreamSentenceCollection(index, chapterId, stream, title, documentOrder) {
|
|
2202
|
-
return index.sentences.map((sentence) => ({
|
|
2203
|
-
chapter: chapterId,
|
|
2204
|
-
field: stream,
|
|
2205
|
-
id: formatTextStreamRangeUri(
|
|
2206
|
-
chapterId,
|
|
2207
|
-
stream,
|
|
2208
|
-
sentence.globalIndex,
|
|
2209
|
-
sentence.globalIndex
|
|
2210
|
-
),
|
|
2211
|
-
position: {
|
|
2212
|
-
chapter: chapterId,
|
|
2213
|
-
documentOrder: documentOrder ?? chapterId,
|
|
2214
|
-
fragment: sentence.fragmentId,
|
|
2215
|
-
sentence: sentence.localIndex
|
|
2216
|
-
},
|
|
2217
|
-
snippet: createSnippet(sentence.text),
|
|
2218
|
-
title,
|
|
2219
|
-
type: stream === "source" ? "source" : "summary"
|
|
2220
|
-
}));
|
|
2221
|
-
}
|
|
2222
|
-
async function listTripleCollection(document, chapterFilter, documentOrders) {
|
|
2223
|
-
const hitsById = /* @__PURE__ */ new Map();
|
|
2224
|
-
for (const chapter of filterChapters(
|
|
2225
|
-
await listChapters(document),
|
|
2226
|
-
chapterFilter
|
|
2227
|
-
)) {
|
|
2228
|
-
for (const link of await document.mentionLinks.listByChapter(
|
|
2229
|
-
chapter.chapterId
|
|
2230
|
-
)) {
|
|
2231
|
-
const [source, target] = await Promise.all([
|
|
2232
|
-
document.mentions.getById(link.sourceMentionId),
|
|
2233
|
-
document.mentions.getById(link.targetMentionId)
|
|
2234
|
-
]);
|
|
2235
|
-
if (source === void 0 || target === void 0) {
|
|
2236
|
-
continue;
|
|
2237
|
-
}
|
|
2238
|
-
const id = formatTripleUri(source.qid, link.predicate, target.qid);
|
|
2239
|
-
const existing = hitsById.get(id);
|
|
2240
|
-
if (existing !== void 0) {
|
|
2241
|
-
hitsById.set(id, {
|
|
2242
|
-
...existing,
|
|
2243
|
-
evidenceLinks: [...existing.evidenceLinks ?? [], link],
|
|
2244
|
-
score: (existing.evidenceLinks?.length ?? 0) + 1
|
|
2245
|
-
});
|
|
2246
|
-
continue;
|
|
2247
|
-
}
|
|
2248
|
-
hitsById.set(id, {
|
|
2249
|
-
chapter: source.chapterId,
|
|
2250
|
-
evidenceLinks: [link],
|
|
2251
|
-
field: "title",
|
|
2252
|
-
id,
|
|
2253
|
-
position: {
|
|
2254
|
-
chapter: source.chapterId,
|
|
2255
|
-
documentOrder: documentOrders?.get(source.chapterId) ?? source.chapterId,
|
|
2256
|
-
sentence: source.sentenceIndex ?? 0
|
|
2257
|
-
},
|
|
2258
|
-
score: 1,
|
|
2259
|
-
snippet: `${source.surface} ${link.predicate} ${target.surface}`,
|
|
2260
|
-
title: `${source.qid} ${link.predicate} ${target.qid}`,
|
|
2261
|
-
triple: {
|
|
2262
|
-
objectLabel: target.surface,
|
|
2263
|
-
predicate: link.predicate,
|
|
2264
|
-
subjectLabel: source.surface
|
|
2265
|
-
},
|
|
2266
|
-
type: "triple"
|
|
2267
|
-
});
|
|
2268
|
-
}
|
|
2269
|
-
}
|
|
2270
|
-
return [...hitsById.values()];
|
|
2271
|
-
}
|
|
2272
|
-
function compareMentions(left, right) {
|
|
2273
|
-
return compareNumbers(left.chapterId, right.chapterId) || compareNumbers(left.sentenceIndex ?? 0, right.sentenceIndex ?? 0) || left.id.localeCompare(right.id);
|
|
2274
|
-
}
|
|
2275
|
-
async function getMentionForTripleSearch(document, cache, mentionId) {
|
|
2276
|
-
const cached = cache.get(mentionId);
|
|
2277
|
-
if (cached !== void 0) {
|
|
2278
|
-
return cached;
|
|
2279
|
-
}
|
|
2280
|
-
const mention = await document.mentions.getById(mentionId);
|
|
2281
|
-
if (mention !== void 0) {
|
|
2282
|
-
cache.set(mentionId, mention);
|
|
2283
|
-
}
|
|
2284
|
-
return mention;
|
|
2285
|
-
}
|
|
2286
|
-
async function hydrateFindHitEvidence(document, hits, options = {}) {
|
|
2287
|
-
const evidenceContext = createEvidenceReadContext();
|
|
2288
|
-
const hydrated = await Promise.all(
|
|
2289
|
-
hits.map(async (rawHit) => {
|
|
2290
|
-
const displayHit = await hydrateEntityDisplayHit(document, rawHit);
|
|
2291
|
-
const hit = await hydrateTextStreamHitContext(
|
|
2292
|
-
document,
|
|
2293
|
-
displayHit,
|
|
2294
|
-
options.sourceContext ?? DEFAULT_SOURCE_CONTEXT,
|
|
2295
|
-
evidenceContext
|
|
2296
|
-
);
|
|
2297
|
-
if (hit.evidence !== void 0 && hit.evidence.sources.length > 0) {
|
|
2298
|
-
return hit;
|
|
2299
|
-
}
|
|
2300
|
-
if (hit.evidence !== void 0 && hit.type === "entity" && options.sessionId !== void 0) {
|
|
2301
|
-
return await hydrateEntitySessionHitEvidence(
|
|
2302
|
-
document,
|
|
2303
|
-
hit,
|
|
2304
|
-
options.sessionId,
|
|
2305
|
-
options.evidenceLimit,
|
|
2306
|
-
options.sourceContext ?? DEFAULT_SOURCE_CONTEXT,
|
|
2307
|
-
evidenceContext
|
|
2308
|
-
);
|
|
2309
|
-
}
|
|
2310
|
-
if (hit.evidenceLinks !== void 0) {
|
|
2311
|
-
if (options.evidenceLimit === void 0) {
|
|
2312
|
-
const { evidenceLinks: _evidenceLinks2, ...publicHit3 } = hit;
|
|
2313
|
-
return publicHit3;
|
|
2314
|
-
}
|
|
2315
|
-
const evidence2 = await createMentionLinkEvidencePreview(
|
|
2316
|
-
document,
|
|
2317
|
-
hit.evidenceLinks,
|
|
2318
|
-
options.evidenceLimit,
|
|
2319
|
-
evidenceContext,
|
|
2320
|
-
options.sourceContext ?? DEFAULT_SOURCE_CONTEXT,
|
|
2321
|
-
options.order ?? "doc-asc"
|
|
2322
|
-
);
|
|
2323
|
-
const { evidenceLinks: _evidenceLinks, ...publicHit2 } = hit;
|
|
2324
|
-
return {
|
|
2325
|
-
...publicHit2,
|
|
2326
|
-
evidence: evidence2
|
|
2327
|
-
};
|
|
2328
|
-
}
|
|
2329
|
-
if (hit.evidenceMentions === void 0) {
|
|
2330
|
-
return hit;
|
|
2331
|
-
}
|
|
2332
|
-
if (options.evidenceLimit === void 0) {
|
|
2333
|
-
const { evidenceMentions: _evidenceMentions2, ...publicHit2 } = hit;
|
|
2334
|
-
return publicHit2;
|
|
2335
|
-
}
|
|
2336
|
-
const evidence = await createMentionEvidencePreview(
|
|
2337
|
-
document,
|
|
2338
|
-
hit.evidenceMentions.map((item) => item.mention),
|
|
2339
|
-
options.evidenceLimit,
|
|
2340
|
-
evidenceContext,
|
|
2341
|
-
options.sourceContext ?? DEFAULT_SOURCE_CONTEXT,
|
|
2342
|
-
options.order ?? "doc-asc"
|
|
2343
|
-
);
|
|
2344
|
-
const { evidenceMentions: _evidenceMentions, ...publicHit } = hit;
|
|
2345
|
-
return {
|
|
2346
|
-
...publicHit,
|
|
2347
|
-
evidence
|
|
2348
|
-
};
|
|
2349
|
-
})
|
|
2350
|
-
);
|
|
2351
|
-
return await coalesceTextStreamFindHits(document, hydrated, evidenceContext);
|
|
2352
|
-
}
|
|
2353
|
-
async function hydrateEntityDisplayHit(document, hit) {
|
|
2354
|
-
if (hit.type !== "entity") {
|
|
2355
|
-
return hit;
|
|
2356
|
-
}
|
|
2357
|
-
const qid = parseEntityQid(hit.id);
|
|
2358
|
-
if (qid === void 0) {
|
|
2359
|
-
return hit;
|
|
2360
|
-
}
|
|
2361
|
-
if (hit.title !== qid && hit.snippet !== qid) {
|
|
2362
|
-
return hit;
|
|
2363
|
-
}
|
|
2364
|
-
const mentions = await document.mentions.listByQid(qid);
|
|
2365
|
-
const [first] = mentions.sort(compareMentions);
|
|
2366
|
-
if (first === void 0) {
|
|
2367
|
-
return hit;
|
|
2368
|
-
}
|
|
2369
|
-
return {
|
|
2370
|
-
...hit,
|
|
2371
|
-
chapter: first.chapterId,
|
|
2372
|
-
position: {
|
|
2373
|
-
chapter: first.chapterId,
|
|
2374
|
-
sentence: first.sentenceIndex ?? 0
|
|
2375
|
-
},
|
|
2376
|
-
snippet: hit.snippet === qid ? first.note ?? first.surface : hit.snippet,
|
|
2377
|
-
title: hit.title === qid ? selectEntityLabel(mentions) : hit.title
|
|
2378
|
-
};
|
|
2379
|
-
}
|
|
2380
|
-
async function hydrateTextStreamHitContext(document, hit, sourceContext, context) {
|
|
2381
|
-
if (sourceContext <= 0 || hit.type !== "source" && hit.type !== "summary") {
|
|
2382
|
-
return hit;
|
|
2383
|
-
}
|
|
2384
|
-
if (hit.matchCount === void 0 && hit.matchedTerms === void 0) {
|
|
2385
|
-
return hit;
|
|
2386
|
-
}
|
|
2387
|
-
const reference = parseTextStreamHitReference(hit.id);
|
|
2388
|
-
if (reference === void 0) {
|
|
2389
|
-
return hit;
|
|
2390
|
-
}
|
|
2391
|
-
const range = await readTextStreamRange(
|
|
2392
|
-
document,
|
|
2393
|
-
reference.chapterId,
|
|
2394
|
-
reference.stream,
|
|
2395
|
-
reference.startSentenceIndex - sourceContext,
|
|
2396
|
-
reference.endSentenceIndex + sourceContext,
|
|
2397
|
-
context
|
|
2398
|
-
);
|
|
2399
|
-
return {
|
|
2400
|
-
...hit,
|
|
2401
|
-
id: range.id,
|
|
2402
|
-
snippet: range.text
|
|
2403
|
-
};
|
|
2404
|
-
}
|
|
2405
|
-
function parseTextStreamHitReference(uri) {
|
|
2406
|
-
if (!isWikiGraphObjectUri(uri)) {
|
|
2407
|
-
return void 0;
|
|
2408
|
-
}
|
|
2409
|
-
try {
|
|
2410
|
-
const reference = parseWikiGraphReference(normalizeWikiGraphObjectUri(uri));
|
|
2411
|
-
return reference.type === "text-stream" ? reference : void 0;
|
|
2412
|
-
} catch {
|
|
2413
|
-
return void 0;
|
|
2414
|
-
}
|
|
2415
|
-
}
|
|
2416
|
-
async function coalesceTextStreamFindHits(document, hits, context) {
|
|
2417
|
-
const entries = [];
|
|
2418
|
-
for (const hit of hits) {
|
|
2419
|
-
const range = parseSearchTextStreamHitRange(hit);
|
|
2420
|
-
if (range === void 0 || hit.backlinks !== void 0) {
|
|
2421
|
-
entries.push({ hit, type: "hit" });
|
|
2422
|
-
continue;
|
|
2423
|
-
}
|
|
2424
|
-
const overlappingIndexes = entries.map(
|
|
2425
|
-
(entry, index) => entry.type === "range" && areMergeableTextStreamHitRanges(entry.range, range) ? index : -1
|
|
2426
|
-
).filter((index) => index >= 0);
|
|
2427
|
-
if (overlappingIndexes.length === 0) {
|
|
2428
|
-
entries.push({ range, type: "range" });
|
|
2429
|
-
continue;
|
|
2430
|
-
}
|
|
2431
|
-
const firstIndex = overlappingIndexes[0] ?? 0;
|
|
2432
|
-
const ranges = overlappingIndexes.flatMap((index) => {
|
|
2433
|
-
const entry = entries[index];
|
|
2434
|
-
return entry?.type === "range" ? [entry.range] : [];
|
|
2435
|
-
});
|
|
2436
|
-
entries[firstIndex] = {
|
|
2437
|
-
range: await mergeTextStreamHitRangeGroup(
|
|
2438
|
-
document,
|
|
2439
|
-
[...ranges, range],
|
|
2440
|
-
context
|
|
2441
|
-
),
|
|
2442
|
-
type: "range"
|
|
2443
|
-
};
|
|
2444
|
-
for (const index of overlappingIndexes.slice(1).reverse()) {
|
|
2445
|
-
entries.splice(index, 1);
|
|
2446
|
-
}
|
|
2447
|
-
}
|
|
2448
|
-
return entries.map(
|
|
2449
|
-
(entry) => entry.type === "range" ? entry.range.hit : entry.hit
|
|
2450
|
-
);
|
|
2451
|
-
}
|
|
2452
|
-
function parseSearchTextStreamHitRange(hit) {
|
|
2453
|
-
if (hit.type !== "source" && hit.type !== "summary") {
|
|
2454
|
-
return void 0;
|
|
2455
|
-
}
|
|
2456
|
-
if (hit.matchCount === void 0 && hit.matchedTerms === void 0) {
|
|
2457
|
-
return void 0;
|
|
2458
|
-
}
|
|
2459
|
-
const reference = parseTextStreamHitReference(hit.id);
|
|
2460
|
-
if (reference === void 0) {
|
|
2461
|
-
return void 0;
|
|
2462
|
-
}
|
|
2463
|
-
return {
|
|
2464
|
-
chapterId: reference.chapterId,
|
|
2465
|
-
endSentenceIndex: reference.endSentenceIndex,
|
|
2466
|
-
hit,
|
|
2467
|
-
startSentenceIndex: reference.startSentenceIndex,
|
|
2468
|
-
stream: reference.stream
|
|
2469
|
-
};
|
|
2470
|
-
}
|
|
2471
|
-
function areMergeableTextStreamHitRanges(left, right) {
|
|
2472
|
-
return left.chapterId === right.chapterId && left.stream === right.stream && right.startSentenceIndex <= left.endSentenceIndex + 1 && left.startSentenceIndex <= right.endSentenceIndex + 1;
|
|
2473
|
-
}
|
|
2474
|
-
async function mergeTextStreamHitRangeGroup(document, ranges, context) {
|
|
2475
|
-
const [representative] = ranges;
|
|
2476
|
-
if (representative === void 0) {
|
|
2477
|
-
throw new Error(
|
|
2478
|
-
"Internal error: cannot merge empty text stream hit group."
|
|
2479
|
-
);
|
|
2480
|
-
}
|
|
2481
|
-
const startSentenceIndex = Math.min(
|
|
2482
|
-
...ranges.map((range) => range.startSentenceIndex)
|
|
2483
|
-
);
|
|
2484
|
-
const endSentenceIndex = Math.max(
|
|
2485
|
-
...ranges.map((range) => range.endSentenceIndex)
|
|
2486
|
-
);
|
|
2487
|
-
const text = await readTextStreamRange(
|
|
2488
|
-
document,
|
|
2489
|
-
representative.chapterId,
|
|
2490
|
-
representative.stream,
|
|
2491
|
-
startSentenceIndex,
|
|
2492
|
-
endSentenceIndex,
|
|
2493
|
-
context
|
|
2494
|
-
);
|
|
2495
|
-
const hits = ranges.map((range) => range.hit);
|
|
2496
|
-
const scores = hits.map((hit) => hit.score).filter((score) => score !== void 0);
|
|
2497
|
-
return {
|
|
2498
|
-
chapterId: representative.chapterId,
|
|
2499
|
-
endSentenceIndex,
|
|
2500
|
-
hit: {
|
|
2501
|
-
...representative.hit,
|
|
2502
|
-
id: text.id,
|
|
2503
|
-
matchCount: Math.max(...hits.map((hit) => hit.matchCount ?? 0)),
|
|
2504
|
-
matchedTerms: mergeStringLists(
|
|
2505
|
-
hits.flatMap((hit) => hit.matchedTerms ?? [])
|
|
2506
|
-
),
|
|
2507
|
-
missingTerms: mergeStringLists(
|
|
2508
|
-
hits.flatMap((hit) => hit.missingTerms ?? [])
|
|
2509
|
-
),
|
|
2510
|
-
...scores.length === 0 ? {} : { score: Math.max(...scores) },
|
|
2511
|
-
snippet: text.text
|
|
2512
|
-
},
|
|
2513
|
-
startSentenceIndex,
|
|
2514
|
-
stream: representative.stream
|
|
2515
|
-
};
|
|
2516
|
-
}
|
|
2517
|
-
async function hydrateFindResultBacklinks(document, result, options) {
|
|
2518
|
-
return {
|
|
2519
|
-
...result,
|
|
2520
|
-
items: await hydrateFindHitBacklinks(document, result.items, options)
|
|
2521
|
-
};
|
|
2522
|
-
}
|
|
2523
|
-
async function hydrateFindHitBacklinks(document, hits, options) {
|
|
2524
|
-
if (options.backlinks !== true) {
|
|
2525
|
-
return hits;
|
|
2526
|
-
}
|
|
2527
|
-
return await Promise.all(
|
|
2528
|
-
hits.map(async (hit) => {
|
|
2529
|
-
const reference = parseSourceBacklinkReference(hit.id);
|
|
2530
|
-
if (reference === void 0) {
|
|
2531
|
-
return hit;
|
|
2532
|
-
}
|
|
2533
|
-
return {
|
|
2534
|
-
...hit,
|
|
2535
|
-
backlinks: await createTextStreamBacklinks(document, reference)
|
|
2536
|
-
};
|
|
2537
|
-
})
|
|
2538
|
-
);
|
|
2539
|
-
}
|
|
2540
|
-
function parseSourceBacklinkReference(uri) {
|
|
2541
|
-
if (!isWikiGraphObjectUri(uri)) {
|
|
2542
|
-
return void 0;
|
|
2543
|
-
}
|
|
2544
|
-
try {
|
|
2545
|
-
const reference = parseWikiGraphReference(normalizeWikiGraphObjectUri(uri));
|
|
2546
|
-
return reference.type === "text-stream" && reference.stream === "source" ? reference : void 0;
|
|
2547
|
-
} catch {
|
|
2548
|
-
return void 0;
|
|
2549
|
-
}
|
|
2550
|
-
}
|
|
2551
|
-
function createFindEvidenceHydrationOptions(options, sessionId) {
|
|
2552
|
-
return {
|
|
2553
|
-
...options.evidenceLimit === void 0 ? {} : { evidenceLimit: options.evidenceLimit },
|
|
2554
|
-
order: options.order ?? "doc-asc",
|
|
2555
|
-
...sessionId === void 0 ? {} : { sessionId },
|
|
2556
|
-
...options.sourceContext === void 0 ? {} : { sourceContext: options.sourceContext }
|
|
2557
|
-
};
|
|
2558
|
-
}
|
|
2559
|
-
async function createTextStreamBacklinks(document, reference) {
|
|
2560
|
-
if (reference.stream !== "source") {
|
|
2561
|
-
return createEmptyBacklinks();
|
|
2562
|
-
}
|
|
2563
|
-
const sentenceKeys = await createTextStreamRangeSentenceKeySet(
|
|
2564
|
-
document,
|
|
2565
|
-
reference
|
|
2566
|
-
);
|
|
2567
|
-
const [chunks, mentions, links] = await Promise.all([
|
|
2568
|
-
createChunkBacklinkHits(document, sentenceKeys),
|
|
2569
|
-
createEntityBacklinkHits(document, sentenceKeys),
|
|
2570
|
-
createTripleBacklinkHits(document, reference.chapterId, sentenceKeys)
|
|
2571
|
-
]);
|
|
2572
|
-
return {
|
|
2573
|
-
chunks: createBacklinkBucket(chunks),
|
|
2574
|
-
entities: createBacklinkBucket(mentions),
|
|
2575
|
-
triples: createBacklinkBucket(links)
|
|
2576
|
-
};
|
|
2577
|
-
}
|
|
2578
|
-
function createEmptyBacklinks() {
|
|
2579
|
-
return {
|
|
2580
|
-
chunks: createBacklinkBucket([]),
|
|
2581
|
-
entities: createBacklinkBucket([]),
|
|
2582
|
-
triples: createBacklinkBucket([])
|
|
2583
|
-
};
|
|
2584
|
-
}
|
|
2585
|
-
function createBacklinkBucket(hits) {
|
|
2586
|
-
const sorted = [...hits].sort(
|
|
2587
|
-
(left, right) => compareListHits(left, right, "doc-asc")
|
|
2588
|
-
);
|
|
2589
|
-
return {
|
|
2590
|
-
items: sorted,
|
|
2591
|
-
limit: sorted.length,
|
|
2592
|
-
nextCursor: null
|
|
2593
|
-
};
|
|
2594
|
-
}
|
|
2595
|
-
async function createTextStreamRangeSentenceKeySet(document, reference) {
|
|
2596
|
-
const index = await createTextStreamIndex(
|
|
2597
|
-
document,
|
|
2598
|
-
reference.chapterId,
|
|
2599
|
-
reference.stream
|
|
2600
|
-
);
|
|
2601
|
-
const lastSentenceIndex = Math.max(0, index.sentences.length - 1);
|
|
2602
|
-
const start = clampInteger(
|
|
2603
|
-
reference.startSentenceIndex,
|
|
2604
|
-
0,
|
|
2605
|
-
lastSentenceIndex
|
|
2606
|
-
);
|
|
2607
|
-
const end = clampInteger(
|
|
2608
|
-
reference.endSentenceIndex,
|
|
2609
|
-
start,
|
|
2610
|
-
lastSentenceIndex
|
|
2611
|
-
);
|
|
2612
|
-
const keys = /* @__PURE__ */ new Set();
|
|
2613
|
-
for (const sentence of index.sentences.slice(start, end + 1)) {
|
|
2614
|
-
keys.add(formatSentenceKey(reference.chapterId, sentence.globalIndex));
|
|
2615
|
-
}
|
|
2616
|
-
return keys;
|
|
2617
|
-
}
|
|
2618
|
-
async function createChunkBacklinkHits(document, sentenceKeys) {
|
|
2619
|
-
return (await document.chunks.listAll()).filter(
|
|
2620
|
-
(chunk) => chunk.sentenceIds.some(
|
|
2621
|
-
(sentenceId) => sentenceKeys.has(formatSentenceIdKey(sentenceId))
|
|
2622
|
-
)
|
|
2623
|
-
).map((chunk) => {
|
|
2624
|
-
const position = createNodePosition(chunk.sentenceIds);
|
|
2625
|
-
return {
|
|
2626
|
-
chapter: chunk.sentenceId[0],
|
|
2627
|
-
field: "content",
|
|
2628
|
-
id: formatNodeId(chunk.id),
|
|
2629
|
-
...position === void 0 ? {} : { position },
|
|
2630
|
-
snippet: createSnippet(chunk.content),
|
|
2631
|
-
title: chunk.label,
|
|
2632
|
-
type: "node"
|
|
2633
|
-
};
|
|
2634
|
-
});
|
|
2635
|
-
}
|
|
2636
|
-
async function createEntityBacklinkHits(document, sentenceKeys) {
|
|
2637
|
-
return listEntityCollection(
|
|
2638
|
-
(await listAllMentions(document)).filter(
|
|
2639
|
-
(mention) => sentenceKeys.has(
|
|
2640
|
-
formatSentenceKey(mention.chapterId, mention.sentenceIndex ?? 0)
|
|
2641
|
-
)
|
|
2642
|
-
)
|
|
2643
|
-
);
|
|
2644
|
-
}
|
|
2645
|
-
async function createTripleBacklinkHits(document, chapterId, sentenceKeys) {
|
|
2646
|
-
const hitsById = /* @__PURE__ */ new Map();
|
|
2647
|
-
for (const link of await document.mentionLinks.listByChapter(chapterId)) {
|
|
2648
|
-
const evidenceSentenceIds = link.evidenceSentenceIds.filter(
|
|
2649
|
-
(sentenceId) => sentenceKeys.has(formatSentenceIdKey(sentenceId))
|
|
2650
|
-
);
|
|
2651
|
-
if (evidenceSentenceIds.length === 0) {
|
|
2652
|
-
continue;
|
|
2653
|
-
}
|
|
2654
|
-
const [source, target] = await Promise.all([
|
|
2655
|
-
document.mentions.getById(link.sourceMentionId),
|
|
2656
|
-
document.mentions.getById(link.targetMentionId)
|
|
2657
|
-
]);
|
|
2658
|
-
if (source === void 0 || target === void 0) {
|
|
2659
|
-
continue;
|
|
2660
|
-
}
|
|
2661
|
-
const id = formatTripleUri(source.qid, link.predicate, target.qid);
|
|
2662
|
-
const existing = hitsById.get(id);
|
|
2663
|
-
const evidenceLink = { ...link, evidenceSentenceIds };
|
|
2664
|
-
if (existing !== void 0) {
|
|
2665
|
-
hitsById.set(id, {
|
|
2666
|
-
...existing,
|
|
2667
|
-
evidenceLinks: [...existing.evidenceLinks ?? [], evidenceLink],
|
|
2668
|
-
score: (existing.evidenceLinks?.length ?? 0) + 1
|
|
2669
|
-
});
|
|
2670
|
-
continue;
|
|
2671
|
-
}
|
|
2672
|
-
hitsById.set(id, {
|
|
2673
|
-
chapter: source.chapterId,
|
|
2674
|
-
evidenceLinks: [evidenceLink],
|
|
2675
|
-
field: "title",
|
|
2676
|
-
id,
|
|
2677
|
-
position: createSentencePosition(
|
|
2678
|
-
[...evidenceSentenceIds].sort(compareSentenceIds)[0] ?? [
|
|
2679
|
-
source.chapterId,
|
|
2680
|
-
source.sentenceIndex ?? 0
|
|
2681
|
-
]
|
|
2682
|
-
),
|
|
2683
|
-
score: 1,
|
|
2684
|
-
snippet: `${source.surface} ${link.predicate} ${target.surface}`,
|
|
2685
|
-
title: `${source.qid} ${link.predicate} ${target.qid}`,
|
|
2686
|
-
triple: {
|
|
2687
|
-
objectLabel: target.surface,
|
|
2688
|
-
predicate: link.predicate,
|
|
2689
|
-
subjectLabel: source.surface
|
|
2690
|
-
},
|
|
2691
|
-
type: "triple"
|
|
2692
|
-
});
|
|
2693
|
-
}
|
|
2694
|
-
return [...hitsById.values()];
|
|
2695
|
-
}
|
|
2696
|
-
function formatSentenceIdKey(sentenceId) {
|
|
2697
|
-
return formatSentenceKey(sentenceId[0], sentenceId[1]);
|
|
2698
|
-
}
|
|
2699
|
-
function formatSentenceKey(chapterId, sentenceIndex) {
|
|
2700
|
-
return `${chapterId}:${sentenceIndex}`;
|
|
2701
|
-
}
|
|
2702
|
-
function createUnscoredEntityEvidenceMention(mention) {
|
|
2703
|
-
return {
|
|
2704
|
-
match: {
|
|
2705
|
-
matchCount: 0,
|
|
2706
|
-
matchedTerms: [],
|
|
2707
|
-
missingTerms: [],
|
|
2708
|
-
score: 0
|
|
2709
|
-
},
|
|
2710
|
-
mention
|
|
2711
|
-
};
|
|
2712
|
-
}
|
|
2713
|
-
async function hydrateEntitySessionHitEvidence(document, hit, sessionId, evidenceLimit, sourceContext, context = createEvidenceReadContext()) {
|
|
2714
|
-
if (evidenceLimit === void 0) {
|
|
2715
|
-
const { evidence: _evidence, ...publicHit } = hit;
|
|
2716
|
-
return publicHit;
|
|
2717
|
-
}
|
|
2718
|
-
const qid = parseEntityQid(hit.id);
|
|
2719
|
-
if (qid === void 0) {
|
|
2720
|
-
return hit;
|
|
2721
|
-
}
|
|
2722
|
-
const mentionsByQid = await document.mentions.listByQid(qid);
|
|
2723
|
-
const mentionsById = new Map(
|
|
2724
|
-
mentionsByQid.map((mention) => [mention.id, mention])
|
|
2725
|
-
);
|
|
2726
|
-
const allMentions = (await readEntitySearchEvidenceMentions(
|
|
2727
|
-
sessionId,
|
|
2728
|
-
mentionsByQid.map((mention) => mention.id),
|
|
2729
|
-
1e4
|
|
2730
|
-
)).flatMap((hit2) => {
|
|
2731
|
-
const mention = mentionsById.get(hit2.mentionId);
|
|
2732
|
-
return mention === void 0 ? [] : [mention];
|
|
2733
|
-
});
|
|
2734
|
-
const ranges = await createMentionEvidenceRanges(document, allMentions);
|
|
2735
|
-
const mergedRanges = await createExpandedSourceEvidenceRanges(
|
|
2736
|
-
document,
|
|
2737
|
-
ranges,
|
|
2738
|
-
sourceContext,
|
|
2739
|
-
context
|
|
2740
|
-
);
|
|
2741
|
-
const sources = await Promise.all(
|
|
2742
|
-
mergedRanges.slice(0, evidenceLimit).map(
|
|
2743
|
-
async (range) => await createSourceEvidenceItem(
|
|
2744
|
-
document,
|
|
2745
|
-
range.chapterId,
|
|
2746
|
-
range.startSentenceIndex,
|
|
2747
|
-
range.endSentenceIndex,
|
|
2748
|
-
context
|
|
2749
|
-
)
|
|
2750
|
-
)
|
|
2751
|
-
);
|
|
2752
|
-
return {
|
|
2753
|
-
...hit,
|
|
2754
|
-
...allMentions[0] === void 0 ? {} : {
|
|
2755
|
-
chapter: allMentions[0].chapterId,
|
|
2756
|
-
position: {
|
|
2757
|
-
chapter: allMentions[0].chapterId,
|
|
2758
|
-
sentence: allMentions[0].sentenceIndex ?? 0
|
|
2759
|
-
},
|
|
2760
|
-
snippet: allMentions[0].note ?? allMentions[0].surface,
|
|
2761
|
-
title: allMentions[0].surface
|
|
2762
|
-
},
|
|
2763
|
-
evidence: {
|
|
2764
|
-
nextCursor: sources.length < mergedRanges.length ? encodeFindCursor(sources.length) : null,
|
|
2765
|
-
shown: sources.length,
|
|
2766
|
-
sources,
|
|
2767
|
-
total: mergedRanges.length
|
|
2768
|
-
}
|
|
2769
|
-
};
|
|
2770
|
-
}
|
|
2771
|
-
function formatTripleUri(subjectQid, predicate, objectQid) {
|
|
2772
|
-
return `wikg://triple/${subjectQid}/${encodeURIComponent(predicate)}/${objectQid}`;
|
|
2773
|
-
}
|
|
2774
|
-
function formatEntityUri(qid) {
|
|
2775
|
-
return `wikg://entity/${qid}`;
|
|
2776
|
-
}
|
|
2777
|
-
function isEntityOnlySearch(options) {
|
|
2778
|
-
return isEntitySearchTypes(options.types ?? null);
|
|
2779
|
-
}
|
|
2780
|
-
function isEntitySearchTypes(types) {
|
|
2781
|
-
return types !== null && types.length === 1 && types[0] === "entity";
|
|
2782
|
-
}
|
|
2783
|
-
function assertSearchCursorTypesMatch(requestedTypes, sessionTypes) {
|
|
2784
|
-
if (requestedTypes === void 0) {
|
|
2785
|
-
return;
|
|
2786
|
-
}
|
|
2787
|
-
if (requestedTypes.length !== (sessionTypes?.length ?? 0)) {
|
|
2788
|
-
throw new Error("Search cursor does not match the requested result types.");
|
|
2789
|
-
}
|
|
2790
|
-
const sessionTypeSet = new Set(sessionTypes ?? []);
|
|
2791
|
-
if (requestedTypes.some((type) => !sessionTypeSet.has(type))) {
|
|
2792
|
-
throw new Error("Search cursor does not match the requested result types.");
|
|
2793
|
-
}
|
|
2794
|
-
}
|
|
2795
|
-
function createEntitySearchCacheInput(hits, indexResult) {
|
|
2796
|
-
const evidenceEvents = [];
|
|
2797
|
-
const evidenceScoresByQid = /* @__PURE__ */ new Map();
|
|
2798
|
-
const propertyScoresByQid = /* @__PURE__ */ new Map();
|
|
2799
|
-
for (const hit of indexResult?.objectHits ?? []) {
|
|
2800
|
-
if (hit.ownerKind !== SEARCH_OBJECT_PROPERTY_OWNER_KIND.entity) {
|
|
2801
|
-
continue;
|
|
2802
|
-
}
|
|
2803
|
-
const scores = propertyScoresByQid.get(hit.ownerId) ?? [];
|
|
2804
|
-
scores.push(hit.score);
|
|
2805
|
-
propertyScoresByQid.set(hit.ownerId, scores);
|
|
2806
|
-
}
|
|
2807
|
-
for (const hit of hits) {
|
|
2808
|
-
if (hit.type !== "entity" || hit.evidenceMentions === void 0) {
|
|
2809
|
-
continue;
|
|
2810
|
-
}
|
|
2811
|
-
const qid = parseEntityQid(hit.id);
|
|
2812
|
-
if (qid === void 0) {
|
|
2813
|
-
continue;
|
|
2814
|
-
}
|
|
2815
|
-
const scores = evidenceScoresByQid.get(qid) ?? [];
|
|
2816
|
-
for (const evidenceMention of hit.evidenceMentions) {
|
|
2817
|
-
const sentenceIndex = evidenceMention.mention.sentenceIndex;
|
|
2818
|
-
if (sentenceIndex === void 0) {
|
|
2819
|
-
continue;
|
|
2820
|
-
}
|
|
2821
|
-
const score = evidenceMention.match.score ?? hit.score ?? 0;
|
|
2822
|
-
evidenceEvents.push({
|
|
2823
|
-
chapterId: evidenceMention.mention.chapterId,
|
|
2824
|
-
evidenceId: evidenceMention.mention.id,
|
|
2825
|
-
evidenceKind: SEARCH_EVIDENCE_KIND.mention,
|
|
2826
|
-
score,
|
|
2827
|
-
sentenceIndex
|
|
2828
|
-
});
|
|
2829
|
-
scores.push(score);
|
|
2830
|
-
}
|
|
2831
|
-
evidenceScoresByQid.set(qid, scores);
|
|
2832
|
-
}
|
|
2833
|
-
const qids = /* @__PURE__ */ new Set([
|
|
2834
|
-
...evidenceScoresByQid.keys(),
|
|
2835
|
-
...propertyScoresByQid.keys()
|
|
2836
|
-
]);
|
|
2837
|
-
return {
|
|
2838
|
-
entityHits: [...qids].map((qid) => ({
|
|
2839
|
-
evidenceTopScores: evidenceScoresByQid.get(qid) ?? [],
|
|
2840
|
-
propertyTopScores: propertyScoresByQid.get(qid) ?? [],
|
|
2841
|
-
qid
|
|
2842
|
-
})),
|
|
2843
|
-
evidenceEvents
|
|
2844
|
-
};
|
|
2845
|
-
}
|
|
2846
|
-
async function createSentenceEvidenceSearchCacheInput(document, indexResult, options) {
|
|
2847
|
-
if (indexResult === void 0 || isTextOnlySearch(options)) {
|
|
2848
|
-
return {
|
|
2849
|
-
chunkHits: [],
|
|
2850
|
-
entityHits: [],
|
|
2851
|
-
evidenceEvents: [],
|
|
2852
|
-
tripleHits: []
|
|
2853
|
-
};
|
|
2854
|
-
}
|
|
2855
|
-
const sourceHits = indexResult.textHits.filter(
|
|
2856
|
-
(hit) => hit.kind === TEXT_SENTENCE_KIND.source
|
|
2857
|
-
);
|
|
2858
|
-
if (sourceHits.length === 0) {
|
|
2859
|
-
return {
|
|
2860
|
-
chunkHits: [],
|
|
2861
|
-
entityHits: [],
|
|
2862
|
-
evidenceEvents: [],
|
|
2863
|
-
tripleHits: []
|
|
2864
|
-
};
|
|
2865
|
-
}
|
|
2866
|
-
const sourceHitScores = /* @__PURE__ */ new Map();
|
|
2867
|
-
const chapterIds = /* @__PURE__ */ new Set();
|
|
2868
|
-
for (const hit of sourceHits) {
|
|
2869
|
-
sourceHitScores.set(
|
|
2870
|
-
createSentenceHitKey(hit.chapterId, hit.sentenceIndex),
|
|
2871
|
-
hit.score
|
|
2872
|
-
);
|
|
2873
|
-
chapterIds.add(hit.chapterId);
|
|
2874
|
-
}
|
|
2875
|
-
const evidenceEvents = [];
|
|
2876
|
-
const entityEvidenceScoresByQid = /* @__PURE__ */ new Map();
|
|
2877
|
-
const chunkEvidenceScoresById = /* @__PURE__ */ new Map();
|
|
2878
|
-
const tripleEvidenceScoresByKey = /* @__PURE__ */ new Map();
|
|
2879
|
-
for (const chapterId of chapterIds) {
|
|
2880
|
-
for (const mention of await document.mentions.listByChapter(chapterId)) {
|
|
2881
|
-
if (mention.sentenceIndex === void 0) {
|
|
2882
|
-
continue;
|
|
2883
|
-
}
|
|
2884
|
-
const score = sourceHitScores.get(
|
|
2885
|
-
createSentenceHitKey(chapterId, mention.sentenceIndex)
|
|
2886
|
-
);
|
|
2887
|
-
if (score === void 0) {
|
|
2888
|
-
continue;
|
|
2889
|
-
}
|
|
2890
|
-
evidenceEvents.push({
|
|
2891
|
-
chapterId,
|
|
2892
|
-
evidenceId: mention.id,
|
|
2893
|
-
evidenceKind: SEARCH_EVIDENCE_KIND.mention,
|
|
2894
|
-
score,
|
|
2895
|
-
sentenceIndex: mention.sentenceIndex
|
|
2896
|
-
});
|
|
2897
|
-
const scores = entityEvidenceScoresByQid.get(mention.qid) ?? [];
|
|
2898
|
-
scores.push(score);
|
|
2899
|
-
entityEvidenceScoresByQid.set(mention.qid, scores);
|
|
2900
|
-
}
|
|
2901
|
-
for (const chunk of await document.chunks.listBySerial(chapterId)) {
|
|
2902
|
-
for (const [, sentenceIndex] of chunk.sentenceIds) {
|
|
2903
|
-
const score = sourceHitScores.get(
|
|
2904
|
-
createSentenceHitKey(chapterId, sentenceIndex)
|
|
2905
|
-
);
|
|
2906
|
-
if (score === void 0) {
|
|
2907
|
-
continue;
|
|
2908
|
-
}
|
|
2909
|
-
evidenceEvents.push({
|
|
2910
|
-
chapterId,
|
|
2911
|
-
evidenceId: String(chunk.id),
|
|
2912
|
-
evidenceKind: SEARCH_EVIDENCE_KIND.chunk,
|
|
2913
|
-
score,
|
|
2914
|
-
sentenceIndex
|
|
2915
|
-
});
|
|
2916
|
-
const scores = chunkEvidenceScoresById.get(chunk.id) ?? [];
|
|
2917
|
-
scores.push(score);
|
|
2918
|
-
chunkEvidenceScoresById.set(chunk.id, scores);
|
|
2919
|
-
}
|
|
2920
|
-
}
|
|
2921
|
-
const mentionCache = /* @__PURE__ */ new Map();
|
|
2922
|
-
for (const link of await document.mentionLinks.listByChapter(chapterId)) {
|
|
2923
|
-
const [source, target] = await Promise.all([
|
|
2924
|
-
getMentionForTripleSearch(document, mentionCache, link.sourceMentionId),
|
|
2925
|
-
getMentionForTripleSearch(document, mentionCache, link.targetMentionId)
|
|
2926
|
-
]);
|
|
2927
|
-
if (source === void 0 || target === void 0) {
|
|
2928
|
-
continue;
|
|
2929
|
-
}
|
|
2930
|
-
for (const [
|
|
2931
|
-
evidenceChapterId,
|
|
2932
|
-
sentenceIndex
|
|
2933
|
-
] of link.evidenceSentenceIds) {
|
|
2934
|
-
const score = sourceHitScores.get(
|
|
2935
|
-
createSentenceHitKey(evidenceChapterId, sentenceIndex)
|
|
2936
|
-
);
|
|
2937
|
-
if (score === void 0) {
|
|
2938
|
-
continue;
|
|
2939
|
-
}
|
|
2940
|
-
evidenceEvents.push({
|
|
2941
|
-
chapterId: evidenceChapterId,
|
|
2942
|
-
evidenceId: link.id,
|
|
2943
|
-
evidenceKind: SEARCH_EVIDENCE_KIND.mentionLink,
|
|
2944
|
-
score,
|
|
2945
|
-
sentenceIndex
|
|
2946
|
-
});
|
|
2947
|
-
const key = formatTripleUri(source.qid, link.predicate, target.qid);
|
|
2948
|
-
const current = tripleEvidenceScoresByKey.get(key) ?? {
|
|
2949
|
-
objectQid: target.qid,
|
|
2950
|
-
predicate: link.predicate,
|
|
2951
|
-
scores: [],
|
|
2952
|
-
subjectQid: source.qid
|
|
2953
|
-
};
|
|
2954
|
-
current.scores.push(score);
|
|
2955
|
-
tripleEvidenceScoresByKey.set(key, current);
|
|
2956
|
-
}
|
|
2957
|
-
}
|
|
2958
|
-
}
|
|
2959
|
-
return {
|
|
2960
|
-
chunkHits: [...chunkEvidenceScoresById.entries()].map(
|
|
2961
|
-
([chunkId, scores]) => ({
|
|
2962
|
-
chunkId,
|
|
2963
|
-
evidenceTopScores: scores
|
|
2964
|
-
})
|
|
2965
|
-
),
|
|
2966
|
-
entityHits: [...entityEvidenceScoresByQid.entries()].map(
|
|
2967
|
-
([qid, scores]) => ({
|
|
2968
|
-
evidenceTopScores: scores,
|
|
2969
|
-
qid
|
|
2970
|
-
})
|
|
2971
|
-
),
|
|
2972
|
-
evidenceEvents,
|
|
2973
|
-
tripleHits: [...tripleEvidenceScoresByKey.values()].map((hit) => ({
|
|
2974
|
-
evidenceTopScores: hit.scores,
|
|
2975
|
-
objectQid: hit.objectQid,
|
|
2976
|
-
predicate: hit.predicate,
|
|
2977
|
-
subjectQid: hit.subjectQid
|
|
2978
|
-
}))
|
|
2979
|
-
};
|
|
2980
|
-
}
|
|
2981
|
-
function createSentenceHitKey(chapterId, sentenceIndex) {
|
|
2982
|
-
return `${chapterId}:${sentenceIndex}`;
|
|
2983
|
-
}
|
|
2984
|
-
function parseEntityQid(id) {
|
|
2985
|
-
const normalized = normalizeWikiGraphObjectUri(id);
|
|
2986
|
-
const prefix = `${WIKI_GRAPH_URI_PREFIX}entity/`;
|
|
2987
|
-
return normalized.startsWith(prefix) ? normalized.slice(prefix.length) : void 0;
|
|
2988
|
-
}
|
|
2989
|
-
function filterLexicalHitsByMatch(hits, search, match) {
|
|
2990
|
-
if (match === "any") {
|
|
2991
|
-
return hits;
|
|
2992
|
-
}
|
|
2993
|
-
const requiredTerms = [...search.phrases];
|
|
2994
|
-
if (requiredTerms.length === 0) {
|
|
2995
|
-
return hits;
|
|
2996
|
-
}
|
|
2997
|
-
return hits.filter(
|
|
2998
|
-
(hit) => requiredTerms.every((term) => hit.matchedTerms?.includes(term) === true)
|
|
2999
|
-
);
|
|
3000
|
-
}
|
|
3001
|
-
async function findChapters(document, search) {
|
|
3002
|
-
const hits = [];
|
|
3003
|
-
for (const chapter of await listChapters(document)) {
|
|
3004
|
-
const title = chapter.title ?? `[chapter ${chapter.chapterId}]`;
|
|
3005
|
-
const titleMatch = matchText(title, search);
|
|
3006
|
-
if (titleMatch !== void 0) {
|
|
3007
|
-
hits.push({
|
|
3008
|
-
chapter: chapter.chapterId,
|
|
3009
|
-
field: "title",
|
|
3010
|
-
id: formatChapterTitleId(chapter.chapterId),
|
|
3011
|
-
...createFindMatchFields(titleMatch),
|
|
3012
|
-
position: {
|
|
3013
|
-
chapter: chapter.chapterId
|
|
3014
|
-
},
|
|
3015
|
-
snippet: title,
|
|
3016
|
-
title,
|
|
3017
|
-
type: "chapter-title"
|
|
3018
|
-
});
|
|
3019
|
-
}
|
|
3020
|
-
hits.push(
|
|
3021
|
-
...await findTextStreamSentences(
|
|
3022
|
-
document,
|
|
3023
|
-
chapter.chapterId,
|
|
3024
|
-
"summary",
|
|
3025
|
-
title,
|
|
3026
|
-
search
|
|
3027
|
-
)
|
|
3028
|
-
);
|
|
3029
|
-
hits.push(
|
|
3030
|
-
...await findTextStreamSentences(
|
|
3031
|
-
document,
|
|
3032
|
-
chapter.chapterId,
|
|
3033
|
-
"source",
|
|
3034
|
-
title,
|
|
3035
|
-
search
|
|
3036
|
-
)
|
|
3037
|
-
);
|
|
3038
|
-
}
|
|
3039
|
-
return hits;
|
|
3040
|
-
}
|
|
3041
|
-
async function findTextStreamSentences(document, chapterId, stream, title, search) {
|
|
3042
|
-
const index = await createTextStreamIndex(document, chapterId, stream);
|
|
3043
|
-
return index.sentences.flatMap((sentence) => {
|
|
3044
|
-
const match = matchText(sentence.text, search);
|
|
3045
|
-
if (match === void 0) {
|
|
3046
|
-
return [];
|
|
3047
|
-
}
|
|
3048
|
-
return [
|
|
3049
|
-
{
|
|
3050
|
-
chapter: chapterId,
|
|
3051
|
-
field: stream,
|
|
3052
|
-
id: formatTextStreamRangeUri(
|
|
3053
|
-
chapterId,
|
|
3054
|
-
stream,
|
|
3055
|
-
sentence.globalIndex,
|
|
3056
|
-
sentence.globalIndex
|
|
3057
|
-
),
|
|
3058
|
-
...createFindMatchFields(match),
|
|
3059
|
-
position: {
|
|
3060
|
-
chapter: chapterId,
|
|
3061
|
-
fragment: sentence.fragmentId,
|
|
3062
|
-
sentence: sentence.localIndex
|
|
3063
|
-
},
|
|
3064
|
-
snippet: createSnippet(sentence.text, getSnippetNeedle(match)),
|
|
3065
|
-
title,
|
|
3066
|
-
type: stream === "source" ? "source" : "summary"
|
|
3067
|
-
}
|
|
3068
|
-
];
|
|
3069
|
-
});
|
|
3070
|
-
}
|
|
3071
|
-
async function readSourceFragment(document, serialId, fragmentId) {
|
|
3072
|
-
const fragment = await document.getSerialFragments(serialId).getFragment(fragmentId);
|
|
3073
|
-
const text = fragment.sentences.map((sentence) => sentence.text).join("\n");
|
|
3074
|
-
return {
|
|
3075
|
-
fragmentId,
|
|
3076
|
-
id: formatFragmentId(serialId, fragmentId),
|
|
3077
|
-
preview: createSnippet(text),
|
|
3078
|
-
sentenceCount: fragment.sentences.length,
|
|
3079
|
-
text,
|
|
3080
|
-
wordsCount: fragment.sentences.reduce(
|
|
3081
|
-
(total, sentence) => total + sentence.wordsCount,
|
|
3082
|
-
0
|
|
3083
|
-
)
|
|
3084
|
-
};
|
|
3085
|
-
}
|
|
3086
|
-
async function createTextStreamRangeFragment(document, reference) {
|
|
3087
|
-
const range = await readTextStreamRange(
|
|
3088
|
-
document,
|
|
3089
|
-
reference.chapterId,
|
|
3090
|
-
reference.stream,
|
|
3091
|
-
reference.startSentenceIndex,
|
|
3092
|
-
reference.endSentenceIndex
|
|
3093
|
-
);
|
|
3094
|
-
return {
|
|
3095
|
-
fragmentId: range.startSentenceIndex,
|
|
3096
|
-
id: range.id,
|
|
3097
|
-
preview: createSnippet(range.text),
|
|
3098
|
-
sentenceCount: range.endSentenceIndex - range.startSentenceIndex + 1,
|
|
3099
|
-
text: range.text,
|
|
3100
|
-
wordsCount: countWords(range.text)
|
|
3101
|
-
};
|
|
3102
|
-
}
|
|
3103
|
-
async function readTextStreamRange(document, chapterId, stream, startSentenceIndex, endSentenceIndex, context = createEvidenceReadContext()) {
|
|
3104
|
-
const index = await getTextStreamIndex(document, chapterId, stream, context);
|
|
3105
|
-
if (index.sentences.length === 0) {
|
|
3106
|
-
throw new Error(
|
|
3107
|
-
`Chapter ${formatChapterId(chapterId)} has no ${stream} text.`
|
|
3108
|
-
);
|
|
3109
|
-
}
|
|
3110
|
-
const lastSentenceIndex = index.sentences.length - 1;
|
|
3111
|
-
if (startSentenceIndex > lastSentenceIndex) {
|
|
3112
|
-
throw new Error(
|
|
3113
|
-
`${stream} range ${formatTextStreamRangeUri(chapterId, stream, startSentenceIndex, endSentenceIndex)} is out of bounds. Last sentence number is ${lastSentenceIndex + 1}.`
|
|
3114
|
-
);
|
|
3115
|
-
}
|
|
3116
|
-
const start = clampInteger(startSentenceIndex, 0, lastSentenceIndex);
|
|
3117
|
-
const end = clampInteger(endSentenceIndex, start, lastSentenceIndex);
|
|
3118
|
-
const sentences = index.sentences.slice(start, end + 1);
|
|
3119
|
-
const text = normalizeRenderedTextStreamRange(
|
|
3120
|
-
await readTextStreamRawRange(document, chapterId, stream, start, end)
|
|
3121
|
-
) ?? joinTextStreamSentences(sentences);
|
|
3122
|
-
return {
|
|
3123
|
-
endSentenceIndex: end,
|
|
3124
|
-
id: formatTextStreamRangeUri(chapterId, stream, start, end),
|
|
3125
|
-
startSentenceIndex: start,
|
|
3126
|
-
text
|
|
3127
|
-
};
|
|
3128
|
-
}
|
|
3129
|
-
async function readTextStreamText(document, chapterId, stream) {
|
|
3130
|
-
const serial = getTextStreamSerial(document, chapterId, stream);
|
|
3131
|
-
const text = await serial.readText?.();
|
|
3132
|
-
if (text !== void 0) {
|
|
3133
|
-
return text;
|
|
3134
|
-
}
|
|
3135
|
-
const index = await createTextStreamIndex(document, chapterId, stream);
|
|
3136
|
-
return joinTextStreamSentences(index.sentences);
|
|
3137
|
-
}
|
|
3138
|
-
async function readTextStreamRawRange(document, chapterId, stream, startSentenceIndex, endSentenceIndex) {
|
|
3139
|
-
const serial = getTextStreamSerial(document, chapterId, stream);
|
|
3140
|
-
return await serial.readTextInRange?.(startSentenceIndex, endSentenceIndex);
|
|
3141
|
-
}
|
|
3142
|
-
function getTextStreamSerial(document, chapterId, stream) {
|
|
3143
|
-
return stream === "summary" ? document.getSummaryFragments(chapterId) : document.getSerialFragments(chapterId);
|
|
3144
|
-
}
|
|
3145
|
-
function joinTextStreamSentences(sentences) {
|
|
3146
|
-
return sentences.map((sentence) => sentence.text).join("");
|
|
3147
|
-
}
|
|
3148
|
-
function normalizeRenderedTextStreamRange(text) {
|
|
3149
|
-
return text?.replace(/^(?:[^\S\r\n]*(?:\r\n|\n|\r))+/u, "").replace(/(?:(?:\r\n|\n|\r)[^\S\r\n]*)+$/u, "");
|
|
3150
|
-
}
|
|
3151
|
-
async function getTextStreamIndex(document, chapterId, stream, context = createEvidenceReadContext()) {
|
|
3152
|
-
const key = `${chapterId}:${stream}`;
|
|
3153
|
-
let index = context.streamIndexes.get(key);
|
|
3154
|
-
if (index === void 0) {
|
|
3155
|
-
index = createTextStreamIndex(document, chapterId, stream);
|
|
3156
|
-
context.streamIndexes.set(key, index);
|
|
3157
|
-
}
|
|
3158
|
-
return await index;
|
|
3159
|
-
}
|
|
3160
|
-
async function createTextStreamIndex(document, chapterId, stream) {
|
|
3161
|
-
if (stream === "summary") {
|
|
3162
|
-
const fragments2 = document.getSummaryFragments(chapterId);
|
|
3163
|
-
const sentences2 = [];
|
|
3164
|
-
for (const fragmentId of await fragments2.listFragmentIds()) {
|
|
3165
|
-
const fragment = await fragments2.getFragment(fragmentId);
|
|
3166
|
-
for (let index = 0; index < fragment.sentences.length; index += 1) {
|
|
3167
|
-
const sentence = fragment.sentences[index];
|
|
3168
|
-
if (sentence === void 0) {
|
|
3169
|
-
continue;
|
|
3170
|
-
}
|
|
3171
|
-
sentences2.push({
|
|
3172
|
-
fragmentId,
|
|
3173
|
-
globalIndex: sentences2.length,
|
|
3174
|
-
localIndex: index,
|
|
3175
|
-
text: sentence.text,
|
|
3176
|
-
wordsCount: sentence.wordsCount
|
|
3177
|
-
});
|
|
3178
|
-
}
|
|
3179
|
-
}
|
|
3180
|
-
return { sentences: sentences2 };
|
|
3181
|
-
}
|
|
3182
|
-
const fragments = document.getSerialFragments(chapterId);
|
|
3183
|
-
const sentences = [];
|
|
3184
|
-
for (const fragmentId of await fragments.listFragmentIds()) {
|
|
3185
|
-
const fragment = await fragments.getFragment(fragmentId);
|
|
3186
|
-
for (let index = 0; index < fragment.sentences.length; index += 1) {
|
|
3187
|
-
const sentence = fragment.sentences[index];
|
|
3188
|
-
if (sentence === void 0) {
|
|
3189
|
-
continue;
|
|
3190
|
-
}
|
|
3191
|
-
sentences.push({
|
|
3192
|
-
fragmentId,
|
|
3193
|
-
globalIndex: sentences.length,
|
|
3194
|
-
localIndex: index,
|
|
3195
|
-
text: sentence.text,
|
|
3196
|
-
wordsCount: sentence.wordsCount
|
|
3197
|
-
});
|
|
3198
|
-
}
|
|
3199
|
-
}
|
|
3200
|
-
return { sentences };
|
|
3201
|
-
}
|
|
3202
|
-
function selectEntityLabel(mentions) {
|
|
3203
|
-
return selectEntityLabels(mentions)[0] ?? mentions[0]?.qid ?? "[entity]";
|
|
3204
|
-
}
|
|
3205
|
-
function selectEntityLabels(mentions) {
|
|
3206
|
-
const counts = /* @__PURE__ */ new Map();
|
|
3207
|
-
for (const mention of mentions) {
|
|
3208
|
-
counts.set(mention.surface, (counts.get(mention.surface) ?? 0) + 1);
|
|
3209
|
-
}
|
|
3210
|
-
return [...counts.entries()].sort((left, right) => {
|
|
3211
|
-
const countComparison = right[1] - left[1];
|
|
3212
|
-
return countComparison === 0 ? left[0].localeCompare(right[0]) : countComparison;
|
|
3213
|
-
}).map(([label]) => label);
|
|
3214
|
-
}
|
|
3215
|
-
async function createTriplePageLabel(document, reference) {
|
|
3216
|
-
const [subjectMentions, objectMentions] = await Promise.all([
|
|
3217
|
-
document.mentions.listByQid(reference.subjectQid),
|
|
3218
|
-
document.mentions.listByQid(reference.objectQid)
|
|
3219
|
-
]);
|
|
3220
|
-
const scopedSubjectMentions = filterMentionsByChapter(
|
|
3221
|
-
subjectMentions,
|
|
3222
|
-
reference.chapterId
|
|
3223
|
-
);
|
|
3224
|
-
const scopedObjectMentions = filterMentionsByChapter(
|
|
3225
|
-
objectMentions,
|
|
3226
|
-
reference.chapterId
|
|
3227
|
-
);
|
|
3228
|
-
const subjectLabel = scopedSubjectMentions.length === 0 ? reference.subjectQid : selectEntityLabel(scopedSubjectMentions);
|
|
3229
|
-
const objectLabel = scopedObjectMentions.length === 0 ? reference.objectQid : selectEntityLabel(scopedObjectMentions);
|
|
3230
|
-
return `${subjectLabel}(${reference.subjectQid}) ${reference.predicate} ${objectLabel}(${reference.objectQid})`;
|
|
3231
|
-
}
|
|
3232
|
-
function countWords(text) {
|
|
3233
|
-
const trimmed = text.trim();
|
|
3234
|
-
return trimmed === "" ? 0 : trimmed.split(/\s+/u).length;
|
|
3235
|
-
}
|
|
3236
|
-
async function listFragmentNodes(document, chapterId, fragmentId) {
|
|
3237
|
-
return (await document.chunks.listBySentenceStartIndexes(chapterId, [fragmentId])).map(createPositionedNodeLabel).sort(comparePositionedNodeLabels).map(({ label }) => label);
|
|
3238
|
-
}
|
|
3239
|
-
function createNodeLabel(node) {
|
|
3240
|
-
return {
|
|
3241
|
-
id: formatNodeId(node.id),
|
|
3242
|
-
title: node.label
|
|
3243
|
-
};
|
|
3244
|
-
}
|
|
3245
|
-
function createPositionedNodeLabel(node) {
|
|
3246
|
-
return {
|
|
3247
|
-
label: createNodeLabel(node),
|
|
3248
|
-
position: createNodePosition(node.sentenceIds)
|
|
3249
|
-
};
|
|
3250
|
-
}
|
|
3251
|
-
function comparePositionedNodeLabels(left, right) {
|
|
3252
|
-
if (left.position !== void 0 && right.position !== void 0) {
|
|
3253
|
-
return compareArchivePositions(left.position, right.position);
|
|
3254
|
-
}
|
|
3255
|
-
if (left.position !== void 0) {
|
|
3256
|
-
return -1;
|
|
3257
|
-
}
|
|
3258
|
-
if (right.position !== void 0) {
|
|
3259
|
-
return 1;
|
|
3260
|
-
}
|
|
3261
|
-
return left.label.id.localeCompare(right.label.id);
|
|
3262
|
-
}
|
|
3263
|
-
function findMeta(meta, search) {
|
|
3264
|
-
if (meta === void 0) {
|
|
3265
|
-
return [];
|
|
3266
|
-
}
|
|
3267
|
-
const fields = [
|
|
3268
|
-
meta.title,
|
|
3269
|
-
...meta.authors,
|
|
3270
|
-
meta.description,
|
|
3271
|
-
meta.publisher
|
|
3272
|
-
].filter(isDefined);
|
|
3273
|
-
const content = fields.join("\n");
|
|
3274
|
-
const contentMatch = matchText(content, search);
|
|
3275
|
-
if (contentMatch === void 0) {
|
|
3276
|
-
return [];
|
|
3277
|
-
}
|
|
3278
|
-
return [
|
|
3279
|
-
{
|
|
3280
|
-
field: "metadata",
|
|
3281
|
-
id: ARCHIVE_ROOT_ID,
|
|
3282
|
-
...createFindMatchFields(contentMatch),
|
|
3283
|
-
snippet: createSnippet(content, getSnippetNeedle(contentMatch)),
|
|
3284
|
-
title: meta.title ?? "Archive metadata",
|
|
3285
|
-
type: "meta"
|
|
3286
|
-
}
|
|
3287
|
-
];
|
|
3288
|
-
}
|
|
3289
|
-
async function findNodes(document, search) {
|
|
3290
|
-
const hits = [];
|
|
3291
|
-
for (const node of await document.chunks.listAll()) {
|
|
3292
|
-
const position = createNodePosition(node.sentenceIds);
|
|
3293
|
-
const labelMatch = matchText(node.label, search);
|
|
3294
|
-
if (labelMatch !== void 0) {
|
|
3295
|
-
hits.push({
|
|
3296
|
-
chapter: node.sentenceId[0],
|
|
3297
|
-
field: "title",
|
|
3298
|
-
id: formatNodeId(node.id),
|
|
3299
|
-
...createFindMatchFields(labelMatch),
|
|
3300
|
-
...position === void 0 ? {} : { position },
|
|
3301
|
-
snippet: node.label,
|
|
3302
|
-
title: node.label,
|
|
3303
|
-
type: "node"
|
|
3304
|
-
});
|
|
3305
|
-
}
|
|
3306
|
-
const contentMatch = matchText(node.content, search);
|
|
3307
|
-
if (contentMatch !== void 0) {
|
|
3308
|
-
hits.push({
|
|
3309
|
-
chapter: node.sentenceId[0],
|
|
3310
|
-
field: "content",
|
|
3311
|
-
id: formatNodeId(node.id),
|
|
3312
|
-
...createFindMatchFields(contentMatch),
|
|
3313
|
-
...position === void 0 ? {} : { position },
|
|
3314
|
-
snippet: createSnippet(node.content, getSnippetNeedle(contentMatch)),
|
|
3315
|
-
title: node.label,
|
|
3316
|
-
type: "node"
|
|
3317
|
-
});
|
|
3318
|
-
}
|
|
3319
|
-
}
|
|
3320
|
-
return hits;
|
|
3321
|
-
}
|
|
3322
|
-
async function requireChapter(document, chapterId) {
|
|
3323
|
-
const chapter = (await listChapters(document)).find(
|
|
3324
|
-
(entry) => entry.chapterId === chapterId
|
|
3325
|
-
);
|
|
3326
|
-
if (chapter === void 0) {
|
|
3327
|
-
throw new Error(`Chapter ${formatChapterId(chapterId)} does not exist.`);
|
|
3328
|
-
}
|
|
3329
|
-
return chapter;
|
|
3330
|
-
}
|
|
3331
|
-
async function createChapterState(document, chapter) {
|
|
3332
|
-
const serial = await document.serials.getById(chapter.chapterId);
|
|
3333
|
-
return {
|
|
3334
|
-
source: chapter.stage === "planned" ? "missing" : "ready",
|
|
3335
|
-
"reading-graph": chapter.stage === "graphed" || chapter.stage === "summarized" ? "ready" : "missing",
|
|
3336
|
-
"reading-summary": chapter.stage === "summarized" ? "ready" : "missing",
|
|
3337
|
-
"knowledge-graph": serial?.knowledgeGraphReady === true ? "ready" : "missing"
|
|
3338
|
-
};
|
|
3339
|
-
}
|
|
3340
|
-
function formatChapterStateSummary(state) {
|
|
3341
|
-
return [
|
|
3342
|
-
`source:${state.source}`,
|
|
3343
|
-
`reading-graph:${state["reading-graph"]}`,
|
|
3344
|
-
`reading-summary:${state["reading-summary"]}`,
|
|
3345
|
-
`knowledge-graph:${state["knowledge-graph"]}`
|
|
3346
|
-
].join(" ");
|
|
3347
|
-
}
|
|
3348
|
-
async function requireNode(document, nodeId) {
|
|
3349
|
-
const chunk = await document.chunks.getById(nodeId);
|
|
3350
|
-
if (chunk === void 0) {
|
|
3351
|
-
throw new Error(`Node ${formatNodeId(nodeId)} does not exist.`);
|
|
3352
|
-
}
|
|
3353
|
-
const chapterId = chunk.sentenceId[0];
|
|
3354
|
-
return {
|
|
3355
|
-
chapterId,
|
|
3356
|
-
node: await getGraphNode(document, chapterId, nodeId)
|
|
3357
|
-
};
|
|
3358
|
-
}
|
|
3359
|
-
async function readNodeSourceFragments(document, node) {
|
|
3360
|
-
const fragmentIds = await collectNodeSourceFragmentIds(document, node);
|
|
3361
|
-
return await Promise.all(
|
|
3362
|
-
fragmentIds.map(async ([chapterId, fragmentId]) => {
|
|
3363
|
-
const fragment = await readSourceFragment(
|
|
3364
|
-
document,
|
|
3365
|
-
chapterId,
|
|
3366
|
-
fragmentId
|
|
3367
|
-
);
|
|
3368
|
-
const index = await createTextStreamIndex(document, chapterId, "source");
|
|
3369
|
-
const fragmentSentences = index.sentences.filter(
|
|
3370
|
-
(sentence) => sentence.fragmentId === fragmentId
|
|
3371
|
-
);
|
|
3372
|
-
const firstSentence = fragmentSentences[0];
|
|
3373
|
-
const lastSentence = fragmentSentences[fragmentSentences.length - 1];
|
|
3374
|
-
const text = truncateSourceExcerpt(fragment.text);
|
|
3375
|
-
return {
|
|
3376
|
-
id: firstSentence === void 0 || lastSentence === void 0 ? fragment.id : formatTextStreamRangeUri(
|
|
3377
|
-
chapterId,
|
|
3378
|
-
"source",
|
|
3379
|
-
firstSentence.globalIndex,
|
|
3380
|
-
lastSentence.globalIndex
|
|
3381
|
-
),
|
|
3382
|
-
text,
|
|
3383
|
-
truncated: text.length < fragment.text.length
|
|
3384
|
-
};
|
|
3385
|
-
})
|
|
3386
|
-
);
|
|
3387
|
-
}
|
|
3388
|
-
async function collectNodeSourceFragmentIds(document, node) {
|
|
3389
|
-
const seen = /* @__PURE__ */ new Set();
|
|
3390
|
-
const fragmentIds = [];
|
|
3391
|
-
const indexes = /* @__PURE__ */ new Map();
|
|
3392
|
-
for (const [chapterId, sentenceIndex] of node.sentenceIds) {
|
|
3393
|
-
let index = indexes.get(chapterId);
|
|
3394
|
-
if (index === void 0) {
|
|
3395
|
-
index = createTextStreamIndex(document, chapterId, "source");
|
|
3396
|
-
indexes.set(chapterId, index);
|
|
3397
|
-
}
|
|
3398
|
-
const sentence = (await index).sentences[sentenceIndex];
|
|
3399
|
-
if (sentence === void 0) {
|
|
3400
|
-
continue;
|
|
3401
|
-
}
|
|
3402
|
-
const fragmentId = sentence.fragmentId;
|
|
3403
|
-
const key = `${chapterId}:${fragmentId}`;
|
|
3404
|
-
if (!seen.has(key)) {
|
|
3405
|
-
seen.add(key);
|
|
3406
|
-
fragmentIds.push([chapterId, fragmentId]);
|
|
3407
|
-
}
|
|
3408
|
-
}
|
|
3409
|
-
return fragmentIds;
|
|
3410
|
-
}
|
|
3411
|
-
function truncateSourceExcerpt(text) {
|
|
3412
|
-
return text.length <= 1200 ? text : `${text.slice(0, 1200)}...`;
|
|
3413
|
-
}
|
|
3414
|
-
function createNodeEvidenceRanges(node) {
|
|
3415
|
-
const ranges = /* @__PURE__ */ new Map();
|
|
3416
|
-
for (const [chapterId, sentenceIndex] of node.sentenceIds) {
|
|
3417
|
-
const key = `${chapterId}`;
|
|
3418
|
-
const current = ranges.get(key);
|
|
3419
|
-
if (current === void 0) {
|
|
3420
|
-
ranges.set(key, [sentenceIndex, sentenceIndex]);
|
|
3421
|
-
} else {
|
|
3422
|
-
ranges.set(key, [
|
|
3423
|
-
Math.min(current[0], sentenceIndex),
|
|
3424
|
-
Math.max(current[1], sentenceIndex)
|
|
3425
|
-
]);
|
|
3426
|
-
}
|
|
3427
|
-
}
|
|
3428
|
-
return [...ranges.entries()].map(([key, [start, end]]) => {
|
|
3429
|
-
const chapterId = Number(key);
|
|
3430
|
-
return {
|
|
3431
|
-
chapterId,
|
|
3432
|
-
endSentenceIndex: end,
|
|
3433
|
-
startSentenceIndex: start
|
|
3434
|
-
};
|
|
3435
|
-
});
|
|
3436
|
-
}
|
|
3437
|
-
async function createMentionEvidencePreview(document, mentions, limit = 3, context = createEvidenceReadContext(), sourceContext = DEFAULT_SOURCE_CONTEXT, order = "doc-asc") {
|
|
3438
|
-
return await createSourceEvidencePreview(
|
|
3439
|
-
document,
|
|
3440
|
-
await createMentionEvidenceRanges(document, mentions),
|
|
3441
|
-
limit,
|
|
3442
|
-
context,
|
|
3443
|
-
sourceContext,
|
|
3444
|
-
order
|
|
3445
|
-
);
|
|
3446
|
-
}
|
|
3447
|
-
async function createMentionEvidenceRanges(document, mentions) {
|
|
3448
|
-
return await Promise.all(
|
|
3449
|
-
mentions.map(async (mention) => {
|
|
3450
|
-
const startSentenceIndex = mention.sentenceIndex ?? await findSentenceIndexAtOffset(
|
|
3451
|
-
document,
|
|
3452
|
-
mention.chapterId,
|
|
3453
|
-
mention.rangeStart
|
|
3454
|
-
);
|
|
3455
|
-
const endSentenceIndex = mention.sentenceIndex ?? await findSentenceIndexAtOffset(
|
|
3456
|
-
document,
|
|
3457
|
-
mention.chapterId,
|
|
3458
|
-
Math.max(0, mention.rangeEnd - 1)
|
|
3459
|
-
);
|
|
3460
|
-
return {
|
|
3461
|
-
chapterId: mention.chapterId,
|
|
3462
|
-
endSentenceIndex,
|
|
3463
|
-
startSentenceIndex
|
|
3464
|
-
};
|
|
3465
|
-
})
|
|
3466
|
-
);
|
|
3467
|
-
}
|
|
3468
|
-
async function createMentionLinkEvidencePreview(document, links, limit = 3, context = createEvidenceReadContext(), sourceContext = DEFAULT_SOURCE_CONTEXT, order = "doc-asc") {
|
|
3469
|
-
return await createSourceEvidencePreview(
|
|
3470
|
-
document,
|
|
3471
|
-
createMentionLinkEvidenceRanges(document, links),
|
|
3472
|
-
limit,
|
|
3473
|
-
context,
|
|
3474
|
-
sourceContext,
|
|
3475
|
-
order
|
|
3476
|
-
);
|
|
3477
|
-
}
|
|
3478
|
-
function createMentionLinkEvidenceRanges(_document, links) {
|
|
3479
|
-
return links.flatMap(
|
|
3480
|
-
(link) => link.evidenceSentenceIds.map(([chapterId, sentenceIndex]) => ({
|
|
3481
|
-
chapterId,
|
|
3482
|
-
endSentenceIndex: sentenceIndex,
|
|
3483
|
-
startSentenceIndex: sentenceIndex
|
|
3484
|
-
}))
|
|
3485
|
-
);
|
|
3486
|
-
}
|
|
3487
|
-
function filterMentionsByChapter(mentions, chapterId) {
|
|
3488
|
-
return chapterId === void 0 ? mentions : mentions.filter((mention) => mention.chapterId === chapterId);
|
|
3489
|
-
}
|
|
3490
|
-
function filterMentionsByChapterSet(mentions, chapterFilter) {
|
|
3491
|
-
return chapterFilter === void 0 ? mentions : mentions.filter((mention) => chapterFilter.has(mention.chapterId));
|
|
3492
|
-
}
|
|
3493
|
-
async function filterMentionLinksByChapter(document, links, chapterId) {
|
|
3494
|
-
if (chapterId === void 0) {
|
|
3495
|
-
return links;
|
|
3496
|
-
}
|
|
3497
|
-
const filtered = [];
|
|
3498
|
-
for (const link of links) {
|
|
3499
|
-
const source = await document.mentions.getById(link.sourceMentionId);
|
|
3500
|
-
if (source?.chapterId === chapterId) {
|
|
3501
|
-
filtered.push(link);
|
|
3502
|
-
}
|
|
3503
|
-
}
|
|
3504
|
-
return filtered;
|
|
3505
|
-
}
|
|
3506
|
-
async function createSourceEvidencePage(document, ranges, options) {
|
|
3507
|
-
const context = createEvidenceReadContext();
|
|
3508
|
-
const limit = options.limit ?? DEFAULT_FIND_LIMIT;
|
|
3509
|
-
const start = decodeFindCursor(options.cursor);
|
|
3510
|
-
const evidenceRanges = await filterAndSortSourceEvidenceRangesByFtsQuery(
|
|
3511
|
-
document,
|
|
3512
|
-
ranges,
|
|
3513
|
-
options.query,
|
|
3514
|
-
options.order ?? "doc-asc"
|
|
3515
|
-
);
|
|
3516
|
-
const displayRanges = await createExpandedSourceEvidenceRanges(
|
|
3517
|
-
document,
|
|
3518
|
-
evidenceRanges,
|
|
3519
|
-
options.sourceContext ?? DEFAULT_SOURCE_CONTEXT,
|
|
3520
|
-
context
|
|
3521
|
-
);
|
|
3522
|
-
const pageRanges = displayRanges.slice(start, start + limit);
|
|
3523
|
-
const nextOffset = start + pageRanges.length;
|
|
3524
|
-
const items = await Promise.all(
|
|
3525
|
-
pageRanges.map(
|
|
3526
|
-
async (range) => await createSourceEvidenceItem(
|
|
3527
|
-
document,
|
|
3528
|
-
range.chapterId,
|
|
3529
|
-
range.startSentenceIndex,
|
|
3530
|
-
range.endSentenceIndex,
|
|
3531
|
-
context,
|
|
3532
|
-
range.score
|
|
3533
|
-
)
|
|
3534
|
-
)
|
|
3535
|
-
);
|
|
3536
|
-
return {
|
|
3537
|
-
items,
|
|
3538
|
-
limit,
|
|
3539
|
-
nextCursor: nextOffset < displayRanges.length ? encodeFindCursor(nextOffset) : null
|
|
3540
|
-
};
|
|
3541
|
-
}
|
|
3542
|
-
async function filterAndSortSourceEvidenceRangesByFtsQuery(document, ranges, queryText, order) {
|
|
3543
|
-
const documentOrders = await document.serials.listDocumentOrders();
|
|
3544
|
-
if (queryText === void 0) {
|
|
3545
|
-
return mergeSourceEvidenceRanges(ranges).sort(
|
|
3546
|
-
(left, right) => compareSourceEvidenceRanges(left, right, documentOrders, order)
|
|
3547
|
-
);
|
|
3548
|
-
}
|
|
3549
|
-
const indexResult = await queryRequiredSearchIndex(document, queryText, {
|
|
3550
|
-
chapters: [...new Set(ranges.map((range) => range.chapterId))],
|
|
3551
|
-
types: ["source"]
|
|
3552
|
-
});
|
|
3553
|
-
if (indexResult === void 0) {
|
|
3554
|
-
return [];
|
|
3555
|
-
}
|
|
3556
|
-
const matchedRanges = /* @__PURE__ */ new Map();
|
|
3557
|
-
const rangesByChapterId = /* @__PURE__ */ new Map();
|
|
3558
|
-
for (const range of ranges) {
|
|
3559
|
-
const chapterRanges = rangesByChapterId.get(range.chapterId) ?? [];
|
|
3560
|
-
chapterRanges.push(range);
|
|
3561
|
-
rangesByChapterId.set(range.chapterId, chapterRanges);
|
|
3562
|
-
}
|
|
3563
|
-
for (const hit of indexResult.textHits) {
|
|
3564
|
-
if (hit.kind !== TEXT_SENTENCE_KIND.source) {
|
|
3565
|
-
continue;
|
|
3566
|
-
}
|
|
3567
|
-
for (const range of rangesByChapterId.get(hit.chapterId) ?? []) {
|
|
3568
|
-
if (hit.sentenceIndex < range.startSentenceIndex || hit.sentenceIndex > range.endSentenceIndex) {
|
|
3569
|
-
continue;
|
|
3570
|
-
}
|
|
3571
|
-
const key = formatSourceEvidenceRangeKey(range);
|
|
3572
|
-
const current = matchedRanges.get(key);
|
|
3573
|
-
matchedRanges.set(key, {
|
|
3574
|
-
...range,
|
|
3575
|
-
score: Math.max(current?.score ?? 0, hit.score)
|
|
3576
|
-
});
|
|
3577
|
-
}
|
|
3578
|
-
}
|
|
3579
|
-
return [...matchedRanges.values()].sort((left, right) => {
|
|
3580
|
-
const scoreComparison = (right.score ?? 0) - (left.score ?? 0);
|
|
3581
|
-
if (scoreComparison !== 0) {
|
|
3582
|
-
return scoreComparison;
|
|
3583
|
-
}
|
|
3584
|
-
return compareSourceEvidenceRanges(left, right, documentOrders, "doc-asc");
|
|
3585
|
-
});
|
|
3586
|
-
}
|
|
3587
|
-
function formatSourceEvidenceRangeKey(range) {
|
|
3588
|
-
return `${range.chapterId}:${range.startSentenceIndex}:${range.endSentenceIndex}`;
|
|
3589
|
-
}
|
|
3590
|
-
function compareSourceEvidenceRanges(left, right, documentOrders, order) {
|
|
3591
|
-
const direction = order === "doc-asc" ? 1 : -1;
|
|
3592
|
-
return (compareNumbers(
|
|
3593
|
-
documentOrders.get(left.chapterId) ?? left.chapterId,
|
|
3594
|
-
documentOrders.get(right.chapterId) ?? right.chapterId
|
|
3595
|
-
) || compareNumbers(left.chapterId, right.chapterId) || compareNumbers(left.startSentenceIndex, right.startSentenceIndex) || compareNumbers(left.endSentenceIndex, right.endSentenceIndex)) * direction;
|
|
3596
|
-
}
|
|
3597
|
-
async function createSourceEvidencePreview(document, ranges, limit, context = createEvidenceReadContext(), sourceContext = DEFAULT_SOURCE_CONTEXT, order = "doc-asc") {
|
|
3598
|
-
const documentOrders = await document.serials.listDocumentOrders();
|
|
3599
|
-
const mergedRanges = mergeSourceEvidenceRanges(ranges).sort(
|
|
3600
|
-
(left, right) => compareSourceEvidenceRanges(left, right, documentOrders, order)
|
|
3601
|
-
);
|
|
3602
|
-
const displayRanges = await createExpandedSourceEvidenceRanges(
|
|
3603
|
-
document,
|
|
3604
|
-
mergedRanges.slice(0, limit),
|
|
3605
|
-
sourceContext,
|
|
3606
|
-
context
|
|
3607
|
-
);
|
|
3608
|
-
const sources = await Promise.all(
|
|
3609
|
-
displayRanges.map(
|
|
3610
|
-
async (range) => await createSourceEvidenceItem(
|
|
3611
|
-
document,
|
|
3612
|
-
range.chapterId,
|
|
3613
|
-
range.startSentenceIndex,
|
|
3614
|
-
range.endSentenceIndex,
|
|
3615
|
-
context
|
|
3616
|
-
)
|
|
3617
|
-
)
|
|
3618
|
-
);
|
|
3619
|
-
return {
|
|
3620
|
-
nextCursor: Math.min(limit, mergedRanges.length) < mergedRanges.length ? encodeFindCursor(Math.min(limit, mergedRanges.length)) : null,
|
|
3621
|
-
shown: sources.length,
|
|
3622
|
-
sources,
|
|
3623
|
-
total: mergedRanges.length
|
|
3624
|
-
};
|
|
3625
|
-
}
|
|
3626
|
-
function mergeSourceEvidenceRanges(ranges) {
|
|
3627
|
-
const rangesBySource = /* @__PURE__ */ new Map();
|
|
3628
|
-
for (const range of ranges) {
|
|
3629
|
-
const key = `${range.chapterId}`;
|
|
3630
|
-
const sourceRanges = rangesBySource.get(key) ?? [];
|
|
3631
|
-
sourceRanges.push({
|
|
3632
|
-
end: range.endSentenceIndex,
|
|
3633
|
-
...range.score === void 0 ? {} : { score: range.score },
|
|
3634
|
-
start: range.startSentenceIndex
|
|
3635
|
-
});
|
|
3636
|
-
rangesBySource.set(key, sourceRanges);
|
|
3637
|
-
}
|
|
3638
|
-
return [...rangesBySource.entries()].flatMap(([key, ranges2]) => {
|
|
3639
|
-
const chapterId = Number(key);
|
|
3640
|
-
return mergeEvidenceRanges(ranges2).map(
|
|
3641
|
-
({ end, score, start }) => ({
|
|
3642
|
-
chapterId,
|
|
3643
|
-
endSentenceIndex: end,
|
|
3644
|
-
...score === void 0 ? {} : { score },
|
|
3645
|
-
startSentenceIndex: start
|
|
3646
|
-
})
|
|
3647
|
-
);
|
|
3648
|
-
});
|
|
3649
|
-
}
|
|
3650
|
-
function mergeSourceEvidenceRangesInInputOrder(ranges) {
|
|
3651
|
-
const merged = [];
|
|
3652
|
-
for (const range of ranges) {
|
|
3653
|
-
const overlappingIndexes = merged.map(
|
|
3654
|
-
(existing, index) => areMergeableSourceEvidenceRanges(existing, range) ? index : -1
|
|
3655
|
-
).filter((index) => index >= 0);
|
|
3656
|
-
if (overlappingIndexes.length === 0) {
|
|
3657
|
-
merged.push(range);
|
|
3658
|
-
continue;
|
|
3659
|
-
}
|
|
3660
|
-
const firstIndex = overlappingIndexes[0] ?? 0;
|
|
3661
|
-
const overlapping = overlappingIndexes.flatMap((index) => {
|
|
3662
|
-
const existing = merged[index];
|
|
3663
|
-
return existing === void 0 ? [] : [existing];
|
|
3664
|
-
});
|
|
3665
|
-
const mergedRange = mergeSourceEvidenceRangeGroup([...overlapping, range]);
|
|
3666
|
-
merged[firstIndex] = mergedRange;
|
|
3667
|
-
for (const index of overlappingIndexes.slice(1).reverse()) {
|
|
3668
|
-
merged.splice(index, 1);
|
|
3669
|
-
}
|
|
3670
|
-
}
|
|
3671
|
-
return merged;
|
|
3672
|
-
}
|
|
3673
|
-
function areMergeableSourceEvidenceRanges(left, right) {
|
|
3674
|
-
return left.chapterId === right.chapterId && right.startSentenceIndex <= left.endSentenceIndex + 1 && left.startSentenceIndex <= right.endSentenceIndex + 1;
|
|
3675
|
-
}
|
|
3676
|
-
function mergeSourceEvidenceRangeGroup(ranges) {
|
|
3677
|
-
const [first] = ranges;
|
|
3678
|
-
if (first === void 0) {
|
|
3679
|
-
throw new Error("Internal error: cannot merge empty evidence range group.");
|
|
3680
|
-
}
|
|
3681
|
-
const scores = ranges.map((range) => range.score).filter((score) => score !== void 0);
|
|
3682
|
-
return {
|
|
3683
|
-
chapterId: first.chapterId,
|
|
3684
|
-
endSentenceIndex: Math.max(
|
|
3685
|
-
...ranges.map((range) => range.endSentenceIndex)
|
|
3686
|
-
),
|
|
3687
|
-
...scores.length === 0 ? {} : { score: Math.max(...scores) },
|
|
3688
|
-
startSentenceIndex: Math.min(
|
|
3689
|
-
...ranges.map((range) => range.startSentenceIndex)
|
|
3690
|
-
)
|
|
3691
|
-
};
|
|
3692
|
-
}
|
|
3693
|
-
async function createExpandedSourceEvidenceRanges(document, ranges, sourceContext, context) {
|
|
3694
|
-
const expanded = await Promise.all(
|
|
3695
|
-
ranges.map(async (range) => {
|
|
3696
|
-
if (sourceContext <= 0) {
|
|
3697
|
-
return range;
|
|
3698
|
-
}
|
|
3699
|
-
const sourceIndex = await getTextStreamIndex(
|
|
3700
|
-
document,
|
|
3701
|
-
range.chapterId,
|
|
3702
|
-
"source",
|
|
3703
|
-
context
|
|
3704
|
-
);
|
|
3705
|
-
const lastSentenceIndex = Math.max(0, sourceIndex.sentences.length - 1);
|
|
3706
|
-
return {
|
|
3707
|
-
...range,
|
|
3708
|
-
endSentenceIndex: clampInteger(
|
|
3709
|
-
range.endSentenceIndex + sourceContext,
|
|
3710
|
-
range.startSentenceIndex,
|
|
3711
|
-
lastSentenceIndex
|
|
3712
|
-
),
|
|
3713
|
-
startSentenceIndex: clampInteger(
|
|
3714
|
-
range.startSentenceIndex - sourceContext,
|
|
3715
|
-
0,
|
|
3716
|
-
lastSentenceIndex
|
|
3717
|
-
)
|
|
3718
|
-
};
|
|
3719
|
-
})
|
|
3720
|
-
);
|
|
3721
|
-
return mergeSourceEvidenceRangesInInputOrder(expanded);
|
|
3722
|
-
}
|
|
3723
|
-
async function createSourceEvidenceItem(document, chapterId, startSentenceIndex, endSentenceIndex, context = createEvidenceReadContext(), score) {
|
|
3724
|
-
const chapter = await getEvidenceChapter(document, chapterId, context);
|
|
3725
|
-
const range = await readTextStreamRange(
|
|
3726
|
-
document,
|
|
3727
|
-
chapterId,
|
|
3728
|
-
"source",
|
|
3729
|
-
startSentenceIndex,
|
|
3730
|
-
endSentenceIndex,
|
|
3731
|
-
context
|
|
3732
|
-
);
|
|
3733
|
-
return {
|
|
3734
|
-
chapterId,
|
|
3735
|
-
endSentenceIndex: range.endSentenceIndex,
|
|
3736
|
-
fragmentId: range.startSentenceIndex,
|
|
3737
|
-
id: formatTextStreamRangeUri(
|
|
3738
|
-
chapterId,
|
|
3739
|
-
"source",
|
|
3740
|
-
range.startSentenceIndex,
|
|
3741
|
-
range.endSentenceIndex
|
|
3742
|
-
),
|
|
3743
|
-
...score === void 0 ? {} : { score },
|
|
3744
|
-
source: range.text,
|
|
3745
|
-
startSentenceIndex: range.startSentenceIndex,
|
|
3746
|
-
title: chapter.title ?? `[chapter ${chapterId}]`,
|
|
3747
|
-
type: "source"
|
|
3748
|
-
};
|
|
3749
|
-
}
|
|
3750
|
-
function createEvidenceReadContext() {
|
|
3751
|
-
return {
|
|
3752
|
-
chapters: /* @__PURE__ */ new Map(),
|
|
3753
|
-
streamIndexes: /* @__PURE__ */ new Map()
|
|
3754
|
-
};
|
|
3755
|
-
}
|
|
3756
|
-
async function getEvidenceChapter(document, chapterId, context) {
|
|
3757
|
-
let chapter = context.chapters.get(chapterId);
|
|
3758
|
-
if (chapter === void 0) {
|
|
3759
|
-
chapter = requireChapter(document, chapterId);
|
|
3760
|
-
context.chapters.set(chapterId, chapter);
|
|
3761
|
-
}
|
|
3762
|
-
return await chapter;
|
|
3763
|
-
}
|
|
3764
|
-
async function findSentenceIndexAtOffset(document, chapterId, offset) {
|
|
3765
|
-
const serial = document.getSerialFragments(chapterId);
|
|
3766
|
-
const sentences = serial.listSentences === void 0 ? [] : await serial.listSentences();
|
|
3767
|
-
if (sentences.length === 0) {
|
|
3768
|
-
return 0;
|
|
3769
|
-
}
|
|
3770
|
-
let cursor = 0;
|
|
3771
|
-
for (let index = 0; index < sentences.length; index += 1) {
|
|
3772
|
-
const sentence = sentences[index];
|
|
3773
|
-
if (sentence === void 0) {
|
|
3774
|
-
continue;
|
|
3775
|
-
}
|
|
3776
|
-
const nextCursor = cursor + sentence.text.length;
|
|
3777
|
-
if (offset <= nextCursor) {
|
|
3778
|
-
return index;
|
|
3779
|
-
}
|
|
3780
|
-
cursor = nextCursor + 1;
|
|
3781
|
-
}
|
|
3782
|
-
return Math.max(0, sentences.length - 1);
|
|
3783
|
-
}
|
|
3784
|
-
function formatTextStreamRangeUri(chapterId, stream, startSentenceIndex, endSentenceIndex) {
|
|
3785
|
-
const startSentenceNumber = startSentenceIndex + 1;
|
|
3786
|
-
const endSentenceNumber = endSentenceIndex + 1;
|
|
3787
|
-
const hash = startSentenceIndex === endSentenceIndex ? String(startSentenceNumber) : `${startSentenceNumber}..${endSentenceNumber}`;
|
|
3788
|
-
return `wikg://chapter/${chapterId}/${stream}#${hash}`;
|
|
3789
|
-
}
|
|
3790
|
-
function mergeEvidenceRanges(ranges) {
|
|
3791
|
-
const sortedRanges = [...ranges].map((range) => ({
|
|
3792
|
-
...range.score === void 0 ? {} : { score: range.score },
|
|
3793
|
-
end: Math.max(range.start, range.end),
|
|
3794
|
-
start: Math.min(range.start, range.end)
|
|
3795
|
-
})).sort(
|
|
3796
|
-
(left, right) => left.start === right.start ? left.end - right.end : left.start - right.start
|
|
3797
|
-
);
|
|
3798
|
-
const mergedRanges = [];
|
|
3799
|
-
for (const { end, score, start } of sortedRanges) {
|
|
3800
|
-
const last = mergedRanges.at(-1);
|
|
3801
|
-
if (last === void 0 || start > last.end + 1) {
|
|
3802
|
-
mergedRanges.push({
|
|
3803
|
-
end,
|
|
3804
|
-
...score === void 0 ? {} : { score },
|
|
3805
|
-
start
|
|
3806
|
-
});
|
|
3807
|
-
} else {
|
|
3808
|
-
last.end = Math.max(last.end, end);
|
|
3809
|
-
if (score !== void 0) {
|
|
3810
|
-
last.score = Math.max(last.score ?? score, score);
|
|
3811
|
-
}
|
|
3812
|
-
}
|
|
3813
|
-
}
|
|
3814
|
-
return mergedRanges;
|
|
3815
|
-
}
|
|
3816
|
-
function clampInteger(value, min, max) {
|
|
3817
|
-
return Math.max(min, Math.min(max, Math.floor(value)));
|
|
3818
|
-
}
|
|
3819
|
-
function parseWikiGraphReference(uri) {
|
|
3820
|
-
uri = normalizeWikiGraphObjectUri(uri);
|
|
3821
|
-
if (!isWikiGraphObjectUri(uri)) {
|
|
3822
|
-
const archiveReference = parseArchiveReference(uri);
|
|
3823
|
-
switch (archiveReference.type) {
|
|
3824
|
-
case "node":
|
|
3825
|
-
return { id: archiveReference.id, type: "chunk" };
|
|
3826
|
-
case "chapter":
|
|
3827
|
-
return { chapterId: archiveReference.id, type: "chapter" };
|
|
3828
|
-
case "chapter-title":
|
|
3829
|
-
return { chapterId: archiveReference.id, type: "chapter-title" };
|
|
3830
|
-
case "summary":
|
|
3831
|
-
return {
|
|
3832
|
-
chapterId: archiveReference.id,
|
|
3833
|
-
endSentenceIndex: Number.POSITIVE_INFINITY,
|
|
3834
|
-
stream: "summary",
|
|
3835
|
-
startSentenceIndex: 0,
|
|
3836
|
-
type: "text-stream"
|
|
3837
|
-
};
|
|
3838
|
-
case "fragment":
|
|
3839
|
-
case "meta":
|
|
3840
|
-
throw new Error(`Evidence is not available for ${uri}.`);
|
|
3841
|
-
}
|
|
3842
|
-
}
|
|
3843
|
-
if (uri === WIKI_GRAPH_URI_PREFIX) {
|
|
3844
|
-
return { type: "meta" };
|
|
3845
|
-
}
|
|
3846
|
-
const [rawPath = "", hash = ""] = uri.slice(WIKI_GRAPH_URI_PREFIX.length).split("#", 2);
|
|
3847
|
-
const pathParts = rawPath.split("/").filter((part) => part !== "");
|
|
3848
|
-
if (pathParts.length === 0) {
|
|
3849
|
-
return { type: "meta" };
|
|
3850
|
-
}
|
|
3851
|
-
if (pathParts[0] === "chapter-tree" && pathParts.length === 1) {
|
|
3852
|
-
return { type: "chapter-tree" };
|
|
3853
|
-
}
|
|
3854
|
-
switch (pathParts[0]) {
|
|
3855
|
-
case "chapter":
|
|
3856
|
-
if (pathParts.length === 2) {
|
|
3857
|
-
return {
|
|
3858
|
-
chapterId: parsePositiveInteger(pathParts[1], uri),
|
|
3859
|
-
type: "chapter"
|
|
3860
|
-
};
|
|
3861
|
-
}
|
|
3862
|
-
if (pathParts[1] !== void 0) {
|
|
3863
|
-
const chapterId = parsePositiveInteger(pathParts[1], uri);
|
|
3864
|
-
switch (pathParts[2]) {
|
|
3865
|
-
case "state":
|
|
3866
|
-
if (pathParts.length === 3) {
|
|
3867
|
-
return { chapterId, type: "chapter-state" };
|
|
3868
|
-
}
|
|
3869
|
-
if (pathParts.length === 4) {
|
|
3870
|
-
return {
|
|
3871
|
-
chapterId,
|
|
3872
|
-
target: parseChapterStateTarget(pathParts[3], uri),
|
|
3873
|
-
type: "chapter-state"
|
|
3874
|
-
};
|
|
3875
|
-
}
|
|
3876
|
-
break;
|
|
3877
|
-
case "title":
|
|
3878
|
-
if (pathParts.length === 3) {
|
|
3879
|
-
return { chapterId, type: "chapter-title" };
|
|
3880
|
-
}
|
|
3881
|
-
break;
|
|
3882
|
-
case "chunk":
|
|
3883
|
-
if (pathParts.length === 4) {
|
|
3884
|
-
return {
|
|
3885
|
-
chapterId,
|
|
3886
|
-
id: parsePositiveInteger(pathParts[3], uri),
|
|
3887
|
-
type: "chunk"
|
|
3888
|
-
};
|
|
3889
|
-
}
|
|
3890
|
-
break;
|
|
3891
|
-
case "entity":
|
|
3892
|
-
if (pathParts.length === 4) {
|
|
3893
|
-
return {
|
|
3894
|
-
chapterId,
|
|
3895
|
-
qid: parseQid(pathParts[3], uri),
|
|
3896
|
-
type: "entity"
|
|
3897
|
-
};
|
|
3898
|
-
}
|
|
3899
|
-
break;
|
|
3900
|
-
case "source":
|
|
3901
|
-
if (pathParts.length === 3) {
|
|
3902
|
-
const [start, end] = parseSentenceRange(hash);
|
|
3903
|
-
return {
|
|
3904
|
-
chapterId,
|
|
3905
|
-
endSentenceIndex: end,
|
|
3906
|
-
stream: "source",
|
|
3907
|
-
startSentenceIndex: start,
|
|
3908
|
-
type: "text-stream"
|
|
3909
|
-
};
|
|
3910
|
-
}
|
|
3911
|
-
break;
|
|
3912
|
-
case "summary":
|
|
3913
|
-
if (pathParts.length === 3) {
|
|
3914
|
-
const [start, end] = parseSentenceRange(hash);
|
|
3915
|
-
return {
|
|
3916
|
-
chapterId,
|
|
3917
|
-
endSentenceIndex: end,
|
|
3918
|
-
stream: "summary",
|
|
3919
|
-
startSentenceIndex: start,
|
|
3920
|
-
type: "text-stream"
|
|
3921
|
-
};
|
|
3922
|
-
}
|
|
3923
|
-
break;
|
|
3924
|
-
case "tree":
|
|
3925
|
-
if (pathParts.length === 3) {
|
|
3926
|
-
return { chapterId, type: "chapter" };
|
|
3927
|
-
}
|
|
3928
|
-
break;
|
|
3929
|
-
case "triple":
|
|
3930
|
-
if (pathParts.length === 6) {
|
|
3931
|
-
return {
|
|
3932
|
-
chapterId,
|
|
3933
|
-
objectQid: parseQid(pathParts[5], uri),
|
|
3934
|
-
predicate: decodeURIComponent(pathParts[4] ?? ""),
|
|
3935
|
-
subjectQid: parseQid(pathParts[3], uri),
|
|
3936
|
-
type: "triple"
|
|
3937
|
-
};
|
|
3938
|
-
}
|
|
3939
|
-
break;
|
|
3940
|
-
}
|
|
3941
|
-
}
|
|
3942
|
-
break;
|
|
3943
|
-
case "chunk":
|
|
3944
|
-
if (pathParts.length === 2) {
|
|
3945
|
-
return {
|
|
3946
|
-
id: parsePositiveInteger(pathParts[1], uri),
|
|
3947
|
-
type: "chunk"
|
|
3948
|
-
};
|
|
3949
|
-
}
|
|
3950
|
-
break;
|
|
3951
|
-
case "entity":
|
|
3952
|
-
if (pathParts.length === 2) {
|
|
3953
|
-
return {
|
|
3954
|
-
qid: parseQid(pathParts[1], uri),
|
|
3955
|
-
type: "entity"
|
|
3956
|
-
};
|
|
3957
|
-
}
|
|
3958
|
-
if (pathParts.length === 3 && pathParts[2] === "wikipage") {
|
|
3959
|
-
return {
|
|
3960
|
-
qid: parseQid(pathParts[1], uri),
|
|
3961
|
-
type: "entity-wikipage"
|
|
3962
|
-
};
|
|
3963
|
-
}
|
|
3964
|
-
break;
|
|
3965
|
-
case "triple":
|
|
3966
|
-
if (pathParts.length === 4) {
|
|
3967
|
-
return {
|
|
3968
|
-
objectQid: parseQid(pathParts[3], uri),
|
|
3969
|
-
predicate: decodeURIComponent(pathParts[2] ?? ""),
|
|
3970
|
-
subjectQid: parseQid(pathParts[1], uri),
|
|
3971
|
-
type: "triple"
|
|
3972
|
-
};
|
|
3973
|
-
}
|
|
3974
|
-
break;
|
|
3975
|
-
}
|
|
3976
|
-
throw new Error(`Invalid Wiki Graph URI: ${uri}`);
|
|
3977
|
-
}
|
|
3978
|
-
function parseQid(value, uri) {
|
|
3979
|
-
if (value !== void 0 && /^Q[1-9][0-9]*$/u.test(value)) {
|
|
3980
|
-
return value;
|
|
3981
|
-
}
|
|
3982
|
-
throw new Error(`Invalid Wiki Graph URI: ${uri}`);
|
|
3983
|
-
}
|
|
3984
|
-
function parseChapterStateTarget(value, uri) {
|
|
3985
|
-
if (value === "source" || value === "reading-graph" || value === "reading-summary" || value === "knowledge-graph") {
|
|
3986
|
-
return value;
|
|
3987
|
-
}
|
|
3988
|
-
throw new Error(`Invalid Wiki Graph URI: ${uri}`);
|
|
3989
|
-
}
|
|
3990
|
-
function parseSentenceRange(hash) {
|
|
3991
|
-
if (hash === "") {
|
|
3992
|
-
return [0, Number.POSITIVE_INFINITY];
|
|
3993
|
-
}
|
|
3994
|
-
const match = /^([1-9][0-9]*)(?:\.\.([1-9][0-9]*))?$/u.exec(hash);
|
|
3995
|
-
if (match?.[1] === void 0) {
|
|
3996
|
-
throw new Error(`Invalid source sentence range: ${hash}`);
|
|
3997
|
-
}
|
|
3998
|
-
const parsedStart = Number(match[1]) - 1;
|
|
3999
|
-
const parsedEnd = Number(match[2] ?? match[1]) - 1;
|
|
4000
|
-
if (Number.isInteger(parsedStart) && parsedStart >= 0 && Number.isInteger(parsedEnd) && parsedEnd >= parsedStart) {
|
|
4001
|
-
return [parsedStart, parsedEnd];
|
|
4002
|
-
}
|
|
4003
|
-
throw new Error(`Invalid source sentence range: ${hash}`);
|
|
4004
|
-
}
|
|
4005
|
-
function parseArchiveReference(id) {
|
|
4006
|
-
const normalized = id.trim();
|
|
4007
|
-
const [type, value] = normalized.split(":", 2);
|
|
4008
|
-
if (type === "meta" && (value === "book" || value === "root")) {
|
|
4009
|
-
return { type: "meta" };
|
|
4010
|
-
}
|
|
4011
|
-
if (type === "chapter" || type === "chapter-title" || type === "summary") {
|
|
4012
|
-
const parsedId = parsePositiveInteger(value, normalized);
|
|
4013
|
-
return { id: parsedId, type };
|
|
4014
|
-
}
|
|
4015
|
-
if (type === "node") {
|
|
4016
|
-
const parsedId = parsePositiveInteger(value, normalized);
|
|
4017
|
-
return {
|
|
4018
|
-
id: parsedId,
|
|
4019
|
-
type: "node"
|
|
4020
|
-
};
|
|
4021
|
-
}
|
|
4022
|
-
if (type === "fragment") {
|
|
4023
|
-
const parts = normalized.slice("fragment:".length).split(":");
|
|
4024
|
-
if (parts.length !== 2) {
|
|
4025
|
-
throw new Error(`Invalid archive object id: ${id}`);
|
|
4026
|
-
}
|
|
4027
|
-
return {
|
|
4028
|
-
fragmentId: parseNonNegativeInteger(parts[1], normalized),
|
|
4029
|
-
serialId: parsePositiveInteger(parts[0], normalized),
|
|
4030
|
-
type: "fragment"
|
|
4031
|
-
};
|
|
4032
|
-
}
|
|
4033
|
-
throw new Error(`Invalid archive object id: ${id}`);
|
|
4034
|
-
}
|
|
4035
|
-
function parsePositiveInteger(value, id) {
|
|
4036
|
-
const parsed = Number(value);
|
|
4037
|
-
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
4038
|
-
throw new Error(`Invalid archive object id: ${id}`);
|
|
4039
|
-
}
|
|
4040
|
-
return parsed;
|
|
4041
|
-
}
|
|
4042
|
-
function parseNonNegativeInteger(value, id) {
|
|
4043
|
-
const parsed = Number(value);
|
|
4044
|
-
if (!Number.isInteger(parsed) || parsed < 0) {
|
|
4045
|
-
throw new Error(`Invalid archive object id: ${id}`);
|
|
4046
|
-
}
|
|
4047
|
-
return parsed;
|
|
4048
|
-
}
|
|
4049
|
-
const DEFAULT_FIND_LIMIT = 20;
|
|
4050
|
-
const GROUP_SCORE_EVIDENCE_LIMIT = 10;
|
|
4051
|
-
const TEXT_ONLY_SEARCH_CACHE_WINDOW = 100;
|
|
4052
|
-
const GROUP_SCORE_MAX_EQUAL_EVIDENCE_BONUS = 0.3;
|
|
4053
|
-
const ARCHIVE_ROOT_ID = "meta:root";
|
|
4054
|
-
function isWikiGraphObjectUri(uri) {
|
|
4055
|
-
return uri.startsWith(WIKI_GRAPH_URI_PREFIX);
|
|
4056
|
-
}
|
|
4057
|
-
function normalizeWikiGraphObjectUri(uri) {
|
|
4058
|
-
return uri;
|
|
4059
|
-
}
|
|
4060
|
-
const BROAD_FIND_LENS_HINT = {
|
|
4061
|
-
lenses: {
|
|
4062
|
-
chapter: "book outline and chapter titles",
|
|
4063
|
-
chunk: "source text ranges",
|
|
4064
|
-
entity: "indexed entities",
|
|
4065
|
-
node: "topology / LLM Wiki structure",
|
|
4066
|
-
triple: "knowledge graph statements"
|
|
4067
|
-
},
|
|
4068
|
-
message: "Choose scope URI lenses such as /chapter, /chunk, /entity, or /triple for broad search."
|
|
4069
|
-
};
|
|
4070
|
-
function createPhraseSearch(query) {
|
|
4071
|
-
const needle = query.trim().toLowerCase();
|
|
4072
|
-
if (needle === "") {
|
|
4073
|
-
return void 0;
|
|
4074
|
-
}
|
|
4075
|
-
return {
|
|
4076
|
-
match: "all",
|
|
4077
|
-
terms: [needle]
|
|
4078
|
-
};
|
|
4079
|
-
}
|
|
4080
|
-
function matchText(value, search) {
|
|
4081
|
-
const lower = value.toLowerCase();
|
|
4082
|
-
const matchedTerms = search.terms.filter((term) => lower.includes(term));
|
|
4083
|
-
const missingTerms = search.terms.filter((term) => !lower.includes(term));
|
|
4084
|
-
if (search.match === "all" && missingTerms.length > 0) {
|
|
4085
|
-
return void 0;
|
|
4086
|
-
}
|
|
4087
|
-
if (search.match === "any" && matchedTerms.length === 0) {
|
|
4088
|
-
return void 0;
|
|
4089
|
-
}
|
|
4090
|
-
const [snippetNeedle] = matchedTerms;
|
|
4091
|
-
if (snippetNeedle === void 0) {
|
|
4092
|
-
return void 0;
|
|
4093
|
-
}
|
|
4094
|
-
return {
|
|
4095
|
-
matchCount: matchedTerms.length,
|
|
4096
|
-
matchedTerms,
|
|
4097
|
-
missingTerms,
|
|
4098
|
-
score: matchedTerms.length / search.terms.length
|
|
4099
|
-
};
|
|
4100
|
-
}
|
|
4101
|
-
function createFindMatchFields(match) {
|
|
4102
|
-
return {
|
|
4103
|
-
matchCount: match.matchCount,
|
|
4104
|
-
matchedTerms: match.matchedTerms,
|
|
4105
|
-
missingTerms: match.missingTerms,
|
|
4106
|
-
score: match.score
|
|
4107
|
-
};
|
|
4108
|
-
}
|
|
4109
|
-
function aggregateEvidenceScores(scores) {
|
|
4110
|
-
const rankedScores = [...scores].filter((score) => score > 0).sort((left, right) => right - left).slice(0, GROUP_SCORE_EVIDENCE_LIMIT);
|
|
4111
|
-
const [bestScore] = rankedScores;
|
|
4112
|
-
if (bestScore === void 0) {
|
|
4113
|
-
return 0;
|
|
4114
|
-
}
|
|
4115
|
-
const evidenceDecayFactor = GROUP_SCORE_MAX_EQUAL_EVIDENCE_BONUS / calculateEvidenceDecayBase();
|
|
4116
|
-
return rankedScores.reduce(
|
|
4117
|
-
(total, score, index) => total + score * (index === 0 ? 1 : evidenceDecayFactor / Math.log2(index + 2)),
|
|
4118
|
-
0
|
|
4119
|
-
);
|
|
4120
|
-
}
|
|
4121
|
-
function calculateEvidenceDecayBase() {
|
|
4122
|
-
let total = 0;
|
|
4123
|
-
for (let rank = 2; rank <= GROUP_SCORE_EVIDENCE_LIMIT; rank += 1) {
|
|
4124
|
-
total += 1 / Math.log2(rank + 1);
|
|
4125
|
-
}
|
|
4126
|
-
return total;
|
|
4127
|
-
}
|
|
4128
|
-
function compareFindEvidenceHits(left, right) {
|
|
4129
|
-
const scoreComparison = (right.score ?? 0) - (left.score ?? 0);
|
|
4130
|
-
if (scoreComparison !== 0) {
|
|
4131
|
-
return scoreComparison;
|
|
4132
|
-
}
|
|
4133
|
-
if (left.position === void 0) {
|
|
4134
|
-
return right.position === void 0 ? 0 : 1;
|
|
4135
|
-
}
|
|
4136
|
-
if (right.position === void 0) {
|
|
4137
|
-
return -1;
|
|
4138
|
-
}
|
|
4139
|
-
return compareArchivePositions(left.position, right.position);
|
|
4140
|
-
}
|
|
4141
|
-
function getSnippetNeedle(match) {
|
|
4142
|
-
const [needle] = match.matchedTerms;
|
|
4143
|
-
if (needle === void 0) {
|
|
4144
|
-
throw new Error("Internal error: missing matched search term.");
|
|
4145
|
-
}
|
|
4146
|
-
return needle;
|
|
4147
|
-
}
|
|
4148
|
-
function createFindResult(query, hits, options, terms = createSearchTerms(query), lens = options.types === void 0 ? "broad" : "typed") {
|
|
4149
|
-
const ranked = createRankedFindResult(query, hits, options, terms, lens);
|
|
4150
|
-
const start = decodeFindCursor(options.cursor);
|
|
4151
|
-
const items = ranked.items.slice(start, start + ranked.limit);
|
|
4152
|
-
const nextOffset = start + items.length;
|
|
4153
|
-
return {
|
|
4154
|
-
...ranked,
|
|
4155
|
-
items,
|
|
4156
|
-
nextCursor: nextOffset < ranked.items.length ? encodeFindCursor(nextOffset) : null
|
|
4157
|
-
};
|
|
4158
|
-
}
|
|
4159
|
-
function createRankedFindResult(query, hits, options, terms = createSearchTerms(query), lens = options.types === void 0 ? "broad" : "typed") {
|
|
4160
|
-
const order = options.order ?? "doc-asc";
|
|
4161
|
-
const limit = options.limit ?? DEFAULT_FIND_LIMIT;
|
|
4162
|
-
const chapters = options.chapters ?? null;
|
|
4163
|
-
const match = options.match ?? "any";
|
|
4164
|
-
const types = options.types ?? null;
|
|
4165
|
-
const ids = options.ids ?? null;
|
|
4166
|
-
const filtered = groupFindHitsByObject(hits).filter((hit) => matchesFindId(hit, ids)).filter((hit) => matchesFindChapter(hit, chapters)).filter((hit) => matchesFindType(hit, types)).filter((hit) => matchesTriplePattern(hit, options.triplePattern)).sort((left, right) => compareSearchHits(left, right, order));
|
|
4167
|
-
return {
|
|
4168
|
-
chapters,
|
|
4169
|
-
items: filtered,
|
|
4170
|
-
lens,
|
|
4171
|
-
lensHint: lens === "broad" ? BROAD_FIND_LENS_HINT : null,
|
|
4172
|
-
limit,
|
|
4173
|
-
match,
|
|
4174
|
-
nextCursor: null,
|
|
4175
|
-
order,
|
|
4176
|
-
query,
|
|
4177
|
-
terms,
|
|
4178
|
-
types
|
|
4179
|
-
};
|
|
4180
|
-
}
|
|
4181
|
-
function groupFindHitsByObject(hits) {
|
|
4182
|
-
const hitsById = /* @__PURE__ */ new Map();
|
|
4183
|
-
for (const hit of hits) {
|
|
4184
|
-
const values = hitsById.get(hit.id) ?? [];
|
|
4185
|
-
values.push(hit);
|
|
4186
|
-
hitsById.set(hit.id, values);
|
|
4187
|
-
}
|
|
4188
|
-
return [...hitsById.values()].map(groupObjectEvidenceHits);
|
|
4189
|
-
}
|
|
4190
|
-
function groupObjectEvidenceHits(evidenceHits) {
|
|
4191
|
-
const rankedHits = [...evidenceHits].sort(compareFindEvidenceHits);
|
|
4192
|
-
const [best] = rankedHits;
|
|
4193
|
-
if (best === void 0) {
|
|
4194
|
-
throw new Error("Internal error: search result candidate is empty.");
|
|
4195
|
-
}
|
|
4196
|
-
if (rankedHits.length === 1) {
|
|
4197
|
-
return best;
|
|
4198
|
-
}
|
|
4199
|
-
return {
|
|
4200
|
-
...best,
|
|
4201
|
-
matchCount: Math.max(...rankedHits.map((hit) => hit.matchCount ?? 0)),
|
|
4202
|
-
matchedTerms: mergeStringLists(
|
|
4203
|
-
rankedHits.flatMap((hit) => hit.matchedTerms ?? [])
|
|
4204
|
-
),
|
|
4205
|
-
missingTerms: mergeStringLists(
|
|
4206
|
-
rankedHits.flatMap((hit) => hit.missingTerms ?? [])
|
|
4207
|
-
),
|
|
4208
|
-
score: aggregateEvidenceScores(rankedHits.map((hit) => hit.score ?? 0))
|
|
4209
|
-
};
|
|
4210
|
-
}
|
|
4211
|
-
function mergeStringLists(values) {
|
|
4212
|
-
return [...new Set(values)];
|
|
4213
|
-
}
|
|
4214
|
-
function createCollectionResult(hits, options) {
|
|
4215
|
-
const order = options.order ?? "doc-asc";
|
|
4216
|
-
const limit = options.limit ?? DEFAULT_FIND_LIMIT;
|
|
4217
|
-
const chapters = options.chapters ?? null;
|
|
4218
|
-
const ids = options.ids ?? null;
|
|
4219
|
-
const types = options.types ?? null;
|
|
4220
|
-
const start = decodeFindCursor(options.cursor);
|
|
4221
|
-
const filtered = hits.filter((hit) => matchesFindId(hit, ids)).filter((hit) => matchesFindChapter(hit, chapters)).filter((hit) => matchesCollectionType(hit, types)).filter((hit) => matchesTriplePattern(hit, options.triplePattern)).sort((left, right) => compareListHits(left, right, order));
|
|
4222
|
-
const items = filtered.slice(start, start + limit);
|
|
4223
|
-
const nextOffset = start + items.length;
|
|
4224
|
-
return {
|
|
4225
|
-
chapters,
|
|
4226
|
-
ids,
|
|
4227
|
-
items,
|
|
4228
|
-
limit,
|
|
4229
|
-
nextCursor: nextOffset < filtered.length ? encodeFindCursor(nextOffset) : null,
|
|
4230
|
-
order,
|
|
4231
|
-
types
|
|
4232
|
-
};
|
|
4233
|
-
}
|
|
4234
|
-
function matchesFindId(hit, ids) {
|
|
4235
|
-
return ids === null || ids.includes(hit.id);
|
|
4236
|
-
}
|
|
4237
|
-
function matchesFindChapter(hit, chapters) {
|
|
4238
|
-
if (chapters === null) {
|
|
4239
|
-
return true;
|
|
4240
|
-
}
|
|
4241
|
-
return hit.chapter !== void 0 && chapters.includes(hit.chapter);
|
|
4242
|
-
}
|
|
4243
|
-
function matchesFindType(hit, types) {
|
|
4244
|
-
if (types === null) {
|
|
4245
|
-
return true;
|
|
4246
|
-
}
|
|
4247
|
-
if (hit.type === "chapter-title" && types.includes("chapter")) {
|
|
4248
|
-
return true;
|
|
4249
|
-
}
|
|
4250
|
-
return isFindFilterType(hit.type) && types.includes(hit.type);
|
|
4251
|
-
}
|
|
4252
|
-
function matchesCollectionType(hit, types) {
|
|
4253
|
-
return types === null || isCollectionType(hit.type) && types.includes(hit.type);
|
|
4254
|
-
}
|
|
4255
|
-
function matchesTriplePattern(hit, pattern) {
|
|
4256
|
-
if (pattern === void 0 || hit.type !== "triple") {
|
|
4257
|
-
return true;
|
|
4258
|
-
}
|
|
4259
|
-
const triple = parseTripleHitUri(hit.id);
|
|
4260
|
-
if (triple === void 0) {
|
|
4261
|
-
return false;
|
|
4262
|
-
}
|
|
4263
|
-
return (pattern.subjectQid === void 0 || pattern.subjectQid === triple.subjectQid) && (pattern.predicate === void 0 || pattern.predicate === triple.predicate) && (pattern.objectQid === void 0 || pattern.objectQid === triple.objectQid);
|
|
4264
|
-
}
|
|
4265
|
-
function parseTripleHitUri(uri) {
|
|
4266
|
-
const match = /^wikg:\/\/triple\/(Q[1-9][0-9]*)\/([^/]+)\/(Q[1-9][0-9]*)$/u.exec(uri);
|
|
4267
|
-
if (match?.[1] === void 0 || match[2] === void 0 || match[3] === void 0) {
|
|
4268
|
-
return void 0;
|
|
4269
|
-
}
|
|
4270
|
-
return {
|
|
4271
|
-
objectQid: match[3],
|
|
4272
|
-
predicate: decodeURIComponent(match[2]),
|
|
4273
|
-
subjectQid: match[1]
|
|
4274
|
-
};
|
|
4275
|
-
}
|
|
4276
|
-
function compareSearchHits(left, right, order) {
|
|
4277
|
-
const direction = order === "doc-asc" ? 1 : -1;
|
|
4278
|
-
const relevance = compareNumbers(getSearchBucket(left.type), getSearchBucket(right.type)) || compareNumbers(right.score ?? 0, left.score ?? 0) || compareNumbers(right.matchCount ?? 0, left.matchCount ?? 0);
|
|
4279
|
-
const position = compareNumbers(
|
|
4280
|
-
getPositionDocumentOrder(left),
|
|
4281
|
-
getPositionDocumentOrder(right)
|
|
4282
|
-
) || compareNumbers(getPositionChapter(left), getPositionChapter(right)) || compareNumbers(getPositionFragment(left), getPositionFragment(right)) || compareNumbers(getPositionSentence(left), getPositionSentence(right)) || compareNumbers(getTypeOrder(left.type), getTypeOrder(right.type)) || left.id.localeCompare(right.id);
|
|
4283
|
-
return relevance || position * direction;
|
|
4284
|
-
}
|
|
4285
|
-
function compareListHits(left, right, order) {
|
|
4286
|
-
const direction = order === "doc-asc" ? 1 : -1;
|
|
4287
|
-
const bucketComparison = compareNumbers(getListBucket(left.type), getListBucket(right.type)) || compareListBucketItems(left, right);
|
|
4288
|
-
if (bucketComparison !== 0) {
|
|
4289
|
-
return bucketComparison;
|
|
4290
|
-
}
|
|
4291
|
-
return compareListPosition(left, right) * direction;
|
|
4292
|
-
}
|
|
4293
|
-
function compareListBucketItems(left, right) {
|
|
4294
|
-
const leftBucket = getListBucket(left.type);
|
|
4295
|
-
if (leftBucket !== getListBucket(right.type)) {
|
|
4296
|
-
return 0;
|
|
4297
|
-
}
|
|
4298
|
-
if (leftBucket === 0) {
|
|
4299
|
-
return compareNumbers(right.score ?? 0, left.score ?? 0);
|
|
4300
|
-
}
|
|
4301
|
-
return 0;
|
|
4302
|
-
}
|
|
4303
|
-
function compareListPosition(left, right) {
|
|
4304
|
-
return compareNumbers(
|
|
4305
|
-
getPositionDocumentOrder(left),
|
|
4306
|
-
getPositionDocumentOrder(right)
|
|
4307
|
-
) || compareNumbers(getPositionChapter(left), getPositionChapter(right)) || compareNumbers(getPositionFragment(left), getPositionFragment(right)) || compareNumbers(getPositionSentence(left), getPositionSentence(right)) || compareNumbers(getTypeOrder(left.type), getTypeOrder(right.type)) || left.id.localeCompare(right.id);
|
|
4308
|
-
}
|
|
4309
|
-
function getListBucket(type) {
|
|
4310
|
-
switch (type) {
|
|
4311
|
-
case "entity":
|
|
4312
|
-
case "triple":
|
|
4313
|
-
return 0;
|
|
4314
|
-
case "node":
|
|
4315
|
-
return 1;
|
|
4316
|
-
case "summary":
|
|
4317
|
-
return 2;
|
|
4318
|
-
case "source":
|
|
4319
|
-
case "fragment":
|
|
4320
|
-
return 3;
|
|
4321
|
-
case "chapter-title":
|
|
4322
|
-
case "chapter":
|
|
4323
|
-
case "chapter-tree":
|
|
4324
|
-
case "meta":
|
|
4325
|
-
return 4;
|
|
4326
|
-
}
|
|
4327
|
-
}
|
|
4328
|
-
function getSearchBucket(type) {
|
|
4329
|
-
switch (type) {
|
|
4330
|
-
case "chapter-title":
|
|
4331
|
-
return 0;
|
|
4332
|
-
case "entity":
|
|
4333
|
-
case "triple":
|
|
4334
|
-
return 1;
|
|
4335
|
-
case "node":
|
|
4336
|
-
return 2;
|
|
4337
|
-
case "source":
|
|
4338
|
-
case "summary":
|
|
4339
|
-
return 3;
|
|
4340
|
-
case "chapter":
|
|
4341
|
-
case "chapter-tree":
|
|
4342
|
-
case "meta":
|
|
4343
|
-
case "fragment":
|
|
4344
|
-
throw new Error(`Unsupported search result bucket type: ${type}`);
|
|
4345
|
-
}
|
|
4346
|
-
}
|
|
4347
|
-
function createSearchTerms(query) {
|
|
4348
|
-
return query.trim().toLowerCase().split(/\s+/u).filter((term) => term !== "");
|
|
4349
|
-
}
|
|
4350
|
-
function getPositionChapter(hit) {
|
|
4351
|
-
return hit.position?.chapter ?? Number.MAX_SAFE_INTEGER;
|
|
4352
|
-
}
|
|
4353
|
-
function getPositionDocumentOrder(hit) {
|
|
4354
|
-
return hit.position?.documentOrder ?? hit.position?.chapter ?? Number.MAX_SAFE_INTEGER;
|
|
4355
|
-
}
|
|
4356
|
-
function getPositionFragment(hit) {
|
|
4357
|
-
return hit.position?.fragment ?? 0;
|
|
4358
|
-
}
|
|
4359
|
-
function getPositionSentence(hit) {
|
|
4360
|
-
return hit.position?.sentence ?? 0;
|
|
4361
|
-
}
|
|
4362
|
-
function getTypeOrder(type) {
|
|
4363
|
-
switch (type) {
|
|
4364
|
-
case "chapter-title":
|
|
4365
|
-
case "chapter":
|
|
4366
|
-
return 0;
|
|
4367
|
-
case "chapter-tree":
|
|
4368
|
-
return 1;
|
|
4369
|
-
case "entity":
|
|
4370
|
-
return 2;
|
|
4371
|
-
case "triple":
|
|
4372
|
-
return 3;
|
|
4373
|
-
case "summary":
|
|
4374
|
-
return 4;
|
|
4375
|
-
case "node":
|
|
4376
|
-
return 5;
|
|
4377
|
-
case "source":
|
|
4378
|
-
return 6;
|
|
4379
|
-
case "fragment":
|
|
4380
|
-
return 6;
|
|
4381
|
-
case "meta":
|
|
4382
|
-
return 7;
|
|
4383
|
-
}
|
|
4384
|
-
}
|
|
4385
|
-
function createNodePosition(sentenceIds, documentOrders) {
|
|
4386
|
-
const [first] = [...sentenceIds].sort(compareSentenceIds);
|
|
4387
|
-
return first === void 0 ? void 0 : createSentencePosition(first, documentOrders);
|
|
4388
|
-
}
|
|
4389
|
-
function createSentencePosition(sentenceId, documentOrders) {
|
|
4390
|
-
return {
|
|
4391
|
-
chapter: sentenceId[0],
|
|
4392
|
-
documentOrder: documentOrders?.get(sentenceId[0]) ?? sentenceId[0],
|
|
4393
|
-
fragment: sentenceId[1],
|
|
4394
|
-
sentence: sentenceId[1]
|
|
4395
|
-
};
|
|
4396
|
-
}
|
|
4397
|
-
function compareSentenceIds(left, right, documentOrders) {
|
|
4398
|
-
return compareNumbers(
|
|
4399
|
-
documentOrders?.get(left[0]) ?? left[0],
|
|
4400
|
-
documentOrders?.get(right[0]) ?? right[0]
|
|
4401
|
-
) || compareNumbers(left[0], right[0]) || compareNumbers(left[1], right[1]);
|
|
4402
|
-
}
|
|
4403
|
-
function compareArchivePositions(left, right) {
|
|
4404
|
-
return compareNumbers(
|
|
4405
|
-
left.documentOrder ?? left.chapter,
|
|
4406
|
-
right.documentOrder ?? right.chapter
|
|
4407
|
-
) || compareNumbers(left.chapter, right.chapter) || compareNumbers(left.fragment ?? 0, right.fragment ?? 0) || compareNumbers(left.sentence ?? 0, right.sentence ?? 0);
|
|
4408
|
-
}
|
|
4409
|
-
function compareNumbers(left, right) {
|
|
4410
|
-
return left === right ? 0 : left < right ? -1 : 1;
|
|
4411
|
-
}
|
|
4412
|
-
function isFindFilterType(type) {
|
|
4413
|
-
return type === "chapter" || type === "chapter-title" || type === "entity" || type === "fragment" || type === "meta" || type === "node" || type === "source" || type === "summary" || type === "triple";
|
|
4414
|
-
}
|
|
4415
|
-
function isCollectionType(type) {
|
|
4416
|
-
return type === "chapter" || type === "chapter-title" || type === "entity" || type === "fragment" || type === "meta" || type === "node" || type === "source" || type === "summary" || type === "triple";
|
|
4417
|
-
}
|
|
4418
|
-
function parseFindLens(value) {
|
|
4419
|
-
if (value === "broad" || value === "exact" || value === "typed") {
|
|
4420
|
-
return value;
|
|
4421
|
-
}
|
|
4422
|
-
throw new Error("Invalid cached search session.");
|
|
4423
|
-
}
|
|
4424
|
-
function parseFindMatch(value) {
|
|
4425
|
-
if (value === "all" || value === "any") {
|
|
4426
|
-
return value;
|
|
4427
|
-
}
|
|
4428
|
-
throw new Error("Invalid cached search session.");
|
|
4429
|
-
}
|
|
4430
|
-
function parseFindTypes(values) {
|
|
4431
|
-
if (values === null) {
|
|
4432
|
-
return null;
|
|
4433
|
-
}
|
|
4434
|
-
return values.map((value) => {
|
|
4435
|
-
if (value === "entity" || value === "fragment" || value === "meta" || value === "node" || value === "source" || value === "summary" || value === "chapter" || value === "chapter-title" || value === "triple") {
|
|
4436
|
-
return value;
|
|
4437
|
-
}
|
|
4438
|
-
throw new Error("Invalid cached search session.");
|
|
4439
|
-
});
|
|
4440
|
-
}
|
|
4441
|
-
function encodeFindCursor(offset) {
|
|
4442
|
-
return Buffer.from(JSON.stringify({ offset, v: 1 })).toString("base64url");
|
|
4443
|
-
}
|
|
4444
|
-
function decodeFindCursor(cursor) {
|
|
4445
|
-
if (cursor === void 0) {
|
|
4446
|
-
return 0;
|
|
4447
|
-
}
|
|
4448
|
-
try {
|
|
4449
|
-
const parsed = JSON.parse(
|
|
4450
|
-
Buffer.from(cursor, "base64url").toString("utf8")
|
|
4451
|
-
);
|
|
4452
|
-
if (typeof parsed === "object" && parsed !== null && "v" in parsed && "offset" in parsed && parsed.v === 1 && Number.isInteger(parsed.offset) && typeof parsed.offset === "number" && parsed.offset >= 0) {
|
|
4453
|
-
return parsed.offset;
|
|
4454
|
-
}
|
|
4455
|
-
} catch {
|
|
4456
|
-
throw new Error("Invalid search cursor.");
|
|
4457
|
-
}
|
|
4458
|
-
throw new Error("Invalid search cursor.");
|
|
4459
|
-
}
|
|
4460
|
-
function isFindCursor(cursor) {
|
|
4461
|
-
try {
|
|
4462
|
-
decodeFindCursor(cursor);
|
|
4463
|
-
return true;
|
|
4464
|
-
} catch {
|
|
4465
|
-
return false;
|
|
4466
|
-
}
|
|
4467
|
-
}
|
|
4468
|
-
function createSnippet(value, needle) {
|
|
4469
|
-
const collapsed = value.replace(/\s+/g, " ").trim();
|
|
4470
|
-
if (needle === void 0) {
|
|
4471
|
-
return collapsed.length > 180 ? `${collapsed.slice(0, 177)}...` : collapsed;
|
|
4472
|
-
}
|
|
4473
|
-
const index = collapsed.toLowerCase().indexOf(needle);
|
|
4474
|
-
if (index < 0) {
|
|
4475
|
-
return collapsed.length > 180 ? `${collapsed.slice(0, 177)}...` : collapsed;
|
|
4476
|
-
}
|
|
4477
|
-
const start = Math.max(0, index - 60);
|
|
4478
|
-
const end = Math.min(collapsed.length, index + needle.length + 120);
|
|
4479
|
-
const prefix = start === 0 ? "" : "...";
|
|
4480
|
-
const suffix = end === collapsed.length ? "" : "...";
|
|
4481
|
-
return `${prefix}${collapsed.slice(start, end)}${suffix}`;
|
|
4482
|
-
}
|
|
4483
|
-
function formatMetaSummary(meta) {
|
|
4484
|
-
if (meta === void 0) {
|
|
4485
|
-
return "[missing]";
|
|
4486
|
-
}
|
|
4487
|
-
return [meta.title, meta.authors.join(", "), meta.publisher].filter((value) => value !== null && value !== "").join(" / ");
|
|
4488
|
-
}
|
|
4489
|
-
function formatMetaTitle(meta) {
|
|
4490
|
-
return meta?.title ?? "Archive metadata";
|
|
4491
|
-
}
|
|
4492
|
-
function createMetaPage(meta) {
|
|
4493
|
-
return {
|
|
4494
|
-
...meta?.authors === void 0 || meta.authors.length === 0 ? {} : { authors: meta.authors },
|
|
4495
|
-
...meta?.description === void 0 || meta.description === null ? {} : { description: meta.description },
|
|
4496
|
-
...meta?.publisher === void 0 || meta.publisher === null ? {} : { publisher: meta.publisher },
|
|
4497
|
-
title: formatMetaTitle(meta)
|
|
4498
|
-
};
|
|
4499
|
-
}
|
|
4500
|
-
function formatMetaText(meta) {
|
|
4501
|
-
const page = createMetaPage(meta);
|
|
4502
|
-
return [
|
|
4503
|
-
`title: ${page.title}`,
|
|
4504
|
-
page.authors === void 0 ? void 0 : `authors: ${page.authors.join(", ")}`,
|
|
4505
|
-
page.publisher === void 0 ? void 0 : `publisher: ${page.publisher}`,
|
|
4506
|
-
page.description === void 0 ? void 0 : `description: ${page.description}`
|
|
4507
|
-
].filter(isDefined).join("\n");
|
|
4508
|
-
}
|
|
4509
|
-
function formatWeight(weight) {
|
|
4510
|
-
return Number.isInteger(weight) ? String(weight) : weight.toFixed(3);
|
|
4511
|
-
}
|
|
4512
|
-
function isDefined(value) {
|
|
4513
|
-
return value !== void 0 && value !== null;
|
|
4514
|
-
}
|
|
4515
|
-
export {
|
|
4516
|
-
clearDirtyArchiveSearchIndex,
|
|
4517
|
-
createArchiveSearchIndexFingerprint,
|
|
4518
|
-
findArchiveObjects,
|
|
4519
|
-
formatChapterId,
|
|
4520
|
-
formatChapterTitleId,
|
|
4521
|
-
formatEdgeId,
|
|
4522
|
-
formatFragmentId,
|
|
4523
|
-
formatNodeId,
|
|
4524
|
-
formatSummaryId,
|
|
4525
|
-
getArchiveIndex,
|
|
4526
|
-
grepArchiveObjects,
|
|
4527
|
-
isArchiveSearchIndexCurrent,
|
|
4528
|
-
listAllArchiveLinks,
|
|
4529
|
-
listArchiveCollection,
|
|
4530
|
-
listArchiveEvidence,
|
|
4531
|
-
listArchiveLinks,
|
|
4532
|
-
listArchiveObjects,
|
|
4533
|
-
listRelatedArchiveObjects,
|
|
4534
|
-
packArchiveContext,
|
|
4535
|
-
readArchivePage,
|
|
4536
|
-
readArchiveSearchIndexStatus,
|
|
4537
|
-
readArchiveText,
|
|
4538
|
-
rebuildArchiveSearchIndex
|
|
4539
|
-
};
|
|
4540
|
-
//# sourceMappingURL=archive-view.js.map
|