Returns the string with a prepended article. The input does not need to begin with a character. Parameters ---------- name : str Name to which to prepend an article definite : bool (default: False) Whether the article is definite or not. Indefinite artic
(name: str, definite: bool = False, capital: bool = False)
| 143 | |
| 144 | |
| 145 | def add_article(name: str, definite: bool = False, capital: bool = False) -> str: |
| 146 | """Returns the string with a prepended article. |
| 147 | |
| 148 | The input does not need to begin with a character. |
| 149 | |
| 150 | Parameters |
| 151 | ---------- |
| 152 | name : str |
| 153 | Name to which to prepend an article |
| 154 | definite : bool (default: False) |
| 155 | Whether the article is definite or not. |
| 156 | Indefinite articles being 'a' and 'an', |
| 157 | while 'the' is definite. |
| 158 | capital : bool (default: False) |
| 159 | Whether the added article should have |
| 160 | its first letter capitalized or not. |
| 161 | """ |
| 162 | if definite: |
| 163 | result = "the " + name |
| 164 | else: |
| 165 | first_letters = re.compile(r"[\W_]+").sub("", name) |
| 166 | if first_letters[:1].lower() in "aeiou": |
| 167 | result = "an " + name |
| 168 | else: |
| 169 | result = "a " + name |
| 170 | if capital: |
| 171 | return result[0].upper() + result[1:] |
| 172 | else: |
| 173 | return result |
| 174 | |
| 175 | |
| 176 | def repr_type(obj: Any) -> str: |