Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Request for firstWord() as Action Operator (Read 7886 times)
steve harf
Full Member
*
Offline



Posts: 76
Cleveland, Ohio
Request for firstWord() as Action Operator
Apr 08th, 2009, 8:25am
 
There is  a lastWord() action operator [paralleling the ^lastWord()^ export code], however firstWord() does not seem to work as an action operator [that would parallel the ^firstWord()^ export code] in version 4.6.1. Can this be added?
Back to top
 
 

- Steve Harf
WWW steveharf   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Request for firstWord() as Action Operator
Reply #1 - Apr 9th, 2009, 10:34am
 
It's easy to add.

How do you plan to use it?  The motivation for lastWord(), of course, is sorting lists of names.
Back to top
 
 
WWW   IP Logged
steve harf
Full Member
*
Offline



Posts: 76
Cleveland, Ohio
Re: Request for firstWord() as Action Operator
Reply #2 - Apr 9th, 2009, 12:06pm
 
My current need is simply to take the name of a person and put the first and last name into separate attributes.

More generally, I would like to quickly create a note and use actions to parse the note name to fill in attributes. For example, I would like to create a note like "John Doe jdoe@domain.com 216-555-1212" and have Tinderbox fill in attributes for email address and phone number.

No doubt there is a way to do this with regex, but the learning curve and debugging seems to be more effort than doing it manually. (Perhaps there is a feature request buried in here to make regex more accessible. Idea: A regex "sandbox" where with use of pop-up menus and other aids code could be tried out and results shown immediately.)
Back to top
 
 

- Steve Harf
WWW steveharf   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Request for firstWord() as Action Operator
Reply #3 - Apr 9th, 2009, 1:31pm
 
Undertstood.

For the moment, if everyone has a first and a last name, you can search for

      $firstName=="" && FullName((.+) +(.+))

with an action

     $firstName=$1

This could, of course, be made more robust.  But notice that it won't replace $firstName if you've already set it; this keeps Tinderbox from having to do the work over, and also lets you hand-type corrections for "Dame Wendy Hall", who is "Wendy" and not "Dame" and other special cases.
Back to top
 
 
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Request for firstWord() as Action Operator
Reply #4 - Apr 9th, 2009, 2:52pm
 
Shouldn't that be $firstName|=$1 with a pipe before the equals, to do as described?
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Request for firstWord() as Action Operator
Reply #5 - Apr 9th, 2009, 4:35pm
 
Since the agent won't gather any notes that already have a first name, we don't need the to use |= in the action
Back to top
 
 
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Request for firstWord() as Action Operator
Reply #6 - Apr 9th, 2009, 6:21pm
 
Indeed, but if $FullName changes, surely $firstName would too?  If $FullName was "John Doe" and is changed to "Dwayne Doe", then $firstName would change from "John" to "Dwayne".

That said, I think that's actually what you'd want to happen! With a |= assignment $firstName would remain as "John". [Later: yes, tested and this is true]
Back to top
 
« Last Edit: Apr 16th, 2009, 3:31am by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
steve harf
Full Member
*
Offline



Posts: 76
Cleveland, Ohio
Re: Request for firstWord() as Action Operator
Reply #7 - Apr 15th, 2009, 9:46pm
 
Is there a way to use regex and extract out the first word in an OnAdd expression?
Back to top
 
 

- Steve Harf
WWW steveharf   IP Logged
Johnnie Wilcox - mistersquid
Full Member
*
Offline



Posts: 84
San Francisco, CA
Re: Request for firstWord() as Action Operator
Reply #8 - Apr 15th, 2009, 10:52pm
 
If you want the first word of a note's name, make your query something like

Code:
(Name(^([^\s]+)))
 



This assumes the first "word" stops when white space begins. If you want your word to stop at punctuation also, use this

Code:
(Name(^([^\s\W]+)))
 



The first query can be read as: find notes whose $Name starts with at least one character that is not a space. The second query: find notes whose $Name starts with at least one character that is nit a space or a punctuation mark. The syntax also asks the agent to remember all the characters up until (in the first version) a space, or (in the second version) a space or a punxtuation mark.

In the $OnAdd section, you can set an attribute, say $a, to the remembered word with

$a=$1

which will place the first word of the captured notes in $a. In my limited testing , this also works with note text. For example,

Code:
(Text(^([^\s]+)))
 



hth
Back to top
 
 
  IP Logged
Pages: 1
Send Topic Print