fix(codev): algo Solution tokenize direct + seuils releves + fiches demo enrichies
This commit is contained in:
@@ -41,15 +41,21 @@ function score(textA: string, hashtagsA: string[], textB: string, hashtagsB: str
|
||||
return jaccard(tokenize(textA), tokenize(textB))
|
||||
}
|
||||
|
||||
const THRESHOLD = 0.15
|
||||
// scoreDirect tokenise TOUJOURS les textes, ignore les hashtags
|
||||
// Utilise pour matchSolution : besoin vs offre doivent etre compares par leur contenu reel
|
||||
function scoreDirect(textA: string, textB: string): number {
|
||||
return jaccard(tokenize(textA), tokenize(textB))
|
||||
}
|
||||
|
||||
export function matchSolution(fiches: CodevFiche[]): CodevMatch[] {
|
||||
export function matchSolution(fiches: CodevFiche[], threshold = 0.18): CodevMatch[] {
|
||||
const matches: CodevMatch[] = []
|
||||
for (const a of fiches) {
|
||||
for (const b of fiches) {
|
||||
if (a.id === b.id) continue
|
||||
const s = score(a.besoin, a.hashtags, b.offre, b.hashtags)
|
||||
if (s >= THRESHOLD) {
|
||||
// Solution : on compare le TEXTE besoin de A avec le TEXTE offre de B
|
||||
// On ignore les hashtags pour differencier besoin et offre
|
||||
const s = scoreDirect(a.besoin, b.offre)
|
||||
if (s >= threshold) {
|
||||
matches.push({ fromId: a.id, toId: b.id, score: s, mode: 'solution' })
|
||||
}
|
||||
}
|
||||
@@ -57,13 +63,14 @@ export function matchSolution(fiches: CodevFiche[]): CodevMatch[] {
|
||||
return matches
|
||||
}
|
||||
|
||||
export function matchAlliance(fiches: CodevFiche[]): CodevMatch[] {
|
||||
export function matchAlliance(fiches: CodevFiche[], threshold = 0.25): CodevMatch[] {
|
||||
const matches: CodevMatch[] = []
|
||||
for (let i = 0; i < fiches.length; i++) {
|
||||
for (let j = i + 1; j < fiches.length; j++) {
|
||||
const a = fiches[i], b = fiches[j]
|
||||
// Alliance : besoins similaires — on compare hashtags si presents, sinon textes
|
||||
const s = score(a.besoin, a.hashtags, b.besoin, b.hashtags)
|
||||
if (s >= THRESHOLD) {
|
||||
if (s >= threshold) {
|
||||
matches.push({ fromId: a.id, toId: b.id, score: s, mode: 'alliance' })
|
||||
}
|
||||
}
|
||||
@@ -71,13 +78,14 @@ export function matchAlliance(fiches: CodevFiche[]): CodevMatch[] {
|
||||
return matches
|
||||
}
|
||||
|
||||
export function matchSurprise(fiches: CodevFiche[]): CodevMatch[] {
|
||||
export function matchSurprise(fiches: CodevFiche[], threshold = 0.25): CodevMatch[] {
|
||||
const matches: CodevMatch[] = []
|
||||
for (let i = 0; i < fiches.length; i++) {
|
||||
for (let j = i + 1; j < fiches.length; j++) {
|
||||
const a = fiches[i], b = fiches[j]
|
||||
// Surprise : offres similaires
|
||||
const s = score(a.offre, a.hashtags, b.offre, b.hashtags)
|
||||
if (s >= THRESHOLD) {
|
||||
if (s >= threshold) {
|
||||
matches.push({ fromId: a.id, toId: b.id, score: s, mode: 'surprise' })
|
||||
}
|
||||
}
|
||||
@@ -88,10 +96,11 @@ export function matchSurprise(fiches: CodevFiche[]): CodevMatch[] {
|
||||
export function computeMatches(
|
||||
fiches: CodevFiche[],
|
||||
mode: 'solution' | 'alliance' | 'surprise',
|
||||
threshold?: number,
|
||||
): CodevMatch[] {
|
||||
switch (mode) {
|
||||
case 'solution': return matchSolution(fiches)
|
||||
case 'alliance': return matchAlliance(fiches)
|
||||
case 'surprise': return matchSurprise(fiches)
|
||||
case 'solution': return matchSolution(fiches, threshold)
|
||||
case 'alliance': return matchAlliance(fiches, threshold)
|
||||
case 'surprise': return matchSurprise(fiches, threshold)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user