1
Fork 0
mirror of https://github.com/Steffo99/unimore-bda-6.git synced 2024-11-25 17:24:20 +00:00

Convert DataTuple to a collections.namedtuple

This commit is contained in:
Steffo 2023-02-04 05:16:54 +01:00
parent e6dcf6e423
commit 4f24d399b8
Signed by: steffo
GPG key ID: 2A24051445686895

View file

@ -5,6 +5,7 @@ import contextlib
import bson import bson
import logging import logging
import itertools import itertools
import collections
from .config import MONGO_HOST, MONGO_PORT, WORKING_SET_SIZE from .config import MONGO_HOST, MONGO_PORT, WORKING_SET_SIZE
@ -26,7 +27,7 @@ class Review(t.TypedDict):
Text = str Text = str
Category = str Category = str
DataTuple = tuple[Text, Category] DataTuple = collections.namedtuple("DataTuple", ["text", "category"])
DataSet = t.Iterable[DataTuple] DataSet = t.Iterable[DataTuple]
@ -86,7 +87,7 @@ def sample_reviews_by_rating(reviews: pymongo.collection.Collection, rating: flo
]) ])
def review_to_datatuple(review: Review) -> tuple[Text, Category]: def review_to_datatuple(review: Review) -> DataTuple:
""" """
Return the label corresponding to the given review. Return the label corresponding to the given review.
@ -116,7 +117,7 @@ def review_to_datatuple(review: Review) -> tuple[Text, Category]:
case _: case _:
category = "unknown" category = "unknown"
return text, category return DataTuple(text, category)
def polar_dataset(collection: pymongo.collection.Collection, amount: int) -> t.Iterator[DataTuple]: def polar_dataset(collection: pymongo.collection.Collection, amount: int) -> t.Iterator[DataTuple]: