ochre-sdk 1.0.69 → 1.0.71

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.
@@ -30,6 +30,11 @@ const XML_ARRAY_TAGS = [
30
30
  "reference",
31
31
  "coord",
32
32
  "area",
33
+ "Page",
34
+ "TextBlock",
35
+ "TextLine",
36
+ "ocrItem",
37
+ "ocrMatch",
33
38
  "footnote",
34
39
  "language",
35
40
  "section",
@@ -73,8 +73,9 @@ async function fetchGallery(parameters, options) {
73
73
  const { success, issues, output } = v.safeParse(XMLGalleryData, data);
74
74
  if (!success) throw createSchemaValidationError("Failed to parse gallery XML", issues);
75
75
  restoreXMLMetadata(output, data);
76
+ const languages = resolveGalleryLanguages(output, requestedLanguages);
76
77
  return {
77
- gallery: parseGallery(output, { languages: resolveGalleryLanguages(output, requestedLanguages) }),
78
+ gallery: parseGallery(output, { languages }),
78
79
  error: null,
79
80
  detailedError: null
80
81
  };
@@ -0,0 +1,44 @@
1
+ import { OcrMatch } from "../types/index.mjs";
2
+ import { FetchFunction } from "../parsers/helpers.mjs";
3
+ //#region src/fetchers/ocr-matches.d.ts
4
+ /**
5
+ * Fetches the locations of OCR text matches within OCHRE resources
6
+ *
7
+ * Matching mirrors the `ocr` Set item query target, so the same value and match
8
+ * mode that selected an item will locate its hits. `matchCountsByUuid` reports
9
+ * the untruncated count, which can exceed the returned matches when
10
+ * `maxMatchesPerItem` caps them.
11
+ *
12
+ * @param parameters - The parameters for the fetch
13
+ * @param parameters.uuids - The resource UUIDs to search, typically from a filtered Set item fetch
14
+ * @param parameters.value - The search value
15
+ * @param parameters.matchMode - Whether to match loosely (stemming and wildcards) or on whole OCR words, defaults to "includes"
16
+ * @param parameters.isCaseSensitive - Whether matching is case sensitive, defaults to false
17
+ * @param parameters.maxMatchesPerItem - The cap on returned matches per requested UUID, defaults to 50
18
+ * @param options - Options for the fetch
19
+ * @param options.fetch - The fetch function to use
20
+ * @returns The OCR matches, or null if the fetch/parse fails
21
+ */
22
+ declare function fetchOcrMatches(parameters: {
23
+ uuids: Array<string>;
24
+ value: string;
25
+ matchMode?: "includes" | "exact";
26
+ isCaseSensitive?: boolean;
27
+ maxMatchesPerItem?: number;
28
+ }, options?: {
29
+ fetch?: FetchFunction;
30
+ }): Promise<{
31
+ matches: Array<OcrMatch>;
32
+ matchesByUuid: Record<string, Array<OcrMatch>>;
33
+ matchCountsByUuid: Record<string, number>;
34
+ error: null;
35
+ detailedError: null;
36
+ } | {
37
+ matches: null;
38
+ matchesByUuid: null;
39
+ matchCountsByUuid: null;
40
+ error: string;
41
+ detailedError: string;
42
+ }>;
43
+ //#endregion
44
+ export { fetchOcrMatches };
@@ -0,0 +1,134 @@
1
+ import { XML_PARSER_OPTIONS } from "../constants.mjs";
2
+ import { createSchemaValidationError, getErrorOutput, stringLiteral } from "../utilities.mjs";
3
+ import { buildOcrTermQueryExpressions } from "../query.mjs";
4
+ import { ocrMatchesParametersSchema } from "../schemas.mjs";
5
+ import { restoreXMLMetadata } from "../xml/metadata.mjs";
6
+ import { parseOcrMatches } from "../parsers/index.mjs";
7
+ import { XMLOcrMatchesData } from "../xml/schemas.mjs";
8
+ import * as v from "valibot";
9
+ import { XMLParser } from "fast-xml-parser";
10
+ //#region src/fetchers/ocr-matches.ts
11
+ /**
12
+ * Build an XQuery string to fetch OCR match locations from the OCHRE API
13
+ *
14
+ * Each OCR word is matched with `cts:contains` against the same per-term CTS
15
+ * queries the Set item filter compiles, so hit locations always agree with what
16
+ * the filter matched — including stemming and wildcards, which cannot be
17
+ * reproduced outside MarkLogic.
18
+ *
19
+ * @param parameters - The parameters for the fetch
20
+ * @param parameters.uuids - The resource UUIDs to search
21
+ * @param parameters.termQueryExpressions - One CTS query expression per search term, in word order
22
+ * @param parameters.maxMatchesPerItem - The cap on returned matches per requested UUID
23
+ * @returns An XQuery string
24
+ */
25
+ function buildXQuery(parameters) {
26
+ const { uuids, termQueryExpressions, maxMatchesPerItem } = parameters;
27
+ return `xquery version "1.0-ml";
28
+
29
+ declare variable $uuids := (${Array.from(uuids, (uuid) => stringLiteral(uuid)).join(", ")});
30
+
31
+ declare variable $termQueries := (
32
+ ${termQueryExpressions.join(",\n ")}
33
+ );
34
+
35
+ declare variable $termCount := ${termQueryExpressions.length};
36
+
37
+ <ochre>{
38
+ <ocrMatches>{
39
+ for $uuid in $uuids
40
+ let $matches :=
41
+ for $page in doc($uuid)//ocr/Page
42
+ let $words := $page//TextLine/string
43
+ let $wordCount := count($words)
44
+ let $resourceUuid := string($page/ancestor::resource[1]/@uuid)
45
+ for $word at $index in $words
46
+ where $index + $termCount - 1 le $wordCount
47
+ and (every $offset in (1 to $termCount)
48
+ satisfies cts:contains($words[$index + $offset - 1], $termQueries[$offset]))
49
+ return <ocrMatch resourceUuid="{$resourceUuid}">{
50
+ $page/@n, $page/@fileName, $page/@WIDTH, $page/@HEIGHT,
51
+ subsequence($words, $index, $termCount)
52
+ }</ocrMatch>
53
+ return <ocrItem uuid="{$uuid}" matchCount="{count($matches)}">{
54
+ subsequence($matches, 1, ${maxMatchesPerItem})
55
+ }</ocrItem>
56
+ }</ocrMatches>
57
+ }</ochre>`;
58
+ }
59
+ /**
60
+ * Fetches the locations of OCR text matches within OCHRE resources
61
+ *
62
+ * Matching mirrors the `ocr` Set item query target, so the same value and match
63
+ * mode that selected an item will locate its hits. `matchCountsByUuid` reports
64
+ * the untruncated count, which can exceed the returned matches when
65
+ * `maxMatchesPerItem` caps them.
66
+ *
67
+ * @param parameters - The parameters for the fetch
68
+ * @param parameters.uuids - The resource UUIDs to search, typically from a filtered Set item fetch
69
+ * @param parameters.value - The search value
70
+ * @param parameters.matchMode - Whether to match loosely (stemming and wildcards) or on whole OCR words, defaults to "includes"
71
+ * @param parameters.isCaseSensitive - Whether matching is case sensitive, defaults to false
72
+ * @param parameters.maxMatchesPerItem - The cap on returned matches per requested UUID, defaults to 50
73
+ * @param options - Options for the fetch
74
+ * @param options.fetch - The fetch function to use
75
+ * @returns The OCR matches, or null if the fetch/parse fails
76
+ */
77
+ async function fetchOcrMatches(parameters, options) {
78
+ try {
79
+ const { uuids, value, matchMode, isCaseSensitive, maxMatchesPerItem } = v.parse(ocrMatchesParametersSchema, parameters);
80
+ const termQueryExpressions = buildOcrTermQueryExpressions({
81
+ value,
82
+ matchMode,
83
+ isCaseSensitive
84
+ });
85
+ if (termQueryExpressions.length === 0) return {
86
+ matches: [],
87
+ matchesByUuid: {},
88
+ matchCountsByUuid: {},
89
+ error: null,
90
+ detailedError: null
91
+ };
92
+ const response = await (options?.fetch ?? fetch)("https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?xquery&xsl=none&lang=\"*\"", {
93
+ method: "POST",
94
+ body: buildXQuery({
95
+ uuids,
96
+ termQueryExpressions,
97
+ maxMatchesPerItem
98
+ }),
99
+ headers: { "Content-Type": "application/xquery" }
100
+ });
101
+ if (!response.ok) throw new Error(`OCHRE API responded with status: ${response.status}`, { cause: response.statusText });
102
+ const dataRaw = await response.text();
103
+ const data = new XMLParser(XML_PARSER_OPTIONS).parse(dataRaw);
104
+ const { success, issues, output } = v.safeParse(XMLOcrMatchesData, data);
105
+ if (!success) throw createSchemaValidationError("Failed to parse OCHRE OCR matches", issues);
106
+ restoreXMLMetadata(output, data);
107
+ const rawOcrItems = output.result.ochre.ocrMatches?.ocrItem ?? [];
108
+ const matches = parseOcrMatches(rawOcrItems);
109
+ const matchesByUuid = {};
110
+ const matchCountsByUuid = {};
111
+ for (const uuid of uuids) {
112
+ matchesByUuid[uuid] = [];
113
+ matchCountsByUuid[uuid] = 0;
114
+ }
115
+ for (const rawOcrItem of rawOcrItems) matchCountsByUuid[rawOcrItem.uuid] = rawOcrItem.matchCount;
116
+ for (const match of matches) matchesByUuid[match.uuid]?.push(match);
117
+ return {
118
+ matches,
119
+ matchesByUuid,
120
+ matchCountsByUuid,
121
+ error: null,
122
+ detailedError: null
123
+ };
124
+ } catch (error) {
125
+ return {
126
+ matches: null,
127
+ matchesByUuid: null,
128
+ matchCountsByUuid: null,
129
+ ...getErrorOutput(error, "Unknown error")
130
+ };
131
+ }
132
+ }
133
+ //#endregion
134
+ export { fetchOcrMatches };
@@ -1,10 +1,10 @@
1
1
  import { BELONGS_TO_COLLECTION_UUID, DEFAULT_LANGUAGES, XML_PARSER_OPTIONS } from "../../constants.mjs";
2
2
  import { createSchemaValidationError, getErrorOutput, stringLiteral } from "../../utilities.mjs";
3
+ import { buildAndCtsQueryExpression, buildBelongsToCollectionQueryExpression, buildQueryPlan } from "../../query.mjs";
3
4
  import { iso639_3Schema, setItemsParametersSchema } from "../../schemas.mjs";
4
5
  import { restoreXMLMetadata } from "../../xml/metadata.mjs";
5
6
  import { parseSetItems } from "../../parsers/index.mjs";
6
7
  import { XMLSetItemsData } from "../../xml/schemas.mjs";
7
- import { buildAndCtsQueryExpression, buildBelongsToCollectionQueryExpression, buildQueryPlan } from "../../query.mjs";
8
8
  import * as v from "valibot";
9
9
  import { XMLParser } from "fast-xml-parser";
10
10
  //#region src/fetchers/set/items.ts
@@ -138,8 +138,8 @@ function buildXQuery(parameters) {
138
138
  const { queries, sort, setScopeUuids, belongsToCollectionScopeUuids, page, pageSize } = parameters;
139
139
  const startPosition = (page - 1) * pageSize + 1;
140
140
  const setScopeDeclaration = `declare variable $setScopeUuids := (${setScopeUuids.map((uuid) => stringLiteral(uuid)).join(", ")});`;
141
- const baseItemsExpression = "doc()/ochre/set[@uuid = $setScopeUuids]/items/*";
142
141
  const compiledQueryPlan = buildQueryPlan({ queries });
142
+ const baseItemsExpression = `doc()/ochre/set[@uuid = $setScopeUuids]/items/*${compiledQueryPlan.itemPredicates}`;
143
143
  const itemsQueryExpressions = [];
144
144
  const belongsToCollectionQueryExpression = buildBelongsToCollectionQueryExpression(belongsToCollectionScopeUuids, BELONGS_TO_COLLECTION_UUID);
145
145
  if (compiledQueryPlan.queryExpression != null) itemsQueryExpressions.push(compiledQueryPlan.queryExpression);
@@ -148,8 +148,10 @@ function buildXQuery(parameters) {
148
148
  const orderedItemsClause = buildOrderedItemsClause(sort);
149
149
  const xqueryDeclarations = ["xquery version \"1.0-ml\";", setScopeDeclaration];
150
150
  if (compiledQueryPlan.prolog !== "") xqueryDeclarations.push(compiledQueryPlan.prolog);
151
- const itemsClause = itemsQueryExpression == null ? `let $items := ${baseItemsExpression}` : `let $query := ${itemsQueryExpression}
152
- let $items := cts:search(${baseItemsExpression}, $query)`;
151
+ const letClauses = Array.from(compiledQueryPlan.ocrBindings, (binding) => `let ${binding.name} := ${binding.expression}`);
152
+ if (itemsQueryExpression == null) letClauses.push(`let $items := ${baseItemsExpression}`);
153
+ else letClauses.push(`let $query := ${itemsQueryExpression}`, `let $items := cts:search(${baseItemsExpression}, $query)`);
154
+ const itemsClause = letClauses.join("\n ");
153
155
  return `${xqueryDeclarations.join("\n\n")}
154
156
 
155
157
  <ochre>{
@@ -1,9 +1,9 @@
1
1
  import { BELONGS_TO_COLLECTION_UUID, DEFAULT_LANGUAGES, XML_PARSER_OPTIONS } from "../../constants.mjs";
2
2
  import { createSchemaValidationError, getErrorOutput, stringLiteral } from "../../utilities.mjs";
3
3
  import { MultilingualString } from "../../parsers/multilingual.mjs";
4
+ import { buildAndCtsQueryExpression, buildBelongsToCollectionQueryExpression, buildQueryPlan } from "../../query.mjs";
4
5
  import { setPropertyValuesParametersSchema } from "../../schemas.mjs";
5
6
  import { parseXMLContent } from "../../parsers/string.mjs";
6
- import { buildAndCtsQueryExpression, buildBelongsToCollectionQueryExpression, buildQueryPlan } from "../../query.mjs";
7
7
  import * as v from "valibot";
8
8
  import { XMLParser } from "fast-xml-parser";
9
9
  //#region src/fetchers/set/property-values.ts
@@ -190,8 +190,8 @@ const responseSchema = v.object({ result: v.object({ ochre: v.object({
190
190
  function buildXQuery(parameters) {
191
191
  const { setScopeUuids, belongsToCollectionScopeUuids, queries, propertyFacetSelectors, attributes, isLimitedToLeafPropertyValues } = parameters;
192
192
  const setScopeDeclaration = `declare variable $setScopeUuids := (${setScopeUuids.map((uuid) => stringLiteral(uuid)).join(", ")});`;
193
- const baseItemsExpression = "doc()/ochre/set[@uuid = $setScopeUuids]/items/*";
194
193
  const compiledQueryPlan = buildQueryPlan({ queries: getItemFilterQueriesFromPropertyValueQueries(queries) });
194
+ const baseItemsExpression = `doc()/ochre/set[@uuid = $setScopeUuids]/items/*${compiledQueryPlan.itemPredicates}`;
195
195
  const itemsQueryExpressions = [];
196
196
  const belongsToCollectionQueryExpression = buildBelongsToCollectionQueryExpression(belongsToCollectionScopeUuids, BELONGS_TO_COLLECTION_UUID);
197
197
  if (compiledQueryPlan.queryExpression != null) itemsQueryExpressions.push(compiledQueryPlan.queryExpression);
@@ -404,8 +404,10 @@ let $period-values :=
404
404
  )`);
405
405
  returnedSequences.push("$period-values");
406
406
  }
407
- const itemsClause = itemsQueryExpression == null ? `let $items := ${baseItemsExpression}` : `let $query := ${itemsQueryExpression}
408
- let $items := cts:search(${baseItemsExpression}, $query)`;
407
+ const letClauses = Array.from(compiledQueryPlan.ocrBindings, (binding) => `let ${binding.name} := ${binding.expression}`);
408
+ if (itemsQueryExpression == null) letClauses.push(`let $items := ${baseItemsExpression}`);
409
+ else letClauses.push(`let $query := ${itemsQueryExpression}`, `let $items := cts:search(${baseItemsExpression}, $query)`);
410
+ const itemsClause = letClauses.join("\n ");
409
411
  return `${xqueryDeclarations.join("\n\n")}
410
412
 
411
413
  <ochre>{
@@ -16,7 +16,8 @@ function parseWebsiteMetadata(data, options) {
16
16
  const identification = parseIdentification(websiteTree.identification, options);
17
17
  const websiteName = identification.label.getText().trim();
18
18
  const metadataDescription = (parseStringLike(rawOchre.metadata.description) ?? "").trim();
19
- const reader = websitePresentationReader(parseSimplifiedProperties(websiteTree.properties, options));
19
+ const properties = parseSimplifiedProperties(websiteTree.properties, options);
20
+ const reader = websitePresentationReader(properties);
20
21
  const webpage = websiteTree.items?.resource?.[0] ?? null;
21
22
  const webpageTitle = webpage != null && "identification" in webpage ? parseIdentification(webpage.identification, options).label : null;
22
23
  return {
@@ -154,8 +155,9 @@ async function fetchWebsiteMetadata(abbreviation, options) {
154
155
  const { success, issues, output } = v.safeParse(XMLWebsiteData, data);
155
156
  if (!success) throw createSchemaValidationError("Failed to parse website metadata XML", issues);
156
157
  restoreXMLMetadata(output, data);
158
+ const metadataLanguages = parseMetadataLanguages(output.result.ochre);
157
159
  return {
158
- websiteMetadata: parseWebsiteMetadata(output, { languages: resolveLanguages(requestedLanguages, parseMetadataLanguages(output.result.ochre)) }),
160
+ websiteMetadata: parseWebsiteMetadata(output, { languages: resolveLanguages(requestedLanguages, metadataLanguages) }),
159
161
  error: null,
160
162
  detailedError: null
161
163
  };
package/dist/getters.mjs CHANGED
@@ -73,12 +73,10 @@ function clonePropertyValues(values) {
73
73
  content: value.content
74
74
  });
75
75
  break;
76
- case "boolean":
77
- clonedValues.push({
78
- ...value,
79
- content: value.content
80
- });
81
- break;
76
+ case "boolean": clonedValues.push({
77
+ ...value,
78
+ content: value.content
79
+ });
82
80
  }
83
81
  return clonedValues;
84
82
  }
@@ -7,6 +7,10 @@ type FlattenedItem<U, T extends LanguageCodes> = Omit<U, "properties"> & {
7
7
  * The default page size to use for fetching paginated items
8
8
  */
9
9
  declare const DEFAULT_PAGE_SIZE = 48;
10
+ /**
11
+ * The default cap on OCR matches returned per requested item
12
+ */
13
+ declare const DEFAULT_MAX_OCR_MATCHES_PER_ITEM = 50;
10
14
  /**
11
15
  * Flatten the properties of an item
12
16
  * @param item - The item whose properties to flatten
@@ -14,4 +18,4 @@ declare const DEFAULT_PAGE_SIZE = 48;
14
18
  */
15
19
  declare function flattenItemProperties<U extends ItemCategory = ItemCategory, V extends ContainedItemCategory<U> = ContainedItemCategory<U>, T extends LanguageCodes = LanguageCodes, W extends ItemPayloadKind = "topLevel">(item: Item<U, V, T, W>): FlattenedItem<Item<U, V, T, W>, T>;
16
20
  //#endregion
17
- export { DEFAULT_PAGE_SIZE, flattenItemProperties };
21
+ export { DEFAULT_MAX_OCR_MATCHES_PER_ITEM, DEFAULT_PAGE_SIZE, flattenItemProperties };
package/dist/helpers.mjs CHANGED
@@ -5,6 +5,10 @@ import { flattenProperties } from "./utilities.mjs";
5
5
  */
6
6
  const DEFAULT_PAGE_SIZE = 48;
7
7
  /**
8
+ * The default cap on OCR matches returned per requested item
9
+ */
10
+ const DEFAULT_MAX_OCR_MATCHES_PER_ITEM = 50;
11
+ /**
8
12
  * Flatten the properties of an item
9
13
  * @param item - The item whose properties to flatten
10
14
  * @returns The item with the properties flattened
@@ -30,4 +34,4 @@ function flattenItemProperties(item) {
30
34
  };
31
35
  }
32
36
  //#endregion
33
- export { DEFAULT_PAGE_SIZE, flattenItemProperties };
37
+ export { DEFAULT_MAX_OCR_MATCHES_PER_ITEM, DEFAULT_PAGE_SIZE, flattenItemProperties };
package/dist/index.d.mts CHANGED
@@ -1,14 +1,15 @@
1
1
  import { MultilingualOptions, MultilingualString, MultilingualStringEntries, MultilingualStringEntry, MultilingualStringInput, MultilingualStringJSON, MultilingualStringObject, MultilingualStringText } from "./parsers/multilingual.mjs";
2
2
  import { AccordionWebBlock, ContextTree, ContextTreeFilterLevel, ContextTreeLevel, ContextTreeLevelItem, ProtectedWebsite, Scope, Style, StylesheetCategory, StylesheetItem, WebAccordionItem, WebBlock, WebBlockByLayout, WebBlockItem, WebBlockLayout, WebElement, WebElementComponent, WebElementComponentName, WebElementComponentOf, WebElementOf, WebImage, WebSidebar, WebTitle, Webpage, Website, WebsiteMetadata, WebsitePropertyQuery, WebsitePropertyQueryNode, WebsiteSegment, WebsiteType } from "./types/website.mjs";
3
- import { AnyBibliography, AnyConcept, AnyItem, AnyPeriod, AnyPerson, AnyPropertyValue, AnyPropertyVariable, AnyResource, AnySet, AnySpatialUnit, AnyText, AnyTree, BaseItem, BaseItemLink, BelongsTo, Bibliography, BibliographyEntryInfo, BibliographyItemLink, BibliographySourceDocument, Concept, ConceptItemLink, ContainedItemCategory, ContainedItemCategoryFromOption, ContainedItemCategoryOption, Context, ContextItem, ContextItemCategory, ContextNode, Coordinates, CoordinatesSource, DictionaryUnitItemLink, EmbeddedBibliography, EmbeddedConcept, EmbeddedItem, EmbeddedPeriod, EmbeddedPerson, EmbeddedPropertyValue, EmbeddedPropertyVariable, EmbeddedResource, EmbeddedSet, EmbeddedSpatialUnit, EmbeddedText, EmbeddedTree, Event, Gallery, Heading, HeadingItemCategory, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, ItemCategory, ItemCategoryFromOption, ItemCategoryOption, ItemCategoryWithEmbeddedItems, ItemContainerCategory, ItemLink, ItemLinkCategory, ItemLinks, ItemPayloadKind, ItemProperty, ItemWithoutEmbeddedItems, LanguageCodes, License, Metadata, Note, Observation, Period, PeriodItemLink, Person, PersonItemLink, Prettify, Property, PropertyLike, PropertyRelation, PropertyValue, PropertyValueContent, PropertyValueDataType, PropertyValueItemLink, PropertyValueQueryItem, PropertyVariable, PropertyVariableItemLink, Query, QueryGroup, QueryLeaf, QueryablePropertyValueDataType, RecursiveItemCategory, Resource, ResourceItemLink, Section, Set, SetAttributeValueQueryItem, SetBibliography, SetConcept, SetItem, SetItemCategory, SetItemLink, SetItemProperty, SetItemSimplifiedProperty, SetItemsSort, SetItemsSortDirection, SetPeriod, SetResource, SetSpatialUnit, SetTree, SimplifiedProperty, SpatialUnit, SpatialUnitItemLink, Text, TextItemLink, TopLevelItem, Tree, TreeItemCategory, TreeItemLink } from "./types/index.mjs";
3
+ import { AnyBibliography, AnyConcept, AnyItem, AnyPeriod, AnyPerson, AnyPropertyValue, AnyPropertyVariable, AnyResource, AnySet, AnySpatialUnit, AnyText, AnyTree, BaseItem, BaseItemLink, BelongsTo, Bibliography, BibliographyEntryInfo, BibliographyItemLink, BibliographySourceDocument, Concept, ConceptItemLink, ContainedItemCategory, ContainedItemCategoryFromOption, ContainedItemCategoryOption, Context, ContextItem, ContextItemCategory, ContextNode, Coordinates, CoordinatesSource, DictionaryUnitItemLink, EmbeddedBibliography, EmbeddedConcept, EmbeddedItem, EmbeddedPeriod, EmbeddedPerson, EmbeddedPropertyValue, EmbeddedPropertyVariable, EmbeddedResource, EmbeddedSet, EmbeddedSpatialUnit, EmbeddedText, EmbeddedTree, Event, Gallery, Heading, HeadingItemCategory, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, ItemCategory, ItemCategoryFromOption, ItemCategoryOption, ItemCategoryWithEmbeddedItems, ItemContainerCategory, ItemLink, ItemLinkCategory, ItemLinks, ItemPayloadKind, ItemProperty, ItemWithoutEmbeddedItems, LanguageCodes, License, Metadata, Note, Observation, OcrMatch, OcrPage, OcrPoint, OcrTextBlock, OcrTextLine, OcrWord, Period, PeriodItemLink, Person, PersonItemLink, Prettify, Property, PropertyLike, PropertyRelation, PropertyValue, PropertyValueContent, PropertyValueDataType, PropertyValueItemLink, PropertyValueQueryItem, PropertyVariable, PropertyVariableItemLink, Query, QueryGroup, QueryLeaf, QueryablePropertyValueDataType, RecursiveItemCategory, Resource, ResourceItemLink, Section, Set, SetAttributeValueQueryItem, SetBibliography, SetConcept, SetItem, SetItemCategory, SetItemLink, SetItemProperty, SetItemSimplifiedProperty, SetItemsSort, SetItemsSortDirection, SetPeriod, SetResource, SetSpatialUnit, SetTree, SimplifiedProperty, SpatialUnit, SpatialUnitItemLink, Text, TextItemLink, TopLevelItem, Tree, TreeItemCategory, TreeItemLink } from "./types/index.mjs";
4
4
  import { fetchGallery } from "./fetchers/gallery.mjs";
5
5
  import { fetchItemChildren } from "./fetchers/item-children.mjs";
6
6
  import { fetchItemLinks } from "./fetchers/item-links.mjs";
7
7
  import { defineLanguages, fetchItem, withLanguages } from "./fetchers/item.mjs";
8
+ import { fetchOcrMatches } from "./fetchers/ocr-matches.mjs";
8
9
  import { fetchSetItems } from "./fetchers/set/items.mjs";
9
10
  import { fetchSetPropertyValues } from "./fetchers/set/property-values.mjs";
10
11
  import { fetchWebsiteMetadata } from "./fetchers/website-metadata.mjs";
11
12
  import { fetchWebsite } from "./fetchers/website.mjs";
12
13
  import { PropertyOptions, filterProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels } from "./getters.mjs";
13
- import { DEFAULT_PAGE_SIZE, flattenItemProperties } from "./helpers.mjs";
14
- export { type AccordionWebBlock, type AnyBibliography, type AnyConcept, type AnyItem, type AnyPeriod, type AnyPerson, type AnyPropertyValue, type AnyPropertyVariable, type AnyResource, type AnySet, type AnySpatialUnit, type AnyText, type AnyTree, type BaseItem, type BaseItemLink, type BelongsTo, type Bibliography, type BibliographyEntryInfo, type BibliographyItemLink, type BibliographySourceDocument, type Concept, type ConceptItemLink, type ContainedItemCategory, type ContainedItemCategoryFromOption, type ContainedItemCategoryOption, type Context, type ContextItem, type ContextItemCategory, type ContextNode, type ContextTree, type ContextTreeFilterLevel, type ContextTreeLevel, type ContextTreeLevelItem, type Coordinates, type CoordinatesSource, DEFAULT_PAGE_SIZE, type DictionaryUnitItemLink, type EmbeddedBibliography, type EmbeddedConcept, type EmbeddedItem, type EmbeddedPeriod, type EmbeddedPerson, type EmbeddedPropertyValue, type EmbeddedPropertyVariable, type EmbeddedResource, type EmbeddedSet, type EmbeddedSpatialUnit, type EmbeddedText, type EmbeddedTree, type Event, type Gallery, type Heading, type HeadingItemCategory, type Identification, type Image, type ImageMap, type ImageMapArea, type Interpretation, type Item, type ItemCategory, type ItemCategoryFromOption, type ItemCategoryOption, type ItemCategoryWithEmbeddedItems, type ItemContainerCategory, type ItemLink, type ItemLinkCategory, type ItemLinks, type ItemPayloadKind, type ItemProperty, type ItemWithoutEmbeddedItems, type LanguageCodes, type License, type Metadata, type MultilingualOptions, MultilingualString, type MultilingualStringEntries, type MultilingualStringEntry, type MultilingualStringInput, type MultilingualStringJSON, type MultilingualStringObject, type MultilingualStringText, type Note, type Observation, type Period, type PeriodItemLink, type Person, type PersonItemLink, type Prettify, type Property, type PropertyLike, PropertyOptions, type PropertyRelation, type PropertyValue, type PropertyValueContent, type PropertyValueDataType, type PropertyValueItemLink, type PropertyValueQueryItem, type PropertyVariable, type PropertyVariableItemLink, type ProtectedWebsite, type Query, type QueryGroup, type QueryLeaf, type QueryablePropertyValueDataType, type RecursiveItemCategory, type Resource, type ResourceItemLink, type Scope, type Section, type Set, type SetAttributeValueQueryItem, type SetBibliography, type SetConcept, type SetItem, type SetItemCategory, type SetItemLink, type SetItemProperty, type SetItemSimplifiedProperty, type SetItemsSort, type SetItemsSortDirection, type SetPeriod, type SetResource, type SetSpatialUnit, type SetTree, type SimplifiedProperty, type SpatialUnit, type SpatialUnitItemLink, type Style, type StylesheetCategory, type StylesheetItem, type Text, type TextItemLink, type TopLevelItem, type Tree, type TreeItemCategory, type TreeItemLink, type WebAccordionItem, type WebBlock, type WebBlockByLayout, type WebBlockItem, type WebBlockLayout, type WebElement, type WebElementComponent, type WebElementComponentName, type WebElementComponentOf, type WebElementOf, type WebImage, type WebSidebar, type WebTitle, type Webpage, type Website, type WebsiteMetadata, type WebsitePropertyQuery, type WebsitePropertyQueryNode, type WebsiteSegment, type WebsiteType, defineLanguages, fetchGallery, fetchItem, fetchItemChildren, fetchItemLinks, fetchSetItems, fetchSetPropertyValues, fetchWebsite, fetchWebsiteMetadata, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels, withLanguages };
14
+ import { DEFAULT_MAX_OCR_MATCHES_PER_ITEM, DEFAULT_PAGE_SIZE, flattenItemProperties } from "./helpers.mjs";
15
+ export { type AccordionWebBlock, type AnyBibliography, type AnyConcept, type AnyItem, type AnyPeriod, type AnyPerson, type AnyPropertyValue, type AnyPropertyVariable, type AnyResource, type AnySet, type AnySpatialUnit, type AnyText, type AnyTree, type BaseItem, type BaseItemLink, type BelongsTo, type Bibliography, type BibliographyEntryInfo, type BibliographyItemLink, type BibliographySourceDocument, type Concept, type ConceptItemLink, type ContainedItemCategory, type ContainedItemCategoryFromOption, type ContainedItemCategoryOption, type Context, type ContextItem, type ContextItemCategory, type ContextNode, type ContextTree, type ContextTreeFilterLevel, type ContextTreeLevel, type ContextTreeLevelItem, type Coordinates, type CoordinatesSource, DEFAULT_MAX_OCR_MATCHES_PER_ITEM, DEFAULT_PAGE_SIZE, type DictionaryUnitItemLink, type EmbeddedBibliography, type EmbeddedConcept, type EmbeddedItem, type EmbeddedPeriod, type EmbeddedPerson, type EmbeddedPropertyValue, type EmbeddedPropertyVariable, type EmbeddedResource, type EmbeddedSet, type EmbeddedSpatialUnit, type EmbeddedText, type EmbeddedTree, type Event, type Gallery, type Heading, type HeadingItemCategory, type Identification, type Image, type ImageMap, type ImageMapArea, type Interpretation, type Item, type ItemCategory, type ItemCategoryFromOption, type ItemCategoryOption, type ItemCategoryWithEmbeddedItems, type ItemContainerCategory, type ItemLink, type ItemLinkCategory, type ItemLinks, type ItemPayloadKind, type ItemProperty, type ItemWithoutEmbeddedItems, type LanguageCodes, type License, type Metadata, type MultilingualOptions, MultilingualString, type MultilingualStringEntries, type MultilingualStringEntry, type MultilingualStringInput, type MultilingualStringJSON, type MultilingualStringObject, type MultilingualStringText, type Note, type Observation, type OcrMatch, type OcrPage, type OcrPoint, type OcrTextBlock, type OcrTextLine, type OcrWord, type Period, type PeriodItemLink, type Person, type PersonItemLink, type Prettify, type Property, type PropertyLike, PropertyOptions, type PropertyRelation, type PropertyValue, type PropertyValueContent, type PropertyValueDataType, type PropertyValueItemLink, type PropertyValueQueryItem, type PropertyVariable, type PropertyVariableItemLink, type ProtectedWebsite, type Query, type QueryGroup, type QueryLeaf, type QueryablePropertyValueDataType, type RecursiveItemCategory, type Resource, type ResourceItemLink, type Scope, type Section, type Set, type SetAttributeValueQueryItem, type SetBibliography, type SetConcept, type SetItem, type SetItemCategory, type SetItemLink, type SetItemProperty, type SetItemSimplifiedProperty, type SetItemsSort, type SetItemsSortDirection, type SetPeriod, type SetResource, type SetSpatialUnit, type SetTree, type SimplifiedProperty, type SpatialUnit, type SpatialUnitItemLink, type Style, type StylesheetCategory, type StylesheetItem, type Text, type TextItemLink, type TopLevelItem, type Tree, type TreeItemCategory, type TreeItemLink, type WebAccordionItem, type WebBlock, type WebBlockByLayout, type WebBlockItem, type WebBlockLayout, type WebElement, type WebElementComponent, type WebElementComponentName, type WebElementComponentOf, type WebElementOf, type WebImage, type WebSidebar, type WebTitle, type Webpage, type Website, type WebsiteMetadata, type WebsitePropertyQuery, type WebsitePropertyQueryNode, type WebsiteSegment, type WebsiteType, defineLanguages, fetchGallery, fetchItem, fetchItemChildren, fetchItemLinks, fetchOcrMatches, fetchSetItems, fetchSetPropertyValues, fetchWebsite, fetchWebsiteMetadata, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels, withLanguages };
package/dist/index.mjs CHANGED
@@ -1,12 +1,13 @@
1
1
  import { filterProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels } from "./getters.mjs";
2
- import { DEFAULT_PAGE_SIZE, flattenItemProperties } from "./helpers.mjs";
2
+ import { DEFAULT_MAX_OCR_MATCHES_PER_ITEM, DEFAULT_PAGE_SIZE, flattenItemProperties } from "./helpers.mjs";
3
3
  import { MultilingualString } from "./parsers/multilingual.mjs";
4
4
  import { fetchGallery } from "./fetchers/gallery.mjs";
5
5
  import { fetchItemChildren } from "./fetchers/item-children.mjs";
6
6
  import { fetchItemLinks } from "./fetchers/item-links.mjs";
7
7
  import { defineLanguages, fetchItem, withLanguages } from "./fetchers/item.mjs";
8
+ import { fetchOcrMatches } from "./fetchers/ocr-matches.mjs";
8
9
  import { fetchSetItems } from "./fetchers/set/items.mjs";
9
10
  import { fetchSetPropertyValues } from "./fetchers/set/property-values.mjs";
10
11
  import { fetchWebsiteMetadata } from "./fetchers/website-metadata.mjs";
11
12
  import { fetchWebsite } from "./fetchers/website.mjs";
12
- export { DEFAULT_PAGE_SIZE, MultilingualString, defineLanguages, fetchGallery, fetchItem, fetchItemChildren, fetchItemLinks, fetchSetItems, fetchSetPropertyValues, fetchWebsite, fetchWebsiteMetadata, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels, withLanguages };
13
+ export { DEFAULT_MAX_OCR_MATCHES_PER_ITEM, DEFAULT_PAGE_SIZE, MultilingualString, defineLanguages, fetchGallery, fetchItem, fetchItemChildren, fetchItemLinks, fetchOcrMatches, fetchSetItems, fetchSetPropertyValues, fetchWebsite, fetchWebsiteMetadata, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels, withLanguages };
@@ -1,12 +1,19 @@
1
1
  import { Webpage } from "../types/website.mjs";
2
- import { Bibliography, ContainedItemCategoryFromOption, ContainedItemCategoryOption, Gallery, Identification, Item, ItemCategory, ItemCategoryFromOption, ItemCategoryOption, ItemContainerCategory, ItemLinks, Metadata, Note, Person, Property, Resource, SetItem, SetItemCategory, SimplifiedProperty } from "../types/index.mjs";
3
- import { XMLBibliography, XMLData, XMLDataItem, XMLGalleryData, XMLIdentification, XMLItemLinks, XMLLink, XMLMetadata, XMLNote, XMLPerson, XMLProperty, XMLResource, XMLSetItems, XMLSimplifiedProperty } from "../xml/types.mjs";
2
+ import { Bibliography, ContainedItemCategoryFromOption, ContainedItemCategoryOption, Gallery, Identification, Item, ItemCategory, ItemCategoryFromOption, ItemCategoryOption, ItemContainerCategory, ItemLinks, Metadata, Note, OcrMatch, Person, Property, Resource, SetItem, SetItemCategory, SimplifiedProperty } from "../types/index.mjs";
3
+ import { XMLBibliography, XMLData, XMLDataItem, XMLGalleryData, XMLIdentification, XMLItemLinks, XMLLink, XMLMetadata, XMLNote, XMLOcrMatchItem, XMLPerson, XMLProperty, XMLResource, XMLSetItems, XMLSimplifiedProperty } from "../xml/types.mjs";
4
4
  import { ParserOptions, getParserOptions, parseStringLike } from "./helpers.mjs";
5
5
  //#region src/parsers/index.d.ts
6
6
  type RawOchre = XMLData["result"]["ochre"];
7
7
  type ResourceViewParser<T extends ReadonlyArray<string>> = (view: XMLResource["view"], context: Pick<Resource<T, "topLevel">, "belongsTo" | "metadata">) => Webpage<T> | null;
8
8
  type SetItemCategoryFromCategories<T extends ReadonlyArray<SetItemCategory> | undefined> = T extends ReadonlyArray<infer U> ? Extract<U, SetItemCategory> : SetItemCategory;
9
9
  declare function parseIdentification<T extends ReadonlyArray<string>>(rawIdentification: XMLIdentification, options: ParserOptions<T>): Identification<T>;
10
+ /**
11
+ * Parse OCR matches returned by the OCHRE API
12
+ * @param rawOcrItems - The raw OCR match items
13
+ * @returns The parsed OCR matches, in request order
14
+ * @internal
15
+ */
16
+ declare function parseOcrMatches(rawOcrItems: Array<XMLOcrMatchItem>): Array<OcrMatch>;
10
17
  declare function parseNotes<T extends ReadonlyArray<string>>(rawNotes: {
11
18
  note: Array<XMLNote>;
12
19
  } | undefined, options: ParserOptions<T>): Array<Note<T>>;
@@ -61,4 +68,4 @@ declare function parseItem(rawData: XMLData, options: {
61
68
  parseResourceView?: ResourceViewParser<ReadonlyArray<string>>;
62
69
  }): Item<ItemCategory, SetItemCategory, ReadonlyArray<string>>;
63
70
  //#endregion
64
- export { type ParserOptions, RawOchre, getParserOptions, parseBibliographyList, parseGallery, parseIdentification, parseItem, parseLinkedItems, parseLinks, parseMetadata, parseMetadataLanguages, parseNotes, parsePersonList, parseProperties, parseSetItems, parseSimplifiedProperties, parseStringLike, resolveDefaultLanguage, resolveLanguages };
71
+ export { type ParserOptions, RawOchre, getParserOptions, parseBibliographyList, parseGallery, parseIdentification, parseItem, parseLinkedItems, parseLinks, parseMetadata, parseMetadataLanguages, parseNotes, parseOcrMatches, parsePersonList, parseProperties, parseSetItems, parseSimplifiedProperties, parseStringLike, resolveDefaultLanguage, resolveLanguages };
@@ -430,6 +430,79 @@ function parseImageMap(rawImageMap) {
430
430
  height: rawImageMap.height
431
431
  };
432
432
  }
433
+ function parseOcrVertices(rawVertices) {
434
+ const vertices = [];
435
+ if (rawVertices == null) return vertices;
436
+ for (const match of rawVertices.matchAll(/\(\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*\)/g)) {
437
+ const x = Number(match[1]);
438
+ const y = Number(match[2]);
439
+ vertices.push({
440
+ x: Number.isNaN(x) ? 0 : x,
441
+ y: Number.isNaN(y) ? 0 : y
442
+ });
443
+ }
444
+ return vertices;
445
+ }
446
+ function parseOcrWords(rawWords) {
447
+ return Array.from(rawWords ?? [], (rawWord) => ({
448
+ content: rawWord.CONTENT,
449
+ x: rawWord.HPOS,
450
+ y: rawWord.VPOS,
451
+ width: rawWord.WIDTH,
452
+ height: rawWord.HEIGHT,
453
+ vertices: parseOcrVertices(rawWord.VERTICES)
454
+ }));
455
+ }
456
+ function joinOcrWordContents(words) {
457
+ return Array.from(words, (word) => word.content).join(" ");
458
+ }
459
+ function parseOcrPage(rawPage) {
460
+ const blocks = Array.from(rawPage.TextBlock ?? [], (rawBlock) => ({ lines: Array.from(rawBlock.TextLine ?? [], (rawLine) => {
461
+ const words = parseOcrWords(rawLine.string);
462
+ return {
463
+ content: joinOcrWordContents(words),
464
+ words
465
+ };
466
+ }) }));
467
+ return {
468
+ number: rawPage.n ?? null,
469
+ fileName: rawPage.fileName ?? null,
470
+ width: rawPage.WIDTH ?? null,
471
+ height: rawPage.HEIGHT ?? null,
472
+ blocks
473
+ };
474
+ }
475
+ function parseOcr(rawOcr) {
476
+ return Array.from(rawOcr?.Page ?? [], (rawPage) => parseOcrPage(rawPage));
477
+ }
478
+ /**
479
+ * Parse OCR matches returned by the OCHRE API
480
+ * @param rawOcrItems - The raw OCR match items
481
+ * @returns The parsed OCR matches, in request order
482
+ * @internal
483
+ */
484
+ function parseOcrMatches(rawOcrItems) {
485
+ const matches = [];
486
+ for (const rawOcrItem of rawOcrItems) {
487
+ const rawMatches = rawOcrItem.ocrMatch ?? [];
488
+ for (const rawMatch of rawMatches) {
489
+ const words = parseOcrWords(rawMatch.string);
490
+ matches.push({
491
+ uuid: rawOcrItem.uuid,
492
+ resourceUuid: rawMatch.resourceUuid ?? null,
493
+ page: {
494
+ number: rawMatch.n ?? null,
495
+ fileName: rawMatch.fileName ?? null,
496
+ width: rawMatch.WIDTH ?? null,
497
+ height: rawMatch.HEIGHT ?? null
498
+ },
499
+ content: joinOcrWordContents(words),
500
+ words
501
+ });
502
+ }
503
+ }
504
+ return matches;
505
+ }
433
506
  function parseNote(rawNote, options) {
434
507
  const authors = Array.from(rawNote.authors?.author ?? [], (author) => parsePerson(author, options));
435
508
  const content = rawNote.content == null ? multilingualFromText(parseXMLString(rawNote), options) : parseRequiredContentLike(rawNote, options);
@@ -635,11 +708,7 @@ function parseSetItemHierarchy(hierarchy, options, categories) {
635
708
  case "text":
636
709
  items.push(parseText(entry.item, options));
637
710
  break;
638
- case "set":
639
- items.push(parseSetSet(entry.item, options));
640
- break;
641
- case "dictionaryUnit":
642
- case "heading": break;
711
+ case "set": items.push(parseSetSet(entry.item, options));
643
712
  }
644
713
  return items;
645
714
  }
@@ -838,10 +907,7 @@ function parseLinks(rawLinks, options) {
838
907
  case "set":
839
908
  links.push(parseSetItemLink(entry.item, options));
840
909
  break;
841
- case "dictionaryUnit":
842
- links.push(parseDictionaryUnitItemLink(entry.item, options));
843
- break;
844
- case "heading": break;
910
+ case "dictionaryUnit": links.push(parseDictionaryUnitItemLink(entry.item, options));
845
911
  }
846
912
  return links;
847
913
  }
@@ -1130,6 +1196,7 @@ function parseResource(rawResource, options) {
1130
1196
  image: parseImage(rawResource.image, options),
1131
1197
  document: parseContentLike(rawResource.document, options),
1132
1198
  imageMap: parseImageMap(rawResource.imagemap),
1199
+ ocr: parseOcr(rawResource.ocr),
1133
1200
  coordinates: parseCoordinates(rawResource.coordinates, options),
1134
1201
  periods: parsePeriodList(rawResource.periods, options),
1135
1202
  links: parseLinks(rawResource.links, options),
@@ -1194,7 +1261,8 @@ function resolveDefaultLanguage(rawOchre, languages) {
1194
1261
  return firstLanguage;
1195
1262
  }
1196
1263
  function parseMetadataPublisher(rawPublisher) {
1197
- return parseStringLike(Array.isArray(rawPublisher) ? rawPublisher[0] : rawPublisher) ?? "";
1264
+ const publisher = Array.isArray(rawPublisher) ? rawPublisher[0] : rawPublisher;
1265
+ return parseStringLike(publisher) ?? "";
1198
1266
  }
1199
1267
  function parseMetadata(rawOchre, options, defaultLanguage) {
1200
1268
  const metadataOptions = options;
@@ -1331,4 +1399,4 @@ function parseItem(rawData, options) {
1331
1399
  };
1332
1400
  }
1333
1401
  //#endregion
1334
- export { getParserOptions, parseBibliographyList, parseGallery, parseIdentification, parseItem, parseLinkedItems, parseLinks, parseMetadata, parseMetadataLanguages, parseNotes, parsePersonList, parseProperties, parseSetItems, parseSimplifiedProperties, parseStringLike, resolveDefaultLanguage, resolveLanguages };
1402
+ export { getParserOptions, parseBibliographyList, parseGallery, parseIdentification, parseItem, parseLinkedItems, parseLinks, parseMetadata, parseMetadataLanguages, parseNotes, parseOcrMatches, parsePersonList, parseProperties, parseSetItems, parseSimplifiedProperties, parseStringLike, resolveDefaultLanguage, resolveLanguages };
@@ -129,9 +129,7 @@ function createMDXComponent(variant, properties) {
129
129
  case "documentLink":
130
130
  returnString = `<ExternalLink${createMDXStringAttribute("href", `https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?uuid=${uuid}&load`)}${createMDXStringAttribute("content", tooltipContent)}>${text}</ExternalLink>`;
131
131
  break;
132
- case "tooltipSpan":
133
- returnString = `<TooltipSpan${createMDXStringAttribute("content", content)}>${text}</TooltipSpan>`;
134
- break;
132
+ case "tooltipSpan": returnString = `<TooltipSpan${createMDXStringAttribute("content", content)}>${text}</TooltipSpan>`;
135
133
  }
136
134
  return returnString;
137
135
  }
@@ -407,18 +405,16 @@ function renderRichTextItem(item, linkString, contentItem, options) {
407
405
  result += component;
408
406
  break;
409
407
  }
410
- default:
411
- result += link.publicationDateTime != null ? createInternalLinkComponent({
412
- uuid: getLinkStringProperty(link, "uuid"),
413
- text: linkString,
414
- content: contentText,
415
- annotationMetadata
416
- }) : createMDXComponent("tooltipSpan", {
417
- uuid: getLinkStringProperty(link, "uuid"),
418
- text: linkString,
419
- content: contentText
420
- });
421
- break;
408
+ default: result += link.publicationDateTime != null ? createInternalLinkComponent({
409
+ uuid: getLinkStringProperty(link, "uuid"),
410
+ text: linkString,
411
+ content: contentText,
412
+ annotationMetadata
413
+ }) : createMDXComponent("tooltipSpan", {
414
+ uuid: getLinkStringProperty(link, "uuid"),
415
+ text: linkString,
416
+ content: contentText
417
+ });
422
418
  }
423
419
  else if (link.publicationDateTime != null) {
424
420
  const component = createInternalLinkComponent({
@@ -472,11 +468,12 @@ function parseXMLContent(item, options) {
472
468
  }
473
469
  function parseXMLContentItem(contentItem, options) {
474
470
  const rawMDXBlocks = [];
475
- let serializedRichText = serializeMDXContent(parseNestedStringItems(contentItem.string, contentItem, {
471
+ const richText = parseNestedStringItems(contentItem.string, contentItem, {
476
472
  ...options,
477
473
  rendering: "rich",
478
474
  rawMDXBlocks
479
- }));
475
+ });
476
+ let serializedRichText = serializeMDXContent(richText);
480
477
  for (const [index, rawMDXBlock] of rawMDXBlocks.entries()) serializedRichText = serializedRichText.replaceAll(`${RAW_MDX_BLOCK_PLACEHOLDER_PREFIX}${index}${RAW_MDX_BLOCK_PLACEHOLDER_SUFFIX}`, () => rawMDXBlock);
481
478
  return {
482
479
  text: parseNestedStringItems(contentItem.string, contentItem, {