> For the complete documentation index, see [llms.txt](https://infinitode-docs.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://infinitode-docs.gitbook.io/documentation/package-documentation/duplipy-package-documentation/duplipy-reference/replication-functions.md).

# Replication Functions

Available functions:

* [`replace_word_with_synonym`](#replace-word-with-synonym)`(word)`: Replace the given word with a synonym.
* [`augment_text_with_synonyms`](#augment-text-with-synonyms)`(text, augmentation_factor, probability, progress=True)`: Augment the input text by replacing words with synonyms.
* [`load_text_file`](#load-text-file)`(filepath)`: Load the contents of a text file.
* [`augment_file_with_synonyms`](#augment-file-with-synonyms)`(file_path, augmentation_factor, probability, progress=True)`: Augment a text file by replacing words with synonyms.
* [`insert_random_word`](#insert-random-word)`(text, word)`: Insert a random word into the input text.
* [`delete_random_word`](#delete-random-word)`(text)`: Delete a random word from the input text.
* [`random_word_deletion`](#random-word-deletion)`(text, num_deletions=1)`: Delete a random word from the input text.
* [`swap_random_words`](#swap-random-words)`(text)`: Swaps two random words in the text.
* [`insert_synonym`](#insert-synonym)`(text, word)`: Insert a synonym of the given word into the input text.
* [`paraphrase`](#paraphrase)`(text)`: Paraphrase the input text.
* [`flip_horizontal`](#flip-horizontal)`(image)`: Flip the input image horizontally.
* [`flip_vertical`](#flip-vertical)`(image)`: Flip the input image vertically.
* [`rotate`](#rotate)`(image, angle)`: Rotate the input image by a specified angle.
* [`random_rotation`](#random-rotation)`(image, max_angle)`: Randomly rotate the input image by an angle within the specified range.
* [`resize`](#resize)`(image, size)`: Resize the input image to the specified size.
* [`crop`](#crop)`(image, box)`: Crop the input image to the specified rectangular region.
* [`random_crop`](#random-crop)`(image, size)`: Randomly crop a region from the input image.
* [`shuffle_words`](#shuffle-words)`(text)`: Randomly shuffle the order of words in each sentence.
* [`random_flip`](#random-flip)`(image, horizontal, vertical)`: Randomly flip the input image horizontally and/or vertically.
* [`random_color_jitter`](#random-color-jitter)`(image, brightness, contrast, saturation, hue)`: Randomly adjust the brightness, contrast, saturation, and hue of the input image.
* [`noise_overlay`](#noise-overlay)`(image, noise_factor, noise_type, grain_factor)`: Overlay noise on the input image.
* [`add_noise`](#add-noise)`(data, noise_factor)`: Add random Gaussian noise to numerical data.
* [`scale_data`](#scale-data)`(data, scaling_factor)`: Scale numerical data by a factor.
* [`shift_data`](#shift-data)`(data, shift_amount)`: Shift numerical data by a constant amount.
* [`augment_time_series`](#augment-time-series)`(data, augmentation_factor)`: Augment time series data by generating new timestamps within the range.
* [`balance_dataset`](#balance-dataset)`(rows, target_column)`: Balance a dataset based on a target categorical column by oversampling minority classes.
* [`augment_csv_data`](#augment-csv-data)`(input_path, output_path, augmentation_factor, balance_column, fill_missing)`: Augment and expand CSV data. Performs imputation, optional balancing, and expansion.

***

### Replace word with synonym

Replace the given word with a synonym.

```
Params:
- `word` (str): The input word to replace with a synonym.

Returns:
- `str`: The synonym for the word.
```

### Augment text with synonyms

Augment the input text by replacing words with synonyms.

```
Parameters:
- `text` (str): The input text to be augmented.
- `augmentation_factor` (int): The number of times to augment the text.
- `probability` (float): The probability of replacing a random word with a synonym.
- `progress` (bool): Whether or not to return current progress during augmentation.

Returns:
- `list`: A list of augmented text.
```

### Load text file

Load the contents of a text file.

```
Parameters:
- `file_path` (str): The path to the target input data.

Returns:
- `str`: The read text from the file.
```

### Augment file with synonyms

Augment a text file by replacing words with synonyms.

```
Parameters:
- `file_path` (str): The path to the target input data.
- `augmentation_factor` (int): The number of times to augment the data.
- `probability` (float): The probability of replacing a random word with its synonym.
- `progress` (bool): Whether or not to print the current progress during augmentation.

Returns:
- `list`: A list of augmented text.
```

### Insert random word

Insert a random word into the input text.

```
Parameters:
- `text` (str): The input text for word insertion.
- `word` (str): The word to be inserted into the text.

Returns:
- `str`: The text with the randomly inserted word.
```

### Delete random word

Delete a random word from the input text.

```
Parameters:
- `text` (str): The input text for word deletion.

Returns:
- `str`: The text with a randomly deleted word.
```

### Insert synonym

Insert a synonym of the given word into the input text.

```
Parameters:
- `text` (str): The input text for synonym insertion.
- `word` (str): The word for which a synonym will be inserted.

Returns:
- `str`: The text with a synonym of the word inserted.
```

### Paraphrase

Paraphrase the input text.

```
Parameters:
- `text` (str): The input text to be paraphrased.

Returns:
- `str`: The paraphrased text.
```

### Flip horizontal

Flip the input image horizontally.

```
Parameters:
- `image` (PIL.Image.Image): The input image to be flipped.

Returns:
- `PIL.Image.Image`: The horizontally flipped image.
```

### Flip vertical

Flip the input image vertically.

```
Parameters:
- `image` (PIL.Image.Image): The input image to be flipped.

Returns:
- `PIL.Image.Image`: The vertically flipped image.
```

### Rotate

Rotate the input image by a specified angle.

```
Parameters:
- `image` (PIL.Image.Image): The input image to be rotated.
- `angle` (float): The angle of rotation in degrees.

Returns:
- `PIL.Image.Image`: The rotated image.
```

### Random rotation

Randomly rotate the input image by an angle within the specified range.

```
Parameters:
- `image` (PIL.Image.Image): The input image to be randomly rotated.
- `max_angle` (float, optional): The maximum absolute angle of rotation in degrees. Default is 30.

Returns:
- `PIL.Image.Image`: The randomly rotated image.
```

### Resize

Resize the input image to the specified size.

```
Parameters:
- `image` (PIL.Image.Image): The input image to be resized.
- `size` (tuple): The new size in the format (width, height).

Returns:
- `PIL.Image.Image`: The resized image.
```

### Crop

Crop the input image to the specified rectangular region.

```
Parameters:
- `image` (PIL.Image.Image): The input image to be cropped.
- `box` (tuple): A tuple (left, upper, right, lower) specifying the region to crop.

Returns:
- `PIL.Image.Image`: The cropped image.
```

### Random crop

Randomly crop a region from the input image.

```
Parameters:
- `image` (PIL.Image.Image): The input image from which to extract the random crop.
- `size` (tuple): The size of the output crop in the format (width, height).

Returns:
- `PIL.Image.Image`: The randomly cropped image region.
```

### Shuffle words

This function takes a list of sentences and randomly shuffles the order of words in each sentence, creating variations for text augmentation or diversity.

```
Parameters:
- `text` (list of str): List of sentences where each sentence's words needs to be shuffled.

Returns:
- `list of str`: List of sentences with randomly shuffled words.
```

### Random flip

This function randomly flips an input image horizontally, vertically, or even both.

```
Parameters:
- `image` (PIL.Image.Image): The input image to be flipped.
- `horizontal` (bool): Whether to flip the image horizontally.
- `vertical` (bool): Whether to flip the image vertically.

Returns:
- `PIL.Image.Image`: The randomly flipped image.
```

### Random color jitter

This function takes an input image and randomly adjusts the brightness, contrast, saturation, and hue.

```
Parameters:
- `image` (PIL.Image.Image): The input image to be color-jittered.
- `brightness` (float): The maximum factor to adjust brightness.
- `contrast` (float): The maximum factor to adjust contrast.
- `saturation` (float): The maximum factor to adjust saturation.
- `hue` (float): The maximum factor to adjust hue.

Returns:
- `PIL.Image.Image`: The color-jittered image.
```

### Noise overlay

This function overlays noise onto the input image.

```
Parameters:
- `image` (PIL.Image.Image): The input image to overlay noise on.
- `noise_factor` (float): The factor to control the intensity of the noise (0.0 to 1.0).
- `noise_type` (str): The type of noise to overlay ("gaussian", "salt_and_pepper"). Defaults to "gaussian".
    - `grain_factor` (float): The factor to control the graininess of the noise (0.0 to 1.0). Defaults to 0.0.

Returns:
- `PIL.Image.Image`: The image with overlaid noise.
```

### Random word deletion

This function randomly deletes a word from the input text, creating variations for text augmentation or diversity.

```
Parameters:
- `text` (str): The input text for word deletion.
- `num_deletions` (int): The number of words to delete.

Returns:
- `str`: The text with a randomly deleted word.
```

### Add noise

Add random Gaussian noise to numerical data.

```
Parameters:
    - `data` (list[float] | np.ndarray): The input numerical data.
    - `noise_factor` (float): The factor to control the intensity of the noise.

Returns:
    - `list[float] | np.ndarray`: The data with added noise.
```

### Scale data

Scale numerical data by a factor.

```
Parameters:
    - `data` (list[float] | np.ndarray): The input numerical data.
    - `scaling_factor` (float): The factor to scale the data by.

Returns:
    - `list[float] | np.ndarray`: The scaled data.
```

### Shift data

Shift numerical data by a constant amount.

```
Parameters:
    - `data` (list[float] | np.ndarray): The input numerical data.
    - `shift_amount` (float): The amount to shift the data by.

Returns:
    - `list[float] | np.ndarray`: The shifted data.
```

### Augment time-series

Augment time series data by generating new timestamps within the range.

```
Parameters:
    - `data` (list[Any]): The input time series data (strings or datetime objects).
    - `augmentation_factor` (int): How many new points to generate per existing point.

Returns:
    - `list[Any]`: The augmented time series data.
```

### Balance dataset

Balance a dataset based on a target categorical column by oversampling minority classes.

```
Parameters:
    - `rows` (list[dict[str, Any]]): The input data as a list of dictionaries.
    - `target_column` (str): The column name to balance by.

Returns:
    - `list[dict[str, Any]]`: The balanced dataset.
```

### Augment CSV data

Augment and expand CSV data. Performs imputation, optional balancing, and expansion.

```
Parameters:
    - `input_path` (str): Path to the input CSV file.
    - `output_path` (str): Path where the augmented CSV will be saved.
    - `augmentation_factor` (int): How many new entries to generate relative to the original.
    - `balance_column` (str | None): Optional column name to balance the dataset by.
    - `fill_missing` (bool): Whether to fill missing values with column modes or means.

Returns:
    - `bool`: True if successful, False otherwise.
```
