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
Enumerating notes, links (w/names), and linked to (Read 4673 times)
Adam Montville
Full Member
*
Offline



Posts: 13

Enumerating notes, links (w/names), and linked to
Sep 16th, 2011, 11:49pm
 
I have what seems to be a rather simple issue.  I have a set of notes, all at the root level and of various prototypes.  For each note, I would like to discover outbound links (with their names) and the name of the note to which the link leads.  I would like to state the following in a note or output about my collection of notes:

  • Note name, prototype
  • (For each outbound link) Note name, link name, linked note name


This seems like something that should be relatively easy to accomplish (the first bullet is easy enough, it's the second bullet I'm having trouble with).  I'd like a plain text output rather than HTML, because this is for loading into a different data representation.  

Anyone have ideas on this?
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Enumerating notes, links (w/names), and linked to
Reply #1 - Sep 17th, 2011, 4:10am
 
There is no tool for the latter. The link-related tools tend to assume you know the linkType name in question or simply want all links.  THe other problem is there's no 'for' loop type of function.  You can fake it with a list and format()  - a recent example here - but you don't have a dynamic list of a given note's existing link types (i.e. those used as opposed to the overall set available).

I think - not tested - the workaround it to write an action that tests a hardcoded linkType value for each linkType of interest (or all of them) in your TBX and returns a list or set of values. You use this on each note and if the note has links of a given type you fetch info relating to that type with existing actions. The inherent weakness of this approach is if you add a new linkType, you'll need to edit the action code to add the new linktype name as an extra if() text.

I think there are 2 feature requests lurking here, a +1 for a loop construct, and an operator returning all discrete link Types currently used with a note|group scope for inbound|outbound|all directionality.
Back to top
 
 

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



Posts: 359

Re: Enumerating notes, links (w/names), and linked to
Reply #2 - Sep 18th, 2011, 2:36pm
 
In my experience TB already has all the constructs needed to run "real" loops, as shown here and here. This takes more code, but for me is easier to understand and more flexible and powerful than "faking" a loop with format().

Here is a link to a demo tbx that uses a loop to generate a report showing two out of the three columns mentioned in the second bullet above: the note name (link source) and linked note name (link destination) for each outbound link.

Three user attributes are used to control the loop: a numerical attribute for a loop "counter" (which keeps track of how many times the loop has run), a numerical attribute for loop size, and a string attribute to hold the current item in the list being "looked at" by the loop.

To generate the links report a list attribute is needed to collect the names of link destinations, and a string attribute to hold an intermediate value that can be thought of as a "line" in the report (here the name of the link source in the first column and the name of the link destination in the second) that will be collected later and combined into a report.

Here three code notes (these could just as well have been macros or stamps, but code notes are easier to edit) do the work.

The first, here called 'cLoopInit', wipes the slate clean, collects the list of outbound links, calculates the "size" of the list (i.e., counts the number of items in order to know how many times to run the loop), and then tells the second code note to run.  

Code:
$LinkReportLine=;$LoopCtr=0;
$LinkList=links.outbound..$Name;
$LoopSize=$LinkList.size;
action($Text("cLoop")); 



The second code note, here called 'cLoop', looks at each item in the list of links (it uses the .at() operator described here with the loop counter to locate the current item) and generates a "report line" containing the two desired columns, quitting after it finishes with the last list item associated with the current note.

Code:
if($LoopCtr<$LoopSize)
{
$CurrListItem=$LinkList.at($LoopCtr);
$LinkReportLine=$LinkReportLine+$Name+"                   "+$CurrListItem+";";
$LoopCtr=$LoopCtr+1;
action($Text("cLoop"));
} 



The first two code notes run for each individual data note. A third code note, here called 'cMakeReport', then collects and formats the "report lines" into a report, here placed in the $Text of the container note.

Code:
$Text(/Notes)="NoteName             LinkedNote"+"
"+collect(children,$LinkReportLine).unique.format("\n") 



Running a loop in this way is similar to the "envelope-letter" approach to export templates for a multi-level outline described in the Tinderbox Way and here and here, among other places.  

I've found this general approach is quite flexible and powerful for "cycling through" the individual items of dynamic sets and lists, which seems to be a fairly frequent need. It's already much easier for a non-programmer like me to do this in TB than with other tools.
Back to top
 
« Last Edit: Sep 18th, 2011, 2:38pm by Sumner Gerard »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Enumerating notes, links (w/names), and linked to
Reply #3 - Sep 19th, 2011, 5:47am
 
@Sumner, yes I'd overlooked this workaround. Incidentally, your dropbox link to the demo seems broken - though your answer and linked articles should give orthers all the necessary pieces of the technique.

However, I still don't see a method - without using 'hard-coded' test values - for getting a list of the discrete link types for inbound/outbound links for a given note. Knowing the latter is necessary for @Adam's task.

I think Adam will have to make a list of those built-in/custom linkTypes used in his TBX, then run a links() call per link type hard-coding in the currently interrogated linkType's name and seeding same into the output listing.

The latter still isn't quite what was asked for. But there's no outbound links object from which - by whatever loop method - each link and its 'properties' can be enumerated.
Back to top
 
 

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



Posts: 359

Re: Enumerating notes, links (w/names), and linked to
Reply #4 - Sep 19th, 2011, 12:32pm
 
Quote:
dropbox link to the demo seems broken

Link should work now. Sorry about that. It turns out that the link itself was valid. But I still get tripped up by the fact that Dropbox, unlike iDisk, doesn't behave like a disk volume. You drag an item out of it to another folder and it moves the item, deleting it from Dropbox, instead of copying it as would be the case with, say, iDisk.  I thought I had been careful to option-drag, but guess not.

Maybe there will be more access to link types in the future... eventually maybe even easier ways to do "loops on lists." Smiley
Back to top
 
 
  IP Logged
Pages: 1
Send Topic Print