Compare commits

..

No commits in common. "41cad0931a0ce52be13db56894123907bdd9aa14" and "fc922fec4d85bfe314c0ae4f2b2732b81be72b49" have entirely different histories.

2 changed files with 17 additions and 23 deletions

View File

@ -258,12 +258,11 @@ 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,21 +185,15 @@ 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, summary_rating, gel in zip(paragraphs, summary_ratings, topic_ratings):
for paragraph in paragraphs:
rows = cur.execute(f"""
INSERT INTO paragraphs (article_id, paragraph_text)
VALUES ({self.cursor_type}, {self.cursor_type})
@ -207,16 +201,13 @@ class ArticleRepository:
""", (article_id, paragraph))
paragraph_id = rows.fetchone()[0]
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):
for topic, rating in zip(topics, topic_ratings):
self._conn.execute(f"""
INSERT INTO topic_ratings (paragraph_id, topic_id, rating)
INSERT INTO paragraph_topic_ratings (paragraph_id, topic_id, rating)
VALUES ({self.cursor_type}, {self.cursor_type}, {self.cursor_type})
""", (paragraph_id, topic_id, rating))
""", (paragraph_id, topic, rating))
self._conn.commit()
@ -259,12 +250,16 @@ 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 FLOAT NOT NULL,
primary key (paragraph_id, topic_id),
rating INTEGER NOT NULL,
primary key (paragraph_id, topic_id, article_id),
unique (topic_id),
foreign key (paragraph_id) references paragraphs(id),
foreign key (topic_id) references topics(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))
)
"""
)