ochre-sdk 1.2.1 → 1.3.0
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>>;
|
|
@@ -150,10 +150,12 @@ const responseSchema = v.object({ result: v.object({ ochre: v.object({
|
|
|
150
150
|
* @param parameters.attributes.bibliographies - Whether to return values for bibliographies
|
|
151
151
|
* @param parameters.attributes.periods - Whether to return values for periods
|
|
152
152
|
* @param parameters.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
|
|
153
|
+
* @param parameters.language - Language of the text value, bibliography, and period labels that facets are keyed by (defaults to `"eng"`)
|
|
153
154
|
* @returns An XQuery string
|
|
154
155
|
*/
|
|
155
156
|
function buildXQuery(parameters) {
|
|
156
|
-
const { setScopeUuids, belongsToCollectionScopeUuids, queries, propertyFacetSelectors, attributes, isLimitedToLeafPropertyValues } = parameters;
|
|
157
|
+
const { setScopeUuids, belongsToCollectionScopeUuids, queries, propertyFacetSelectors, attributes, isLimitedToLeafPropertyValues, language } = parameters;
|
|
158
|
+
const languageLiteral = stringLiteral(language);
|
|
157
159
|
const valueFilter = isLimitedToLeafPropertyValues ? "[not(@i)]" : "";
|
|
158
160
|
const returnedSequences = [];
|
|
159
161
|
const xqueryDeclarations = ["declare namespace map = \"http://marklogic.com/xdmp/map\";", `declare function local:increment-count($counts, $key) {
|
|
@@ -173,7 +175,7 @@ declare function local:normalize-data-type($data-type) {
|
|
|
173
175
|
|
|
174
176
|
declare function local:value-display-text($v) {
|
|
175
177
|
if ($v/content)
|
|
176
|
-
then string-join($v/content[@xml:lang
|
|
178
|
+
then string-join($v/content[@xml:lang=${languageLiteral}]//text(), "")
|
|
177
179
|
else string($v)
|
|
178
180
|
};
|
|
179
181
|
|
|
@@ -332,7 +334,7 @@ let $_bibliography-aggregation := xdmp:eager(
|
|
|
332
334
|
let $seen := map:map()
|
|
333
335
|
return
|
|
334
336
|
for $bibliography in $item/bibliographies/bibliography${notSupplemental}
|
|
335
|
-
let $label := string-join($bibliography/identification/label/content[@xml:lang
|
|
337
|
+
let $label := string-join($bibliography/identification/label/content[@xml:lang=${languageLiteral}]//text(), "")
|
|
336
338
|
where string-length($label) gt 0
|
|
337
339
|
return local:add-attribute-facet($bibliography-counts, $seen, $label)
|
|
338
340
|
)
|
|
@@ -352,7 +354,7 @@ let $_period-aggregation := xdmp:eager(
|
|
|
352
354
|
let $seen := map:map()
|
|
353
355
|
return
|
|
354
356
|
for $period in $item/periods/period${notSupplemental}
|
|
355
|
-
let $label := string-join($period/identification/label/content[@xml:lang
|
|
357
|
+
let $label := string-join($period/identification/label/content[@xml:lang=${languageLiteral}]//text(), "")
|
|
356
358
|
where string-length($label) gt 0
|
|
357
359
|
return local:add-attribute-facet($period-counts, $seen, $label)
|
|
358
360
|
)
|
|
@@ -439,6 +441,7 @@ function collectAttributeValues(parsedAttributeValues) {
|
|
|
439
441
|
* @param parameters.attributes.bibliographies - Whether to return values for bibliographies
|
|
440
442
|
* @param parameters.attributes.periods - Whether to return values for periods
|
|
441
443
|
* @param parameters.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
|
|
444
|
+
* @param parameters.language - Language of the text value, bibliography, and period labels that facets are keyed by (defaults to `"eng"`)
|
|
442
445
|
* @param options - Options for the fetch
|
|
443
446
|
* @param options.fetch - The fetch function to use
|
|
444
447
|
* @returns Parsed Set property values and requested attribute values.
|
|
@@ -446,7 +449,7 @@ function collectAttributeValues(parsedAttributeValues) {
|
|
|
446
449
|
*/
|
|
447
450
|
async function fetchSetPropertyValues(parameters, options) {
|
|
448
451
|
try {
|
|
449
|
-
const { setScopeUuids, belongsToCollectionScopeUuids, queries, attributes, isLimitedToLeafPropertyValues } = v.parse(setPropertyValuesParametersSchema, parameters);
|
|
452
|
+
const { setScopeUuids, belongsToCollectionScopeUuids, queries, attributes, isLimitedToLeafPropertyValues, language } = v.parse(setPropertyValuesParametersSchema, parameters);
|
|
450
453
|
const propertyFacetSelectors = getPropertyFacetSelectors(queries);
|
|
451
454
|
if (propertyFacetSelectors.length === 0 && !attributes.bibliographies && !attributes.periods) return {
|
|
452
455
|
propertyValues: [],
|
|
@@ -464,7 +467,8 @@ async function fetchSetPropertyValues(parameters, options) {
|
|
|
464
467
|
queries,
|
|
465
468
|
propertyFacetSelectors,
|
|
466
469
|
attributes,
|
|
467
|
-
isLimitedToLeafPropertyValues
|
|
470
|
+
isLimitedToLeafPropertyValues,
|
|
471
|
+
language
|
|
468
472
|
});
|
|
469
473
|
const output = await requestOchre({
|
|
470
474
|
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
|