Skip to main content
Solved

Compare two columns (Category and Class) and detect if the Class entered is in the right Category


Forum|alt.badge.img

Hello,

I have two columns Category and Class already filled. I would like to compare and see if the class entered is in the right category.

Example :

Category = 10 / Class = 20, 40, 60

Category = 11 / Class = 20, 21, 22, 23, 24

Category = 12 / Class = 23, 25, 27, 29, 31

 

Category

 

Class

 

RESULT

 

10

 

20

 

True

 

10

 

22

 

False

 

11

 

23

 

True

 

12

 

23

 

True

 

10

 

29

 

False

 

12

 

31

 

True

 

10

 

60

 

True

 

 

Thank you very much in advance for your help.

Best Regards

Best answer by itay

Hi,

There are a number of possibilities, just had @david_r mentions.

I would use an AttributeCreator and conditional values:

Probably can be fancied up by some regex....

View original
Did this help you find an answer to your question?

10 replies

david_r
Celebrity
  • September 18, 2019

One possible solution would be to use an AttributeValueMapper to calculate the correct class based on the category value, then a Tester to compare the correct class with the existing class value.


itay
Supporter
Forum|alt.badge.img+17
  • Supporter
  • Best Answer
  • September 18, 2019

Hi,

There are a number of possibilities, just had @david_r mentions.

I would use an AttributeCreator and conditional values:

Probably can be fancied up by some regex....


Forum|alt.badge.img
  • Author
  • September 18, 2019
david_r wrote:

One possible solution would be to use an AttributeValueMapper to calculate the correct class based on the category value, then a Tester to compare the correct class with the existing class value.

Thank you very much for your answer.

Could you be more specific please?

The problem is that each category has multiple class value and sometimes one class value could be in different categories.


ebygomm
Influencer
Forum|alt.badge.img+39
  • Influencer
  • September 18, 2019

Classes can correctly be in more than one category?


Forum|alt.badge.img
  • Author
  • September 18, 2019
itay wrote:

Hi,

There are a number of possibilities, just had @david_r mentions.

I would use an AttributeCreator and conditional values:

Probably can be fancied up by some regex....

It works, thank you very much for your answer


takashi
Evangelist
  • September 18, 2019

I would create an external table mapping each Category and comma-separated possible classes like this,

CategoryPossibleClasses1020,40,601120,21,22,23,241223,25,27,29,31

merge an appropriate possible classes to each record using a DatabaseJointer or a FeatureMerger, and then determine if the class is in the possible classes with conditional value setting.


david_r
Celebrity
  • September 18, 2019
mi wrote:

Thank you very much for your answer.

Could you be more specific please?

The problem is that each category has multiple class value and sometimes one class value could be in different categories.

Depends on what you consider to be the correct Category for Class = 20? Are both values 10 and 11 correct?


ebygomm
Influencer
Forum|alt.badge.img+39
  • Influencer
  • September 18, 2019
takashi wrote:

I would create an external table mapping each Category and comma-separated possible classes like this,

CategoryPossibleClasses1020,40,601120,21,22,23,241223,25,27,29,31

merge an appropriate possible classes to each record using a DatabaseJointer or a FeatureMerger, and then determine if the class is in the possible classes with conditional value setting.

This the approach i would take, for ease of maintenance. Although i'm getting an odd result with the In Test

inissue.fmwt

You could also use an AttributeValueMapper to add the possible class values, then do the test. Might be a better option than a FeatureMerger if it the values aren't changing.


itay
Supporter
Forum|alt.badge.img+17
  • Supporter
  • September 18, 2019
mi wrote:

It works, thank you very much for your answer

Glad I could help.


takashi
Evangelist
  • September 19, 2019
ebygomm wrote:

This the approach i would take, for ease of maintenance. Although i'm getting an odd result with the In Test

inissue.fmwt

You could also use an AttributeValueMapper to add the possible class values, then do the test. Might be a better option than a FeatureMerger if it the values aren't changing.

Hi @egomm, I was able to reproduce the odd behavior. I suspect that there is a potential bug regarding the IN operator, Comparison Mode, or somewhere. I reported the issue to Safe support already, and they filed a problem report.

In the interim, you can get correct result if you set a string mode (Case Sensitive or Case Insensitive) to the Comparison Mode parameter in the Tester.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings