Skip to content

Commit

Permalink
Update doc for regex rules in transform (#874)
Browse files Browse the repository at this point in the history
* Merge back 1.1.0rc1 (#861)

* Update CHANGLOG.md - v1.1.0rc1
* Update version.py
* Update CHANGELOG.md format

Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com>

* Update PR template (#866)

* Update PR template

* Update PR template

* Update doc for regex rules

* Modify annotation for Rename

* Fix reverse link syntax

* Fix markdownlint

---------

Signed-off-by: Kim, Vinnam <vinnam.kim@intel.com>
Co-authored-by: Vinnam Kim <vinnam.kim@intel.com>
Co-authored-by: Emily Chun <emily.chun@intel.com>
  • Loading branch information
3 people authored Mar 22, 2023
1 parent bb72953 commit 967180d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
7 changes: 4 additions & 3 deletions datumaro/plugins/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,25 +501,26 @@ class Rename(ItemTransform, CliPlugin):
the pattern and replacement parts. Replacement part can also
contain `str.format` replacement fields with the `item`
(of type `DatasetItem`) object available.|n
Please use doulbe quotes to represent regex.|n
|n
Examples:|n
|s|s- Replace 'pattern' with 'replacement':|n
.. code-block::
|s|s|s|srename -e '|pattern|replacement|'|n
|s|s|s|srename -e "|pattern|replacement|"|n
|n
|s|s- Remove 'frame_' from item ids:|n
.. code-block::
|s|s|s|srename -e '|^frame_||'|n
|s|s|s|srename -e "|^frame_||"|n
|n
|s|s- Rename by regex:|n
.. code-block::
|s|s|s|srename -e '|frame_(\d+)_extra|{item.subset}_id_\1|'
|s|s|s|srename -e "|frame_(\d+)_extra|{item.subset}_id_\1|"
"""

@classmethod
Expand Down
13 changes: 8 additions & 5 deletions site/content/en/docs/user-manual/command-reference/transform.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ datum transform -t random_split --overwrite path/to/dataset:voc
```

- Rename images in a project data source by a regex from `frame_XXX` to `XXX`:

**NOTE:** Please use double quotes (`"`) for regex representation. Check [Reason to use double quotes](https://stackoverflow.com/questions/51080215/differences-between-single-and-double-quotes-in-cmd).

``` bash
datum create <...>
datum import <...> -n source-1
datum transform -t rename source-1 -- -e '|^frame_||'
datum transform -t rename source-1 -- -e "|^frame_||"
```

<a id="builtin-transforms"></a>
Expand Down Expand Up @@ -152,22 +155,22 @@ Optional arguments:
Examples:
Replace 'pattern' with 'replacement':
```bash
datum transform -t rename -- -e '|pattern|replacement|'
datum transform -t rename -- -e "|pattern|replacement|"
```

Remove the `frame_` prefix from item ids:
```bash
datum transform -t rename -- -e '|^frame_|\1|'
datum transform -t rename -- -e "|^frame_|\1|"
```

Collect images from subdirectories into the base image directory using regex:
```bash
datum transform -t rename -- -e '|^((.+[/\\])*)?(.+)$|\2|'
datum transform -t rename -- -e "|^((.+[/\\])*)?(.+)$|\2|"
```

Add subset prefix to images:
```bash
datum transform -t rename -- -e '|(.*)|{item.subset}_\1|'
datum transform -t rename -- -e "|(.*)|{item.subset}_\1|"
```

<a id="id_from_image_name-transform"></a>
Expand Down

0 comments on commit 967180d

Please sign in to comment.