Flatten hierarchical keywords with synonyms

Started by mosdubindi1, March 02, 2025, 06:49:17 PM

Previous topic - Next topic

mosdubindi1

Hello Mario,

First thank you very much for the new IMatch 2025! I'm fun of IMatch and the new version is really cool and better than ever before!

I've got one task, which I cannot finish without your help. In my main database I have keywords as usual: hierarchical  (HierarchicalSubject) and xmp (Subject) flattened by Preferences (2 flags active - Write hierarchical keywords and Write path elements). Files, which are for stock agency, I'm going to transfer to another database using Batch Processor. During processing I'm using Custom Metadata variable {File.MD.hierarchicalkeywords|splicelist:~;|,-HierarchicalSubject=,{cr}{lf},trimdupes}.

At the end I got a new file with flattened hierarchical keywords = xmp keywords, and this is what I need. It is working fine if there are no synonyms.

In case of synonyms the process a bit confusing. VarToy result of {File.MD.hierarchicalkeywords|splicelist:~;|,-HierarchicalSubject=,{cr}{lf},trimdupes}:
-HierarchicalSubject=02_Who
-HierarchicalSubject=animals
-HierarchicalSubject=chordata
-HierarchicalSubject=mammal
-HierarchicalSubject=cetartiodactyla
-HierarchicalSubject=bovidae
-HierarchicalSubject=aepyceros
-HierarchicalSubject=
impala,02_Who
-HierarchicalSubject=
melampus,02_Who
-HierarchicalSubject=rooibok

Attached the following screenshots:

1. Thesaurus with synonyms in main database (see attached).
2. Keywords flattened by IMatch Preferences in main database.
3. Batch Processor Metadata.
4. Batch Processor result - keywords in output file. Here the result is not OK - 2 duplicates pop up.
5. If open Keyword Editor and press Apply Changes, then duplicates are removed and the result became OK ( flattened hierarchical keywords = xmp keywords).

Is there a way to avoid manual removing duplicates, which obviously coming from synonyms?

Thanks in advance,
Dmitry



Mario

As soon as a keyword and it's synonyms are assigned, they become normal keywords. XMP and IPTC have no concept for synonyms.

impala|02_Who
melampus|02_Who

are two different hierarchical keywords.
When I understand you correctly, IMatch flattens the keywords correctly, without duplicates.
Small images are always hard to read and a simple copy & paste of the keywords would have been helpful.

I'm a bit lost about your process, complex variables splitting hierarchical keywords manually etc. I had never a reason to do such a thing.


QuoteDuring processing I'm using Custom Metadata variable {File.MD.hierarchicalkeywords|splicelist:~;|,-HierarchicalSubject=,{cr}{lf},trimdupes}.
Why don't you just use the flattened keywords IMatch has produced (without dupes) instead?

mosdubindi1

In fact, the reason is the issue:

https://www.photools.com/community/index.php/topic,14056.msg98875.html#msg98875

In the main database I keep dummy keywords to have a good structure in @Keywords category.
Source File Keywords (screenshot Keywords_main_database.jpg)

In the separate database I need to delete dummy keywords in mass by Metadata Mechanic.
Output File Keywords how it should be in separate database (screenshot Keywords_separate_database.jpg)

Batch Processor converts automatically keywords in the output file using variable. For Hierarchical keywords without synonyms, it is working fine. 

For Hierarchical keywords with synonyms, I cannot get the desired result automatically.
After conversion there are 2 duplicates (screenshot Keywords_separate_database_synonyms.jpg)

To remove these duplicates, I have to delete manually the duplicates by Keyword editor. This is because for synonyms the variable gives:

-HierarchicalSubject=impala,02_Who
-HierarchicalSubject=melampus,02_Who

Instead, as synonym is normal keyword, I would expect the result of the variable as follows:
-HierarchicalSubject=impala
-HierarchicalSubject=melampus

So, my question is how to avoid the manual step of removing the duplicates?

Sorry I cannot use copy & paste, because the images are not visible on preview and on top of this, I've got message on exceeding 60000 chars.

Mario

#3
Why don't you use {File.MD.subject} which contains the flattened keywords?

trimdupes cannot work because
impala,02_Who
melampus,02_Who


are obviously not duplicates.
Show the hierarchical keywords in the source (the file you use in the BP) with as text. Copy them from the Keywords Panel into your reply. I need to see what the variable returns before you split and replace. No screen shots, plain text please.

mosdubindi1

Thank you for the idea, I'm trying another variable and it is working fine.

The hierarchical keywords source file:
02_Who|animals|chordata|mammal|cetartiodactyla|bovidae|aepyceros|impala, 02_Who|animals|chordata|mammal|cetartiodactyla|bovidae|aepyceros|melampus, 02_Who|animals|chordata|mammal|cetartiodactyla|bovidae|aepyceros|rooibok

Variable:{File.MD.subject|foreach:-HierarchicalSubject={value|splitlist:|,last}#;replace:#=={cr}{lf}}

Result:
-HierarchicalSubject=02_Who
-HierarchicalSubject=animals
-HierarchicalSubject=chordata
-HierarchicalSubject=mammal
-HierarchicalSubject=cetartiodactyla
-HierarchicalSubject=bovidae
-HierarchicalSubject=aepyceros
-HierarchicalSubject=impala
-HierarchicalSubject=melampus
-HierarchicalSubject=rooibok 

The hierarchical keywords output file: 

02_Who, animals, chordata, mammal, cetartiodactyla, bovidae, aepyceros, impala, melampus, rooibok

Mario

QuoteThank you for the idea, I'm trying another variable and it is working fine.
Very good. So the problem is solved?

mosdubindi1