diff --git a/src/eoaauthors2/views.py b/src/eoaauthors2/views.py index 5dbc834..2ff647e 100644 --- a/src/eoaauthors2/views.py +++ b/src/eoaauthors2/views.py @@ -5,6 +5,10 @@ from .models import Author # NSMAP = { "tei" : "http://www.tei-c.org/ns/1.0" } +from eoapublications2.views import Publication +from eoapublications2.views import Chapter +from eoapublications2 import xquery_templates + def author(request, authorslug): """View for detail page of an author diff --git a/src/eoapublications2/__init__.py b/src/eoapublications2/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/eoapublications2/admin.py b/src/eoapublications2/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/src/eoapublications2/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/src/eoapublications2/apps.py b/src/eoapublications2/apps.py new file mode 100644 index 0000000..b2a1e53 --- /dev/null +++ b/src/eoapublications2/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class Eoapublications2Config(AppConfig): + name = 'eoapublications2' diff --git a/src/eoapublications2/migrations/__init__.py b/src/eoapublications2/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/eoapublications2/models.py b/src/eoapublications2/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/src/eoapublications2/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/src/eoapublications2/tests.py b/src/eoapublications2/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/src/eoapublications2/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/src/eoapublications2/views.py b/src/eoapublications2/views.py new file mode 100644 index 0000000..f61d671 --- /dev/null +++ b/src/eoapublications2/views.py @@ -0,0 +1,58 @@ +from django.shortcuts import render +from django.template.defaultfilters import slugify + +# Create your views here. + +class Publication(): + "Publication class" + + def __init__(self, title, serie, number, coverpath, abstract_short, mainlanguage, creators, creator_suffix, translated_and): + self.Title = title + self.Serie = serie + self.Number = number + self.Cover = coverpath + self.Descriptionshort = abstract_short + self.Mainlanguage = mainlanguage + self.Creators = creators + self.Creatorsuffix = creator_suffix + self.Conjunction = translated_and + # def __init__ ends here + + + def __str__(self): + return self.Title + # def __str__ ends here +# class Publication ends here + + +class Chapter(): + "Chapter class" + + def __init__(self, long_title, short_title, abstract, mainlanguage, creators, order, appears_in): + self.Longtitle = long_title + self.Shorttitle = short_title + self.Mainlanguage = mainlanguage + self.Order = order + self.Creators = creators + self.Chapterabstract = abstract + self.Partofpublication = appears_in + # def __init__ ends here + + def __str__(self): + return self.Longtitle + # def __str__ ends here +# class Chapter ends here + + +class Author(): + "Author class" + + def __init__(self, name): + self.Name = name + self.Sortname = slugify(name) + # def __init__ ends here + + def __str__(self): + return self.Name + # def __str__ ends here +# class Author ends here diff --git a/src/eoapublications2/xquery_templates.py b/src/eoapublications2/xquery_templates.py new file mode 100644 index 0000000..90e0ae7 --- /dev/null +++ b/src/eoapublications2/xquery_templates.py @@ -0,0 +1,178 @@ +def author_is_creator_of_which_publications(firstname, lastname): + """Building a personalized xquery string + + For debugging purposes, this is authorpublication.xq + """ + + pubquiz_string = """ +xquery version "3.1"; + +declare namespace tei = "http://www.tei-c.org/ns/1.0"; + + + { + let $firstname := '%s' + let $lastname := '%s' + + for $book in collection('/db/xml_files/publications') + let $authorid := + concat('#', + $book//tei:respStmt/tei:persName[./tei:forename = $firstname and ./tei:surname = $lastname]/../@xml:id) + let $series := $book//tei:seriesStmt/tei:title/text() + let $number := xs:int($book//tei:seriesStmt/tei:idno/text()) + let $abstract := $book//tei:profileDesc/tei:abstract[@n = 'brief']/tei:p + let $title := $book//tei:titleStmt/tei:title[@type = 'main']/node() + let $coverimage := $book//tei:text/tei:front/tei:figure[@type = 'cover']/tei:graphic/@url + return + { + if ($book//tei:fileDesc/tei:titleStmt/(tei:editor[@role = 'volumeeditor'] | tei:author)/@ref = $authorid) +then ( + {$title}, + {$series}, + {$number}, + {$abstract}, + { concat("/", lower-case($series), "/", $number, "/", $coverimage) } +) + else + "" + } + + } + + +""" % (firstname, lastname) + + return pubquiz_string +# def author_is_creator_of_which_publications ends here + + +def author_is_creator_of_which_chapters(firstname, lastname): + """Return all chapters with author involved. + + For debugging purposes, this is chapterauthor.xq + """ + + pubquiz_string = """ +xquery version "3.1"; + + +declare namespace tei = "http://www.tei-c.org/ns/1.0"; + + + +{ + let $firstname := '%s' + let $lastname := '%s' + for $book in collection('/db/xml_files/publications') + let $authorid := + $book//tei:respStmt/tei:persName[./tei:forename = $firstname and ./tei:surname = $lastname]/../@xml:id + let $series := $book//tei:seriesStmt/tei:title/text() + let $number := xs:int($book//tei:seriesStmt/tei:idno/text()) + let $title := $book//tei:titleStmt/tei:title[@type = 'main']/node() + let $chapter := $book//tei:text//tei:div[@type = 'chapter'] + for $bit in $chapter + let $chaptertitle := $bit/tei:head/node() + let $chapterlanguage := xs:string($bit/@xml:lang) + let $chapterabstract := $bit/ab[@type='chapterabstract'] + let $resp := xs:string($bit/@resp) + let $resplist := tokenize($resp, " ") + return + { + if ($resplist = concat('#', $authorid)) then + ({ $chaptertitle }, { $title }, { $series }, + { $number }, { index-of($chapter, $bit) }, {$chapterlanguage}, {$chapterabstract},{$resplist}) + else + "" + } + +} + +""" % (firstname, lastname) + + return pubquiz_string +# def author_is_creator_of_which_chapters ends here + + +def author_is_creator_of_which_other_chapters(firstname, lastname): + """Return all chapters with author involved except where she or he is + author or volume editor. + + For debugging purposes, this is chapterauthor_notinownbook.xq + """ + + pubquiz_string = """ +xquery version "3.1"; + + +declare namespace tei = "http://www.tei-c.org/ns/1.0"; + + + +{ + let $firstname := '%s' + let $lastname := '%s' + for $book in collection('/db/xml_files/publications') + let $authorid := + $book//tei:respStmt/tei:persName[./tei:forename = $firstname and ./tei:surname = $lastname]/../@xml:id + let $authorrefs := $book//tei:fileDesc/tei:titleStmt/(tei:editor[@role = 'volumeeditor'] | tei:author)/@ref + let $listofcreators := string-join($authorrefs, " ") + let $series := $book//tei:seriesStmt/tei:title/text() + let $number := xs:int($book//tei:seriesStmt/tei:idno/text()) + let $title := $book//tei:titleStmt/tei:title[@type = 'main']/node() + let $chapter := $book//tei:text//tei:div[@type = 'chapter'] + for $bit in $chapter + let $chaptertitle := $bit/tei:head/node() + let $chapterlanguage := xs:string($bit/@xml:lang) + let $chapterabstract := $bit/ab[@type = 'chapterabstract'] + let $resp := xs:string($bit/@resp) + let $resplist := tokenize($resp, " ") + return + + { + if (empty($authorid)) then + "" + else + (if (tokenize($listofcreators, " ") = '#' || $authorid) then + ("") + else + (if ($resplist = concat('#', $authorid)) then + ({ $chaptertitle }, { $title }, + { $series }, + { $number }, { index-of($chapter, $bit) }, + { $chapterlanguage }, { $chapterabstract }, + + { + for $pp in $resplist + let $localname := xs:string($book/*//tei:respStmt[@xml:id = substring-after($pp, "#")]/tei:persName/@xml:lang) + let $inbookid := xs:string($book/*//tei:respStmt[@xml:id = substring-after($pp, "#")]/@xml:id) + let $firstname := + $book/*//tei:respStmt[@xml:id = substring-after($pp, + "#")]/tei:persName/tei:forename/node() + let $lastname := + $book/*//tei:respStmt[@xml:id = substring-after($pp, + "#")]/tei:persName/tei:surname/node() + return + { + if ($localname = "zh") then + (concat($lastname, ' ', $firstname)) + else + (concat($firstname, ' ', $lastname)) + } + { $firstname } + { $lastname } + { $inbookid } + + } + ) + else + "" + ) + ) + } + +} + +""" % (firstname, lastname) + + return pubquiz_string +# def author_is_creator_of_which_other_chapters ends here diff --git a/src/eoaseries2/views.py b/src/eoaseries2/views.py index 25b61fd..a8cb2d6 100644 --- a/src/eoaseries2/views.py +++ b/src/eoaseries2/views.py @@ -1,51 +1,15 @@ from django.http import HttpResponse from django.shortcuts import get_object_or_404, render -from django.template.defaultfilters import slugify from lxml import etree import re from .models import Series from xsl import xsl_lib +from eoapublications2.views import Publication +from eoapublications2.views import Chapter +from eoapublications2.views import Author NSMAP = { "tei" : "http://www.tei-c.org/ns/1.0" } -class Author(): - "Author class" - - def __init__(self, name): - self.Name = name - self.Sortname = slugify(name) - # def __init__ ends here - - def __str__(self): - return self.Name - # def __str__ ends here - - pass -# class Author ends here - - -class Publication(): - "Publication class" - - def __init__(self, title, serie, number, coverpath, abstract_short, mainlanguage, creators, creator_suffix, translated_and): - self.Title = title - self.Serie = serie - self.Number = number - self.Cover = coverpath - self.Descriptionshort = abstract_short - self.Mainlanguage = mainlanguage - self.Creators = creators - self.Creatorsuffix = creator_suffix - self.Conjunction = translated_and - # def __init__ ends here - - - def __str__(self): - return self.Title - # def __str__ ends here -# class Publication ends here - - def evaluate_xml(series_query, translations): """Get data from XML"""