Hi, |
Re: Count for Number of shall
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
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 llandale - Thu Oct 20 13:40:30 EDT 2011
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
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
|
Re: Count for Number of shall 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"
}
|
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"
}
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.
|
Re: Count for Number of shall llandale - Tue Oct 25 15:05:22 EDT 2011
Chris AnnalDOORS Database Administrator / SW Test Engineer Saab Sensis Corporation, East Syracuse, New York chrisa@saabsensis.com |
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"
}
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
count++ combine(outBuf, inBuf, from, sstart) from += (end 0) + 1 combine(outBuf, inBuf, from)
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Count for Number of shall 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
count++ combine(outBuf, inBuf, from, sstart) from += (end 0) + 1 combine(outBuf, inBuf, from)
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Chris Annal DOORS 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
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
count++ combine(outBuf, inBuf, from, sstart) from += (end 0) + 1 combine(outBuf, inBuf, from)
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"
|