Compare two attributes with multi-value enumerated data

Hi,

I want to compare two attribute which contain multi-value enumerated data. Both attributes have the sama data type (enumeration).

For example attribute 1 "Name" and attribute 2 "Has been registered". The first attribute contains one or more names and the second one contains some of the first attribute:
Name
DummyA
DummyB
DummyC

Has been registered
DummyC

Now I have to compare these attributes. I'd like to have "DummyA and DummyC is missing" as output.

I already tried to read all enumerations in the data type and checked using a loop for isMember(attrRef, string s) which values are set in the first attribute.
But a loop for all objects take too much time to execute. The enumeration data-type consists of ~30 names.

Does anybody have an hint what I can do?

Thanks for you help!
TCDev. - Mon Apr 26 05:41:21 EDT 2010

Re: Compare two attributes with multi-value enumerated data
Mathias Mamsch - Mon Apr 26 11:00:06 EDT 2010

It should really not take that long to compare two attributes using the ismember function, but that is just a guess. Anyway it is not neccessary if you want to compare two attribute values to check for all possible values.

There are two possibilities to realize a comparison (I am not sure which one is faster but always use Buffers for the tasks):

a) You append a newline character to the second Attributes value (to make sure all lines have a newline at the end). Then you split up the first attributes values line by line (using a rexexp or a loop and search for (value + newline) in the second attribute. You can do the same other way around.

b) You split both strings line by line and sort the values into two skip lists with key and value the lines (string keys!). Then you try to find values of the first in the second and get a "missing" information for each attribute.

If you have problems with writing the code, just post them.

Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant Requirement Engineering and DOORS

Re: Compare two attributes with multi-value enumerated data
llandale - Mon Apr 26 12:51:44 EDT 2010

I think you are wanting to find out if the two enumerated attributes are defined with the same enumerations; and don't really care about object values. If so ... I've scribbled this up, good luck.

AttrDef     ad1 = find(mod, NameAttr1)
AttrDef         ad2 = find(mod, NameAttr2)
 
AttrType        at1 = ad1.type
AttrType        at2 = at2.type
 
AttrBaseType    abt1 = at1.type
AttrBasetype    abt2 = at2.type
 
if    (abt1 != attrEnumeration and abt2 != attrEnumeration) // neither enumerated
elseif(abt1 != attrEnumeration and abt2 == attrEnumeration) // 2 is enumerated, 1 is not
elseif(abt1 == attrEnumeration and abt2 != attrEnumeration) // 1 is enumerated, 2 is not
elseif(abt1 == attrEnumeration and abt2 == attrEnumeration)
{     // Both Enumerated
                // Get list of Enumerations
        Skip    skp1 = createString()
        Skip    skp2 = createString()
        int     i
        string  Enum
        for (i=0; i<at1.size; i++)  put(skp1, at1.strings[i], at1.strings[i])
        for (i=0; i<at2.size; i++)  put(skp2, at2.strings[1], at2.strings[i])
                // Find 1 enums that don't exist in 2
        for Enum in skp1 do
        {  if (!find(skp1, Enum)) print NameAtt1 " has enum, not in " NameAttr2 ":\t'" Enum "'\n"
        }
                // Find 2 enums that don't exist in 1
        for Enum in skp2 do
        {  if (!find(skp1, Enum)) print NameAtt2 " has enum, not in " NameAttr1 ":\t'" Enum "'\n"
        }
        delete(skp1)
        delete(skp2)
}     // end checking when both are Enumerated


If you care also about the order in which the Enums are defined; "A" then "B" is different than "B" then "A", then its trickier, since you have to define two string arrays at size at.size, and compare the two arrays for content, and then use a two-fingered algorithm to see if the values are in the same order; being able to skip values in one array not in the other.

 

 

  • Louie

 

 

Re: Compare two attributes with multi-value enumerated data
TCDev. - Thu Apr 29 04:20:01 EDT 2010

Hi,

thanks for your help. The idea from Mathias worked finally for me. I try to split the value of the first attribute and check the values against the second attribute using isMember().

Here some parts of my code if anybody has to fix the same problem:
 

attr_a = o."Attribute A"
 
[...]
 
// split the values of the first attribute
Regexp line = regexp ".*"
while (!null attr_a && line attr_a) {
    if ( !isMember(o."Attribute B", attr_a[match 0]) ) {
                // do something
                // Contains the current value of the Attribute: attr_a[match 0]
        }
                                
    // match 0 is whole of match
    attr_a = attr_a[end 0 + 2:]
} 
 
// if Attribute A is empty
if(null attr_a) {
    // do something
}

Re: Compare two attributes with multi-value enumerated data
TCDev. - Thu Apr 29 04:26:25 EDT 2010

TCDev. - Thu Apr 29 04:20:01 EDT 2010

Hi,

thanks for your help. The idea from Mathias worked finally for me. I try to split the value of the first attribute and check the values against the second attribute using isMember().

Here some parts of my code if anybody has to fix the same problem:
 

attr_a = o."Attribute A"
 
[...]
 
// split the values of the first attribute
Regexp line = regexp ".*"
while (!null attr_a && line attr_a) {
    if ( !isMember(o."Attribute B", attr_a[match 0]) ) {
                // do something
                // Contains the current value of the Attribute: attr_a[match 0]
        }
                                
    // match 0 is whole of match
    attr_a = attr_a[end 0 + 2:]
} 
 
// if Attribute A is empty
if(null attr_a) {
    // do something
}

...hm - I cannot modify my last post.

Some additional information about performance:
My first try was to get the type of the attribute and do a loop for every element. But since the type consists of about ~30 elements and one module has about 300 objects and I am checking more than 10 modules using one script I got a timeout.

That's why it was very important to split the really selected values of "Attribute A" and check them against "Attribute B". This increases performance since max. 5 values of "Attribute A" are selected each object.

Thanks again for your help!

Christian

Re: Compare two attributes with multi-value enumerated data
Mathias Mamsch - Thu Apr 29 04:40:13 EDT 2010

TCDev. - Thu Apr 29 04:26:25 EDT 2010
...hm - I cannot modify my last post.

Some additional information about performance:
My first try was to get the type of the attribute and do a loop for every element. But since the type consists of about ~30 elements and one module has about 300 objects and I am checking more than 10 modules using one script I got a timeout.

That's why it was very important to split the really selected values of "Attribute A" and check them against "Attribute B". This increases performance since max. 5 values of "Attribute A" are selected each object.

Thanks again for your help!

Christian

If you get "timeouts" in your script you can use 'pragma runLim, 0' to disable or 'pragma runLim, <number>' to increase your timeout. See also the DXL help. Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: Compare two attributes with multi-value enumerated data
llandale - Thu Apr 29 11:04:11 EDT 2010

Mathias Mamsch - Thu Apr 29 04:40:13 EDT 2010
If you get "timeouts" in your script you can use 'pragma runLim, 0' to disable or 'pragma runLim, <number>' to increase your timeout. See also the DXL help. Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Yes. runLim default is 1000000 (one million), probably 'execution cycles', executing a single command.

Scripts with loops, especially recursive, should be tested with an explicit limit, perhaps
pragma runLim, 10000000

When done, set it to zero meaning 'no limit'
pragma runLim, 0