RDF output from triples

This commit is contained in:
george 2012-02-27 04:37:05 +00:00
parent f4ca0dfb6e
commit d2cf2f64d3
3 changed files with 106 additions and 12 deletions

View File

@ -37,7 +37,7 @@ INITFARY(ZFARY) ; INITIALIZE FILE NUMBERS AND OTHER USEFUL THINGS
S @ZFARY@("C0XSFN")=172.201 ; TRIPLES STRINGS FILE NUMBER
S @ZFARY@("C0XTN")=$NA(^C0X(101)) ; TRIPLES GLOBAL NAME
S @ZFARY@("C0XSN")=$NA(^C0X(201)) ; STRING FILE GLOBAL NAME
S @ZFARY@("C0XDIR")="/home/vista/gpl/C0Q/trunk/rdf/"
S @ZFARY@("C0XDIR")="/home/glilly/fmts/trunk/samples/smart-rdf-in/"
S @ZFARY@("BLKLOAD")=1 ; this file supports block load
S @ZFARY@("FMTSSTYLE")="F2N" ; fileman style
S @ZFARY@("REPLYFMT")="JSON"
@ -270,7 +270,7 @@ PROCESS(ZRTN,ZRDF,ZGRF,ZMETA,FARY) ; PROCESS AN INCOMING RDF FILE
. I ZVOC'="" S C0XVOC(ZVOC)=$G(@ZDOM@(1,"A",ZI))
W !,"VOCABS:"
N ZZ S ZZ=""
F S ZZ=$O(C0XVOC(ZZ)) Q:ZZ="" W !,ZZ,":",C0CVOC(ZZ)
F S ZZ=$O(C0XVOC(ZZ)) Q:ZZ="" W !,ZZ,":",C0XVOC(ZZ)
;
; -- look for children called rdf:Description. quit if none. not an rdf file
;
@ -397,6 +397,7 @@ ADD(ZG,ZS,ZP,ZO,FARY) ; ADD A TRIPLE TO THE TRIPLESTORE. ALL VALUES ARE TEXT
;S ZPIEN=$$IENOF(ZP)
;S ZOIEN=$$IENOF(ZO)
;I $D(C0XFDA) D UPDIE ; ADD THE STRINGS IF NEEDED
I '$D(BATCNT) S BATCNT=0
S BATCNT=BATCNT+1
S C0XCNT=C0XCNT+1
I $G(BLKLOAD)=1 D ; we are using bulk load
@ -411,6 +412,7 @@ ADD(ZG,ZS,ZP,ZO,FARY) ; ADD A TRIPLE TO THE TRIPLESTORE. ALL VALUES ARE TEXT
. S C0XFDA(C0XTFN,"?+"_BATCNT_",",.03)=$O(ZIENS("IEN","ZS",""))
. S C0XFDA(C0XTFN,"?+"_ATCNT_",",.04)=$O(ZIENS("IEN","ZP",""))
. S C0XFDA(C0XTFN,"?+"_BATCNT_",",.05)=$O(ZIENS("IEN","ZO",""))
I '$D(BATMAX) S BATMAX=10000
I BATCNT=BATMAX D ; BATCH IS DONE
. I $G(BLKLOAD) D ; bulk load
. . D BULKLOAD(.C0XFDA) ; bulk load the batch
@ -451,7 +453,7 @@ IENOF(ZSTRING,FARY) ; EXTRINSIC WHICH RETURNS THE IEN OF ZS IN THE STRINGS FILE
. K C0XFDA2
Q ZIEN
;
IENOFA(ZOUTARY,ZINARY,FARY) ; RESOLVE STRINGS TO IEN IN STRINGS FILE
IENOFA(ZOUTARY,INARY,FARY) ; RESOLVE STRINGS TO IEN IN STRINGS FILE
; OR ADD THEM IF
; MISSING. ZINARY AND ZOUTARY ARE PASSED BY REFERENCE
; ZINARY LOOKS LIKE ZINARY("VAR","VAL")=""
@ -461,7 +463,13 @@ IENOFA(ZOUTARY,ZINARY,FARY) ; RESOLVE STRINGS TO IEN IN STRINGS FILE
. S FARY="C0XFARY"
K ZOUTARY ; START WITH CLEAN RESULTS
K C0XFDA2 ; USE A SEPARATE FDA FOR THIS
I '$D(C0XVOC) D INITVOC^C0XUTIL
N ZINARY
N ZI S ZI=""
F S ZI=$O(INARY(ZI)) Q:ZI="" D ;
. N ZK
. S ZK=$O(INARY(ZI,""))
. S ZINARY($$EXT^C0XUTIL(ZI),$$EXT^C0XUTIL(ZK))=""
N ZV,ZIEN
N ZCNT S ZCNT=0
F S ZI=$O(ZINARY(ZI)) Q:ZI="" D ; LOOK FOR MISSING STRINGS

View File

@ -113,16 +113,9 @@ triples(triplertn,sub,pred,obj,graph,fary) ; returns triples
s zgraph=$$IENOF^C0XF2N($g(graph),fary) ; ien of graph
W !,"s:",zsub," p:",zpred," o:",zobj
d trip(.tmprtn,zsub,zpred,zobj,zgraph,fary)
n zzz,zrsub,zrpred,zrobj,zgraph,zcnt,zrary
s zzz=""
f s zzz=$o(tmprtn(zzz)) q:zzz="" d ;
. s zrsub=$$GET1^DIQ(C0XTFN,zzz_",",.03,"E")
. s zrpred=$$GET1^DIQ(C0XTFN,zzz_",",.04,"E")
. s zrobj=$$GET1^DIQ(C0XTFN,zzz_",",.05,"E")
. s zrgraph=$$GET1^DIQ(C0XTFN,zzz_",",.02,"E")
. s zrary(zrsub,zrpred_"^"_zrobj)=""
;b
d ien2tary(.zrary,"tmprtn") ; convert to triples
;
d rdfout^C0XRDF(.triplertn,.zrary) q ;
i REPLYFMT="JSON" d jsonout(.triplertn,.zrary) q ; what follows is 'else'
;
; if no reply format is found we just output an array of triples
@ -136,6 +129,20 @@ triples(triplertn,sub,pred,obj,graph,fary) ; returns triples
. . s zcnt=zcnt+1
q
;
ien2tary(zrary,zinary) ; zinary is an array of iens passed by name
; zrary is passed by reference and is return array of triples
; format zrary(zsub,"zpred^zobj")=""
;
n zzz,zrsub,zrpred,zrobj,zgraph,zcnt
s zzz=""
f s zzz=$o(@zinary@(zzz)) q:zzz="" d ;
. s zrsub=$$GET1^DIQ(C0XTFN,zzz_",",.03,"E")
. s zrpred=$$GET1^DIQ(C0XTFN,zzz_",",.04,"E")
. s zrobj=$$GET1^DIQ(C0XTFN,zzz_",",.05,"E")
. s zrgraph=$$GET1^DIQ(C0XTFN,zzz_",",.02,"E")
. s zrary(zrsub,zrpred_"^"_zrobj)=""
q
;
jsonout(jout,zary) ;
d REPLYSTART^FMQLJSON("jout")
d LISTSTART^FMQLJSON("jout","results")

79
p/C0XRDF.m Normal file
View File

@ -0,0 +1,79 @@
C0XRDF ; GPL - Fileman Triples RDF out ;11/07/11 17:05
;;0.1;C0X;nopatch;noreleasedate;Build 7
;Copyright 2012 George Lilly. Licensed under the terms of the GNU
;General Public License See attached copy of the License.
;
;This program is free software; you can redistribute it and/or modify
;it under the terms of the GNU General Public License as published by
;the Free Software Foundation; either version 2 of the License, or
;(at your option) any later version.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License along
;with this program; if not, write to the Free Software Foundation, Inc.,
;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
;
Q
;
REPLYSTART(ZARY);
D ADD(ZARY,"<?xml version=""1.0"" encoding=""UTF-8""?>")
D ADD(ZARY,"<rdf:RDF xmlns:rdf=""http://www.w3.org/1999/02/22-rdf-syntax-ns#"">")
Q
;
LISTSTART(ZARY,ZNAM)
Q
;
DICTSTART(ZARY,ZSUB)
I ZSUB["http" D Q ;
. D ADD(ZARY,"<rdf:Description rdf:about="""_ZSUB_""">")
I $E(ZSUB,1,1)="/" D Q ;
. D ADD(ZARY,"<rdf:Description rdf:about="""_ZSUB_""">")
D ADD(ZARY,"<rdf:Description rdf:nodeID="""_ZSUB_""">")
Q
;
DASSERT(ZARY,ZPRED,ZOBJ)
I ZPRED[":" D Q ;
. I ZPRED="rdf:type" D Q ;
. . D ADD(ZARY,"rdf:type rdf:Resource="""_ZOBJ_"""/>")
. N ZA,ZB
. S ZA=$P(ZPRED,":",1)
. S ZB=$P(ZPRED,":",2)
. D ADD(ZARY,"<"_ZA_" xmlns="""_ZB_""">"_ZOBJ_"</"_ZA_">")
Q
;
DICTEND(ZARY)
D ADD(ZARY,"</rdf:Description")
Q
;
LISTEND(ZARY)
Q
;
REPLYEND(ZARY)
D ADD(ZARY,"</rdf:RDF>")
Q
;
ADD(ZARY,ZELE)
N ZI
I '$D(ZARY) S @ZARY@(1)=ZELE Q ;
S ZI=$O(@ZARY@(""),-1)
S @ZARY@(ZI+1)=ZELE
Q
;
rdfout(rdfout,zary) ;
d REPLYSTART("rdfout")
d LISTSTART("rdfout","results")
n zi s zi=""
f s zi=$o(zary(zi)) q:zi="" d ; for each subject
. n zii s zii=""
. D DICTSTART("rdfout",zi)
. f s zii=$o(zary(zi,zii)) q:zii="" d ; for each pred^obj pair
. . d DASSERT("rdfout",$p(zii,"^",1),$p(zii,"^",2))
. D DICTEND("rdfout")
d LISTEND("rdfout")
d REPLYEND("rdfout")
q
;