Skip to content
Snippets Groups Projects
Commit dc1846d7 authored by dre0059's avatar dre0059
Browse files

Dokumentácia update

parent f27300c9
Branches
No related merge requests found
Showing with 163 additions and 26 deletions
# Articleprocessor GROBID version 1.0 # Articleprocessor GROBID version
- The main program runs at : *http://localhost:8080/upload* or *http://localhost:8080* - The main program runs at : *http://localhost:8080/upload* or *http://localhost:8080*
- H2 database can be found on : *http://localhost:8080/h2-console/login.jsp?jsessionid=9af0ea4b83284ff0a4574769b0336943* - H2 database can be found on : *http://localhost:8080/h2-console/login.jsp?jsessionid=9af0ea4b83284ff0a4574769b0336943*
- Password for the DBS can be found in : `resources/application.properties` - Password for the DBS can be found in : `resources/application.properties`
- GROBID server available on address *http://158.196.98.65:8080/* at university network - GROBID server available on address *http://158.196.98.65:8080/* in university network
_VŠB-TUO 2025_
_Eliška Kozáčiková - DRE0059_
---------
--------- ---------
......
...@@ -20,19 +20,39 @@ import reactor.core.publisher.Mono; ...@@ -20,19 +20,39 @@ import reactor.core.publisher.Mono;
import java.io.File; import java.io.File;
import java.net.ConnectException; import java.net.ConnectException;
/**
* Tento klient používa WebClient na odosielanie požiadaviek
* na server GROBID a získavanie spracovaných metadát,
* referencií a hlavičiek z PDF dokumentov.
* *
* Implementuje metódy na komunikáciu s API Grobid servera pre rôzne
* typy analýz PDF dokumentov.
*/
@Service @Service
public class GrobidClient { public class GrobidClient {
private final WebClient webClient; private final WebClient webClient;
public GrobidClient(GrobidProperties grobidProperties) { /**
* Konštrukto, ktorý inicializuje WebClient pre komunikáciu s GROBID serverom
*
* @param grobidProperties Konfigurácia obsahujúca URL hostiteľa GROBID servera.
*/
public GrobidClient(GrobidProperties grobidProperties) {
this.webClient = WebClient.builder() this.webClient = WebClient.builder()
.baseUrl(grobidProperties.getHost()) // URL kde beží GROBID server .baseUrl(grobidProperties.getHost()) // URL kde beží GROBID server
.build(); .build();
} }
// get METADATA of the file /**
* Posiela požiadavku na server GROBID na spracovanie hlavičky PDF dokumentu.
* Metóda získa základné informácie o dokumente
* (názov dokumentu, autorov a ďalšie metadáta z hlavičky)
*
* @param pdfFile PDF súbor, ktorý sa má spracovať.
* @return JSON reťazec obsahujúci extrahované metadáta o dokumente.
* @throws RuntimeException ak nastane problém pri komunikácii so serverom GROBID alebo pri spracovaní odpovede.
*/
public String processHeader(File pdfFile){ // Mono - vráti jeden string, výsledok je JSON public String processHeader(File pdfFile){ // Mono - vráti jeden string, výsledok je JSON
try { try {
...@@ -59,18 +79,15 @@ public class GrobidClient { ...@@ -59,18 +79,15 @@ public class GrobidClient {
} }
} }
public String processFullMetadata(File pdfFile) {
return webClient.post()
.uri("/api/processFullMetadata")
.contentType(MediaType.MULTIPART_FORM_DATA)
.body(BodyInserters.fromMultipartData("input", new FileSystemResource(pdfFile)))
.retrieve()
.bodyToMono(String.class)
.block();
}
// spracuje REFERENCIE z PDF /**
* Posiela požiadavku na server GROBID
* na SPRACOVANIE REFERENCIÍ v PDF dokumente.
*
* @param pdfFile PDF súbor, ktorý sa má spracovať.
* @return JSON reťazec obsahujúci extrahované bibliografické referencie.
* @throws RuntimeException ak nastane problém pri komunikácii so serverom GROBID alebo pri spracovaní odpovede.
*/
public String processReferences(File pdfFile){ public String processReferences(File pdfFile){
try { try {
return webClient.post() return webClient.post()
......
...@@ -13,6 +13,7 @@ import com.dre0059.articleprocessor.model.Reference; ...@@ -13,6 +13,7 @@ import com.dre0059.articleprocessor.model.Reference;
import com.dre0059.articleprocessor.repository.AuthorRepository; import com.dre0059.articleprocessor.repository.AuthorRepository;
import com.dre0059.articleprocessor.repository.DocumentRepository; import com.dre0059.articleprocessor.repository.DocumentRepository;
import com.dre0059.articleprocessor.repository.ReferenceRepository; import com.dre0059.articleprocessor.repository.ReferenceRepository;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.w3c.dom.Document; import org.w3c.dom.Document;
...@@ -31,7 +32,17 @@ import java.util.HashMap; ...@@ -31,7 +32,17 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/**
*
* Trieda na extrahovanie a ukladanie referencií medzi dokumentmi.
* *
* Táto trieda :
* - spracováva XML dáta s referenciami (získané z GROBID servera)
* - vyhľadáva v databáze existujúce dokumenty a autorov
* - vytvára nové referencie medzi dokumentami
*/
@Service @Service
@Setter
public class ReferenceService { public class ReferenceService {
private final DocumentRepository documentRepository; private final DocumentRepository documentRepository;
...@@ -48,15 +59,31 @@ public class ReferenceService { ...@@ -48,15 +59,31 @@ public class ReferenceService {
this.referenceRepository = referenceRepository; this.referenceRepository = referenceRepository;
} }
/**
* Nastaví dokument, z ktorého sa cituje
(dokument v ktorom sa zoznam referencií nachádzal = PDF dokument)
*
* @param fromDocument Dokument, z ktorého sa referencuje
*/
public void setFromDocument(Dokument fromDocument) { public void setFromDocument(Dokument fromDocument) {
this.fromDocument = fromDocument; this.fromDocument = fromDocument;
System.out.println("From document: " + fromDocument.getTitle()); System.out.println("From document: " + fromDocument.getTitle());
} }
/**
* Nastaví dokument, na ktorý je citovaný
*
* @param doc Dokument, na ktorý sa referencuje
*/
public void setToDocument(Dokument doc){ public void setToDocument(Dokument doc){
this.toDocument = doc; this.toDocument = doc;
} }
/**
* Extrahuje referencie z XML TEI dokumentu a uloží ich do databázy.
*
* @param xmlTeiReferences XML reťazec obsahujúci referencie
*/
public void extractReferences(String xmlTeiReferences) { public void extractReferences(String xmlTeiReferences) {
List<Author> databaseAuthors = this.authorRepository.findAll(); List<Author> databaseAuthors = this.authorRepository.findAll();
Map<String, Author> authorMap = new HashMap<>(); Map<String, Author> authorMap = new HashMap<>();
...@@ -67,6 +94,7 @@ public class ReferenceService { ...@@ -67,6 +94,7 @@ public class ReferenceService {
} }
try { try {
// Vytvorenie DocumentBuilder pre načítanie XML dokumentu
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true); factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder(); DocumentBuilder builder = factory.newDocumentBuilder();
...@@ -74,10 +102,12 @@ public class ReferenceService { ...@@ -74,10 +102,12 @@ public class ReferenceService {
InputSource inputSource = new InputSource(new StringReader(xmlTeiReferences)); InputSource inputSource = new InputSource(new StringReader(xmlTeiReferences));
Document doc = builder.parse(inputSource); Document doc = builder.parse(inputSource);
// Nastavenie XPath pre vyhľadávanie v XML
XPathFactory xpathFactory = XPathFactory.newInstance(); XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath(); XPath xpath = xpathFactory.newXPath();
xpath.setNamespaceContext(new TEINamespaceContext()); xpath.setNamespaceContext(new TEINamespaceContext());
// Výber všetkých biblioštruktúr (referencií) v XML dokumente
NodeList biblNodes = (NodeList) xpath.evaluate("//tei:biblStruct", doc, XPathConstants.NODESET); NodeList biblNodes = (NodeList) xpath.evaluate("//tei:biblStruct", doc, XPathConstants.NODESET);
// for each reference // for each reference
...@@ -121,8 +151,10 @@ public class ReferenceService { ...@@ -121,8 +151,10 @@ public class ReferenceService {
String firstName = xpath.evaluate(".//tei:forename", authorNode); String firstName = xpath.evaluate(".//tei:forename", authorNode);
String lastName = xpath.evaluate(".//tei:surname", authorNode); String lastName = xpath.evaluate(".//tei:surname", authorNode);
// Vytvorenie kľúča pre autora
String authorKey = lastName.toLowerCase() + "," + firstName.toLowerCase(); String authorKey = lastName.toLowerCase() + "," + firstName.toLowerCase();
// Ak autor existuje v databáze, pridá sa do zoznamu, inak sa vytvorí nový
if (authorMap.containsKey(authorKey)) { if (authorMap.containsKey(authorKey)) {
authors.add(authorMap.get(authorKey)); authors.add(authorMap.get(authorKey));
System.out.println("Author: " + authorMap.get(authorKey) + " already exists in database."); System.out.println("Author: " + authorMap.get(authorKey) + " already exists in database.");
...@@ -135,15 +167,14 @@ public class ReferenceService { ...@@ -135,15 +167,14 @@ public class ReferenceService {
referencedDocument.setAuthors(authors); referencedDocument.setAuthors(authors);
List<String> authorLastNames= authors.stream().map(Author::getLastname).toList(); List<String> authorLastNames= authors.stream().map(Author::getLastname).toList();
// check if document exists in dbs
boolean exists = documentRepository.existsByTitleAndAuthorsIn(title, authorLastNames);
// check whether the document is already saved in DBS // check whether the document is already saved in DBS
boolean exists = documentRepository.existsByTitleAndAuthorsIn(title, authorLastNames);
if(exists){ if(exists){
System.out.println("Document with this title and authors already exist"); System.out.println("Document with this title and authors already exist");
// vyhľadaj dokument podľa TITLE alebo AUTORA a nastav ho ako toDokument // vyhľadaj dokument podľa TITLE alebo AUTORA a nastav ho ako toDokument
referencedDocument = documentRepository.findByTitleAndAuthorsIn(title, authorLastNames) referencedDocument = documentRepository.findByTitleAndAuthorsIn(title, authorLastNames)
.orElseThrow(() -> new IllegalStateException("Document should exist but was NOT FOUND.")); .orElseThrow(() -> new IllegalStateException("Document should exist but was NOT FOUND."));
...@@ -157,7 +188,8 @@ public class ReferenceService { ...@@ -157,7 +188,8 @@ public class ReferenceService {
this.authorRepository.saveAll(authors); this.authorRepository.saveAll(authors);
} }
Reference reference = new Reference(/*referenceID,*/ fromDocument, toDocument); // Vytvorenie a uloženie referencie
Reference reference = new Reference(fromDocument, toDocument);
// extract ID from the document // extract ID from the document
String referenceID = xpath.evaluate("@*[local-name()='id']", biblNode); String referenceID = xpath.evaluate("@*[local-name()='id']", biblNode);
......
...@@ -10,7 +10,19 @@ package com.dre0059.articleprocessor.service; ...@@ -10,7 +10,19 @@ package com.dre0059.articleprocessor.service;
import javax.xml.namespace.NamespaceContext; import javax.xml.namespace.NamespaceContext;
import java.util.Iterator; import java.util.Iterator;
/**
* Implementácia rozhrania NamespaceContext pre XPath dotazy na TEI XML dokumenty.
* *
* Táto trieda poskytuje správne názvové priestory pre XPath dotazy.
*/
public class TEINamespaceContext implements NamespaceContext { public class TEINamespaceContext implements NamespaceContext {
/**
* Kontroluje, či je prefix "tei"
*
* @param prefix prefix to check
* @return URL, ktoré je názvovým priestorom pre TEI (resp. null)
*/
@Override @Override
public String getNamespaceURI(String prefix) { public String getNamespaceURI(String prefix) {
if ("tei".equals(prefix)) { if ("tei".equals(prefix)) {
...@@ -19,6 +31,10 @@ public class TEINamespaceContext implements NamespaceContext { ...@@ -19,6 +31,10 @@ public class TEINamespaceContext implements NamespaceContext {
return null; return null;
} }
/**
* povinné metódy z rozhrania
* nevyužívame tieto dve metódy
*/
@Override @Override
public String getPrefix(String namespaceURI) { return null; } public String getPrefix(String namespaceURI) { return null; }
@Override @Override
......
<!--
Autor: Eliška Kozáčiková
Škola: VŠB-TUO
Fakulta: Fakulta Elektrotechniky a informatiky
Dátum: 30.04.2025
Tento HTML dokument obsahuje informácie o projekte
-->
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"> <html lang="en" xmlns:th="http://www.thymeleaf.org">
<head> <head>
......
<!DOCTYPE html> <!--
Autor: Eliška Kozáčiková
Škola: VŠB-TUO
Fakulta: Fakulta Elektrotechniky a informatiky
Dátum: 30.04.2025
Tento HTML dokument zobrazuje graf dokumentu a jeho refrencií.
-->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"> <html xmlns:th="http://www.thymeleaf.org">
<head> <head>
<!-- zobrazuje graf článku na /statistics/citation-timeline?documentId={id} --> <!-- zobrazuje graf článku na /statistics/citation-timeline?documentId={id} -->
......
<!--
Autor: Eliška Kozáčiková
Škola: VŠB-TUO
Fakulta: Fakulta Elektrotechniky a informatiky
Dátum: 30.04.2025
Tento HTML dokument zobrazuje graf viacerých dokumentov a ich cítácií
-->
<!DOCTYPE html> <!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"> <html xmlns:th="http://www.thymeleaf.org">
<head> <head>
......
<!--
Autor: Eliška Kozáčiková
Škola: VŠB-TUO
Fakulta: Fakulta Elektrotechniky a informatiky
Dátum: 30.04.2025
Tento HTML dokument obsahuje všetobecné štatistiky o dokumentoch v celej aplikácii
-->
<!DOCTYPE html> <!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"> <html xmlns:th="http://www.thymeleaf.org">
<head> <head>
......
<!--
Autor: Eliška Kozáčiková
Škola: VŠB-TUO
Fakulta: Fakulta Elektrotechniky a informatiky
Dátum: 30.04.2025
Tento HTML dokument zobrazuje úvodnú stránku,
umožňuje užívateľovi nahrať PDF dokument,
priradiť mu kategóriu a tagy a odoslať ho na spracovanie
-->
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"> <html lang="en" xmlns:th="http://www.thymeleaf.org">
<head> <head>
......
<!--
Autor: Eliška Kozáčiková
Škola: VŠB-TUO
Fakulta: Fakulta Elektrotechniky a informatiky
Dátum: 30.04.2025
Tento HTML dokument zobrazuje zoznam všetkých existujúcich článkov v databáze
-->
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"> <html lang="en" xmlns:th="http://www.thymeleaf.org">
<head> <head>
......
<!--
Autor: Eliška Kozáčiková
Škola: VŠB-TUO
Fakulta: Fakulta Elektrotechniky a informatiky
Dátum: 30.04.2025
Tento HTML dokument zobrazuje jeden článok, informácie o ňom a zoznam jeho referencií
(referencie sú klikateľné odkazy na iné články v DBS)
-->
<!DOCTYPE html> <!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"> <html xmlns:th="http://www.thymeleaf.org">
<head> <head>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment