Author Topic: category formula : find exactly 2 persons  (Read 1741 times)

peterverm

  • Jr. Member
  • *
  • Posts: 68
category formula : find exactly 2 persons
« on: July 23, 2018, 08:47:24 PM »
At the highest level, I have "@All|who ?", "@All|what ?" and "@All|where ?" categories.  All are detailed with child categories.

If i want to find all pictures with exact 1 given person on it, and no other persons, i use "@CatDistinct[@All\|who \?\|we\|Peter Vermeyen;@All\|who \?\|we]".  It works fine.  The "@All|what ?" and "@All|where ?" categories are ignored as it should.

But I want to find all pictures with exact 2 persons on it, Ann and Peter, and no other persons.  I tried "@CatDistinct[@All\|who \?|we\|(Ann Verhetsel|Peter Vermeyen);@All\|who \?\|we]".  It gives error.

I thought it would work because it is a regular expression.  But no.

Can someone help me ?

Thanks,

Peter Vermeyen

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 28570
Re: category formula : find exactly 2 persons
« Reply #1 on: July 23, 2018, 09:12:07 PM »
Use the AND operator. It allows you to do things like "Cat A" AND "Cat B". There is also OR and NOT. And ( and )

See https://www.photools.com/help/imatch/#cat_formulas.htm?dl=h-4

peterverm

  • Jr. Member
  • *
  • Posts: 68
Re: category formula : find exactly 2 persons
« Reply #2 on: July 23, 2018, 09:24:01 PM »
I tried AND (before i wrote the post !) : "@CatDistinct[@All\|wie \?|wij\|Ann Verhetsel;@All\|wie \?\|wij]" AND "@CatDistinct[@All\|wie \?|wij\|Peter Vermeyen;@All\|wie \?\|wij]"

It does not work, you cannot have a picture with 1 distinct person A and 1 distinct person B, because there would be 2 distinct persons.

OR works of course, but then i get all the pictures with only A plus all the pictures with only B.

What i need is something like 'contains A' AND 'contains B' AND 'total number of persons = 2'.

Regards,

Peter

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 28570
Re: category formula : find exactly 2 persons
« Reply #3 on: July 23, 2018, 09:48:44 PM »
"Mary" AND "Peter" returns all files which have both categories applied. There may be other persons also shown in these images. Since IMatch has no information about how many persons or other objects are contained in your image, it is impossible to achieve what you want.

You need to setup a category hierarchy which counts the number of persons per image. Do you use face annotations? Then maybe a data-driven category based on the corresponding collection will do that automatically...you can then include these categories in your formula to limit something like "Mary" and "Peter" AND "PersonCount.2".

If you work with @Keywords categories, you can setup a data-driven category which is based on the keyword count, with a regexp to consider only persons. This could also produce a category which counts the number of persons per image. I did not try this, just an idea.

Another idea would be something like a new category formula which counts how many categories inside a specific hierarchy level are assigned to a file...but that would require a feature request and probably not easy to implement and critical performance-wise.
« Last Edit: July 23, 2018, 09:51:28 PM by Mario »

mastodon

  • Sr. Member
  • **
  • Posts: 353
Re: category formula : find exactly 2 persons
« Reply #4 on: July 23, 2018, 10:56:55 PM »
That is challenge for me, too. I think I will make categories like alone, pair, threesome etc. and group. But I will set only that pictures in that categories that are really useful for that purpose and not just "mention" these persons.

PaulS

  • Full Member
  • **
  • Posts: 142
Re: category formula : find exactly 2 persons
« Reply #5 on: July 24, 2018, 02:31:57 AM »
Another idea would be something like a new category formula which counts how many categories inside a specific hierarchy level are assigned to a file...but that would require a feature request and probably not easy to implement and critical performance-wise.

Actually this is already implemented and works quite well for me.  Especially with the enhancement for IMatch 2018 (Thanks Mario!) that allows Alias categories to be excluded.  In my case, the formula is:

    {File.Categories.DirectNoAlias|filter:^Subject\|People;count:true}

If I guess correctly, in Peter's case it might be:

    {File.Categories.DirectNoAlias|filter:^who \?;count:true}

Use the VarToy app to confirm proper variable definition. 

I've attached a screen shot of my setup and the resulting category.  I used the Replace Mask to add a leading 0 to force sort order of the categories.  Make sure that Automatic Update is Off or you will have a performance hit as Mario said, and then manually Refresh Data from time to time to keep the category updated.

You can then create a Formula category with the desired number category AND the desired people categories.

Alternatively, you can just select the desired number category and use the Filter Panel to select the desired people using AND.  (By the way, I just found that I have only 18 pictures of just my wife and me out of 28,413 ::))

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 28570
Re: category formula : find exactly 2 persons
« Reply #6 on: July 24, 2018, 08:27:57 AM »
This is a good way to do it. Thank you for sharing.

For details, search for DirectNoAlias in this help topic: https://www.photools.com/help/imatch/#var_basics.htm

It seems a bit complicated, but tasks like "Crete a category with files showing only these two persons but no other" are complicated by nature. Unless you maintain a separate "People Count" category hierarchy or a "Single/Pair/Three/Group/Larger Group" hierarchy some users maintain. In that case you can directly use that in your category formula.

axel.hennig

  • Full Member
  • **
  • Posts: 180
Re: category formula : find exactly 2 persons
« Reply #7 on: July 24, 2018, 01:31:04 PM »
There was a very similar post about this problem (and I think the solution is very good):

https://www.photools.com/community/index.php?topic=7403.msg51484

@Peter Vermeyen: Maybe this helps.

peterverm

  • Jr. Member
  • *
  • Posts: 68
Re: category formula : find exactly 2 persons
« Reply #8 on: July 24, 2018, 06:49:23 PM »
OK thank you all, your feedback will get me going.  Peter

peterverm

  • Jr. Member
  • *
  • Posts: 68
Re: category formula : find exactly 2 persons
« Reply #9 on: July 25, 2018, 07:58:35 PM »
Dears,

your solution works fine, thanks, only, there is something strange.

{File.Categories|filter:^wie \?;count:true} works fine.

{File.Categories.Direct|filter:^wie \?;count:true} works fine.

{File.Categories.DirectNoAlias|filter:^wie \?;count:true} does not work.  All files end up in "Other".  I do not use Alias categories.  So this is strange.  Can you explain it ?

Regards,

Peter

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 28570
Re: category formula : find exactly 2 persons
« Reply #10 on: July 25, 2018, 08:37:35 PM »
Export your categories and attach a ZIP.

peterverm

  • Jr. Member
  • *
  • Posts: 68
Re: category formula : find exactly 2 persons
« Reply #11 on: July 25, 2018, 09:02:29 PM »
please.

Peter

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 28570
Re: category formula : find exactly 2 persons
« Reply #12 on: July 26, 2018, 09:30:27 AM »
I've imported your categories and then assigned images to child categories of "wie ?"

I assigned one set of files to one category, and a second set to another category.
A 3rd set was assigned to two categories below "wie ?"

I then used your variables in the VarToy app to see what they return, like this:

{File.Categories|filter:^wie \?;count:true}
{File.Categories.Direct|filter:^wie \?;count:true}
{File.Categories.DirectNoAlias|filter:^wie \?;count:true}


as expected, all variables returned the same result for all files (1 or 2).
Then I created an Alias category named "ALIAS familie Ann" under "wie ?", aliasing "familie Ann".
Now the results of  DirectNoAlias and Direct differ. Direct shows a count of 2 for the files in the Alias category, DirectNoAlias shows 1.  Correct.

I've tried both variables in a data-driven category and the results are correct.
The only way to produce a result which has only "Other" is an invalid variable, as far as I can tel. Did you check for syntax errors?

peterverm

  • Jr. Member
  • *
  • Posts: 68
Re: category formula : find exactly 2 persons
« Reply #13 on: July 26, 2018, 05:39:06 PM »
Mario,

thanks for your efforts. 

I tried the 3 variables with the VarToy.

For all pictures that i tried,
- {File.Categories|filter:^wie \?;count:true} and {File.Categories.Direct|filter:^wie \?;count:true} give a result, but
- {File.Categories.DirectNoAlias|filter:^wie \?;count:true} gives never a result.

See print screen in attachment.

Regards,

Peter

sinus

  • Global Moderator
  • *****
  • Posts: 4345
  • IMatch-User since 2001 (IMatch 3.6)
Re: category formula : find exactly 2 persons
« Reply #14 on: July 26, 2018, 06:36:25 PM »
Peter,
Do you have really any alias-categories?
Best wishes from Switzerland! :-)
Markus

peterverm

  • Jr. Member
  • *
  • Posts: 68
Re: category formula : find exactly 2 persons
« Reply #15 on: July 26, 2018, 07:03:33 PM »
Thanks for the wishes.  Enjoy Switserland.

No i do not have an Alias category. 

I just created one as a test, i see no difference in the behavior : {File.Categories.DirectNoAlias|filter:^wie \?;count:true} returns "other".

Regards,

Peter

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 28570
Re: category formula : find exactly 2 persons
« Reply #16 on: July 26, 2018, 08:16:28 PM »
Did you copy/paste my variable setup from above?
It produces correct results for all my databases.

What happens if you change the expression for NoAlias, e.g. to include the entire DB?

sinus

  • Global Moderator
  • *****
  • Posts: 4345
  • IMatch-User since 2001 (IMatch 3.6)
Re: category formula : find exactly 2 persons
« Reply #17 on: July 26, 2018, 08:58:10 PM »
And a remark:

This variable (from the help):

{File.Categories.DirectNoAlias|filter:^People;count:true}

gives me the number 1, what is wrong.

This variable:
{File.Categories.DirectNoAlias|filter:^People|;count:true}

gives me the number 5, what is correct.

The difference is the symbol | after the Category.


But I am not sure with all this stuff here.  :-[
« Last Edit: July 26, 2018, 09:00:14 PM by sinus »
Best wishes from Switzerland! :-)
Markus

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 28570
Re: category formula : find exactly 2 persons
« Reply #18 on: July 26, 2018, 09:10:50 PM »
The | has a special meaning in regular expressions. If you want to use a literal | you need to escape it with \ => \|
If the result is wrong is impossible to know unless we know your category structure.

peterverm

  • Jr. Member
  • *
  • Posts: 68
Re: category formula : find exactly 2 persons
« Reply #19 on: July 26, 2018, 09:21:20 PM »
@Mario : not sure what you mean, but this is what i did : i copy/paste the variables from your reply, i removed filter, and next i removed count as well.

1. {File.Categories}
2. {File.Categories.Direct}
3. {File.Categories.DirectNoAlias}
xxx
4. {File.Categories|count:true}
5. {File.Categories.Direct|count:true}
6. {File.Categories.DirectNoAlias|count:true}
xxx

Same result as before : cases 3. and 6. give no result.  See print screen.  So it has nothing to do with filter or count.

@sinus : the symbol | after the Category makes no difference, even if i escape it \|.

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 28570
Re: category formula : find exactly 2 persons
« Reply #20 on: July 26, 2018, 09:27:37 PM »
This is what I get (IMatch 2018.7.4):


PaulS

  • Full Member
  • **
  • Posts: 142
Re: category formula : find exactly 2 persons
« Reply #21 on: July 27, 2018, 02:12:35 AM »
Hello Peter,

Just a wild guess. I changed the variable to something which is undefined as shown below and get the result you describe of all files in Other.

    File.Categories.DirectYesAlias

By any chance are you still using IMatch 2017?  File.Categories.DirectNoAlias was added in IMatch 2018, it is undefined in IMatch 2017 and I expect it would give the result you describe.

Paul









Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 28570
Re: category formula : find exactly 2 persons
« Reply #22 on: July 27, 2018, 09:09:54 AM »
Good point!

I never saw a log file for this issue so I don't know either. As you said, the ...Alias formula is available in IMatch 2018 only.

peterverm

  • Jr. Member
  • *
  • Posts: 68
Re: category formula : find exactly 2 persons
« Reply #23 on: July 27, 2018, 06:15:04 PM »
OK, victory !  I was 2017.14.2, i upgraded to 2018.7.4, and File.Categories.DirectNoAlias works fine.

Thanks,

Peter

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 28570
Re: category formula : find exactly 2 persons
« Reply #24 on: July 27, 2018, 08:01:07 PM »
Since you don't use Alias categories, the File.Categories.Direct would do the trick.
Thanks for upgrading!  :) You are actively supporting IMatch and I hope you enjoy using it.