Skip to content

Commit

Permalink
Addition of the RDF generator
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandaalvaf committed Jan 3, 2024
1 parent 5defc2f commit 99f6061
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
6 changes: 6 additions & 0 deletions app/controller.xql
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ else if ((contains($exist:resource, "PD_BEACON.txt") or contains($exist:path,"PD
<set-header name="Content-Type" value="text/plain"/>
<forward url="{$exist:controller}/modules/BEACON_gen.xql"/>
</dispatch>

else if ((contains($exist:resource, "PD_RDF.txt") or contains($exist:path,"PD_RDF.txt"))) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<set-header name="Content-Type" value="text/plain"/>
<forward url="{$exist:controller}/modules/RDF_gen.xql"/>
</dispatch>

else if (contains($exist:resource,".json")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
Expand Down
3 changes: 0 additions & 3 deletions app/modules/BEACON_gen.xql
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ let $header :=
"&#xA;"
)

let $message := 'periodicals here'


return (
$header,
(
Expand Down
76 changes: 76 additions & 0 deletions app/modules/RDF_gen.xql
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
xquery version "1.0";
declare namespace tei = "http://www.tei-c.org/ns/1.0";
declare option exist:serialize "method=text media-type=text/turtle";

let $doc := doc('xmldb:exist:///db/apps/pessoa/data/indices.xml')
let $ampersand := '&#38;' (: ampersand :)
let $tab := '&#9;' (: tab :)
let $header := concat(
"@prefix ccehperson: <http://www.pessoadigital.pt/index/names#> .&#xA;",
"@prefix ccehperiodical: <http://www.pessoadigital.pt/index/periodicals#> .&#xA;",
"@prefix ccehpublications: <http://www.pessoadigital.pt/pub/> .&#xA;",
"@prefix crm: <http://www.cidoc-crm.org/cidoc-crm/> .&#xA;",
"@prefix dbo: <http://dbpedia.org/ontology/> .&#xA;",
"@prefix foaf: <http://xmlns.com/foaf/0.1/> .&#xA;",
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .&#xA;",
"@prefix wd: <http://www.wikidata.org/entity/> .&#xA;",
"@prefix viaf: <http://viaf.org/viaf/> .&#xA;",
"&#xA;"
)

return (
$header,
(for $person in $doc//tei:person
let $person_id := $person/@xml:id
let $main_name := $person/tei:persName[@type='main']/data(.)
let $gender := $person/tei:sex/data(.)
let $labels := $person/tei:persName[not(@type='main')]/data(.)
return (
concat('ccehperson:',$person_id, ' a crm:E21_Person ;', '&#xA;'),
concat($tab,'rdfs:label "', $main_name,'" ;','&#xA;'),
for $viaf_id in $person/tei:idno[@type='viaf']
return if ($viaf_id) then concat($tab,'= ', 'viaf:',$viaf_id, '>', ' ;','&#xA;') else (),
for $gnd_id in $person/tei:idno[@type='gnd']
return if ($gnd_id) then concat($tab,'= ', '<','http://d-nb.info/gnd/',$gnd_id, '>', ' ;','&#xA;') else (),
for $wikidata_id in $person/tei:idno[@type='wikidata']
return if ($wikidata_id) then concat($tab,'= ','wd:',$wikidata_id, '>', ' ;','&#xA;') else (),
concat($tab, 'foaf:gender "', $gender, '" ;','&#xA;'),
if (exists($labels)) then concat($tab, 'foaf:name ') else (),
(
for $label at $i in $labels
return if ($label) then
if ($i = count($labels))
then concat('"',$label,'";&#xA;')
else concat('"',$label,'", ')
else ()
),
'&#xA;')
),
(for $periodical in $doc//tei:list[@type='periodical']/tei:item
let $periodical_id := $periodical/@xml:id/data(.)
let $periodical_name := $periodical/tei:title/data(.)
return(
concat('ccehperiodical:',$periodical_id, ' a dbo:Journal ;','&#xA;'),
concat($tab,'rdfs:label "', $periodical_name,'" ;','&#xA;'),
for $viaf_id in $periodical/tei:idno[@type='viaf']
return if ($viaf_id) then concat($tab,'= ', 'viaf:',$viaf_id, '>', ' ;','&#xA;') else (),
for $gnd_id in $periodical/tei:idno[@type='gnd']
return if ($gnd_id) then concat($tab,'= ', '<','http://d-nb.info/gnd/',$gnd_id, '>', ' ;','&#xA;') else (),
for $wikidata_id in $periodical/tei:idno[@type='wikidata']
return if ($wikidata_id) then concat($tab,'= ','wd:',$wikidata_id, '>', ' ;','&#xA;') else (),
'&#xA;')),
(for $publication in $doc//tei:list[@type='publications']/tei:item
let $publication_id := $publication/@xml:id/data(.)
let $publication_name := $publication/tei:title/data(.)
return(
concat('ccehpublication:',$publication_id, ' a dbo:LiteraryWork ;','&#xA;'),
concat($tab,'rdfs:label "', $publication_name,'" ;','&#xA;'),
for $viaf_id in $publication/tei:idno[@type='viaf']
return if ($viaf_id) then concat($tab,'= ', 'viaf:',$viaf_id, '>', ' ;','&#xA;') else (),
for $gnd_id in $publication/tei:idno[@type='gnd']
return if ($gnd_id) then concat($tab,'= ', '<','http://d-nb.info/gnd/',$gnd_id, '>', ' ;','&#xA;') else (),
for $wikidata_id in $publication/tei:idno[@type='wikidata']
return if ($wikidata_id) then concat($tab,'= ','wd:',$wikidata_id, '>', ' ;','&#xA;') else (),
'&#xA;'))
)

0 comments on commit 99f6061

Please sign in to comment.