Compare commits

...

2 Commits

Author SHA1 Message Date
Brett 41cad0931a no idea if this works 2025-07-01 15:44:07 -04:00
Brett 56cfe626d7 topics 2025-07-01 15:27:48 -04:00
2 changed files with 23 additions and 17 deletions

View File

@ -258,11 +258,12 @@ async def handle_article_url(message: discord.Message, url: str) -> None:
for i, x in enumerate(paragraph_relevance):
paragraph_relevance[i] = int(x)
await article_repository.set_paragraphs(url, paragraphs, summary, paragraph_relevance, keywords, paragraph_restitutions)
average_relevance = (sum(int(x) for x in paragraph_relevance) / len(paragraph_relevance) + sum(paragraph_keypoints)) / 2
median_relevance = sorted(int(ref) for ref in paragraph_relevance)[len(paragraph_relevance) // 2]
median_relevance2 = sorted(paragraph_keypoints)[len(paragraph_keypoints) // 2]
relevance_cutoff = min(average_relevance, (median_relevance + median_relevance2) / 2)
LOGGER.info(f"Relevance cutoff: {relevance_cutoff} From ({average_relevance}, {(median_relevance + median_relevance2) / 2})")

View File

@ -185,15 +185,21 @@ class ArticleRepository:
rows = cur.execute(f"""
INSERT INTO topics (article_id, topic_text, type)
VALUES ({self.cursor_type}, {self.cursor_type}, {self.cursor_type})
RETURNING id;
""", (article_id, summary, "summary"))
summary_id = rows.fetchone()[0]
cur.execute(f"""
INSERT INTO topic_ratings (paragraph_id, topic_id, rating)
""")
topic_ids = []
for topic in topics:
rows = cur.execute(f"""
INSERT INTO topics (article_id, topic_text, type)
VALUES ({self.cursor_type}, {self.cursor_type}, {self.cursor_type})
RETURNING id;
""", (article_id, topic, "keypoint"))
topic_ids.append(rows.fetchone()[0])
for paragraph in paragraphs:
for paragraph, summary_rating, gel in zip(paragraphs, summary_ratings, topic_ratings):
rows = cur.execute(f"""
INSERT INTO paragraphs (article_id, paragraph_text)
VALUES ({self.cursor_type}, {self.cursor_type})
@ -201,13 +207,16 @@ class ArticleRepository:
""", (article_id, paragraph))
paragraph_id = rows.fetchone()[0]
for topic, rating in zip(topics, topic_ratings):
cur.execute(f"""
INSERT INTO topic_ratings (paragraph_id, topic_id, rating) VALUES ({self.cursor_type}, {self.cursor_type}, {self.cursor_type})
""", (paragraph_id, summary_id, float(summary_rating)))
for topic_id, rating in zip(topic_ids, gel):
self._conn.execute(f"""
INSERT INTO paragraph_topic_ratings (paragraph_id, topic_id, rating)
INSERT INTO topic_ratings (paragraph_id, topic_id, rating)
VALUES ({self.cursor_type}, {self.cursor_type}, {self.cursor_type})
""", (paragraph_id, topic, rating))
""", (paragraph_id, topic_id, rating))
self._conn.commit()
@ -250,16 +259,12 @@ class ArticleRepository:
foreign key (article_id) references articles(id)
);
CREATE TABLE IF NOT EXISTS topic_ratings (
article_id INTEGER,
paragraph_id INTEGER,
topic_id INTEGER NOT NULL,
rating INTEGER NOT NULL,
primary key (paragraph_id, topic_id, article_id),
unique (topic_id),
rating FLOAT NOT NULL,
primary key (paragraph_id, topic_id),
foreign key (paragraph_id) references paragraphs(id),
foreign key (topic_id) references topics(id),
CHECK ((article_id IS NOT NULL AND paragraph_id IS NULL)
OR (article_id IS NULL AND paragraph_id IS NOT NULL))
foreign key (topic_id) references topics(id)
)
"""
)