-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from BeethovensWerkstatt/dev
include module 1
- Loading branch information
Showing
33 changed files
with
7,297 additions
and
73 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
xquery version "3.1"; | ||
|
||
(: | ||
get_MEI_file_as_XML.xql | ||
This xQuery … | ||
:) | ||
|
||
declare namespace xhtml="http://www.w3.org/1999/xhtml"; | ||
declare namespace mei="http://www.music-encoding.org/ns/mei"; | ||
declare namespace svg="http://www.w3.org/2000/svg"; | ||
declare namespace request="http://exist-db.org/xquery/request"; | ||
declare namespace util="http://exist-db.org/xquery/util"; | ||
declare namespace transform="http://exist-db.org/xquery/transform"; | ||
|
||
import module namespace config="https://api.beethovens-werkstatt.de" at "../../xqm/config.xqm"; | ||
|
||
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization"; | ||
|
||
(: set output to XML:) | ||
declare option output:method "xml"; | ||
declare option output:media-type "text/plain"; | ||
|
||
let $file.id := request:get-parameter('file.id','') | ||
|
||
let $doc := collection($config:module1-root)//mei:mei[@xml:id = $file.id] | ||
|
||
return | ||
$doc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
xquery version "3.1"; | ||
|
||
(: | ||
get_MEI_file_as_XML.xql | ||
This xQuery … | ||
:) | ||
|
||
declare namespace xhtml="http://www.w3.org/1999/xhtml"; | ||
declare namespace mei="http://www.music-encoding.org/ns/mei"; | ||
declare namespace svg="http://www.w3.org/2000/svg"; | ||
declare namespace request="http://exist-db.org/xquery/request"; | ||
declare namespace util="http://exist-db.org/xquery/util"; | ||
declare namespace transform="http://exist-db.org/xquery/transform"; | ||
|
||
import module namespace config="https://api.beethovens-werkstatt.de" at "../../xqm/config.xqm"; | ||
|
||
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization"; | ||
|
||
(: set output to XML:) | ||
declare option output:method "xml"; | ||
declare option output:media-type "text/plain"; | ||
|
||
let $edition.id := request:get-parameter('edition.id','') | ||
let $element.id := request:get-parameter('element.id','') | ||
|
||
let $doc := collection($config:module1-root)//mei:mei[@xml:id = $edition.id] | ||
let $elem := $doc/id($element.id) | ||
|
||
return | ||
$elem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
xquery version "3.1"; | ||
|
||
(: | ||
get_SVG_file_as_XML.xql | ||
This xQuery … | ||
:) | ||
|
||
declare namespace xhtml="http://www.w3.org/1999/xhtml"; | ||
declare namespace mei="http://www.music-encoding.org/ns/mei"; | ||
declare namespace svg="http://www.w3.org/2000/svg"; | ||
declare namespace request="http://exist-db.org/xquery/request"; | ||
declare namespace util="http://exist-db.org/xquery/util"; | ||
declare namespace transform="http://exist-db.org/xquery/transform"; | ||
declare namespace local="no:where"; | ||
|
||
import module namespace config="https://api.beethovens-werkstatt.de" at "../../xqm/config.xqm"; | ||
|
||
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization"; | ||
|
||
(: set output to XML:) | ||
declare option output:method "xml"; | ||
declare option output:media-type "text/plain"; | ||
|
||
(: return a deep copy of the elements and attributes without ANY namespaces :) | ||
declare function local:remove-namespaces($element as element()) as element() { | ||
element { local-name($element) } { | ||
for $att in $element/@* | ||
return | ||
attribute {local-name($att)} {$att}, | ||
for $child in $element/node() | ||
return | ||
if ($child instance of element()) | ||
then local:remove-namespaces($child) | ||
else $child | ||
} | ||
}; | ||
|
||
let $file.id := request:get-parameter('file.id','') | ||
|
||
let $svg := collection($config:module1-root)//svg:svg[@id = replace($file.id,'.svg','')] | ||
|
||
return | ||
local:remove-namespaces($svg) |
108 changes: 108 additions & 0 deletions
108
source/xql/module1/get_all_MEI_files_from_DB_as_JSON.xql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
xquery version "3.1"; | ||
|
||
(: | ||
get_all_MEI_files_from_DB_as_JSON.xql | ||
This xQuery … | ||
:) | ||
|
||
import module namespace config="https://api.beethovens-werkstatt.de" at "../../xqm/config.xqm"; | ||
|
||
declare namespace xhtml="http://www.w3.org/1999/xhtml"; | ||
declare namespace mei="http://www.music-encoding.org/ns/mei"; | ||
declare namespace svg="http://www.w3.org/2000/svg"; | ||
declare namespace request="http://exist-db.org/xquery/request"; | ||
declare namespace util="http://exist-db.org/xquery/util"; | ||
declare namespace transform="http://exist-db.org/xquery/transform"; | ||
|
||
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization"; | ||
|
||
(: set output to JSON:) | ||
declare option output:method "json"; | ||
declare option output:media-type "application/json"; | ||
|
||
(: | ||
$preview.width and .height are used to specify the dimensions | ||
of a preview image of the edition, which can be displayed as | ||
"appetizer" for the edition. Dimensions are actually doubled | ||
(to prepare for for retina displays) | ||
:) | ||
let $preview.width := 240 | ||
let $preview.height := 180 | ||
|
||
let $header-addition := response:set-header("Access-Control-Allow-Origin","*") | ||
|
||
let $all.docs := collection($config:module1-root)//mei:mei[mei:meiHead/mei:altId[@type = 'VideApp']] | ||
let $works := distinct-values($all.docs//mei:altId[@type = 'VideApp' and @subtype = 'work']/@label) | ||
let $docs := | ||
for $work in $works | ||
let $files := $all.docs[.//mei:altId[@type = 'VideApp' and @subtype = 'work' and @label = $work]] | ||
let $versions := distinct-values($files//mei:altId[@type = 'VideApp' and @subtype = 'version']/@n) | ||
let $max.level1 := max(for $version in $versions return number(tokenize($version,'\.')[1])) | ||
let $versions.max1 := $versions[number(tokenize(.,'\.')[1]) = $max.level1] | ||
let $max.level2 := max(for $version in $versions.max1 return number(tokenize($version,'\.')[2])) | ||
let $versions.max2 := $versions.max1[number(tokenize(.,'\.')[2]) = $max.level2] | ||
let $max.level3 := max(for $version in $versions.max2 return number(tokenize($version,'\.')[3])) | ||
let $current.version := $versions.max2[number(tokenize(.,'\.')[3]) = $max.level3] | ||
return | ||
$files[.//mei:altId[@type = 'VideApp' and @subtype = 'version']/@n = $current.version] | ||
|
||
let $entries := | ||
|
||
map:merge( | ||
for $doc in $docs | ||
let $filename := tokenize(document-uri($doc/root()),'/')[last()] | ||
let $edition.id := $doc/string(@xml:id) | ||
let $edition.title := normalize-space($doc//mei:fileDesc/mei:titleStmt/mei:title[@type = 'editionTitle'][1]/string-join(text(),' ')) | ||
let $videApp.workId := normalize-space($doc//mei:altId[@type = 'VideApp' and @subtype = 'work']/@label) | ||
let $videApp.main := normalize-space($doc//mei:fileDesc/mei:titleStmt/mei:title[@type = 'videApp.main'][1]/string-join(text(),' ')) | ||
let $videApp.sub := normalize-space($doc//mei:fileDesc/mei:titleStmt/mei:title[@type = 'videApp.sub'][1]/string-join(text(),' ')) | ||
let $edition.desc := normalize-space(string-join($doc//mei:fileDesc/mei:notesStmt/mei:annot[@type = 'editionDesc']/mei:p/normalize-space(string-join(text(),' ')),' ')) | ||
let $preview.zone := //$doc/id($doc//mei:fileDesc/mei:notesStmt/mei:annot[@type = 'editionDesc']/replace(@plist,'#','')) | ||
let $preview.baseURI := $preview.zone/parent::mei:surface/mei:graphic[@type = 'iiif']/@target | ||
let $preview.zone.width := number($preview.zone/@lrx) - number($preview.zone/@ulx) | ||
let $preview.zone.height := number($preview.zone/@lry) - number($preview.zone/@uly) | ||
let $preview.region := $preview.zone/@ulx || ',' || $preview.zone/@uly || ',' || $preview.zone.width || ',' || $preview.zone.height || '/' | ||
let $preview.size := string($preview.width * 2) || ',' || string($preview.height * 2) || '/' | ||
let $supportedViews := | ||
for $app in $doc//mei:application[@type = 'videApp'] | ||
let $map := map { | ||
'id': $app/string(@xml:id), | ||
'version': $app/string(@version) | ||
} | ||
let $output := | ||
if ($app/@subtype) | ||
then map:put($map, 'feature', $app/string(@subtype)) | ||
else $map | ||
return $output | ||
|
||
let $revisions := | ||
for $version in $all.docs[.//mei:altId[@type = 'VideApp' and @subtype = 'work' and @label = $videApp.workId]]/normalize-space(.//mei:altId[@type = 'VideApp' and @subtype = 'version']/string(@n)) | ||
return $version | ||
|
||
return | ||
map:entry($edition.id, map { | ||
'id': $edition.id, | ||
'title': $videApp.main, | ||
'opus': $videApp.sub, | ||
'fullTitle': $edition.title, | ||
'desc': $edition.desc, | ||
'revisions': array { $revisions }, | ||
'previewUri': $preview.baseURI || $preview.region || $preview.size || '0/default.jpg', | ||
'supportedViews': array { $supportedViews} | ||
}) | ||
(: '"' || $edition.id || '":{' || | ||
'"id":"' || $edition.id || '",' || | ||
'"title":"' || $videApp.main || '",' || | ||
'"opus":"' || $videApp.sub || '",' || | ||
'"fullTitle":"' || $edition.title || '",' || | ||
'"desc":"' || $edition.desc || '",' || | ||
'"revisions":[' || string-join($revisions,',') || '],' || | ||
'"previewUri":"' || $preview.baseURI || $preview.region || $preview.size || '0/default.jpg' || '",' || | ||
'"supportedViews":[' || string-join($supportedViews,',') || ']' || | ||
'}' :) | ||
) | ||
|
||
|
||
|
||
return $entries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
xquery version "3.1"; | ||
|
||
(: | ||
get_annotations_as_JSON.xql | ||
This xQuery seeks to extract the exact positions of all notes, rests and similar, | ||
trying to provide Verovio with all the information it needs to render a | ||
diplomatic transcript | ||
:) | ||
|
||
declare namespace xhtml="http://www.w3.org/1999/xhtml"; | ||
declare namespace mei="http://www.music-encoding.org/ns/mei"; | ||
declare namespace svg="http://www.w3.org/2000/svg"; | ||
declare namespace request="http://exist-db.org/xquery/request"; | ||
declare namespace util="http://exist-db.org/xquery/util"; | ||
declare namespace transform="http://exist-db.org/xquery/transform"; | ||
declare namespace vide="http://beethovens-werkstatt.de/ns/vide"; | ||
declare namespace functx="http://www.functx.com"; | ||
|
||
import module namespace console="http://exist-db.org/xquery/console"; | ||
import module namespace config="https://api.beethovens-werkstatt.de" at "../../xqm/config.xqm"; | ||
|
||
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization"; | ||
|
||
(: set output to JSON:) | ||
declare option output:method "json"; | ||
declare option output:media-type "application/json"; | ||
|
||
let $edition.id := request:get-parameter('edition.id','') | ||
|
||
let $doc := collection($config:module1-root)//mei:mei[@xml:id = $edition.id] | ||
|
||
let $annotations := | ||
for $annot in $doc//mei:annot[@type = 'editorialComment'] | ||
let $id := $annot/string(@xml:id) | ||
let $title := $annot/mei:title/text() | ||
let $plist := | ||
for $p in $annot/tokenize(replace(@plist,'#',''),' ') | ||
return $p | ||
let $plist.strings := | ||
for $p in $plist | ||
return '"' || $p || '"' | ||
let $elements := | ||
for $p in $plist | ||
return $doc/id($p) | ||
let $facs := | ||
for $facs.ref in $elements//@facs/tokenize(normalize-space(replace(.,'#','')),' ') | ||
return $facs.ref | ||
let $pageMap := map {} | ||
|
||
let $pages := | ||
map:merge( | ||
for $page in $doc//mei:graphic[@type = 'shapes'] | ||
where (some $shape in $facs satisfies collection($config:module1-root)//svg:svg[@id = $page/@target]//svg:path[@id = $shape]) | ||
let $shapes := | ||
for $shape in $facs | ||
where collection($config:module1-root)//svg:svg[@id = $page/@target]//svg:path[@id = $shape] | ||
return $shape | ||
|
||
return | ||
map:entry($page/parent::mei:surface/string(@xml:id), array { $shapes }) | ||
) | ||
|
||
return map { | ||
'id': $id, | ||
'title': $title, | ||
'plist': array { $plist.strings }, | ||
'facs': $pages | ||
} | ||
|
||
return array { $annotations } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
xquery version "3.1"; | ||
|
||
(: | ||
get_annotations_as_JSON.xql | ||
This xQuery seeks to extract the exact positions of all notes, rests and similar, | ||
trying to provide Verovio with all the information it needs to render a | ||
diplomatic transcript | ||
:) | ||
|
||
declare namespace xhtml="http://www.w3.org/1999/xhtml"; | ||
declare namespace mei="http://www.music-encoding.org/ns/mei"; | ||
declare namespace svg="http://www.w3.org/2000/svg"; | ||
declare namespace request="http://exist-db.org/xquery/request"; | ||
declare namespace util="http://exist-db.org/xquery/util"; | ||
declare namespace transform="http://exist-db.org/xquery/transform"; | ||
declare namespace vide="http://beethovens-werkstatt.de/ns/vide"; | ||
declare namespace functx="http://www.functx.com"; | ||
|
||
import module namespace config="https://api.beethovens-werkstatt.de" at "../../xqm/config.xqm"; | ||
|
||
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization"; | ||
|
||
(: set output to JSON:) | ||
declare option output:method "json"; | ||
declare option output:media-type "application/json"; | ||
|
||
let $edition.id := request:get-parameter('edition.id','') | ||
let $page.id := request:get-parameter('page.id','') | ||
|
||
let $doc := collection($config:module1-root)//mei:mei[@xml:id = $edition.id] | ||
let $svg.file := collection($config:module1-root)//svg:svg[@id = $doc/id($page.id)/mei:graphic[@type = 'shapes']/@target] | ||
|
||
let $annotations := | ||
for $annot in $doc//mei:annot[@type = 'editorialComment'] | ||
let $id := $annot/string(@xml:id) | ||
let $title := $annot/mei:title/text() | ||
let $plist := | ||
for $p in $annot/tokenize(replace(@plist,'#',''),' ') | ||
return $p | ||
let $elements := | ||
for $p in $plist | ||
return $doc/id($p) | ||
let $facs := | ||
for $facs.ref in $elements//@facs/tokenize(normalize-space(replace(.,'#','')),' ') | ||
return $facs.ref | ||
|
||
let $shapes := | ||
for $shape in $facs | ||
where exists($svg.file//svg:path[@id = $shape]) | ||
return $shape | ||
|
||
where (some $shape in $facs satisfies exists($svg.file//svg:path[@id = $shape])) | ||
|
||
return map { | ||
'id': $id, | ||
'page': $page.id, | ||
'title': $title, | ||
'plist': array { $plist }, | ||
'facs': array { $shapes } | ||
} | ||
|
||
return array { $annotations } |
Oops, something went wrong.