Skip to content

Commit

Permalink
Implement note annotation
Browse files Browse the repository at this point in the history
This provides Text API with note annotations which
are then displayed in Tido Viewer.
  • Loading branch information
asajedi committed Sep 29, 2021
1 parent 68fba10 commit 98d55cb
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 6 deletions.
42 changes: 39 additions & 3 deletions Model/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ class Document implements DocumentInterface
private string $id;
private ?string $title = Null;
private string $content;

private string $editedText;
private string $transcriptedText;


private ?string $author = Null;
private ?string $recipient = Null;
private ?string $originPlace = Null;
Expand All @@ -41,6 +38,9 @@ class Document implements DocumentInterface
private ?array $related_items = Null;
private ?array $entities = Null;
private ?array $annotationIds = Null;
private ?array $pageNotes = Null;
private ?array $pageNotesIds = Null;
private ?array $pageSegs = Null;

public function getId(): string
{
Expand Down Expand Up @@ -389,4 +389,40 @@ public function setAnnotationIds(?array $annotationIds): DocumentInterface

return $this;
}

public function getPageNotes(): ?array
{
return $this->pageNotes;
}

public function setPageNotes(?array $pageNotes): DocumentInterface
{
$this->pageNotes = $pageNotes;

return $this;
}

public function getPageNotesIds(): ?array
{
return $this->pageNotesIds;
}

public function setPageNotesIds(?array $pageNotesIds): DocumentInterface
{
$this->pageNotesIds = $pageNotesIds;

return $this;
}

public function getPageSegs(): ?array
{
return $this->pageSegs;
}

public function setPageSegs(?array $pageSegs): DocumentInterface
{
$this->pageSegs = $pageSegs;

return $this;
}
}
24 changes: 24 additions & 0 deletions Model/DocumentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,28 @@ public function getGndKeywords(): ?array;
public function setGndKeywords(?array $gndKeywords): DocumentInterface;
public function getFreeKeywords(): ?array;
public function setFreeKeywords(?array $freeKeywords): DocumentInterface;
public function getInstitution(): ?string;
public function setInstitution(?string $institution): DocumentInterface;
public function getShelfmark(): ?string;
public function setShelfmark(?string $shelfmark): DocumentInterface;
public function getScriptSource(): ?string;
public function setScriptSource(?string $script_source): DocumentInterface;
public function getWriter(): ?array;
public function setWriter(?array $writer): DocumentInterface;
public function getReference(): ?string;
public function setReference(?string $reference): DocumentInterface;
public function getResponse(): ?string;
public function setResponse(?string $response): DocumentInterface;
public function getRelatedItems(): ?array;
public function setRelatedItems(?array $related_items): DocumentInterface;
public function getEntities(): ?array;
public function setEntities(?array $entities): DocumentInterface;
public function getAnnotationIds(): ?array;
public function setAnnotationIds(?array $annotationIds): DocumentInterface;
public function getPageNotes(): ?array;
public function setPageNotes(?array $pageNotes): DocumentInterface;
public function getPageNotesIds(): ?array;
public function setPageNotesIds(?array $pageNotesIds): DocumentInterface;
public function getPageSegs(): ?array;
public function setPageSegs(?array $pageSegs): DocumentInterface;
}
55 changes: 52 additions & 3 deletions Service/PresentationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,21 +359,54 @@ private function getItems(DocumentInterface $document)
}
}

if (!empty($document->getPageNotes())) {
foreach ($document->getPageNotes() as $key => $pageNote) {
if (!empty($pageNote) && (isset($document->getPageNotesIds()[$key]) && !empty($document->getPageNotesIds()[$key]))) {
$item = new AnnotationItem();
$item->setBody($this->getNoteAnnotationBody($pageNote, $document->getPageSegs()[$key]));
$item->setTarget($this->getNoteAnnotationTarget($document->getPageNotesIds()[$key], $document->getId() ));
$id = $this->mainDomain . '/' . $document->getId() . '/annotation-' . $document->getPageNotesIds()[$key];
$item->setId($id);
$items[] = $item;
}
}
}

return $items;
}

private function getBody(string $entityGnd)
private function getNoteAnnotationBody(string $pageNote, string $pageSeg): Body
{
$body = new Body();
$body->setValue($this->getLemmatizedNote($pageNote, $pageSeg));
$body->setXContentType('Editorial Comment');

return $body;
}

private function getNoteAnnotationTarget($annotationId, $documentId): Target
{
$target = new Target();
$id = $this->mainDomain . '/' . $documentId . '/' . $annotationId;
$target->setId($id);
$target->setFormat('text/xml');
$target->setLanguag('ger');

return $target;
}

private function getBody(string $entityGnd): Body
{
$entity = $this->emoTranslator->getEntity($entityGnd);

$body = new Body();
$body->setValue($entity['entity_name']);
$body->setValue($entity['mostly_used_name']);
$body->setXContentType(ucfirst($entity['entitytype']));

return $body;
}

private function getTarget($annotationId, $documentId)
private function getTarget($annotationId, $documentId): Target
{
$target = new Target();
$id = $this->mainDomain.'/'.$documentId.'/'.$annotationId;
Expand All @@ -383,4 +416,20 @@ private function getTarget($annotationId, $documentId)

return $target;
}

private function getLemmatizedNote(string $note, string $pageSeg): string
{
$noteAnnotation = $pageSeg;
$count = str_word_count($pageSeg);
if (!empty($count) && 2 < $count) {
$containedWords = str_word_count($pageSeg, 1);
$firstWord = $containedWords[0];
$lastWord = $containedWords[$count - 1];
$noteAnnotation = $firstWord.' ... '.$lastWord;
}

$noteAnnotation = $noteAnnotation.']'.' '.$note;

return $noteAnnotation;
}
}
12 changes: 12 additions & 0 deletions Translator/SubugoeTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ public function getDocumentById(string $id): DocumentInterface
$document->setAnnotationIds($solrDocument['annotation_ids']);
}

if (isset($solrDocument['page_segs']) && !empty($solrDocument['page_segs'])) {
$document->setPageSegs($solrDocument['page_segs']);
}

if (isset($solrDocument['page_notes']) && !empty($solrDocument['page_notes'])) {
$document->setPageNotes($solrDocument['page_notes']);
}

if (isset($solrDocument['page_notes_ids']) && !empty($solrDocument['page_notes_ids'])) {
$document->setPageNotesIds($solrDocument['page_notes_ids']);
}

$document
->setLicense($solrDocument['license'])
->setLanguage($solrDocument['language'])
Expand Down

0 comments on commit 98d55cb

Please sign in to comment.