source: fmts/trunk/p/C0XOTLN.m@ 1611

Last change on this file since 1611 was 1611, checked in by George Lilly, 12 years ago

moving on

File size: 4.3 KB
Line 
1C0XOTLN ; GPL - Fileman Triples Outline Processing ;2/20/13 17:05
2 ;;0.1;C0X;nopatch;noreleasedate;Build 7
3 ;Copyright 2013 George Lilly. Licensed under the terms of the GNU
4 ;General Public License See attached copy of the License.
5 ;
6 ;This program is free software; you can redistribute it and/or modify
7 ;it under the terms of the GNU General Public License as published by
8 ;the Free Software Foundation; either version 2 of the License, or
9 ;(at your option) any later version.
10 ;
11 ;This program is distributed in the hope that it will be useful,
12 ;but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;GNU General Public License for more details.
15 ;
16 ;You should have received a copy of the GNU General Public License along
17 ;with this program; if not, write to the Free Software Foundation, Inc.,
18 ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ;
20 Q
21 ;
22roots(rtn) ; return the root subjects - defined by subjects with no parents
23 ; but with children
24 n sn,on,zi
25 s sn=$na(^C0X(101,"SOP")) ; subject index
26 S on=$na(^C0X(101,"OSP")) ; object index
27 s zi=""
28 f s zi=$o(@sn@(zi)) q:zi="" d ; for each subject
29 . i $d(@on@(zi)) q ; it is a child
30 . n zj s zj=""
31 . n hasChild s hasChild=0
32 . f s zj=$o(@sn@(zi,zj)) q:zj="" d ; for each object in this subject
33 . . i $d(@sn@(zj)) s hasChild=1
34 . s:hasChild rtn($$STR^C0XGET1(zi))=""
35 q
36 ;
37showorg ;
38 d roots(.g)
39 ;s DEBUG=1
40 d showlist(.g2,"g","*")
41 q
42 ;
43showlist(zrtn,lst,prefix) ;
44 n zi,zj,zk
45 w:$g(DEBUG) !,"entering showlist "_prefix_" ",$o(@lst@(""))
46 s zi=""
47 f s zi=$o(@lst@(zi)) q:zi="" d ;
48 . n zs s zs=$$NSP2^C0XUTIL(zi)
49 . ;w !,prefix_" ",zs
50 . n tr
51 . d triples^C0XGET1(.tr,zs,,,,"array")
52 . i '$d(tr) q ;
53 . s zj=""
54 . f s zj=$o(tr(zj)) q:zj="" d ;
55 . . w !,prefix_"* "_$$NSP2^C0XUTIL($p(tr(zj),"^",2))_" "
56 . . n isub s isub=$$isSubject($p(tr(zj),"^",3))
57 . . i isub d ;
58 . . . n tr2 s tr2($p(tr(zj),"^",3))=""
59 . . . d showlist(.zrtn,"tr2",prefix_"*")
60 . . i 'isub w $p(tr(zj),"^",3)
61 q
62 ;
63isSubject(zy) ; extrinsic which returns true if zy is a pointer to a subject
64 n zr s zr=0
65 i $d(^C0X(101,"SPO",$$IENOF^C0XF2N(zy))) s zr=1
66 q zr
67 ;
68 ; -- some python that does a tree
69 ;def tree(node, prefix='|--'):
70 ; txt=('' if (node.text is None) or (len(node.text) == 0) else node.text);
71 ; txt2 = txt.replace('\n','');
72 ; print prefix+cdautil.clean(node.tag)+' '+txt2;
73 ; for att in node.attrib:
74 ; print prefix+' : '+cdautil.clean2(att)+'^'+node.attrib[att];
75 ; for child in node:
76 ; tree(child,'| '+prefix );
77tree(where,prefix) ; show a tree starting at a node in MXML. node is passed by name
78 ;
79 i $g(prefix)="" s prefix="|--" ; starting prefix
80 i '$d(C0XJOB) s C0XJOB=$J
81 n node s node=$na(^TMP("MXMLDOM",C0XJOB,1,where))
82 n txt s txt=$$CLEAN($$ALLTXT(node))
83 w !,prefix_@node_" "_txt
84 n zi s zi=""
85 f s zi=$o(@node@("A",zi)) q:zi="" d ;
86 . w !,prefix_" : "_zi_"^"_$g(@node@("A",zi))
87 f s zi=$o(@node@("C",zi)) q:zi="" d ;
88 . d tree(zi,"| "_prefix)
89 q
90 ;
91show(what) ;
92 ;S C0XJOB=26295
93 I '$D(C0XJOB) S C0XJOB=$J
94 d tree(what)
95 q
96 ;
97ALLTXT(where) ; extrinsic which returns all text lines from the node .. concatinated
98 ; together
99 n zti s zti=""
100 n ztr s ztr=""
101 f s zti=$o(@where@("T",zti)) q:zti="" d ;
102 . s ztr=ztr_$g(@where@("T",zti))
103 q ztr
104 ;
105CLEAN(STR) ; extrinsic function; returns string - gpl borrowed from the CCR package
106 ;; Removes all non printable characters from a string.
107 ;; STR by Value
108 N TR,I
109 F I=0:1:31 S TR=$G(TR)_$C(I)
110 S TR=TR_$C(127)
111 N ZR S ZR=$TR(STR,TR)
112 S ZR=$$LDBLNKS(ZR) ; get rid of leading blanks
113 QUIT ZR
114 ;
115LDBLNKS(st) ; extrinsic which removes leading blanks from a string
116 n pos f pos=1:1:$l(st) q:$e(st,pos)'=" "
117 q $e(st,pos,$l(st))
118 ;
119VACCD ; set C0XJOB to the VA CCD
120 s C0XJOB=14921
121 q
122 ;
123NLMVS ; set C0XJOB to the NLM Values Set xml
124 s C0XJOB=26295
125 Q
126 ;
127agenda(zrtn,docId) ; produce an agenda for the docId in the MXML dom
128 ; generally, a first level index to the document
129 ; set C0XJOB if you want to use a different $J to locate the dom
130 ; zrtn passed by name
131 ;
132 ;s C0XJOB=26295
133 n zi s zi=""
134 i '$d(docId) s docId=1
135 i '$D(C0XJOB) s C0XJOB=$J
136 n dom s dom=$na(^TMP("MXMLDOM",C0XJOB,docId))
137 f s zi=$o(@dom@(1,"C",zi)) q:zi="" d ;
138 . n zn s zn=@dom@(1,"C",zi)
139 . s zn=zn_" "_$g(@dom@(zi,"A","displayName"))
140 . s @zrtn@(zn,zi)=""
141 q
142 ;
Note: See TracBrowser for help on using the repository browser.