class UserProfile: def __init__(self): self.reading_history = [] self.category_preferences = {} self.reading_time_pattern = {} self.favorite_authors = set() self.book_ratings = {} self.bookmarks = set() def update_book_rating(self, book_id, rating): """更新书籍评分""" self.book_ratings[book_id] = rating def add_bookmark(self, book_id): """添加书签""" self.bookmarks.add(book_id) def update_reading_history(self, reading_record): """更新阅读历史""" self.reading_history.append(reading_record) def update_preferences(self, reading_record): """更新用户阅读偏好""" category = reading_record['category'] self.category_preferences[category] = \ self.category_preferences.get(category, 0) + 1 self.favorite_authors.add(reading_record['author'])