[ADD] samples

This commit is contained in:
Andy Bunce 2022-09-19 20:18:26 +01:00
parent c4699b2e50
commit 862e090526
8 changed files with 39191 additions and 31978 deletions

14
markdown/mermaid.md Normal file
View file

@ -0,0 +1,14 @@
# mermaid
```mermaid
flowchart TB
_ -- ./ --> util
_ --> json_hal
_ --> api_problem
_ --> cors
_ -- data/ --> types
_ -- data/ --> data_changes
data_changes -- ../--> util
```

7
semantic/sparql.rq Normal file
View file

@ -0,0 +1,7 @@
@prefix card: <http://www.w3.org/People/Berners-Lee/card#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
card:i foaf:name "Timothy Berners-Lee" .
<http://bblfish.net/people/henry/card#me> foaf:name "Henry Story" .
<http://www.cambridgesemantics.com/people/about/lee> foaf:name "Lee Feigenbaum" .
card:amy foaf:name "Amy van der Hiel" .

File diff suppressed because it is too large Load diff

View file

@ -3,40 +3,45 @@
: apb Jan 2013 : apb Jan 2013
:) :)
declare namespace doc = "http://www.xqdoc.org/1.0"; declare namespace doc = "http://www.xqdoc.org/1.0";
declare namespace dotml = "http://www.martin-loetzsch.de/DOTML"; declare namespace dotml = "http://www.martin-loetzsch.de/DOTML";
declare namespace hash = "http://basex.org/modules/hash"; declare namespace hash = "http://basex.org/modules/hash";
declare variable $ns-ignore := ("http://www.w3.org/2005/xpath-functions", declare variable $ns-ignore := ("http://www.w3.org/2005/xpath-functions",
"http://www.w3.org/2010/xslt-xquery-serialization", "http://www.w3.org/2010/xslt-xquery-serialization",
"http://www.w3.org/2001/XMLSchema", "http://www.w3.org/2001/XMLSchema",
"http://www.w3.org/2005/xpath-functions/math"); "http://www.w3.org/2005/xpath-functions/math");
declare function local:sid($s as xs:string) declare function local:sid($s as xs:string)
as xs:string{ as xs:string { "A" || xs:hexBinary(hash:md5($s)) };
"A" || xs:hexBinary(hash:md5($s))
};
declare function local:fid($uri as xs:string ,$name as xs:string,$arity as xs:string){ declare function local:fid($uri as xs:string, $name as xs:string,
let $a:=fn:trace(($uri || "*" || $name || "*" || $arity),"fid: ") $arity as xs:string) { let $a :=
return "A" || xs:hexBinary(hash:md5($uri || $name ||$arity)) fn:trace(($uri || "*" || $name || "*" || $arity), "fid: ")
}; return "A" || xs:hexBinary(hash:md5($uri || $name || $arity)) };
declare function local:foo($dml) { declare function local:foo($dml) {
let $moduri:=$dml/doc:xqdoc/doc:module/doc:uri/fn:string() let $moduri :=
$dml/doc:xqdoc/doc:module/doc:uri/fn:string()
return return
<dotml:graph file-name="graphs/bgcolor" rankdir="LR" label="a test" > <dotml:graph file-name="graphs/bgcolor" rankdir="LR" label="a test" >
{ for $import in $dml//doc:import { for $import in $dml//doc:import
let $ns := $import/doc:uri/fn:string() let $ns := $import/doc:uri/fn:string()
where some $call in $dml//doc:invoked satisfies $call/doc:uri=$import/doc:uri where some $call in $dml//doc:invoked satisfies $call/doc:uri =
$import/doc:uri
return <dotml:cluster id="{local:sid($ns)}" return
<dotml:cluster id="{ local:sid($ns)}"
label="{ $ns}" label="{ $ns}"
bgcolor="#FF8080" > bgcolor="#FF8080" >
{ for $call in $dml//doc:invoked[doc:uri = $import/doc:uri] { for $call in $dml//doc:invoked[doc:uri = $import/doc:uri]
return <dotml:node return
id="{local:fid($call/doc:name/@uri,$call/doc:name/@localname,$call/@arity)}" <dotml:node
id="{ local:fid($call/doc:name/@uri,
$call/doc:name/@localname, $call/@arity)}"
label="{ $call/doc:name/fn:string()}" label="{ $call/doc:name/fn:string()}"
fillcolor="lightblue" style="filled"/> fillcolor="lightblue" style="filled"/>
} }
@ -47,28 +52,34 @@ declare function local:foo($dml){
bgcolor="seashell" bgcolor="seashell"
> >
{ for $f in $dml//doc:function { for $f in $dml//doc:function
return <dotml:node id="{local:fid($moduri,$f/doc:name,$f/@arity)}" label="{$f/doc:name}" fillcolor="yellow" style="filled"/>, return
<dotml:node id="{ local:fid($moduri, $f/doc:name, $f/@arity)}" label="{
$f/doc:name}" fillcolor="yellow" style="filled"/>,
for $v in $dml//doc:variable for $v in $dml//doc:variable
return <dotml:node id="{generate-id($v)}" label="{$v/doc:name}" fillcolor="green" style="filled"/> return
<dotml:node id="{ generate-id($v)}" label="{ $v/doc:name}"
fillcolor="green" style="filled"/>
} }
</dotml:cluster> </dotml:cluster>
{ for $call in $dml//doc:invoked { for $call in $dml//doc:invoked
let $f := $call/.. let $f := $call/..
where not($call/doc:name/@uri/fn:string() = $ns-ignore) where not($call/doc:name/@uri/fn:string() = $ns-ignore)
return <dotml:edge return
<dotml:edge
from="{ local:fid($moduri, $f/doc:name, $f/@arity)}" from="{ local:fid($moduri, $f/doc:name, $f/@arity)}"
to="{local:fid($call/doc:name/@uri,$call/doc:name/@localname,$call/@arity)}"/> } to="{ local:fid($call/doc:name/@uri, $call/doc:name/@localname,
</dotml:graph> $call/@arity)}"/> }
}; </dotml:graph> };
let $a := local:foo(/) let $a := local:foo(/)
(: (:
let $req:=<http:request method="POST" > : let $req:=<http:request method="POST" >
<http:body media-type="application/x-www-form-urlencoded">data={fn:encode-for-uri(fn:serialize($a))}</http:body> : <http:body
</http:request> : media-type="application/x-www-form-urlencoded">data={fn:encode-for-uri(fn:serialize($a))}</http:body>
let $ws:= http:send-request($req,"http://localhost:8984/restxq/graphxq/api/dotml") : </http:request>
return file:write("aa.svg",$ws[2]) : let $ws:=
:) : http:send-request($req,"http://localhost:8984/restxq/graphxq/api/dotml")
return $a : return file:write("aa.svg",$ws[2])
:) return $a

View file

@ -4,27 +4,41 @@
:) :)
module namespace gr="apb.graphviz"; module namespace gr="apb.graphviz";
declare default function namespace 'apb.graphviz'; declare default function namespace 'apb.graphviz';
import module namespace proc = "http://basex.org/modules/proc"; import module namespace proc = "http://basex.org/modules/proc";
import module namespace file = "http://expath.org/ns/file"; import module namespace file = "http://expath.org/ns/file";
import module namespace xslt = "http://basex.org/modules/xslt"; import module namespace xslt = "http://basex.org/modules/xslt";
import module namespace random = "http://basex.org/modules/random"; import module namespace random = "http://basex.org/modules/random";
declare namespace svg = "http://www.w3.org/2000/svg"; declare namespace svg = "http://www.w3.org/2000/svg";
declare namespace xlink = "http://www.w3.org/1999/xlink"; declare namespace xlink = "http://www.w3.org/1999/xlink";
declare %private variable $gr:dotpath := if (fn:environment-variable("DOTPATH")) declare %private variable $gr:dotpath := if (fn:environment-variable("DOTPATH"))
then fn:environment-variable("DOTPATH") then
else "dot"; fn:environment-variable("DOTPATH")
else
"dot";
(:~ (:~
: folder for temp files \=windows : folder for temp files \=windows
:) :)
declare %private variable $gr:tmpdir:=if(file:dir-separator()="\") declare %private variable $gr:tmpdir := if (file:dir-separator() = "\") then
then fn:environment-variable("TEMP") || "\" fn:environment-variable("TEMP") || "\"
else "/tmp/"; else
"/tmp/";
declare %private variable $gr:empty:= declare %private variable $gr:empty := <svg xmlns="http://www.w3.org/2000/svg"
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 20" version="1.1" viewBox="0 0 300 20" version="1.1"
width="100%" height="100%" preserveAspectRatio="xMidYMid meet"> width="100%" height="100%" preserveAspectRatio="xMidYMid meet">
<text x="150" y="10" text-anchor="middle">Empty.</text> <text x="150" y="10" text-anchor="middle">Empty.</text>
</svg>; </svg>;
@ -32,47 +46,53 @@ width="100%" height="100%" preserveAspectRatio="xMidYMid meet">
(:~ (:~
: Layout one or more graphs given in the DOT language and render them as SVG. : Layout one or more graphs given in the DOT language and render them as SVG.
:) :)
declare function dot( $dot as xs:string*, $params as xs:string*) as node()*{ declare function dot($dot as xs:string*, $params as xs:string*)
let $params:=("-Tsvg") as node()* { let $params := ("-Tsvg")
for $d in $dot for $d in $dot
return if(fn:not($d)) return
then $gr:empty if (fn:not($d)) then
else let $r:=dot-execute($d,$params) $gr:empty
else
let $r := dot-execute($d, $params)
return dot-svg($r) return dot-svg($r)
}; };
(:~ run dot command :) (:~ run dot command :)
declare %private function dot-execute( $dot as xs:string, $params as xs:string*) as element(result){ declare %private function dot-execute($dot as xs:string, $params as xs:string*)
let $fname:=$gr:tmpdir || random:uuid() as element(result) { let $fname := $gr:tmpdir || random:uuid()
let $junk := file:write-text($fname, $dot) let $junk := file:write-text($fname, $dot)
let $r := proc:execute($gr:dotpath, ($params, $fname)) let $r := proc:execute($gr:dotpath, ($params, $fname))
let $junk := file:delete($fname) let $junk := file:delete($fname)
return if($r/code!="0") return
then fn:error(xs:QName('gr:dot1'),$r/error) if ($r/code != "0") then
else $r fn:error(xs:QName('gr:dot1'), $r/error)
else
$r
}; };
(:~ run dot command returning binary :) (:~ run dot command returning binary :)
declare function dot-executeb( $dot as xs:string, $params as xs:string*) as xs:base64Binary{ declare function dot-executeb($dot as xs:string, $params as xs:string*)
let $fname:=$gr:tmpdir || random:uuid() as xs:base64Binary { let $fname := $gr:tmpdir || random:uuid()
let $oname := $fname || ".o" let $oname := $fname || ".o"
let $junk := file:write-text($fname, $dot) let $junk := file:write-text($fname, $dot)
let $r := proc:execute($gr:dotpath, ($params, "-o" || $oname, $fname)) let $r := proc:execute($gr:dotpath, ($params, "-o" || $oname, $fname))
let $junk := file:delete($fname) let $junk := file:delete($fname)
return if($r/code!="0") return
then fn:error(xs:QName('gr:dot1'),$r/error) if ($r/code != "0") then
else let $d:=file:read-binary($oname) fn:error(xs:QName('gr:dot1'), $r/error)
(: let $junk:=file:delete($oname) :) else
return $d let $d := file:read-binary($oname)
(: let $junk:=file:delete($oname) :) return $d
}; };
(:~ cleanup dot svg result :) (:~ cleanup dot svg result :)
declare %private function dot-svg( $r as element(result)) as element(svg:svg){ declare %private function dot-svg($r as element(result))
let $s:=fn:parse-xml($r/output) (: o/p has comment nodes :) as element(svg:svg) { let $s := fn:parse-xml($r/output)
let $ver:=$s/comment()[1]/fn:normalize-space() (: o/p has comment nodes :) let $ver := $s/comment()[1]/fn:normalize-space()
let $title := $s/comment()[2]/fn:normalize-space() let $title := $s/comment()[2]/fn:normalize-space()
let $svg := $s/* let $svg := $s/*
return <svg xmlns="http://www.w3.org/2000/svg" return
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" > xmlns:xlink="http://www.w3.org/1999/xlink" >
{ $svg/@*, { $svg/@*,
<metadata> <metadata>
@ -95,26 +115,22 @@ declare %private function dot-svg( $r as element(result)) as element(svg:svg){
</rdf:RDF> </rdf:RDF>
</metadata>, </metadata>,
$svg/*} $svg/*}
</svg> </svg> };
};
(:~ (:~
: set svg to autosize 100% : set svg to autosize 100%
:) :)
declare function autosize($svg as node()) as node(){ declare function autosize($svg as node())
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" as node() { <svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="100%" height="100%" preserveAspectRatio="xMidYMid meet"> width="100%" height="100%" preserveAspectRatio="xMidYMid meet">
{ $svg/@* except ($svg/@width, $svg/@height, $svg/@preserveAspectRatio), { $svg/@* except ($svg/@width, $svg/@height, $svg/@preserveAspectRatio),
$svg/*} $svg/*}
</svg> </svg> };
};
(:~ (:~
: set svg to autosize 100% : set svg to autosize 100%
:) :)
declare function autosize-old($svg as node()) as node(){ declare function autosize-old($svg as node())
xslt:transform($svg , fn:resolve-uri("dotml/dotpatch.xsl")) as node() { xslt:transform($svg, fn:resolve-uri("dotml/dotpatch.xsl")) };
};

13
xquery/run.xq Normal file
View file

@ -0,0 +1,13 @@
declare variable $inp := "Merry Christmas, and a happy new year! (2014)";
declare variable $m :=
"
¡,#$%⅋,)(*+'-˙/0ƖᄅƐㄣϛ9ㄥ86:;>=<¿@∀qƆpƎℲפHIſʞ˥WNOԀQɹS┴∩ΛMX⅄Z]\[^‾,ɐqɔpǝɟƃɥᴉɾʞlɯuodbɹsʇnʌʍxʎz}|{~";
declare variable $M := ((1 to 31), string-to-codepoints($m));
for $s in util:chars($inp)
return
codepoints-to-string(reverse(for $c in string-to-codepoints($s)
return $M[$c]))

Binary file not shown.

6013
xslt-out/result1.xml Normal file

File diff suppressed because it is too large Load diff