Skip to content

Instantly share code, notes, and snippets.

@emchateau
Created June 16, 2020 14:26
Show Gist options
  • Save emchateau/45f56e403562dc5008e47204bb94fc7b to your computer and use it in GitHub Desktop.
Save emchateau/45f56e403562dc5008e47204bb94fc7b to your computer and use it in GitHub Desktop.
Network function to get parisian experts collaborations (ANR Experts)
xquery version "3.1";
declare namespace xpr = "xpr";
declare default element namespace "eac";
declare function local:pairsCombinations($seq) {
if (fn:count($seq) = 1) then
map{
'source' : $seq
}
else for $i at $pos in $seq
for $j in fn:subsequence($seq, $pos+1, fn:count($seq))
return map{
'source' : $i,
'target' : $j
}
};
let $db := db:open('xpr')
let $nodes := $db//*:eac-cpf[*:cpfDescription/*:identity[@localType = 'expert']]
let $edges :=
for $affaires in db:open('xpr')//xpr:expertise
let $participants := $affaires/xpr:description/xpr:participants/xpr:experts
return local:pairsCombinations($participants/xpr:expert/@ref ! data())
let $description := "Associations d’experts"
return
<gexf xmlns="http://www.gexf.net/1.2draft" version="1.2">
<meta lastmodifieddate="{fn:current-date()}">
<creator>ANR Experts</creator>
<description>{$description}</description>
</meta>
<graph mode="static" defaultedgetype="directed">
<attributes class="node">
<attribute id="0" title="category" type="string"/>
</attributes>
<nodes>{
for $node in $nodes
let $label := $node//*:cpfDescription/*:identity/*:nameEntry[*:authorizedForm]/*:part
let $functions := $node//*:functions
let $function :=
switch ($functions)
case ($functions[fn:count(*:function) = 1][*:function/*:term = 'Expert bourgeois']) return 'architecte'
case ($functions[fn:count(*:function) = 1][*:function/*:term = 'Expert entrepreneur']) return 'entrepreneur'
case ($functions[fn:count(*:function) = 1][*:function/*:term = 'Arpenteur']) return 'arpenteur'
case ($functions[fn:count(*:function) >= 2][*:function/*:term = 'Expert entrepreneur' and *:function/*:term = 'Expert bourgeois']) return 'transfuge'
case ($functions[fn:count(*:function) >= 2][*:function/*:term = 'Expert entrepreneur'][fn:not(*:function/*:term = 'Expert bourgeois')]) return 'entrepreneur'
case ($functions[fn:count(*:function) >= 2][*:function/*:term = 'Expert bourgeois'][fn:not(*:function/*:term = 'Expert entrepreneur')]) return 'architecte'
default return 'unknown'
return
<node id="{$node/@xml:id}" label="{$label}">
<attvalues>
<attvalue for="0" value="{$function}"/>
</attvalues>
</node>
}</nodes>
<edges>{
for $edge at $i in $edges
return <edge id="{random:uuid()}" source="{$edge?source}" target="{$edge?target}"/>
}</edges>
</graph>
</gexf>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment