// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // ! This script is provided "as is" by Applied Maths. ! // ! You are free to use and modify this script for your own needs. ! // ! Redistribution or reproduction of the script is prohibited. ! // ! DISCLAIMER: ! // ! Improper use of scripts may corrupt your database. ! // ! Running this script is entirely at your own responsibility. ! // ! Applied Maths accepts no lialibility for any consequences ! // ! resulting from its use. ! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //$MENU window=comparison;popup=File;insertafter=Export similarity matrix...;name=Export Dendrogram (XML) string fieldlist,fieldsel,filename,key,st; integer i,method,ok,nodecount,idx,parentID; DIALOG dlg; BRANCH root,nde,parentnde,nodelist[]; XMLNODE xmldoc,xmlroot,xmlnd,xmlnd2,xmlparent,xmlnodelist[]; float simil; if not(CmpIsPresent) then CmpAttach; if not(CmpIsPresent) then { message("ERROR: no comparison present!"); stop; } if CluGetCurrent="" then { message("ERROR: there is no dendrogram displayed"); stop; } fieldlist="Key"; for i=1 to dbgetfieldcount do fieldlist=fieldlist+" "+DbGetFieldName(i); fieldsel=fieldlist;fieldsel=splitstring(fieldsel," "); DlgAddText(dlg,"Select the field to export",15,15,150,15); DlgAddList(dlg,fieldlist,fieldsel,15,40,150,150,"LIST"); method=0; DlgAddCheck(dlg,"Hierarchical node set",method,15,190,150,20); if not(DlgShow(dlg,"Export dendrogram '"+CluGetCurrent+"' as XML",280,250)) then stop; filename="*.XML"; if not(FilePromptName("Enter export file",filename,0)) then stop; if substring(filename,length(filename)-3,9999)<>".xml" then filename=filename+".xml"; setbusy("Exporting..."); XMLNodeCreateDoc("Tree",xmldoc,xmlroot); CluGetRoot(CluGetCurrent,root); ok=CluEnumStart(root,nde); nodecount=0; while ok do { idx=CluGetEntryNr(nde); CluGetInfo(nde,simil,0.1,0,0,0); xmlparent=xmlroot;parentID=0; if CluGetParent(nde,parentnde) then { i=nodecount; while i>0 do { if CluIsEqual(parentnde,nodelist[i]) then { xmlparent=xmlnodelist[i]; parentID=i; i=-1; } i=i-1; } } if method=0 then xmlparent=xmlroot; xmlnd=XMLNodeAddChild(xmlparent,"Node"); XMLNodeAddAttrib(xmlnd,"Similarity",str(simil,0,2)); if idx>0 then { key=CmpGetEntryKey(idx);st=key; if fieldsel<>"Key" then st=DbGetField(key,fieldsel); XMLNodeAddText(xmlnd,st); } nodecount=nodecount+1;CluGetCommon(nde,nde,nodelist[nodecount]); if method=0 then { XMLNodeAddAttrib(xmlnd,"ID",str(nodecount,0,0)); XMLNodeAddAttrib(xmlnd,"ParentID",str(parentID,0,0)); } xmlnodelist[nodecount]=xmlnd; ok=CluEnumNext(nde); } XMLNodeToFile(xmldoc,filename); XMLNodeCloseDocument(xmldoc); setbusy("");