Solved

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

  • 18 September 2019
  • 10 replies
  • 0 views

Badge

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

icon

Best answer by itay 18 September 2019, 11:09

View original

10 replies

Userlevel 4

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.

Badge +16

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....

Badge

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.

Userlevel 1
Badge +21

Classes can correctly be in more than one category?

Badge

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

Userlevel 2
Badge +17

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.

Userlevel 4

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?

Userlevel 1
Badge +21

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.

Badge +16

It works, thank you very much for your answer

Glad I could help.

Userlevel 2
Badge +17

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