Version 1 of treeql

Updated 2004-10-01 14:30:42 by CMCc

TreeQL treeql is a cost-like tree and editing and query language.

The fundamental idea is to require of a tree-like object a simple API [L1 ] and to use that to generate and filter a list of tree nodes by using methods which map or apply methods and predicates to the nodes in the node set.

The language form is very tcl-ish and quite free-form, which was entirely inspired by Cost.

I should point out, in passing, that this approach is quite non-standard, and there are other more standard approaches to the problem of searching and editing trees, such as the excellent tdom.

20041001 treeql is now part of tcllib. AKU ported it to tcl8.4, and helped a lot with QA.


TreeQL adaptor has some examples using treeql.

I've put TreeQL docs here [L2 ] and the current version here: [L3 ] - CMcC Updated: 20040820

Included with the library are a couple of adaptors, one to give file systems tree-semantics which gives file systems treecl/cost semantics. Beats the hell out of [glob] :)

Another adaptor is doc, which uses parsehtml and the shallow xml parser to generate trees for scanning.

I have to point out, however, this is very much a work in progress.


Some Examples from the included doc.tcl

Create a doc given a URL:

    doc homepage -url http://sharedtech.dyndns.org/

Create a Costq query over the doc tree:

    Costq nh -tree homepage

Print only the PCDATA content of the page:

    puts "TEXT: [nh query tree content]"

Print the href attributes of all <a> tags:

    puts "A: [nh query tree withtag a attval href]"

Another way to do the same:

    puts "A2: [nh query tree hasatt href attval href]"

Print the size of the tree:

    puts "SIZE: [homepage size]"

Brian Theado - 20040813 - Any chance you could package this up with all its dependencies in a starkit? I'd like to be able to do "source treecl.kit; package require costq". I tried to download and run it to try and understand better what it does and what it can be used for and stumbled because I don't have a recent enough tcllib (it appears to require struct packages that haven't been released and can only be found in CVS). I can get all the dependencies myself and right now I'm not going to take the time.

CMcC 20040816 - Can I work on it a bit more before thinking about packaging? I'm not sure what is needed to starkitify it. I'm also looking at changing the file names a bit.

Brian Theado Also, what is needed before executing the above code? Package require treecl? Package require costq?

CMcC it's lifted from the doc.tcl program, which should be instructive in this matter, but which I haven't yet documented.

Brian Theado For those interested in using this with tcllib's struct::tree, it appears that a small wrapper to convert the "rootname" method to "root" and add a "descendents" method, should do the trick. Am I right?

CMcC I think that's so, Brian. I've tried to keep the interface as close as possible, but I may have erred. If someone would like to write the adaptor, I'd be happy to incorporate it. It might even work with struct::graph, and that would make a port to e4graph easier too.

Brian Theado - same day - Thanks for sharing what you have so far. I find it easier to understand what something is good for by using it and I still haven't been successful in using it. You warned that this is a work in progress. When I requested a starkit version, what I was really after was the dependencies (struct::list, struct::set, snit, all with a version newer than the latest 1.6.1 release). Starkits are so easy once you've done it, I figured that was easier than describing what the dependencies are. FWIW, I have made a starkit that goes at least part of the way towards fulfilling the dependencies at http://tkoutline.sourceforge.net/treecl.kit . If unfamiliarity with starkits is one of your obstacles, then maybe that will give you a start. The last dependency I encountered that I didn't get around was Tcl 8.5's {expand}. I'll come back to it some other time.

BTW, I just saw that AK added ancestors and descendants methods to struct::tree in the latest CVS. Now the only adapting needed is root -> rootname.

CMcC Cool! I'll change it to rootname, it's a minor change (done). Obviously I could get around the {expand}, but the code is so much clearer with it.