Author Topic: Find and Replace Multiple Keywords  (Read 5276 times)

Offline PauloBMB

  • Member
  • **
  • Posts: 64
    • View Profile
Find and Replace Multiple Keywords
« on: January 05, 2021, 04:22:53 AM »
Hi,

I am trying to clean the mess lightroom hierarchical keywords did, but I can not seem to be able to replace (delete) multiple keywords at the same time, I have to do it one at a time. Is it possible to do it somehow?
I am attaching a sample screenshot so it makes it easier to understand what is happening.


Running PM build 5435 (a72913) on win 10

Thanks a lot

Paulo
« Last Edit: January 05, 2021, 08:30:06 AM by PauloBMB »

Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 24730
    • View Profile
    • Camera Bits, Inc.
Re: Find and Replace Multiple Keywords
« Reply #1 on: January 05, 2021, 01:52:29 PM »
Paulo,

I am trying to clean the mess lightroom hierarchical keywords did, but I can not seem to be able to replace (delete) multiple keywords at the same time, I have to do it one at a time. Is it possible to do it somehow?

Possibly, using Grep.  But what is your desired outcome?  What do you want the Keywords field to look like when the job is done?

-Kirk

Offline PauloBMB

  • Member
  • **
  • Posts: 64
    • View Profile
Re: Find and Replace Multiple Keywords
« Reply #2 on: January 05, 2021, 02:04:48 PM »
Thanks, I will try to explain.
I just need to delete the A, B and C letters, I had those letters in lightroom as an organization method just to keep the list easier to navigate, in lightroom they were set to not export, but since they are inside DNG now all my organization structure that should not be visible is picked up by PM, like that I had others. let me give you another example.

I have this in another picture:

-Clientes-, 15 Anos, A, Aniversario, Carolina Herreros, -Clientes- | Carolina Herreros, A | Aniversario

 Lightroom made a mess here. All I need is:

15 Anos, Aniversario, Carolina Herreros

I need to exclude:
-Clientes-
A
and all the | sign

I have a snapshot that takes care of the | sign and therefore excludes the duplicates. Then I have to exclude (replace with empty) The Capital letter one by one, when I have 1000 images selected that takes ages each time.

hopefully, I made it easier to understand




Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 24730
    • View Profile
    • Camera Bits, Inc.
Re: Find and Replace Multiple Keywords
« Reply #3 on: January 05, 2021, 03:15:16 PM »
Paulo,

OK, I understand better now.  For your first example you would use this as the find text:

[ACD]{1}[ \| ]+|[ACD]{1}\b

You'll have to turn Grep on.  And you should turn "Treat repeating fields as single string" on.

For the second example you would use this as the find text (keep grep and repeating fields both on) :

-Clientes-[ \| ]+|-Clientes-|[ACD]{1}[ \| ]+|[ACD]{1}\b

Please let me know if you have any problems.

-Kirk

Offline PauloBMB

  • Member
  • **
  • Posts: 64
    • View Profile
Re: Find and Replace Multiple Keywords
« Reply #4 on: January 05, 2021, 03:20:55 PM »
Thank you very much Kirk!


I will give t a try.


Do you have any documentation where I can learn how to do this myself from now on? I would love to be able to create the syntax you used but I would need to understand where and why to use what...


Anyway thanks for your patience and support!


Paulo

Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 24730
    • View Profile
    • Camera Bits, Inc.
Re: Find and Replace Multiple Keywords
« Reply #5 on: January 05, 2021, 03:42:22 PM »
Paulo,

Do you have any documentation where I can learn how to do this myself from now on? I would love to be able to create the syntax you used but I would need to understand where and why to use what...


Anyway thanks for your patience and support!

You're welcome.  This is the resource that I use: https://regexr.com/

It lets you interactively create your regular expressions.  It has documentation and handy cheat sheets that pop out on the left side that you can learn from and reference.

-Kirk

Offline PauloBMB

  • Member
  • **
  • Posts: 64
    • View Profile
Re: Find and Replace Multiple Keywords
« Reply #6 on: January 05, 2021, 03:48:31 PM »
It works, but I needed two passes. I really need to understand the language so I  can extrapolate for different situations..


This is what I've got:

From:  A, Avenues, C, Corporativo, D, Decoraçao, A | Avenues, C | Corporativo, D | Decoraçao

ran this: [ACD]{1}[ \| ]+|[ACD]{1}\b

Got this: Avenues, Corporativo, Decoraçao, | Avenues, | Corporativo, | Decoraçao


Second Replace pass to get rid of the | sign

To finish with:  Avenues, Corporativo, Decoraçao.

Tried to figure out how to do it in one pass but no success.

Still, 2 is better than 4.


« Last Edit: January 05, 2021, 03:55:44 PM by Kirk Baker »

Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 24730
    • View Profile
    • Camera Bits, Inc.
Re: Find and Replace Multiple Keywords
« Reply #7 on: January 05, 2021, 04:04:22 PM »
Paulo,

That's odd.  I took your sample text, pasted it into an image and ran the Find and Replace with the same find text and it worked in a single pass.  Did you set both checkboxes that I said needed to be set?

I can tell you what [ACD]{1}[ \| ]+|[ACD]{1}\b does:

First it matches A, or C, or D exactly one time followed by a space, or a vertical bar one or more times, OR it matches A, or C, or D exactly one time on a word boundary.

It could be better expressed as:  [ACD]{1}[ \|]+|[ACD]{1}\b

(it doesn't need that extra space after the escaped vertical bar).

-Kirk

Offline PauloBMB

  • Member
  • **
  • Posts: 64
    • View Profile
Re: Find and Replace Multiple Keywords
« Reply #8 on: January 05, 2021, 04:19:50 PM »
This what I have done. and the escape vertical bar is not going away.

Offline PauloBMB

  • Member
  • **
  • Posts: 64
    • View Profile
Re: Find and Replace Multiple Keywords
« Reply #9 on: January 05, 2021, 04:22:53 PM »
It is odd...


The expression should be working but it does not ...

Offline Kirk Baker

  • Senior Software Engineer
  • Camera Bits Staff
  • Superhero Member
  • *****
  • Posts: 24730
    • View Profile
    • Camera Bits, Inc.
Re: Find and Replace Multiple Keywords
« Reply #10 on: January 05, 2021, 04:37:47 PM »
Paulo,

This what I have done. and the escape vertical bar is not going away.

Turn off the Whole words checkbox.

-Kirk

Offline PauloBMB

  • Member
  • **
  • Posts: 64
    • View Profile
Re: Find and Replace Multiple Keywords
« Reply #11 on: January 05, 2021, 04:44:28 PM »
You are a lifesaver!!!

I will spend some time on the Reg Ex Reference site trying to understand the logic behind all that, hopefully, will not have to bother you anymore!

As always best customer support ever!!


Online davidgordon

  • Full Member
  • ***
  • Posts: 142
    • View Profile
    • davidgordon.co.uk
Re: Find and Replace Multiple Keywords
« Reply #12 on: January 06, 2021, 01:19:04 AM »
Paulo,

I am trying to clean the mess lightroom hierarchical keywords did, but I can not seem to be able to replace (delete) multiple keywords at the same time, I have to do it one at a time. Is it possible to do it somehow?

Possibly, using Grep.  But what is your desired outcome?  What do you want the Keywords field to look like when the job is done?

This seems to be the exact problem I posted about here http://forums.camerabits.com/index.php?topic=13877.0 yesterday.

I disagree this is "mess lightroom hierarchical keywords did", I believe it is caused by Photo Mechanic reading the XMP <lr:hierarchicalSubject> and writing those keywords and containing keywords back to the <dc:subject> field.

The solution is for PM to have an option not to read <lr:hierarchicalSubject>.

Surely a lot easier than Grep?

Offline PauloBMB

  • Member
  • **
  • Posts: 64
    • View Profile
Re: Find and Replace Multiple Keywords
« Reply #13 on: January 06, 2021, 04:39:32 AM »
Paulo,

I am trying to clean the mess lightroom hierarchical keywords did, but I can not seem to be able to replace (delete) multiple keywords at the same time, I have to do it one at a time. Is it possible to do it somehow?

Possibly, using Grep.  But what is your desired outcome?  What do you want the Keywords field to look like when the job is done?

This seems to be the exact problem I posted about here http://forums.camerabits.com/index.php?topic=13877.0 yesterday.

I disagree this is "mess lightroom hierarchical keywords did", I believe it is caused by Photo Mechanic reading the XMP <lr:hierarchicalSubject> and writing those keywords and containing keywords back to the <dc:subject> field.

The solution is for PM to have an option not to read <lr:hierarchicalSubject>.

Surely a lot easier than Grep?

I guess you have a point here, but I am still happy Kirk provided me with a solution for my immediate problem. If they can come up with a global solution like what you suggest in the future even better.

Offline Graham1

  • Full Member
  • ***
  • Posts: 148
    • View Profile
Re: Find and Replace Multiple Keywords
« Reply #14 on: January 06, 2021, 08:25:53 AM »
I am finding this sort-of GREP mini tutorial very helpful in sorting out the mess Lightroom makes in exporting keywords.  For example, I keep my keyword categories in square brackets.  I do not want to have them in my flat keywords and I can get rid of them in images exported from LR using Find and Replace, searching for \[(.*?)\] and replacing it with a blank.  So far, so good.

What I cannot get rid of though is the separator, whether as a result of adding hierarchical keywords through Lightroom or the use of the Metadata (IPTC) Template.  In Kirk's examples above, the code is [ \¦], but I have had to type the vertical pipe in, because copying and pasting, here and in RegExr and in the Find and Replace panel, comes out as a comma, as in [ \,].  Using the comma, with or without spaces either side, does not work.  Using the pipe symbol typed in replaces all the spaces between words, not the separators.  I have also tried using the unicode number u007c, but to no avail.  I have made sure that IPTC data is set to unicode.

I know this is not a GREP help forum, but I have not been able to find the answer, trying to create an addition to \[(.*?)\] which will also remove the vertical separators (and not delete other non-alphabetic characters such as hyphens in my keywords).  Is this because I am on Windows 10, not a Mac? Clearly it worked for Paulo.

If I can sort this out, it makes deleting all duplicate flat keywords after export from Lightroom developing much easier.  My next ambition is them to do the opposite, which is to strip out flat keywords for images I want in Lightroom.  I think that, however, there is going to be a fundamental problem with this round tripping, even preserving separators, in that although both Photo Mechanic and Lightroom recognise synonyms, and display them accordingly, EXIF does not and so far as EXIF is concerned they are all just keywords.  This seems to mean that if there is a new word which is a keyword in one and and a already a synonym in the other, of a duplicate keyword in the destination application, it does not know where to put this, so LR treats it as a flat keyword even though it should be hierarchical.  I don't know whether I have explained this very well, but whatever I have done over many months trying to get keywords to round trip between PM to LR and back seems to fall over if the same word appears in more than one location in the vocabulary/library, particularly if you think you are adding a new keyword in PM: if it exists in a different location in LR or with different synonyms, LR refuses to see it as other than a new flat keyword or (even worse) a new partial hierarchy hidden within part of its existing hierarchy, causing horrendous duplication.  I am hoping I can use GREP to sort out some of the messes that LR makes, and to take out the flat keywords where I try to send a file keyworded in PM to LR after syncing the keyword vocabularies.

Any help/thoughts on the GREP issue would be much appreciated.

Graham