ChemPal Documentation - v1.6.0
    Preparing search index...

    Function pickBroadestName

    • Picks the best single search term from a list of candidate chemical names for the same compound — the broadest form, which tends to yield the most store results (precision is recovered later by scoring each result against every candidate). Chooses the shortest candidate that still contains the primary name's longest word (the compound's distinctive token), so a general synonym like "Sodium hexametaphosphate" beats the more specific primary "Hexasodium hexametaphosphate", while unrelated short synonyms (brand names like "Calgon") are ignored. A one-name (or empty-after-filter) list returns its primary.

      Parameters

      • candidates: readonly string[]

        Candidate names for one compound, primary first (e.g. the PubChem Title).

      Returns undefined | string

      The broadest search name, or undefined when candidates is empty.

      pickBroadestName(["Hexasodium hexametaphosphate", "Calgon", "Sodium hexametaphosphate"]);
      // "Sodium hexametaphosphate"
      pickBroadestName(["Acetone", "propan-2-one", "dimethyl ketone"]); // "Acetone"
      export function pickBroadestName(candidates: readonly string[]): string | undefined {
      const primary = candidates[0];
      if (primary === undefined) {
      return undefined;
      }
      const core = primary
      .split(/\s+/)
      .reduce((longest, token) => (token.length > longest.length ? token : longest), '')
      .toLowerCase();
      let best = primary;
      for (const candidate of candidates) {
      if (candidate.length < best.length && candidate.toLowerCase().includes(core)) {
      best = candidate;
      }
      }
      return best;
      }