Compare commits

..

No commits in common. "40a292d05e1fc547183bc7fd5beeb1200cda6e2e" and "4f777f00031b8b95c5e842fc48636588014888c2" have entirely different histories.

View File

@ -75,19 +75,14 @@ class ChatInputComponent extends HTMLElement {
authors.forEach(author => { authors.forEach(author => {
const lowerAuthor = author.toLowerCase(); const lowerAuthor = author.toLowerCase();
let distance = this.levenshteinDistance(lowerMention, lowerAuthor); let distance = this.levenshteinDistance(lowerMention, lowerAuthor);
if(!this.isSubsequence(lowerMention,lowerAuthor)) { if(!this.isSubsequence(lowerMention,lowerAuthor)) {
distance += 10 distance += 1
} }
console.warn([ mention, author, distance ]);
if (distance < minDistance) { if (distance < minDistance) {
minDistance = distance; minDistance = distance;
closestAuthor = author; closestAuthor = author;
console.info({ mention, closestAuthor, distance });
} }
}); });
return { mention, closestAuthor, distance: minDistance }; return { mention, closestAuthor, distance: minDistance };
@ -129,9 +124,11 @@ levenshteinDistance(a, b) {
const mentions = this.extractMentions(text); const mentions = this.extractMentions(text);
const matches = this.matchMentionsToAuthors(mentions, authors); const matches = this.matchMentionsToAuthors(mentions, authors);
console.info(matches)
let updatedText = text; let updatedText = text;
matches.forEach(({ mention, closestAuthor }) => { matches.forEach(({ mention, closestAuthor }) => {
const mentionRegex = new RegExp(`@${mention}`, 'g'); const mentionRegex = new RegExp(`@${mention}`, 'g');
console.info(closestAuthor)
updatedText = updatedText.replace(mentionRegex, `@${closestAuthor}`); updatedText = updatedText.replace(mentionRegex, `@${closestAuthor}`);
}); });