Categories->Keywords - Starting From Specific Hierarchical Level

Started by Darius1968, October 23, 2021, 10:52:58 AM

Previous topic - Next topic

Darius1968

So, I now have a file, for which, I've entered a few keywords and assigned just one IMatch Category: 
I now wish, via a metadata template, to simply add in that category to the list of keywords, that I already have. 
The category is structured like this:  Private Categories|Interests|Paintings|Jewelry|Bracelets.  What I want copied over, however, is:  Paintings|Jewelry|Bracelets.  So far, for "Fill the tag from this data:", I've tried something like this:  {File.Categories|filter:(^Paintings)}, without success.  So, how do I get the job done? 

Mario

Your question is unclear.
Do you need only this one category? Then hard-code, just add the category name.
If you work with multiple categories, look into the level and filter functions for categories: Go to Variables and search for File.Categories|level
If all your categories have the same hierarchy depth, you can use a level. Else use a filter. Note: You cannot combine filter and level.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Darius1968

Well, let me try to put my question in different words, so that, hopefully, you understand better: 

Assume an IMatch Category Tree Structure, Like this: 
--Private Categories
----Interests
------Paintings
--------Jewelry
----------Bracelets
Now, let's say, that I've ticked, "Bracelets", and I want this to be mapped into the XMP keywords.  However, I want the structure, in the keywords, to look like this:
--Paintings
----Jewelry
------Bracelets.   

So, how would I make use of a Metadata Template, to achieve what I've outlined, above.  I know the concept (what variables are involved), but I need to know what the correct syntax - {File.Categories|filter:(^Paintings)} - is.  "{File.Categories|filter:(^Paintings)}" is not doing anything. 

Mario

Did you try level:3?
Use the VarToy app to quickly test variables.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Darius1968

Well, "level:2" enumerates the "Paintings" node, but not the following two nodes - "Jewelry", "Bracelets".  Is this possible?  I know, it can readily be done manually, but what I need, is the possibility, to enumerate nodes, from level 2 to the leaf node, where the number of nodes, between level 2 and the leaf node could vary. 

Mario

Maybe use a replace to replace the text with an empty string of the categories you want to exclude? The path you want to remove.
Not everything is possible, not even in IMatch. You can extract individual levels, but not snip the category hierarchy into individual segments.

In your case I recommend you use keywords from a start and the thesaurus. Trying to somehow make group-level keywords and exclusion levels work with categories is not really the best way to deal with this.
Keywords have the features you want, categories don't. Categories are not designed to be used that way.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Tveloso

I recently did something very similar to this with a Category variable, and thought that using the substr function would solve this for Darius1968.

I actually started to write a post last night to suggest it, but when I tested it by changing my variable to mirror what Darius1968 needs, I found that there's an unexpected result that I think could possibly be a bug.

Using the example Category that Darius gave:

        Private Categories|Interests|Paintings|Jewelry|Bracelets

...I believe this variable:

        {File.Categories|filter:^Private Categories|Interests|;substr:29}

...will return this:

        Paintings|Jewelry|Bracelets

...which I believe is what Darius needs...(and if the depth varies, it will still return the entire path needed).

However, if a given file should belong to more than one category in that branch...for example, if the file belongs to both of these categories:

        Private Categories|Interests|Paintings|Jewelry|Bracelets
        Private Categories|Interests|Paintings|Jewelry|Rings

...then the variable returns this:

        Paintings|Jewelry|Bracelets;Private Categories|Interests|Paintings|Jewelry|Rings

I would expect that it should be returning this instead:

        Paintings|Jewelry|Bracelets;Paintings|Jewelry|Rings

It seems that the substr function is being applied only once, after the entire string has been built, when I would expect it to be applied to each category (i.e. inside the loop where the variable is inspecting each category for inclusion in the output string).

I now that changing the behavior of variables (which is a long-standing, and core feature of IMatch) could break things for other users, but I think in this case, the current behavior could actually be regarded as a bug.
--Tony

Mario

Category variables are very special. See also https://www.photools.com/community/index.php?topic=11930.0
When you request categories via a variable, IMatch builds a semicolon-separated list of all categories. That is the output of that function. Same for all other variables working with repeatable metadata tags.
Your substr is then applied to the result, like with any other variable. IMatch does not evaluate the variable for each category found.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Tveloso

Quote from: Mario on October 24, 2021, 05:09:31 PM
Your substr is then applied to the result, like with any other variable. IMatch does not evaluate the variable for each category found.
It still strikes me as something that IMatch should do though...(that for variables that return repeatable tags, the formatting functions should be applied to each item - just as the Level function is).

But I understand Mario, if this is something that you will not want to change (especially since it could impact many users, who rely on the current behavior).

BTW, in the other topic you referenced, the variable is working perfectly for me...(but I have learned from the discussion here, that it's only because, in my case, a given file is assigned to only one of the categories, in the category branch that's being filtered for).
--Tony

Mario

Variables don't have a "for each in list" functionality. There are complexity limits, even for IMatch. Variables are complex enough internally, as it is. 
And there is not nearly enough demand for enhancements to move me to consider a rewrite or massive internal changes. Variables work great for 98% of all use-cases, even complex ones. And for all other highly specific features, a small app or script does the trick nicely.

-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Tveloso

Completely understandable.  Thank you Mario.

Quote from: Mario on October 24, 2021, 08:38:06 PM
Variables work great for 98% of all use-cases, even complex ones. And for all other highly specific features, a small app or script does the trick nicely.
Agreed.  Thank you so much for such an incredible piece of software!
--Tony

Mario

I have improved the way filter works in combination with level. The filter is now applied to each category individually, before combining the category levels into the semicolon-separated list.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook