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 >> reformatting some set attributes
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1207269093

Message started by Rafter T. Sass on Apr 3rd, 2008, 8:31pm

Title: reformatting some set attributes
Post by Rafter T. Sass on Apr 3rd, 2008, 8:31pm

It's me again.

So, I'm no longer adding superfluous quotes to my set values, thanks to the kind clarifications of Amber and the Marks.

But I've still got the superfluous quotes, making my queries and set attribute fields all... mucky.

Is there a way, elegant or no, by which I can replace the quoted values for non-quoted, without schlepping together a value-for-value agent or team of agents?

I seem to remember someone posting a suggestion about this, but either it mysteriously disappeared, or I dreamed it. (Odds are running about 60/40 in favor of having dreamed it...)

Thanks!

Title: Re: reformatting some set attributes
Post by Mark Bernstein on Apr 4th, 2008, 9:57am

There's an easy way but tacky way, and a harder (in this case) but more elegant way.

Easy way: make a copy of the tinderbox file. Open the copy in a text editor.  Search for the set value; you'll find some examples in quotes:

     <attribute name="tags" >&quot;frogs&quot;;dogs</attribute>

Delete the &quot; elements.  So, global replace of &quot;frogs&quot; with frogs wil do the trick.

A nicer solution would be to make an agent that collects notes with the old tag, remove that tag, and add a new tag.  The query would be

    Query: tags("frogs")

where tags is your set attribute.

The action would be

    Action: tags = $tags -  TheBadTag + TheGoodTag

The tricky bit here is that quotation marks are meaningful in actions, so we need to find a way to say "yes, I mean that the crazy tag does have a quotation mark!"  The easiest way to do this is to make a user attribute TheBadTag, and in the agent give that attribute the value of "frogs" including the quotation mark.  So, the action would be

    Action: tags=$tags - $TheBadTag(agent) + "frogs"



Title: Re: reformatting some set attributes
Post by DerikBadman on Apr 4th, 2008, 12:06pm

Couldn't you do something with a regex to replace them all at once?

Searching for a \"(.+?)\" and replacing with $1

Not that I've tried it out...

Title: Re: reformatting some set attributes
Post by Mark Bernstein on Apr 4th, 2008, 12:29pm

DerikBadman: You'd want to search for &quot;(.+)&quot; or something like that (and do you need to escape the ampersand?)  .  This would save some time.  But you only need to do this once, and it's reassuring to see the changes as they're made.

Title: Re: reformatting some set attributes
Post by Mark Anderson on Apr 4th, 2008, 1:15pm

Yes, in a text editor that supports regular expressions find/replace like BBEdit (or its free little brother TextWrangler) you can look for the attribute, but it's not the thing to try unless you understand a little about regexs. Lets assume the bad data is in a set-type user attribute "MySet". First, we back up the file! Now open the TBX file in your text editor so you can see the source XML. We need to find all lines like:

<attribute name="MySet" >Good;&quot;Bad&quot;;Bad;Nice;&quot;Poor&quot;;OK</attribute>

Note how the unwanted " quotes around the 'bad' values are saved in the source as &quot. Your replacement regex can't just remove the &quot unless you know the quoted vaues aren't also present as unquoted values. TB normally removes dupes when setting values so creating them in source by turning Good;&quot;Bad&quot;;Bad; into Good;Bad;Bad; might upset things. You need to allow for quotes in any position and for there being no semi-colon after the last value, etc.... I'll leave it to someone with more regex experience to suggest the actual regex!

If there aren't 000s of entries and you don't fancy tackling a replacement regex but don't mind manually editing each entry, do a regex find for:

<attribute name="MySet" >.*(&quot;)+.*</attribute>

that will find MySet entries but only those with quotes in the values. In BBEdit/TextWrangler you can do a 'Find All' and use that report window to work through all the bad entries correcting them. Run the find again when done to check you missed nothing. Unless it's very few entries, I'd go the agent route Mark B's suggested. But the question was asked...

Title: Re: reformatting some set attributes
Post by Mark Bernstein on Apr 4th, 2008, 1:29pm

Tip:  these techniques are also very useful for merging tags and topics that turn out, over time, to mean the same thing.

For example, my weblog has categories for "food" and for "cooking".  At one point, I suppose I had a reason for the two categories, but now I can't remember what it is.  But I do need to remember to apply both tags to dinner!  The tricks in this discussion apply just as well to replacing two tags with one.

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.