parseEndpointName()

in src/processors/CodeGenNameConventions.js [81:165]


  parseEndpointName(endpoint: string, boostWords: string[], clsName: string) {
    if (endpoint === 'leadgen_forms') {
      return ['lead', 'gen', 'forms'];
    }
    if (endpoint === 'leadgen_context_cards') {
      return ['lead', 'gen', 'context', 'cards'];
    }
    if (endpoint === 'leadgen_whitelisted_users') {
      return ['lead', 'gen', 'whitelisted', 'users'];
    }
    if (endpoint === 'ExtendedCreditOwningCreditAllocationConfigs') {
      return [
        'extended',
        'credit',
        'owning',
        'credit',
        'allocation',
        'configs',
      ];
    }

    let mergedDict = _decodeDict;
    if (boostWords) {
      mergedDict = merge(
        true,
        _decodeDict,
        boostWords.reduce((prev, curr) => {
          prev[curr] = 10;
          const pluralWord = pluralize(curr);
          if (pluralWord !== curr) {
            prev[pluralWord] = 1;
          }
          return prev;
        }, {}),
      );
    }

    // $FlowFixMe
    const lattice = {0: [0]};
    const candidates = [1];
    for (let index = 0; index < endpoint.length; ++index) {
      if (!candidates[index]) {
        continue;
      }

      const weight = lattice[index][0];
      let newWeight = 0;
      // deal with the underscores in endpoints
      if (endpoint.charAt(index) === '_') {
        const newIndex = index + 1;
        if (!lattice[newIndex]) {
          lattice[newIndex] = [newWeight, '#'];
          candidates[newIndex] = 1;
        }
      }

      for (const word in mergedDict) {
        if (_startsWith(endpoint, word, index)) {
          const newIndex = index + word.length;
          newWeight = weight + mergedDict[word];
          if (!lattice[newIndex] || lattice[newIndex][0] < newWeight) {
            lattice[newIndex] = [newWeight, word];
            candidates[newIndex] = 1;
          }
        }
      }
    }

    const parts = [];
    let endPost = endpoint.length;
    if (!lattice[endPost]) {
      throw Error(
        'cannot decode endpoint ' + endpoint + ' in class ' + clsName,
      );
    }
    while (endPost) {
      if (lattice[endPost][1] !== '#') {
        parts.push(lattice[endPost][1]);
      }
      endPost -= lattice[endPost][1].length;
    }

    parts.reverse();
    return parts;
  },