Skip to content

Commit

Permalink
adds paper and volume SQLmodel
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Mar 17, 2024
1 parent c96ad3b commit 830c8e3
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
68 changes: 68 additions & 0 deletions ceurws/models/ceur.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
Created on 2024-03-17
CEUR Workshop Proceedings (CEUR-WS.org)
Metamodel
@author: wf
"""
from sqlmodel import SQLModel, Field
from typing import Optional
from datetime import datetime, date

class Volume(SQLModel, table=True):
"""
a single CEUR-WS Volume
"""
__tablename__ = "volumes"

fromLine: Optional[int] = Field(default=None)
toLine: Optional[int] = Field(default=None)
valid: Optional[int] = Field(default=None)
url: Optional[str] = Field(default=None)
acronym: Optional[str] = Field(default=None)
title: Optional[str] = Field(default=None)
seealso: Optional[str] = Field(default=None)
editors: Optional[str] = Field(default=None)
submittedBy: Optional[str] = Field(default=None)
published: Optional[str] = Field(default=None)
pubDate: Optional[datetime] = Field(default=None)
number: int = Field(primary_key=True)
archive: Optional[str] = Field(default=None)
desc: Optional[str] = Field(alias="description", default=None) # 'desc' is a SQL keyword, so it's aliased
h1: Optional[str] = Field(default=None)
h3: Optional[str] = Field(default=None)
volname: Optional[str] = Field(default=None)
homepage: Optional[str] = Field(default=None)
year: Optional[str] = Field(default=None)
urn: Optional[str] = Field(default=None)
vol_number: Optional[int] = Field(default=None)
loctime: Optional[str] = Field(default=None)
volume_number: Optional[str] = Field(default=None)
voltitle: Optional[str] = Field(default=None)
dateFrom: Optional[date] = Field(default=None)
dateTo: Optional[date] = Field(default=None)
city: Optional[str] = Field(default=None)
cityWikidataId: Optional[str] = Field(default=None)
country: Optional[str] = Field(default=None)
countryWikidataId: Optional[str] = Field(default=None)
urn_check_digit: Optional[int] = Field(default=None)
urn_ok: Optional[int] = Field(default=None)
ceurpubdate: Optional[str] = Field(default=None)
colocated: Optional[str] = Field(default=None)
virtualEvent: Optional[int] = Field(default=None)
tdtitle: Optional[str] = Field(default=None)

class Paper(SQLModel, table=True):
"""
Represents a paper with details such as authors, volume number, and title.
"""
__tablename__ = "papers"
authors: Optional[str] = Field(default=None, index=False)
vol_number: Optional[int] = Field(default=None, index=True)
pdf_name: Optional[str] = Field(default=None, index=False)
id: str = Field(primary_key=True)
title: Optional[str] = Field(default=None, index=False)
pages: Optional[str] = Field(default=None, index=False)
fail: Optional[str] = Field(default=None, index=False)

37 changes: 37 additions & 0 deletions tests/test_ceur.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
Created on 2024-03-17
@author: wf
"""
from tests.basetest import Basetest
from ceurws.models.ceur import Volume, Paper
from ceurws.cache import SqlDB
from ceurws.ceur_ws import CEURWS
from sqlmodel import SQLModel, Session, create_engine, Field, select # Added 'select' here

class TestCEUR(Basetest):
"""
tests CEUR-WS SQLmodel data caching
"""

def setUp(self, debug=True, profile=True):
Basetest.setUp(self, debug=debug, profile=profile)
self.sql_db = SqlDB(CEURWS.CACHE_FILE, debug=False)

def testCEUR(self):
"""
test CEUR tables
"""
for clazz in Paper, Volume:
entity_plural_name=clazz.__tablename__
clazz.metadata.create_all(self.sql_db.engine)
# Attempt to read volumes from the database.
with self.sql_db.get_session() as session:
instances = session.exec(select(clazz)).all()

# You can replace this assertion with more specific tests as needed.
self.assertIsNotNone(instances, f"Failed to retrieve {entity_plural_name} from the database")
if self.debug:
print(f"Retrieved {len(instances)} {entity_plural_name} from the database")


0 comments on commit 830c8e3

Please sign in to comment.