mwg-kw:HierarchicalKeywords1 and HierarchicalKeywords1Children - real examples?

Started by colink, May 26, 2018, 11:07:45 AM

Previous topic - Next topic

colink

HierarchicalKeywords and Child keywords is referenced here
https://metacpan.org/pod/distribution/Image-ExifTool/lib/Image/ExifTool/TagNames.pod

The MWG working group document gives some explanation of Hierarchical keywords - see below (but I cannot find much online)http://www.metadataworkinggroup.org/pdf/mwg_guidance.pdf

 Places          I assume this is XMP-mwg-kw:HierarchicalKeywords1
 States         I assume this is XMP-mwg-kw:HierarchicalKeywords2
    - Georgia     I assume this is XMP-mwg-kw:HierarchicalKeywords3
    - Wyoming   I assume this is XMP-mwg-kw:HierarchicalKeywords3
 People
   - Georgia
   - Cat
 Animals
 Mammals
   - Cat
   - Dog

But how would I write XMP-mwg-kw:HierarchicalKeywords3 - Georgia,Wyoming?

But then how would I write cities for both of those states? Georgia:Agusta;Savannah, Wyoming:Cheyenne;Laramie

Is Child keywords part of the answer?
XMP-mwg-kw:HierarchicalKeywords1Children
XMP-mwg-kw:HierarchicalKeywords2Children
XMP-mwg-kw:HierarchicalKeywords3Children

Perhaps someone could suggest a structure for these states and cities or give some other example.

Thanks in advance ColinK

StarGeek

First, direct link to MWG Keywords in the docs rather than cpan.
Direct link to the correct page in the pdf.

I'll also mention that this could be considered a pretty uncommon tag structure.  I collect a lot of images from the web and haven't see it out in the wild and can't remember any software I've tested that use it.

Structures are complicated and IMO, not easy to keep synchronized properly unless you keep them together using the -Struct option, which requires writing them in a completely different way (see Structured Information).  Exiftool gives you the ability to write them through the flattened keywords (HierarchicalKeywords1, HierarchicalKeywords2, etc) but you may not be able to keep the keywords together in the proper hierarchy if you write them like that.

To use the example you list (taken from the pdf), you would write the whole thing like this.
exiftool -struct -KeywordInfo="{Hierarchy=[{Children=[{Children=[{Keyword=Georgia},{Keyword=Wyoming}],Keyword=States}],Keyword=Places},{Children=[{Keyword=Cat},{Keyword=Georgia}],Keyword=People},{Children=[{Children=[{Keyword=Cat},{Keyword=Dog}],Keyword=Mammals}],Keyword=Animals}]}" FileOrDir

At least, I think I have that right.  There's a reason I don't mess with structures.  I'm pretty much learning this as I write this post.  And will probably promptly forget it all.

But the output using the flattened tags doesn't keep the associations:
C:\>exiftool -g1 -a -s -XMP-mwg-kw:all y:\!temp\Test4.jpg
---- XMP-mwg-kw ----
HierarchicalKeywords3           : Georgia, Wyoming, Cat, Dog
HierarchicalKeywords2           : States, Cat, Georgia, Mammals
HierarchicalKeywords1           : Places, People, Animals


So if you want to keep the proper associations, you'll have to parse the structured output.  Or add the -json or XML -x option to make the output easier to parse for other apps.

The whole thing is messy and overly complex, IMO.  There's a reason I find HierarchicalSubject much easier to use, other than the fact that it's more common in DAM software.  The same hierarchy in HierarchicalSubject would be like this:
exiftool -HierarchicalSubject="Places|States|Georgia" -HierarchicalSubject="Places|States|Wyoming" -HierarchicalSubject="People|Georgia" -HierarchicalSubject="People|Cat" -HierarchicalSubject="Animals|Mammals|Cat" -HierarchicalSubject="Animals|Mammals|Dog"
And the listing would be:
C:\>exiftool -g1 -a -s -hs y:\!temp\Test4.jpg
---- XMP-lr ----
HierarchicalSubject             : Places|States|Georgia, Places|States|Wyoming, People|Georgia, People|Cat, Animals|Mammals|Cat, Animals|Mammals|Dog
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

colink

@StarGeek

Thanks again for giving a detailed reply and thanks for giving direct links - I did not realise I was viewing a bookmark on metacpan.org

I see the complexity of HierarchicalKeywords and the difficulty in relationships.

I hope you do not mind me asking if you could expand on your HierarchicalSubject example focusing on 1 city
How could you write the following:

State = Georgia; City = Agusta; Population =  197,000;  ZipCodes = 30901, 30904, 30906, 30907, 30909, 30912, 30815



StarGeek

I would try to figure out the hierarchy ahead of time first, similar to the way the MWG example is.  In this case, I would probably go:
State
City
Population
Zip Codes


One of my rules is to make sure that each child node is meaningful by itself in some way, even if it means duplicating some data from the parent node.  This comes from the fact that some of my software isn't able to read XMP metadata (I'm looking at you, irfanview, it's been requested for over 10 years) and that I duplicate the final node to XMP:Subject and IPTC:Keywords.  In this case, the final child nodes are just numbers, which aren't meaningful without context.

In your example data, my hierarchy would be similar to this:
Georgia
Atlanta
Atlanta Population 197,000
Atlanta Zip Code 30901
Atlanta Zip Code 30904
Atlanta Zip Code 30906
Atlanta Zip Code 30907
Atlanta Zip Code 30909
Atlanta Zip Code 30912
Atlanta Zip Code 30815


After that, it's just a case of collapsing it down into a single string for each final child node, separating each node with a pipe | character.  If you desire the parent nodes to be added separately as well, you can do that also.
Georgia|Atlanta|Atlanta Population 197,000
Georgia|Atlanta|Atlanta Zip Code 30901
Georgia|Atlanta|Atlanta Zip Code 30904
Georgia|Atlanta|Atlanta Zip Code 30906
Georgia|Atlanta|Atlanta Zip Code 30907
Georgia|Atlanta|Atlanta Zip Code 30909
Georgia|Atlanta|Atlanta Zip Code 30912
Georgia|Atlanta|Atlanta Zip Code 30815


You would then just add each of those items to HierarchicalSubject like normal list items (see FAQ #17).

Of course, if you're only reading HierarchicalSubject and don't duplicate to other tags, you can condense the HierarchicalSubject a bit.  This is how I do things and it's grown out of what software I have and find easy to use.  It's certainly not hard rules and you should try and figure out what works for you. 

You can always change how you do things later if you like.  That leads to my number one rule, Get the data into the file.  Once it's in there, you can always move it elsewhere with exiftool.  It may take a while to run the command or you may need help crafting the command, but it can be done.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

colink

Thanks @StarGeek

I would not have thought of repeating the parent data in the child data to maintain the relationship

ColinK