Compare commits
3 Commits
4f777f0003
...
40a292d05e
| Author | SHA1 | Date | |
|---|---|---|---|
| 40a292d05e | |||
| bf723db2cc | |||
| 46052172b2 |
@ -75,14 +75,19 @@ class ChatInputComponent extends HTMLElement {
|
||||
authors.forEach(author => {
|
||||
const lowerAuthor = author.toLowerCase();
|
||||
let distance = this.levenshteinDistance(lowerMention, lowerAuthor);
|
||||
|
||||
|
||||
if(!this.isSubsequence(lowerMention,lowerAuthor)) {
|
||||
distance += 1
|
||||
distance += 10
|
||||
}
|
||||
|
||||
console.warn([ mention, author, distance ]);
|
||||
if (distance < minDistance) {
|
||||
minDistance = distance;
|
||||
closestAuthor = author;
|
||||
console.info({ mention, closestAuthor, distance });
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return { mention, closestAuthor, distance: minDistance };
|
||||
@ -124,11 +129,9 @@ levenshteinDistance(a, b) {
|
||||
const mentions = this.extractMentions(text);
|
||||
|
||||
const matches = this.matchMentionsToAuthors(mentions, authors);
|
||||
console.info(matches)
|
||||
let updatedText = text;
|
||||
matches.forEach(({ mention, closestAuthor }) => {
|
||||
const mentionRegex = new RegExp(`@${mention}`, 'g');
|
||||
console.info(closestAuthor)
|
||||
updatedText = updatedText.replace(mentionRegex, `@${closestAuthor}`);
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user