Skip to content

Commit 9586cb7

Browse files
authored
Image type information (#626)
* added image types fields * bump impresso-jscommons to v1.10.0; add image facet support (schema, types, solr mappings, resolvers, extractors, transformer, impressoPy)
1 parent c9948d2 commit 9586cb7

20 files changed

Lines changed: 381 additions & 20 deletions

File tree

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"graphology-metrics": "^2.3.1",
8989
"helmet": "^3.21.1",
9090
"http-proxy-middleware": "^3.0.5",
91-
"impresso-jscommons": "github:impresso/impresso-jscommons#v1.9.0",
91+
"impresso-jscommons": "github:impresso/impresso-jscommons#v1.10.0",
9292
"ioredis": "5.8.1",
9393
"json-bigint": "github:sidorares/json-bigint#8208aa1352eba252b60756672ab7c17f300d6ccd",
9494
"json2csv": "^4.3.3",

src/data/constants.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,10 @@ const trPassagesSolrMappings = {
499499
},
500500
} satisfies ISolrMappings<TextReusePassageFacet>
501501

502-
export type ImageFacet = Extract<FilterType, 'newspaper' | 'year'>
502+
export type ImageFacet = Extract<
503+
FilterType,
504+
'newspaper' | 'year' | 'imageVisualContent' | 'imageTechnique' | 'imageCommunicationGoal' | 'imageContentType'
505+
>
503506

504507
const imagesSolrMappings = {
505508
facets: {
@@ -517,6 +520,34 @@ const imagesSolrMappings = {
517520
limit: 400, // 400 years
518521
numBuckets: true,
519522
},
523+
imageVisualContent: {
524+
type: 'terms',
525+
field: 'type_l0_tp',
526+
mincount: 1,
527+
limit: 20,
528+
numBuckets: true,
529+
},
530+
imageTechnique: {
531+
type: 'terms',
532+
field: 'type_l1_tp',
533+
mincount: 1,
534+
limit: 20,
535+
numBuckets: true,
536+
},
537+
imageCommunicationGoal: {
538+
type: 'terms',
539+
field: 'type_l2_tp',
540+
mincount: 1,
541+
limit: 20,
542+
numBuckets: true,
543+
},
544+
imageContentType: {
545+
type: 'terms',
546+
field: 'type_l3_tp',
547+
mincount: 1,
548+
limit: 20,
549+
numBuckets: true,
550+
},
520551
},
521552
} satisfies ISolrMappings<ImageFacet>
522553

src/internalServices/cachedResolvers.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
Newspaper as INewspaper,
1515
Partner as IPartner,
1616
} from '../models/generated/schemas'
17+
import { FacetWithLabel } from '../models/generated/shared'
18+
import { ImageTypeValueLookup } from '../services/images/images.class'
1719
export type CachedFacetType =
1820
| 'newspaper'
1921
| 'topic'
@@ -24,7 +26,11 @@ export type CachedFacetType =
2426
| 'partner'
2527
| 'nag'
2628
| 'organisation'
27-
export type CachedFacetTypes = ITopic | IYear | IEntity | ICollection | INewspaper | IPartner
29+
| 'imageVisualContent'
30+
| 'imageTechnique'
31+
| 'imageCommunicationGoal'
32+
| 'imageContentType'
33+
export type CachedFacetTypes = ITopic | IYear | IEntity | ICollection | INewspaper | IPartner | FacetWithLabel
2834

2935
export type IResolver<T> = (id: string) => Promise<T | undefined>
3036

@@ -38,6 +44,10 @@ export type ICachedResolvers = {
3844
partner: IResolver<IPartner>
3945
nag: IResolver<IEntity>
4046
organisation: IResolver<IEntity>
47+
imageVisualContent: IResolver<FacetWithLabel>
48+
imageTechnique: IResolver<FacetWithLabel>
49+
imageCommunicationGoal: IResolver<FacetWithLabel>
50+
imageContentType: IResolver<FacetWithLabel>
4151
}
4252

4353
// Record<CachedFacetType, IResolver<T>>
@@ -95,6 +105,14 @@ const getNewspaperResolver = (app: ImpressoApplication): IResolver<NewspaperInte
95105
}
96106
}
97107

108+
const imageTypeResolver = async (id: string, field: keyof typeof ImageTypeValueLookup) => {
109+
const lookup = ImageTypeValueLookup[field]
110+
return {
111+
id,
112+
label: lookup[id] ?? id,
113+
} satisfies FacetWithLabel
114+
}
115+
98116
export const buildResolvers = (app: ImpressoApplication): ICachedResolvers => {
99117
return {
100118
collection: getCollectionResolver(app),
@@ -106,5 +124,9 @@ export const buildResolvers = (app: ImpressoApplication): ICachedResolvers => {
106124
partner: getPartnerResolver(app),
107125
nag: (id: string) => entityResolver(id, 'nag'),
108126
organisation: (id: string) => entityResolver(id, 'organisation'),
127+
imageVisualContent: (id: string) => imageTypeResolver(id, 'type_l0_tp'),
128+
imageTechnique: (id: string) => imageTypeResolver(id, 'type_l1_tp'),
129+
imageCommunicationGoal: (id: string) => imageTypeResolver(id, 'type_l2_tp'),
130+
imageContentType: (id: string) => imageTypeResolver(id, 'type_l3_tp'),
109131
}
110132
}

src/logic/filters/impressoPy.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ const FilterTypeToPythonArgumentName = {
3939
sourceMedium: '',
4040
organisation: '',
4141
embedding: 'embedding',
42+
imageVisualContent: 'visual_content',
43+
imageTechnique: 'technique',
44+
imageCommunicationGoal: 'communication_goal',
45+
imageContentType: 'content_type',
4246
} satisfies Record<FilterType, string>
4347

4448
const BooleanTypes: FilterType[] = ['hasTextContents', 'isFront']

src/models/generated/schemas.d.ts

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,24 @@ export interface Image {
14811481
*/
14821482
type?: "newspaper";
14831483
};
1484+
imageTypes?: {
1485+
/**
1486+
* Whether the content is an image or not.
1487+
*/
1488+
visualContent?: string;
1489+
/**
1490+
* Determines if the image is a photograph.
1491+
*/
1492+
technique?: string;
1493+
/**
1494+
* Purpose or communicative function of the image.
1495+
*/
1496+
communicationGoal?: string;
1497+
/**
1498+
* Classification of the visual content.
1499+
*/
1500+
visualContentType?: string;
1501+
};
14841502
/**
14851503
* The date of the image or the date of the issue that the image belongs to.
14861504
*/
@@ -1846,7 +1864,7 @@ export interface SearchFacetBucket {
18461864
/**
18471865
* The item in the bucket. Particular objct schema depends on the facet type
18481866
*/
1849-
item?: Newspaper | Collection | Entity | Topic | Year | Partner;
1867+
item?: Newspaper | Collection | Entity | Topic | Year | Partner | FacetWithLabel;
18501868
}
18511869
/**
18521870
* A newspaper
@@ -2164,6 +2182,19 @@ export interface Partner {
21642182
*/
21652183
url?: string;
21662184
}
2185+
/**
2186+
* An facet that has a value and a label
2187+
*/
2188+
export interface FacetWithLabel {
2189+
/**
2190+
* Unique identifier of the facet
2191+
*/
2192+
id: string;
2193+
/**
2194+
* Label of the facet
2195+
*/
2196+
label: string;
2197+
}
21672198
/**
21682199
* Facet bucket
21692200
*/
@@ -2206,7 +2237,7 @@ export interface SearchFacetBucket {
22062237
/**
22072238
* The item in the bucket. Particular objct schema depends on the facet type
22082239
*/
2209-
item?: Newspaper | Collection | Entity | Topic | Year | Partner;
2240+
item?: Newspaper | Collection | Entity | Topic | Year | Partner | FacetWithLabel;
22102241
}
22112242
/**
22122243
* A newspaper
@@ -2524,6 +2555,19 @@ export interface Partner {
25242555
*/
25252556
url?: string;
25262557
}
2558+
/**
2559+
* An facet that has a value and a label
2560+
*/
2561+
export interface FacetWithLabel {
2562+
/**
2563+
* Unique identifier of the facet
2564+
*/
2565+
id: string;
2566+
/**
2567+
* Label of the facet
2568+
*/
2569+
label: string;
2570+
}
25272571

25282572

25292573
/**

src/models/generated/schemasPublic.d.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,25 @@ export interface EntityMention {
390390
}
391391

392392

393+
/**
394+
* Information about an available experiment including its identifier, name, and description.
395+
*/
396+
export interface ExperimentInfo {
397+
/**
398+
* The unique identifier of the experiment.
399+
*/
400+
id: string;
401+
/**
402+
* The display name of the experiment.
403+
*/
404+
name: string;
405+
/**
406+
* A description of what the experiment does.
407+
*/
408+
description?: string;
409+
}
410+
411+
393412
/**
394413
* Freeform schema - a schema that allows any property to be added to the object.
395414
*/
@@ -426,6 +445,24 @@ export interface Image {
426445
* The page numbers of the issue that the image belongs to.
427446
*/
428447
pageNumbers?: number[];
448+
imageTypes?: {
449+
/**
450+
* Whether the content is an image or not.
451+
*/
452+
visualContent?: string;
453+
/**
454+
* Determines if the image is a photograph.
455+
*/
456+
technique?: string;
457+
/**
458+
* Purpose or communicative function of the image.
459+
*/
460+
communicationGoal?: string;
461+
/**
462+
* Classification of the visual content.
463+
*/
464+
visualContentType?: string;
465+
};
429466
/**
430467
* The media source of the image
431468
*/

src/models/generated/shared.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,21 @@ export interface Error {
149149
}
150150

151151

152+
/**
153+
* An facet that has a value and a label
154+
*/
155+
export interface FacetWithLabel {
156+
/**
157+
* Unique identifier of the facet
158+
*/
159+
id: string;
160+
/**
161+
* Label of the facet
162+
*/
163+
label: string;
164+
}
165+
166+
152167
/**
153168
* A single filter criteria
154169
*/

src/models/generated/solr.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ export interface Image {
5252
iiif_url_s?: string;
5353
iiif_link_s?: string;
5454
cc_b?: boolean;
55+
/**
56+
* Whether the content is an image or not.
57+
*/
58+
type_l0_tp?: string;
59+
/**
60+
* Determines if the image is a photograph.
61+
*/
62+
type_l1_tp?: string;
63+
/**
64+
* Purpose or communicative function of the image.
65+
*/
66+
type_l2_tp?: string;
67+
/**
68+
* Classification of the visual content.
69+
*/
70+
type_l3_tp?: string;
5571
rights_data_domain_s?: string;
5672
rights_copyright_s?: string;
5773
rights_perm_use_explore_plain?: string[];

src/models/search-facets.model.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@ import {
1111
Partner as IPartner,
1212
} from './generated/schemas'
1313
import { ImpressoApplication } from '../types'
14+
import { FacetWithLabel } from './generated/shared'
1415

1516
type FacetType = 'newspaper' | 'language' | 'topic' | 'person' | 'location' | 'collection' | 'year'
1617

1718
interface SearchFacetBucketOptions {
1819
val: string
1920
count: number
2021
uid?: string
21-
item?: ITopic | IYear | IEntity | ICollection | INewspaper | IPartner
22+
item?: ITopic | IYear | IEntity | ICollection | INewspaper | IPartner | FacetWithLabel
2223
}
2324

2425
class SearchFacetBucket implements ISearchFacetBucket {
2526
public count: number
2627
public val: string
2728
public uid?: string
28-
public item?: ITopic | IYear | IEntity | ICollection | INewspaper | IPartner
29+
public item?: ITopic | IYear | IEntity | ICollection | INewspaper | IPartner | FacetWithLabel
2930
public lower?: number
3031
public upper?: number
3132

0 commit comments

Comments
 (0)