diff --git a/requirements.txt b/requirements.txt index 89ad107608..97e93ab92e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ codecov ghp-import pyright types-PyYAML +inflect diff --git a/src/generator/lib/util.py b/src/generator/lib/util.py index 275f1247a1..0ddc7616b1 100644 --- a/src/generator/lib/util.py +++ b/src/generator/lib/util.py @@ -2,6 +2,7 @@ import os import re import subprocess +import inflect from dataclasses import dataclass from typing import Any, Dict, List, Mapping, Tuple from copy import deepcopy @@ -94,6 +95,10 @@ data_unit_multipliers = { '%': 1, } + +inflection = inflect.engine() + + HUB_TYPE_PARAMETERS = ('S',) @@ -284,11 +289,15 @@ def md_italic(l): def singular(s): - if s.endswith('ies'): - return s[:-3] + 'y' - if s[-1] == 's': - return s[:-1] - return s + if s.lower().endswith('data'): + return s + + single_noun = inflection.singular_noun(s) + + if single_noun is False: + return s + else: + return single_noun def split_camelcase_s(s):