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
Note rule not working if preceeded by other rule (Read 1194 times)
B.Moreira
Full Member
*
Offline



Posts: 71

Note rule not working if preceeded by other rule
Jan 5th, 2016, 6:11am
 
Hi everyone. I am trying to figure this out but I can't find the "bug" ...

Take for example a note with this $Name:

lorem ipsum {Campos, V. (2012)} {date:1990>2006}

I am trying to populate some of this note's attribute's with info from the $Name.

Using this as $Rule:

if $Name.contains("\{date:(.+)>(.+)\}"){$quoteCitedStartTime=$1;$quoteCitedEndTime=
$2};

and I can populate the quoteCitedStartTime and quoteCitedEndTime attributes;

using this as $Rule

if $Name.contains("\{(\D+) \((\d+)\)\}"){$quoteAuthor=$1;$quoteYear=$2};

and I can populate quoteAuthor and quoteYear;

BUT

if I use both in the $Rule:

if $Name.contains("\{(\D+) \((\d+)\)\}"){$quoteAuthor=$1;$quoteYear=$2};
if $Name.contains("\{date:(.+)>(.+)\}"){$quoteCitedStartTime=$1;$quoteCitedEndTime=
$2};

quoteCitedStartTime gets assigned "never" and quoteCitedEndTime gets assigned an odd value.

Thanks for the help!


Back to top
 
« Last Edit: Jan 06th, 2016, 6:20am by B.Moreira »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Note rule not working if preceeded by other rule
Reply #1 - Jan 5th, 2016, 6:59am
 
OK, I'll start by assuming - based on data offered that the user attributes are:
$quoteCitedStartTime / Date-type
$quoteCitedEndTime / Date-type
$quoteAuthor / String type
$quoteYear / String type

Your first rule - as quoted doesn't work as it doesn't match the example title given. If I adjust as follows (red=edit, layout for clarity only):

if $Name.contains("\{time:(.+)-(.+)\}"){
$quoteCitedStartTime=$1;
$quoteCitedEndTime=$2;
};


...then $quoteCitedStartTime and $quoteCitedEndTime both get the correct start or stop year from the $Name but with an unexpected day/month and a time of 00:00. Whereas (on my UK system) the test $quoteCitedStartTime is "15/06/1990, 00:00" (15 June 1990), were you to use a String-type attribute here the answer would be "1990".

Or use an rule like:

$quoteCitedStartTime=date($1,1,1,12,0);

to give a consistent known day/month to your year figure, e.g. "01/01/1990, 12:00".

Quote:
if $Name.contains("\{date:(.+)>(.+)\}"){$quoteCitedStartTime=$1;$quoteCitedEndTime=

$2};
if $Name.contains("\{date:(.+)>(.+)\}"){$quoteCitedStartTime=$1;$quoteCitedEndTime=

$2}

quoteCitedStartTime gets assigned "never" and quoteCitedEndTime gets assigned an odd value.


Looks like simple operator error, both rules are the same. If we vix the previous regex error, I think you mean to use (again, layout for clarity only):

if $Name.contains("\{time:(.+)-(.+)\}"){
$quoteCitedStartTime=$1;
$quoteCitedEndTime=$2;
};
if $Name.contains("\{(.+)\(\d{4}\)\}"){
$quoteAuthor=$1;
$quoteYear=$2;
};


Indeed, the latter if() rule re-uses the $1 & $2 for the first if query: author is "1990" and year os "2006". I think this is unintentional , simply because usage like this was never envisaged back when that functionality was added. The range and scope of Action code function was more limited back then!

That's easily worked around though. Try this:

if $Name.contains("\{(.+)\(\d{4}\)\} \{time:(.+)-(.+)\}"){
$quoteAuthor=$1;
$quoteYear=$2;
$quoteCitedStartTime=$3;
$quoteCitedEndTime=$4;
};


I now get and another of "Campos, V." and year of "2012".
Back to top
 
« Last Edit: Jan 5th, 2016, 7:06am by Mark Anderson »  

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

User - not staff!

Posts: 5689
Southsea, UK
Re: Note rule not working if preceeded by other rule
Reply #2 - Jan 5th, 2016, 7:16am
 
Follow up, I've reported this issue on (elsewhere) and in doing so I tested a logical further case, where the second if() within a single rule queries a different string. For instance, based on the above:

if $Name.contains("\{timeSad.+)-(.+)\}"){
 $quoteCitedStartTime=$1;
 $quoteCitedEndTime=$2;
};
if $MyString.contains("\{(.+)\(\d{4}\)\}"){
 $quoteAuthor=$1;
 $quoteYear=$2;
};


Note the second if() is now based on a $MyString (to which I added some relevant data). I can confirm that the same problem occurs in the that second if applies $1 and $2 from the first query so my workaround above could not be used.
Back to top
 
 

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



Posts: 71

Re: Note rule not working if preceeded by other rule
Reply #3 - Jan 6th, 2016, 6:22am
 
First of all, thank you for the deep explanation and have a nice 2016!
Sorry for the mistakes in the original post. I wrote it on the notepad before pasting it to the forum, but then made an error pasting the information.
I have modified my original post and now it makes sense.
Will go through your explanation and try the suggestions, thanks!
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Note rule not working if preceeded by other rule
Reply #4 - Jan 6th, 2016, 7:14am
 
Thank you - it was an interesting problem. As the follow up test showed, there is an issue. It'd not regard it as a bug per se, given the design of the app at the time the feature was added. Rather it's an emergent issue that needs documentation at least (I've a note to self to add something to aTbRef) and possibly a fix - although the latter might be complex/expensive for an edge case problem.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Pages: 1
Send Topic Print