Initial worker service

This commit is contained in:
Ruslan Bakiev
2026-05-05 12:05:55 +07:00
commit e87f9b3c57
44 changed files with 13700 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
type OntologyLeaf = {
id: string;
keywords: string[];
};
type OntologyAxis = {
id: string;
leaves: OntologyLeaf[];
};
export const placeOntology: OntologyAxis[] = [
{
id: 'energy',
leaves: [
{ id: 'calm', keywords: ['quiet', 'calm', 'slow', 'soft', 'peaceful'] },
{ id: 'dynamic', keywords: ['busy', 'loud', 'alive', 'fast', 'crowd'] },
],
},
{
id: 'privacy',
leaves: [
{ id: 'intimate', keywords: ['private', 'cozy', 'small', 'hidden'] },
{ id: 'open', keywords: ['open', 'public', 'visible', 'spacious'] },
],
},
{
id: 'sociality',
leaves: [
{ id: 'solo', keywords: ['alone', 'focus', 'work', 'read'] },
{ id: 'group', keywords: ['friends', 'date', 'talk', 'party'] },
],
},
{
id: 'intent',
leaves: [
{ id: 'reset', keywords: ['rest', 'breathe', 'reset', 'recover'] },
{ id: 'impress', keywords: ['impress', 'beautiful', 'special', 'wow'] },
{ id: 'transit', keywords: ['quick', 'nearby', 'stop', 'between'] },
],
},
{
id: 'aesthetic',
leaves: [
{ id: 'clean', keywords: ['clean', 'minimal', 'simple', 'bright'] },
{ id: 'expressive', keywords: ['design', 'art', 'unusual', 'texture'] },
],
},
];
export type PlaceAnalysis = {
placeName: string;
tags: string[];
signals: Array<{
axis: string;
leaf: string;
matches: string[];
}>;
};
export function buildPlaceAnalysis(input: {
placeName: string;
transcript: string;
}): PlaceAnalysis {
const normalized = input.transcript.toLowerCase();
const signals = placeOntology.flatMap((axis) =>
axis.leaves
.map((leaf) => ({
axis: axis.id,
leaf: leaf.id,
matches: leaf.keywords.filter((keyword) => normalized.includes(keyword)),
}))
.filter((signal) => signal.matches.length > 0),
);
return {
placeName: input.placeName,
tags: signals.map((signal) => `${signal.axis}:${signal.leaf}`),
signals,
};
}