-
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 #35 from scaife-viewer/feature/image-annotations
Merge #30 into develop
- Loading branch information
Showing
15 changed files
with
611 additions
and
67 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
#!/bin/bash | ||
python manage.py prepare_db | ||
python manage.py loaddata fixtures/sites.json |
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
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,70 @@ | ||
from posixpath import join as urljoin | ||
from urllib.parse import quote_plus, unquote | ||
|
||
|
||
class IIIFResolver: | ||
BASE_URL = "https://image.library.jhu.edu/iiif/" | ||
# @@@ figure out what this actually is in IIIF spec terms | ||
CANVAS_BASE_URL = "https://rosetest.library.jhu.edu/rosademo/iiif3/" | ||
COLLETION_SUBDIR = "homer/VA" | ||
iruri_kwargs = { | ||
"region": "full", | ||
"size": "full", | ||
"rotation": "0", | ||
"quality": "default", | ||
"format": "jpg", | ||
} | ||
|
||
def __init__(self, urn): | ||
""" | ||
IIIFResolver("urn:cite2:hmt:vaimg.2017a:VA012VN_0514") | ||
""" | ||
self.urn = urn | ||
|
||
@property | ||
def munged_image_path(self): | ||
image_part = self.urn.rsplit(":", maxsplit=1).pop() | ||
return image_part.replace("_", "-") | ||
|
||
@property | ||
def iiif_image_id(self): | ||
path = urljoin(self.COLLETION_SUBDIR, self.munged_image_path) | ||
return quote_plus(path) | ||
|
||
@property | ||
def identifier(self): | ||
return urljoin(self.BASE_URL, self.iiif_image_id) | ||
|
||
@property | ||
def info_url(self): | ||
info_path = "image.json" | ||
return urljoin(self.identifier, info_path) | ||
|
||
def build_image_request_url(self, **kwargs): | ||
iruri_kwargs = {} | ||
iruri_kwargs.update(self.iruri_kwargs) | ||
iruri_kwargs.update(**kwargs) | ||
return urljoin( | ||
self.identifier, | ||
"{region}/{size}/{rotation}/{quality}.{format}".format(**iruri_kwargs), | ||
) | ||
|
||
@property | ||
def image_url(self): | ||
return self.build_image_request_url() | ||
|
||
@property | ||
def canvas_url(self): | ||
path = unquote(self.iiif_image_id) | ||
return urljoin(self.CANVAS_BASE_URL, path, "canvas") | ||
|
||
def get_region_by_pct(self, dimensions): | ||
percentages = ",".join( | ||
[ | ||
f'{dimensions["x"]:.2f}', | ||
f'{dimensions["y"]:.2f}', | ||
f'{dimensions["w"]:.2f}', | ||
f'{dimensions["h"]:.2f}', | ||
] | ||
) | ||
return f"pct:{percentages}" |
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
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
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
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
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
Empty file.
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,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class WebAnnotationConfig(AppConfig): | ||
name = "web_annotation" |
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,61 @@ | ||
from django.db.models import Q | ||
from django.utils.functional import cached_property | ||
|
||
from ..library.models import Node, TextAlignmentChunk | ||
from ..library.utils import ( | ||
extract_version_urn_and_ref, | ||
get_textparts_from_passage_reference, | ||
) | ||
from .utils import preferred_folio_urn | ||
|
||
|
||
class AlignmentsShim: | ||
""" | ||
Shim to allow us to retrieve alignment data indirectly from the database | ||
eventually, we'll likely want to write out bonding box info as standoff annotation | ||
and ship to explorehomer directly. | ||
""" | ||
|
||
def __init__(self, folio_urn): | ||
self.folio_urn = preferred_folio_urn(folio_urn) | ||
|
||
@cached_property | ||
def folio_lines(self): | ||
return Node.objects.filter(urn__startswith=self.folio_urn).filter(kind="line") | ||
|
||
@cached_property | ||
def line_urns(self): | ||
return [l.urn for l in self.folio_lines] | ||
|
||
def get_ref(self): | ||
first = self.line_urns[0].rsplit(":", maxsplit=1)[1] | ||
last = self.line_urns[-1].rsplit(":", maxsplit=1)[1] | ||
# @@@ strip folios | ||
first = first.split(".", maxsplit=1)[1] | ||
last = last.split(".", maxsplit=1)[1] | ||
if first == last: | ||
return first | ||
return f"{first}-{last}" | ||
|
||
def get_alignment_data(self, idx=None, fields=None): | ||
if fields is None: | ||
fields = ["idx", "items", "citation"] | ||
|
||
ref = self.get_ref() | ||
version_urn = "urn:cts:greekLit:tlg0012.tlg001.perseus-grc2:" | ||
passage_reference = f"{version_urn}{ref}" | ||
|
||
# @@@ add as a Node manager method | ||
version_urn, ref = extract_version_urn_and_ref(passage_reference) | ||
try: | ||
version = Node.objects.get(urn=version_urn) | ||
except Node.DoesNotExist: | ||
raise Exception(f"{version_urn} was not found.") | ||
|
||
textparts_queryset = get_textparts_from_passage_reference( | ||
passage_reference, version | ||
) | ||
alignments = TextAlignmentChunk.objects.filter( | ||
Q(start__in=textparts_queryset) | Q(end__in=textparts_queryset) | ||
).values(*fields) | ||
return list(alignments) |
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,12 @@ | ||
from django.conf import settings | ||
|
||
from django.contrib.sites.models import Site | ||
|
||
|
||
def build_absolute_url(url): | ||
# get_current should cache: | ||
# https://docs.djangoproject.com/en/2.2/ref/contrib/sites/#caching-the-current-site-object | ||
current_site = Site.objects.get_current() | ||
return "{scheme}://{host}{url}".format( | ||
scheme=settings.DEFAULT_HTTP_PROTOCOL, host=current_site.domain, url=url | ||
) |
Oops, something went wrong.