-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBook.py
41 lines (33 loc) · 1.15 KB
/
Book.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from Vectorizer import Vectorizer
class Book:
"""Represents a book entity with title, author, genre, and a vectorized representation."""
def __init__(self, title, author, genre):
"""
Initialize a Book object.
:param title: The title of the book.
:type title: str
:param author: The author of the book.
:type author: str
:param genre: The genre of the book.
:type genre: str
"""
self.title = title
self.author = author
self.genre = genre
self.vector = Vectorizer()
# Combine book parameters into a single string
combined_info = f"{title} {author} {genre}"
# Vectorize the combined string
self.vector = self.vector.vectorize(combined_info)
def to_dict(self):
"""
Convert the book entity to a dictionary suitable for indexing in Elasticsearch.
:return: A dictionary representing the book entity.
:rtype: dict
"""
return {
"title": self.title,
"author": self.author,
"genre": self.genre,
"vector": self.vector.tolist()
}