search for explicit pronoun declarations first

This commit is contained in:
ItsVipra 2023-08-14 13:38:43 +02:00 committed by nachtjasmin
parent 075d6cc3ff
commit 0ad785e025
No known key found for this signature in database
3 changed files with 21 additions and 15 deletions

View file

@ -1,6 +1,6 @@
/* eslint-disable no-console -- Logging should only be done with this module. */
import { isLogging } from "./settings";
import { isLogging } from "./settings.js";
/** @param {any[]} args */
export function error(...args) {

View file

@ -1,6 +1,7 @@
import sanitizeHtml from "sanitize-html";
import { htmlDecode } from "./domhelpers.js";
import { allKnownPronouns } from "./generated/pronouns/index.js";
import {debug} from "../libs/logging.js";
const fieldMatchers = [/\bpro.*nouns?\b/i, /\bpronomen\b/i, /(i )?go(es)? by/i];
const knownPronounUrls = [
@ -231,6 +232,22 @@ function sanitizePronouns(str) {
function searchForKnownPronouns(text) {
if (!text) return null;
debug("Searching for explicit naming, any/no pronouns");
//search for explicitly mentioned pronouns first, lower likelyhood of false positives
const followedByColon = text.matchAll(/pronouns?:\W+([\w/+]+)/gi);
for (const match of followedByColon) {
return match.pop() ?? null; // first group is last entry in array
}
const anyAllPronouns = text.match(/(any|all) +pronouns/gi);
if (anyAllPronouns) {
return anyAllPronouns[0];
}
const noPronouns = text.match(/(no|none) +pronouns/);
if (noPronouns) {
return noPronouns[0];
}
debug("Searching for known pronouns");
// This is a rather complex regular expression to search for pronouns. Therefore, here's the explanation
// in plain English: We search for all words that are followed by a slash (/),
// which are followed by at least one another word that matches this pattern.
@ -260,18 +277,6 @@ function searchForKnownPronouns(text) {
}
}
const followedByColon = text.matchAll(/pronouns?:\W+([\w/+]+)/gi);
for (const match of followedByColon) {
return match.pop() ?? null; // first group is last entry in array
}
const anyAllPronouns = text.match(/(any|all) +pronouns/gi);
if (anyAllPronouns) {
return anyAllPronouns[0];
}
const noPronouns = text.match(/(no|none) +pronouns/);
if (noPronouns) {
return noPronouns[0];
}
debug("No known pronouns found");
return null;
}

View file

@ -1,4 +1,5 @@
import { storage } from "webextension-polyfill";
import browser from "webextension-polyfill";
const { storage } = browser;
let settings;