Skip to content

Commit

Permalink
updated old class to convert words to new format
Browse files Browse the repository at this point in the history
  • Loading branch information
theorm committed Feb 25, 2025
1 parent 5aa6d9c commit 93fee45
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 54 deletions.
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"@types/node": "^22.5.5",
"@types/node-fetch": "^2.5.6",
"@types/sinon": "^17.0.3",
"@types/uuid": "^10.0.0",
"@types/wikidata-sdk": "^5.15.0",
"eslint": "^8.18.0",
"eslint-config-standard": "^17.0.0",
Expand Down
10 changes: 5 additions & 5 deletions src/services/embeddings/embeddings-v1.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ class Service {
}

async find(params) {
const namespace = `embeddings_${params.query.language}`
const namespace = `embeddings_${params.query.language_code}`
// use en to get embedding vector for the queried word
//
// https:// solrdev.dhlab.epfl.ch/solr/impresso_embeddings_de/select?q=word_s:amour&fl=embedding_bv
debug('[find] with params', params.query)

const bvRequest = {
q: `word_s:(${escapeValue(params.query.q)})`,
q: `word_s:(${escapeValue(params.query.term)})`,
fl: 'embedding_bv',
namespace,
}
const bv = await measureTime(
() =>
asFindAll(this.solr, namespace, bvRequest).then(res => {
if (!res.response.docs.length) {
throw new NotFound(`word "${params.query.q}" not found in available embeddings`)
throw new NotFound(`word "${params.query.term}" not found in available embeddings`)
}
return res.response.docs[0].embedding_bv
}),
Expand Down Expand Up @@ -60,8 +60,8 @@ class Service {
limit: params.query.limit,
offset: params.query.offset,
info: {
q: params.query.q,
language: params.query.language,
q: params.query.term,
language: params.query.language_code,
},
}
}
Expand Down
49 changes: 0 additions & 49 deletions src/services/embeddings/embeddings-v1.hooks.js

This file was deleted.

72 changes: 72 additions & 0 deletions src/services/embeddings/embeddings-v1.hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { HookContext } from '@feathersjs/feathers'
import { ImpressoApplication } from '../../types'
import { v4 } from 'uuid'
import { WordMatch } from '../../models/generated/schemas'

const { queryWithCommonParams, validate } = require('../../hooks/params')

export default {
before: {
all: [],
find: [
validate(
{
language_code: {
choices: ['fr', 'de', 'lb'],
},
term: {
required: true,
regex: /^[A-zÀ-ÿ'()\s]+$/,
max_length: 500,
transform: (d: string) =>
d
.replace(/[^A-zÀ-ÿ]/g, ' ')
.toLowerCase()
.split(/\s+/)
.sort((a: string, b: string) => a.length - b.length)
.pop(),
},
},
'GET'
),
queryWithCommonParams(),
],
get: [],
create: [],
update: [],
patch: [],
remove: [],
},

after: {
all: [],
find: [
(context: HookContext<ImpressoApplication>) => {
if (Array.isArray(context.result.data)) {
context.result.data = context.result.data.map((word: string) => {
return {
word,
id: v4(),
languageCode: context.params.query.language ?? 'fr',
} satisfies WordMatch
})
}
},
],
get: [],
create: [],
update: [],
patch: [],
remove: [],
},

error: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: [],
},
}

0 comments on commit 93fee45

Please sign in to comment.