ochre-sdk 1.2.1 → 1.3.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.
|
@@ -11,6 +11,7 @@ import { OchreRequestOptions } from "../request.mjs";
|
|
|
11
11
|
* @param parameters.attributes.bibliographies - Whether to return values for bibliographies
|
|
12
12
|
* @param parameters.attributes.periods - Whether to return values for periods
|
|
13
13
|
* @param parameters.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
|
|
14
|
+
* @param parameters.language - Language of the text value, bibliography, and period labels that facets are keyed by (defaults to `"eng"`)
|
|
14
15
|
* @param options - Options for the fetch
|
|
15
16
|
* @param options.fetch - The fetch function to use
|
|
16
17
|
* @returns Parsed Set property values and requested attribute values.
|
|
@@ -24,6 +25,7 @@ export declare function fetchSetPropertyValues(parameters: {
|
|
|
24
25
|
periods: boolean;
|
|
25
26
|
};
|
|
26
27
|
isLimitedToLeafPropertyValues?: boolean;
|
|
28
|
+
language?: string;
|
|
27
29
|
}, options?: OchreRequestOptions): Promise<{
|
|
28
30
|
propertyValues: Array<PropertyValueQueryItem>;
|
|
29
31
|
propertyValuesByPropertyVariableUuid: Record<string, Array<PropertyValueQueryItem>>;
|
|
@@ -124,12 +124,13 @@ const propertyValueQueryItemSchema = v.pipe(v.object({
|
|
|
124
124
|
const attributeValueQueryItemSchema = v.pipe(v.object({
|
|
125
125
|
attributeType: v.picklist(["bibliographies", "periods"]),
|
|
126
126
|
count: countSchema,
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
key: v.optional(v.string()),
|
|
128
|
+
content: v.optional(v.array(propertyValueLabelContentSchema))
|
|
129
129
|
}), v.transform((value) => ({
|
|
130
130
|
attributeType: value.attributeType,
|
|
131
131
|
count: value.count,
|
|
132
|
-
content: value.
|
|
132
|
+
content: value.key != null && value.key !== "" ? value.key : null,
|
|
133
|
+
label: parsePropertyValueLabel(value.content, value.key)
|
|
133
134
|
})));
|
|
134
135
|
/**
|
|
135
136
|
* Schema for the property values OCHRE API response
|
|
@@ -150,10 +151,12 @@ const responseSchema = v.object({ result: v.object({ ochre: v.object({
|
|
|
150
151
|
* @param parameters.attributes.bibliographies - Whether to return values for bibliographies
|
|
151
152
|
* @param parameters.attributes.periods - Whether to return values for periods
|
|
152
153
|
* @param parameters.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
|
|
154
|
+
* @param parameters.language - Language of the text value, bibliography, and period labels that facets are keyed by (defaults to `"eng"`)
|
|
153
155
|
* @returns An XQuery string
|
|
154
156
|
*/
|
|
155
157
|
function buildXQuery(parameters) {
|
|
156
|
-
const { setScopeUuids, belongsToCollectionScopeUuids, queries, propertyFacetSelectors, attributes, isLimitedToLeafPropertyValues } = parameters;
|
|
158
|
+
const { setScopeUuids, belongsToCollectionScopeUuids, queries, propertyFacetSelectors, attributes, isLimitedToLeafPropertyValues, language } = parameters;
|
|
159
|
+
const languageLiteral = stringLiteral(language);
|
|
157
160
|
const valueFilter = isLimitedToLeafPropertyValues ? "[not(@i)]" : "";
|
|
158
161
|
const returnedSequences = [];
|
|
159
162
|
const xqueryDeclarations = ["declare namespace map = \"http://marklogic.com/xdmp/map\";", `declare function local:increment-count($counts, $key) {
|
|
@@ -173,7 +176,7 @@ declare function local:normalize-data-type($data-type) {
|
|
|
173
176
|
|
|
174
177
|
declare function local:value-display-text($v) {
|
|
175
178
|
if ($v/content)
|
|
176
|
-
then string-join($v/content[@xml:lang
|
|
179
|
+
then string-join($v/content[@xml:lang=${languageLiteral}]//text(), "")
|
|
177
180
|
else string($v)
|
|
178
181
|
};
|
|
179
182
|
|
|
@@ -325,45 +328,35 @@ let $property-values :=
|
|
|
325
328
|
)`);
|
|
326
329
|
returnedSequences.push("$property-values");
|
|
327
330
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
let
|
|
331
|
+
for (const [attributeType, attributePath] of [["bibliographies", "bibliographies/bibliography"], ["periods", "periods/period"]]) {
|
|
332
|
+
if (!attributes[attributeType]) continue;
|
|
333
|
+
queryBlocks.push(`let $${attributeType}-counts := map:map()
|
|
334
|
+
let $${attributeType}-labels := map:map()
|
|
335
|
+
let $_${attributeType}-aggregation := xdmp:eager(
|
|
331
336
|
for $item in ${items}
|
|
332
337
|
let $seen := map:map()
|
|
333
338
|
return
|
|
334
|
-
for $
|
|
335
|
-
let $label :=
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
return <attributeValue attributeType="bibliographies" count="{map:get($bibliography-counts, $label)}" content="{$label}" />
|
|
345
|
-
)`);
|
|
346
|
-
returnedSequences.push("$bibliography-values");
|
|
347
|
-
}
|
|
348
|
-
if (attributes.periods) {
|
|
349
|
-
queryBlocks.push(`let $period-counts := map:map()
|
|
350
|
-
let $_period-aggregation := xdmp:eager(
|
|
351
|
-
for $item in ${items}
|
|
352
|
-
let $seen := map:map()
|
|
353
|
-
return
|
|
354
|
-
for $period in $item/periods/period${notSupplemental}
|
|
355
|
-
let $label := string-join($period/identification/label/content[@xml:lang="eng"]//text(), "")
|
|
356
|
-
where string-length($label) gt 0
|
|
357
|
-
return local:add-attribute-facet($period-counts, $seen, $label)
|
|
339
|
+
for $attribute in $item/${attributePath}${notSupplemental}
|
|
340
|
+
let $label := $attribute/identification/label
|
|
341
|
+
let $key := string-join($label/content[@xml:lang=${languageLiteral}]//text(), "")
|
|
342
|
+
where string-length($key) gt 0
|
|
343
|
+
return (
|
|
344
|
+
if (empty(map:get($${attributeType}-labels, $key)))
|
|
345
|
+
then map:put($${attributeType}-labels, $key, local:value-label-content($label))
|
|
346
|
+
else (),
|
|
347
|
+
local:add-attribute-facet($${attributeType}-counts, $seen, $key)
|
|
348
|
+
)
|
|
358
349
|
)
|
|
359
350
|
|
|
360
|
-
let
|
|
351
|
+
let $${attributeType}-values :=
|
|
361
352
|
(
|
|
362
|
-
$
|
|
363
|
-
for $
|
|
364
|
-
return <attributeValue attributeType="
|
|
353
|
+
$_${attributeType}-aggregation,
|
|
354
|
+
for $key in map:keys($${attributeType}-counts)
|
|
355
|
+
return <attributeValue attributeType="${attributeType}" count="{map:get($${attributeType}-counts, $key)}" key="{$key}">{
|
|
356
|
+
map:get($${attributeType}-labels, $key)
|
|
357
|
+
}</attributeValue>
|
|
365
358
|
)`);
|
|
366
|
-
returnedSequences.push(
|
|
359
|
+
returnedSequences.push(`$${attributeType}-values`);
|
|
367
360
|
}
|
|
368
361
|
return queryBlocks;
|
|
369
362
|
}
|
|
@@ -424,7 +417,8 @@ function collectAttributeValues(parsedAttributeValues) {
|
|
|
424
417
|
if (attributeValue.content == null || attributeValue.content === "") continue;
|
|
425
418
|
attributeValuesByType[attributeValue.attributeType].push({
|
|
426
419
|
count: attributeValue.count,
|
|
427
|
-
content: attributeValue.content
|
|
420
|
+
content: attributeValue.content,
|
|
421
|
+
label: attributeValue.label
|
|
428
422
|
});
|
|
429
423
|
}
|
|
430
424
|
return attributeValuesByType;
|
|
@@ -439,6 +433,7 @@ function collectAttributeValues(parsedAttributeValues) {
|
|
|
439
433
|
* @param parameters.attributes.bibliographies - Whether to return values for bibliographies
|
|
440
434
|
* @param parameters.attributes.periods - Whether to return values for periods
|
|
441
435
|
* @param parameters.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
|
|
436
|
+
* @param parameters.language - Language of the text value, bibliography, and period labels that facets are keyed by (defaults to `"eng"`)
|
|
442
437
|
* @param options - Options for the fetch
|
|
443
438
|
* @param options.fetch - The fetch function to use
|
|
444
439
|
* @returns Parsed Set property values and requested attribute values.
|
|
@@ -446,7 +441,7 @@ function collectAttributeValues(parsedAttributeValues) {
|
|
|
446
441
|
*/
|
|
447
442
|
async function fetchSetPropertyValues(parameters, options) {
|
|
448
443
|
try {
|
|
449
|
-
const { setScopeUuids, belongsToCollectionScopeUuids, queries, attributes, isLimitedToLeafPropertyValues } = v.parse(setPropertyValuesParametersSchema, parameters);
|
|
444
|
+
const { setScopeUuids, belongsToCollectionScopeUuids, queries, attributes, isLimitedToLeafPropertyValues, language } = v.parse(setPropertyValuesParametersSchema, parameters);
|
|
450
445
|
const propertyFacetSelectors = getPropertyFacetSelectors(queries);
|
|
451
446
|
if (propertyFacetSelectors.length === 0 && !attributes.bibliographies && !attributes.periods) return {
|
|
452
447
|
propertyValues: [],
|
|
@@ -464,7 +459,8 @@ async function fetchSetPropertyValues(parameters, options) {
|
|
|
464
459
|
queries,
|
|
465
460
|
propertyFacetSelectors,
|
|
466
461
|
attributes,
|
|
467
|
-
isLimitedToLeafPropertyValues
|
|
462
|
+
isLimitedToLeafPropertyValues,
|
|
463
|
+
language
|
|
468
464
|
});
|
|
469
465
|
const output = await requestOchre({
|
|
470
466
|
xquery,
|
package/dist/query.mjs
CHANGED
|
@@ -229,11 +229,8 @@ function buildAndCtsQueryExpression(queryExpressions) {
|
|
|
229
229
|
return buildAndCtsQueryExpressionInternal(queryExpressions);
|
|
230
230
|
}
|
|
231
231
|
function buildContentLanguageQuery(language) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
attributeName: "xml:lang",
|
|
235
|
-
value: searchValue(language)
|
|
236
|
-
});
|
|
232
|
+
const languageValue = searchValue(language);
|
|
233
|
+
return `cts:element-attribute-value-query(xs:QName("content"), xs:QName("xml:lang"), ${languageValue.expression}, fn:concat("lang=", ${languageValue.expression}))`;
|
|
237
234
|
}
|
|
238
235
|
function buildPropertyLabelQuery(propertyVariable) {
|
|
239
236
|
return buildPlainElementAttributeValueQueryExpression({
|
package/dist/schemas.d.mts
CHANGED
|
@@ -54,6 +54,7 @@ export declare const setPropertyValuesParametersSchema: v.ObjectSchema<{
|
|
|
54
54
|
readonly periods: false;
|
|
55
55
|
}>;
|
|
56
56
|
readonly isLimitedToLeafPropertyValues: v.GenericSchema<unknown, boolean>;
|
|
57
|
+
readonly language: v.GenericSchema<unknown, string>;
|
|
57
58
|
}, undefined>;
|
|
58
59
|
/**
|
|
59
60
|
* Schema for validating the parameters for the item OCR data fetching function
|
package/dist/schemas.mjs
CHANGED
|
@@ -237,7 +237,8 @@ const setPropertyValuesParametersSchema = v.object({
|
|
|
237
237
|
bibliographies: false,
|
|
238
238
|
periods: false
|
|
239
239
|
}),
|
|
240
|
-
isLimitedToLeafPropertyValues: defaultBoolean(false)
|
|
240
|
+
isLimitedToLeafPropertyValues: defaultBoolean(false),
|
|
241
|
+
language: defaultString("eng")
|
|
241
242
|
});
|
|
242
243
|
/**
|
|
243
244
|
* Schema for validating the parameters for the item OCR data fetching function
|
package/dist/types/index.d.mts
CHANGED
|
@@ -794,10 +794,14 @@ export type PropertyValueQueryItem = {
|
|
|
794
794
|
};
|
|
795
795
|
/**
|
|
796
796
|
* Represents a grouped Set attribute value query item
|
|
797
|
+
*
|
|
798
|
+
* `content` is the label in the requested language, which facet queries match
|
|
799
|
+
* on; `label` carries the label in every language for display.
|
|
797
800
|
*/
|
|
798
801
|
export type SetAttributeValueQueryItem = {
|
|
799
802
|
count: number;
|
|
800
803
|
content: string;
|
|
804
|
+
label: MultilingualString | null;
|
|
801
805
|
};
|
|
802
806
|
/**
|
|
803
807
|
* Represents sorting direction for Set items
|