Commit 5008f63761793bee0c81e88e6f12ad9aff63e12c
Merge pull request #91 from biometrics/subject_transform
Rework SubjectTransform
Showing
1 changed file
with
11 additions
and
7 deletions
openbr/plugins/misc.cpp
| ... | ... | @@ -354,32 +354,36 @@ BR_REGISTER(Transform, AsTransform) |
| 354 | 354 | |
| 355 | 355 | /*! |
| 356 | 356 | * \ingroup transforms |
| 357 | - * \brief Change the template subject using a regular expresion matched to the file's base name. | |
| 357 | + * \brief Apply the input regular expression to the value of inputProperty, store the matched portion in outputProperty. | |
| 358 | 358 | * \author Josh Klontz \cite jklontz |
| 359 | 359 | */ |
| 360 | -class SubjectTransform : public UntrainableMetaTransform | |
| 360 | +class RegexPropertyTransform : public UntrainableMetaTransform | |
| 361 | 361 | { |
| 362 | 362 | Q_OBJECT |
| 363 | 363 | Q_PROPERTY(QString regexp READ get_regexp WRITE set_regexp RESET reset_regexp STORED false) |
| 364 | + Q_PROPERTY(QString inputProperty READ get_inputProperty WRITE set_inputProperty RESET reset_inputProperty STORED false) | |
| 365 | + Q_PROPERTY(QString outputProperty READ get_outputProperty WRITE set_outputProperty RESET reset_outputProperty STORED false) | |
| 364 | 366 | BR_PROPERTY(QString, regexp, "(.*)") |
| 367 | + BR_PROPERTY(QString, inputProperty, "name") | |
| 368 | + BR_PROPERTY(QString, outputProperty, "Label") | |
| 365 | 369 | |
| 366 | 370 | void project(const Template &src, Template &dst) const |
| 367 | 371 | { |
| 368 | 372 | dst = src; |
| 369 | 373 | QRegularExpression re(regexp); |
| 370 | - QRegularExpressionMatch match = re.match(dst.file.baseName()); | |
| 374 | + QRegularExpressionMatch match = re.match(dst.file.get<QString>(inputProprety)); | |
| 371 | 375 | if (!match.hasMatch()) |
| 372 | - qFatal("Unable to match regular expression \"%s\" to base name \"%s\"!", qPrintable(regexp), qPrintable(dst.file.baseName())); | |
| 373 | - dst.file.set("Subject", match.captured(match.lastCapturedIndex())); | |
| 376 | + qFatal("Unable to match regular expression \"%s\" to base name \"%s\"!", qPrintable(regexp), qPrintable(dst.file.get<QString>(inputProperty))); | |
| 377 | + dst.file.set(outputProperty, match.captured(match.lastCapturedIndex())); | |
| 374 | 378 | } |
| 375 | 379 | }; |
| 376 | 380 | |
| 377 | -BR_REGISTER(Transform, SubjectTransform) | |
| 381 | +BR_REGISTER(Transform, RegexPropertyTransform) | |
| 378 | 382 | |
| 379 | 383 | /*! |
| 380 | 384 | * \ingroup transforms |
| 381 | 385 | * \brief Remove templates with the specified file extension or metadata value. |
| 382 | - * \author Josh Klontz \cite jklontz | |
| 386 | + * \author Charles Otto \cite caotto | |
| 383 | 387 | */ |
| 384 | 388 | class RemoveTemplatesTransform : public UntrainableMetaTransform |
| 385 | 389 | { | ... | ... |