Count for Number of shall

Hi,

I need DXL script for counting the number of Shalls in the particular requirement text.

As iam new to DXL please paste the code also.
GABE_surendra_Reddy - Thu Oct 20 06:40:50 EDT 2011

Re: Count for Number of shall
OurGuest - Thu Oct 20 08:39:55 EDT 2011

Here is a demo that is about as simple as possible to make to give you a starting point.
 

//ShallsInRange
/*Demo to count shall statments between object with ids 30 and 100*/
int i1=30
int i2=1000
 
Object o
Module m=current
int i
int iC=0 
bool bCount=false
string s
 
for o in m do
{ i=o."Absolute Number"
  if(i==i1)bCount=true
  if(bCount)
  { s=o."Object Text" ""
    if(matches("[Ss]hall",s))iC++
  }
  if(i==i2){break}
}
print  iC " shalls"

Re: Count for Number of shall
llandale - Thu Oct 20 13:40:30 EDT 2011

You need to find "shall" as a full word, not counting words like "marshall" and "shallow". Maybe someone in here can fill this in, but a Regular Expression with the following characteristics: Look for string "XshallY" such that X and Y are not alpha characters. I wonder if the contains(Buffer, string, string) funtion would work here since it seems to want to search for words, not just strings.

  • Louie

But maybe X and Y are optional, allowing 'shall' at the start or end of the string. Does "Shall do A" count? Maybe disallow double quotes, so you don't count this sentance: .

Re: Count for Number of shall
dofstead - Thu Oct 20 15:44:39 EDT 2011

llandale - Thu Oct 20 13:40:30 EDT 2011
You need to find "shall" as a full word, not counting words like "marshall" and "shallow". Maybe someone in here can fill this in, but a Regular Expression with the following characteristics: Look for string "XshallY" such that X and Y are not alpha characters. I wonder if the contains(Buffer, string, string) funtion would work here since it seems to want to search for words, not just strings.

  • Louie

But maybe X and Y are optional, allowing 'shall' at the start or end of the string. Does "Shall do A" count? Maybe disallow double quotes, so you don't count this sentance: .

Also, if you want the number of shalls in a single requiremetn text (instead of number of requirements that have a shall), then you need something like:
 

Regexp shall = regexp2 "[Ss]hall"
 
txt = "Shall it rain?  The rain shall fall
mainly in Spain it shall.   it shall not fall
in Georgia.   it shallshall rain."
 
int count = 0
while (!null txt && shall txt) {
    txt = txt[end 0 + 1:]
    count++
}
 
print count "\n" // = 6

 


Incorporating some of Louie's points... maybe something like:

 

 

Regexp shall = regexp2 "[^\"a-zA-z]([Ss]hall)[^\"a-zA-z]"
 
string txt = "What do we mean by \"shall\"?  Shall it rain?  The rain shall fall
mainly in Spain it shall.   it shall not fall
in Georgia.   But, what about the Marshall Islands?"
 
int count = 0
while (!null txt && shall txt) {
    txt = txt[end 1 + 1:] 
    count++
}
 
print count "\n"  // = 4



beg pardon for rhyming skills...



 

Re: Count for Number of shall
ChrisAnnal - Tue Oct 25 09:23:10 EDT 2011

I've used this to perform a quick count of "shalls" in a module...

// Count Shalls
 
/* This script looks for "Shall" or "shall" in the object text and increments the count integer for each one it finds,
   whether the shall is in plain or boldfaced font.
   

   WARNING! If the Object Text attribute contains text with a "shall" AND
   an OLE object, this script will ignore the "shall". 

   Developed in DOORS 7.1 p12
   Chris Annal
*/
 
 
if (confirm("This script will count the number of shalls in " (current Module)."Name" " .\nDo you want to continue?",msgInfo)) 
{
 
    Object o
 
        int from = 0
        int sstart = 0
        int send = 0
        int count = 0
        Buffer inBuf = create
        Buffer outBuf = create
        Regexp re = regexp "([Ss]hall)"
 
        for o in current Module do 
        {
 
                        inBuf = richTextWithOle(o."Object Text")
                        outBuf = ""
                        from = 0
                        sstart = 0
                        send = 0
                        
 
                        // search inBuf for regexp and apply format tags
                        while (search(re, inBuf, from)) 
                        {
                                // start and end functions return regexp position relative to where
                                // search started. Must add starting position to get absolute position
                                sstart = from + start 0
                                send = from + end 0
 
                                        count++
                                        outBuf += inBuf[from:sstart]
                                        from += end 0+1
                                        outBuf += inBuf[from:]
                                        
 
                        }
                
 
 
 
        }
infoBox "Found shall a total of " count " times " "\nin " (current Module)."Name" ""
        delete(inBuf)
        delete(outBuf)
        
}
else {
        infoBox "Script operation cancelled. No data was changed" "\n"
        }

 


Chris Annal
DOORS Database Administrator / SW Test Engineer
Saab Sensis Corporation, East Syracuse, New York
chrisa@saabsensis.com

 

Re: Count for Number of shall
llandale - Tue Oct 25 15:05:22 EDT 2011

ChrisAnnal - Tue Oct 25 09:23:10 EDT 2011

I've used this to perform a quick count of "shalls" in a module...

// Count Shalls
 
/* This script looks for "Shall" or "shall" in the object text and increments the count integer for each one it finds,
   whether the shall is in plain or boldfaced font.
   

   WARNING! If the Object Text attribute contains text with a "shall" AND
   an OLE object, this script will ignore the "shall". 

   Developed in DOORS 7.1 p12
   Chris Annal
*/
 
 
if (confirm("This script will count the number of shalls in " (current Module)."Name" " .\nDo you want to continue?",msgInfo)) 
{
 
    Object o
 
        int from = 0
        int sstart = 0
        int send = 0
        int count = 0
        Buffer inBuf = create
        Buffer outBuf = create
        Regexp re = regexp "([Ss]hall)"
 
        for o in current Module do 
        {
 
                        inBuf = richTextWithOle(o."Object Text")
                        outBuf = ""
                        from = 0
                        sstart = 0
                        send = 0
                        
 
                        // search inBuf for regexp and apply format tags
                        while (search(re, inBuf, from)) 
                        {
                                // start and end functions return regexp position relative to where
                                // search started. Must add starting position to get absolute position
                                sstart = from + start 0
                                send = from + end 0
 
                                        count++
                                        outBuf += inBuf[from:sstart]
                                        from += end 0+1
                                        outBuf += inBuf[from:]
                                        
 
                        }
                
 
 
 
        }
infoBox "Found shall a total of " count " times " "\nin " (current Module)."Name" ""
        delete(inBuf)
        delete(outBuf)
        
}
else {
        infoBox "Script operation cancelled. No data was changed" "\n"
        }

 


Chris Annal
DOORS Database Administrator / SW Test Engineer
Saab Sensis Corporation, East Syracuse, New York
chrisa@saabsensis.com

 

I don't see the benefit of searching through all that rich text markup. Besides wasting a great deal of time and memory, I suspect it won't work if the word "shall" has split markup, such as the "sh" is italicized and the rest not.
inBuf = o."Object Text"
should suffice, letting you scan through raw text which seems to me what you really want. ... or perhaps you want to search for "shall" inside your OLE diagrams. If the OLE is messing you up, then consider
inBuf = richTextNoOle(o."Object Text")

Not sure what you are doing with outBuf but it looks like you are getting the original string without any "shall"s. Didn't check, but perhaps that one line should be this:
outBuf += inBuffrom:sstart-1

And, as with other shall searches, you will count "shallow" and "marshall". Still hoping someone comes up with a clean RegExp to handle that.

  • Louie

Re: Count for Number of shall
ChrisAnnal - Wed Oct 26 08:15:59 EDT 2011

llandale - Tue Oct 25 15:05:22 EDT 2011
I don't see the benefit of searching through all that rich text markup. Besides wasting a great deal of time and memory, I suspect it won't work if the word "shall" has split markup, such as the "sh" is italicized and the rest not.
inBuf = o."Object Text"
should suffice, letting you scan through raw text which seems to me what you really want. ... or perhaps you want to search for "shall" inside your OLE diagrams. If the OLE is messing you up, then consider
inBuf = richTextNoOle(o."Object Text")

Not sure what you are doing with outBuf but it looks like you are getting the original string without any "shall"s. Didn't check, but perhaps that one line should be this:
outBuf += inBuffrom:sstart-1

And, as with other shall searches, you will count "shallow" and "marshall". Still hoping someone comes up with a clean RegExp to handle that.

  • Louie

Thanks for tearing it apart, Louie. It works and I stand by it.

Chris AnnalDOORS
Database Administrator / SW Test Engineer
Saab Sensis Corporation, East Syracuse, New York
chrisa@saabsensis.com

Re: Count for Number of shall
Mathias Mamsch - Wed Nov 02 04:20:14 EDT 2011

ChrisAnnal - Tue Oct 25 09:23:10 EDT 2011

I've used this to perform a quick count of "shalls" in a module...

// Count Shalls
 
/* This script looks for "Shall" or "shall" in the object text and increments the count integer for each one it finds,
   whether the shall is in plain or boldfaced font.
   

   WARNING! If the Object Text attribute contains text with a "shall" AND
   an OLE object, this script will ignore the "shall". 

   Developed in DOORS 7.1 p12
   Chris Annal
*/
 
 
if (confirm("This script will count the number of shalls in " (current Module)."Name" " .\nDo you want to continue?",msgInfo)) 
{
 
    Object o
 
        int from = 0
        int sstart = 0
        int send = 0
        int count = 0
        Buffer inBuf = create
        Buffer outBuf = create
        Regexp re = regexp "([Ss]hall)"
 
        for o in current Module do 
        {
 
                        inBuf = richTextWithOle(o."Object Text")
                        outBuf = ""
                        from = 0
                        sstart = 0
                        send = 0
                        
 
                        // search inBuf for regexp and apply format tags
                        while (search(re, inBuf, from)) 
                        {
                                // start and end functions return regexp position relative to where
                                // search started. Must add starting position to get absolute position
                                sstart = from + start 0
                                send = from + end 0
 
                                        count++
                                        outBuf += inBuf[from:sstart]
                                        from += end 0+1
                                        outBuf += inBuf[from:]
                                        
 
                        }
                
 
 
 
        }
infoBox "Found shall a total of " count " times " "\nin " (current Module)."Name" ""
        delete(inBuf)
        delete(outBuf)
        
}
else {
        infoBox "Script operation cancelled. No data was changed" "\n"
        }

 


Chris Annal
DOORS Database Administrator / SW Test Engineer
Saab Sensis Corporation, East Syracuse, New York
chrisa@saabsensis.com

 

Ouch, bad memory leak and maybe a typo detected:
 

count++
outBuf += inBuf[from:sstart] // leak a temp buffer
from += end 0+1   // are you sure you do not mean (end 0) + 1 ? 
outBuf += inBuf[from:] // leak another temp buffer

 


The [] operator for buffers can either return a string or a buffer. Unfortunately the \+= operator for buffers can also take a string or a buffer. Therefore DOORS will choose the buffer variant and those temporary buffers that are created of the substrings are never freed. Always use combine to do buffer manipulation. It is faster and does not have the built in danger of memory leaks.

 

 

 

count++
combine(outBuf, inBuf, from, sstart)
from += (end 0) + 1 
combine(outBuf, inBuf, from)



Hope that helps, regards, Mathias



 

 

 


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

 

Re: Count for Number of shall
ChrisAnnal - Wed Nov 02 08:29:40 EDT 2011

Mathias Mamsch - Wed Nov 02 04:20:14 EDT 2011

Ouch, bad memory leak and maybe a typo detected:
 

count++
outBuf += inBuf[from:sstart] // leak a temp buffer
from += end 0+1   // are you sure you do not mean (end 0) + 1 ? 
outBuf += inBuf[from:] // leak another temp buffer

 


The [] operator for buffers can either return a string or a buffer. Unfortunately the \+= operator for buffers can also take a string or a buffer. Therefore DOORS will choose the buffer variant and those temporary buffers that are created of the substrings are never freed. Always use combine to do buffer manipulation. It is faster and does not have the built in danger of memory leaks.

 

 

 

count++
combine(outBuf, inBuf, from, sstart)
from += (end 0) + 1 
combine(outBuf, inBuf, from)



Hope that helps, regards, Mathias



 

 

 


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

 

It works faster and cleaner with those lines (47-50 in the above script) replaced with your suggested lines. Thanks, Mathias!!

Chris Annal
DOORS Database Administrator / SW Test Engineer
Saab Sensis Corporation, East Syracuse, New York
chrisa@saabsensis.com

Re: Count for Number of shall
dofstead - Wed Nov 02 15:05:44 EDT 2011

Mathias Mamsch - Wed Nov 02 04:20:14 EDT 2011

Ouch, bad memory leak and maybe a typo detected:
 

count++
outBuf += inBuf[from:sstart] // leak a temp buffer
from += end 0+1   // are you sure you do not mean (end 0) + 1 ? 
outBuf += inBuf[from:] // leak another temp buffer

 


The [] operator for buffers can either return a string or a buffer. Unfortunately the \+= operator for buffers can also take a string or a buffer. Therefore DOORS will choose the buffer variant and those temporary buffers that are created of the substrings are never freed. Always use combine to do buffer manipulation. It is faster and does not have the built in danger of memory leaks.

 

 

 

count++
combine(outBuf, inBuf, from, sstart)
from += (end 0) + 1 
combine(outBuf, inBuf, from)



Hope that helps, regards, Mathias



 

 

 


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

 

If we use apply a string to a buffer with "+=" or "=":
 

Buffer b
 
b = ""
 
...
 
b += "more text"

 


Does this have the same memory leak?