Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Agent, Actions, Rules & Automation >> how to automate a text-finding agent
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1478752779

Message started by Gregg Williams on Nov 9th, 2016, 11:39pm

Title: how to automate a text-finding agent
Post by Gregg Williams on Nov 9th, 2016, 11:39pm

In my TBX document, a top-level container named "Items" contains, of course, multiple notes.

If I want to create an agent that finds all the notes inside Items that contain, say, "todo", I simply create an agent note that has

    $AgentQuery = "(inside(items)) & $Name.contains("todo");"

Fair enough.

Now here is what I want to do:

* create a new agent and name it "pending"
* set the prototype of this agent to, say, "protoNameTextAgent"

What I would like to do is have this agent named "pending" automatically find all the notes inside "items" that contain the word "pending" (i.e., the same text as the $Name of the agent itself). This way I can quickly create agents that find notes that have a given word in them.

- - -

I've confirmed that such an agent works when

    $AgentQuery = "(inside(items)) & $Name.contains($Name(agent));"

However, I haven't figured out how to make this happen through the mechanism of assigning a prototype to a new agent. I'm open to other ways to create the same result without having to do everything manually.

Any ideas? Thanks!

Title: Re: how to automate a text-finding agent
Post by Mark Anderson on Nov 10th, 2016, 4:50am

Your agent query should be:

inside("Items") & $Name.contains("todo")

You don't need the extra parentheses around the inside() operator. Also, 'Items' is a note name and so should be enclosed in quotes (by convention, only designator strings like 'parent' or 'agent' aren't quoted, but still work if quoted). Note names are case sensitive so an inside() call for "items" will not match notes in "Items".

To set that via an action, place the whole action in quotes. As double quotes are already used, use the single quotes for this:

$AgentAction = 'inside("Items") & $Name.contains("todo")';

But, you don't need to do the latter. Make a prototype note [sic] with the name 'protoNameTextAgent'. Use Get Info or Quickstamp to set the note's $AgentQuery. Althuogh note's don't make use of attributes in the 'Agent' group, they may still have values assigned - for scenarios just like this one here. IF using Get Info, don't use the 'agent' sub tab as only actual agents have that active, you must use the 'attributes' sub-tab and then select the 'Agent' group. The value to paste into $AgentQuery is:

inside("Items") & $Name.contains($Name(agent))

No outer quotes needed as were setting the value directly into the attribute rather than by an action.

Now, to use the prototype, make a new agent and immediately close the pop-over that opens. Rename the agent to the desired search term and set the agent to use the protoNameTextAgent prototype.

If you want you can make a container with the $OnAdd:

$Prototype = "protoNameTextAgent";

This will automate the last step above for you for any new agents you make in that container.

Title: Re: how to automate a text-finding agent
Post by Gregg Williams on Nov 16th, 2016, 11:44pm

Mark, many thanks for your excellent and thorough response. Your info saved the day! GW

Title: Re: how to automate a text-finding agent
Post by Mark Anderson on Nov 17th, 2016, 6:09am

Glad to hear it.  Thanks for the feedback - I think it can be useful for later readers to know if suggestions have actually helped.

Title: Re: how to automate a text-finding agent
Post by J Fallows on Dec 23rd, 2016, 9:57am

Chiming in a month later to say to Mark A: Yes, thanks for this obvious-once-it's-pointed-out code. Very handy! And thanks to Gregg W for asking.

Title: Re: how to automate a text-finding agent
Post by Mark Bernstein on Dec 23rd, 2016, 11:16am

If you find yourself wanting to do this, or something like it, take a moment to think about Attribute Browser.  

That won't suffice in this specific case, but it would if you "todo" and "pending" were $Tags rather than found in the text.  And extracting tags from text is not hard to do, either:

     Query: $Text.contains("todo")
     Action: $Tags = $Tags + "todo"


Title: Re: how to automate a text-finding agent
Post by J Fallows on Dec 23rd, 2016, 10:54pm


Quote:
take a moment to think about Attribute Browser


Yes, 100% agree and was going to add this (but obviously didn't). It's a TB feature I use every day.

Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.