hafez 0.2.9__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hafez
3
- Version: 0.2.9
3
+ Version: 0.4.0
4
4
  Summary: Hafez Poems
5
5
  Author-email: Kaveh Bakhtiyari <kbakhtiyari@yahoo.com>
6
6
  Project-URL: Homepage, https://github.com/kavehbc/hafez
@@ -65,11 +65,12 @@ It returns the poem in a dictionary format (see Poem Data Structure)
65
65
  It returns a random poem in a dictionary format (see Poem Data Structure)
66
66
 
67
67
 
68
- - `hafez.search(qeury: str)` -> `list`
68
+ - `hafez.search(qeury: str, exact_match: bool = False)` -> `list`
69
69
  <br />
70
70
  It returns a list of poems in a dictionary format (see Poem Data Structure)
71
71
 
72
72
  - `query: str`: It is a string to search within the verses of the Divan Hafez
73
+ - `exact_match: bool': if True, it will search for exact match of the query
73
74
 
74
75
 
75
76
  - `hafez.download_all_audio(force: boolean = False)` -> `int`
@@ -99,6 +100,7 @@ It returns the absolute path of the audio file related to the given `poem`.
99
100
  {"id": 1,
100
101
  "poem": [],
101
102
  "interpretation": "",
103
+ "alt_interpretation": "",
102
104
  "mp3": "https://..."}
103
105
  ```
104
106
 
@@ -50,11 +50,12 @@ It returns the poem in a dictionary format (see Poem Data Structure)
50
50
  It returns a random poem in a dictionary format (see Poem Data Structure)
51
51
 
52
52
 
53
- - `hafez.search(qeury: str)` -> `list`
53
+ - `hafez.search(qeury: str, exact_match: bool = False)` -> `list`
54
54
  <br />
55
55
  It returns a list of poems in a dictionary format (see Poem Data Structure)
56
56
 
57
57
  - `query: str`: It is a string to search within the verses of the Divan Hafez
58
+ - `exact_match: bool': if True, it will search for exact match of the query
58
59
 
59
60
 
60
61
  - `hafez.download_all_audio(force: boolean = False)` -> `int`
@@ -84,6 +85,7 @@ It returns the absolute path of the audio file related to the given `poem`.
84
85
  {"id": 1,
85
86
  "poem": [],
86
87
  "interpretation": "",
88
+ "alt_interpretation": "",
87
89
  "mp3": "https://..."}
88
90
  ```
89
91
 
@@ -103,13 +103,14 @@ def get_poem(poem_id) -> dict:
103
103
  return lst_poem[0]
104
104
 
105
105
 
106
- def search(query) -> list:
106
+ def search(query: str=None, exact_match: bool = False) -> list:
107
107
  """
108
108
  It searches through the verses of Divan and once a record found, it returns the whole poem.
109
109
  :param query: the string term to query into Divan
110
+ :param exact_match: if True, it will search for exact match of the query
110
111
  :return: a list of dictionary containing all the poems which have the queried terms
111
112
  """
112
- df = search_data(query)
113
+ df = search_data(query, exact_match=exact_match)
113
114
  df = filter_columns(df)
114
115
  lst_poem = df_to_dict(df)
115
116
 
@@ -1,4 +1,5 @@
1
1
  import pandas as pd
2
+ import numpy as np
2
3
  import pathlib
3
4
  import os
4
5
  import json
@@ -27,15 +28,30 @@ def get_data(id: int = None):
27
28
  return df
28
29
 
29
30
 
30
- def search_data(query: str = None):
31
+ def search_data(query: str = None, exact_match: bool = False) -> pd.DataFrame:
32
+ query = query.strip()
31
33
 
32
34
  _, df = get_connection()
33
35
  df['poem_string'] = [','.join(map(str, l)) for l in df['poem']]
34
36
 
35
37
  if query is not None and len(query) > 0:
36
- lst_query = query.split(" ")
37
- df = df[df["poem_string"].str.contains('|'.join(lst_query))]
38
-
38
+ if exact_match:
39
+ lst_query = [query]
40
+ else:
41
+ # Split the query into words for searching
42
+ if " " in query:
43
+ lst_query = query.split(" ")
44
+ else:
45
+ lst_query = [query]
46
+
47
+ # AND Logic
48
+ contains = [df["poem_string"].str.contains(i) for i in lst_query]
49
+ df = df[np.all(contains, axis=0)]
50
+
51
+ # OR Logic
52
+ # df = df[df["poem_string"].str.contains('|'.join(lst_query))]
53
+
54
+ df.drop(columns=["poem_string"], inplace=True, axis=1)
39
55
  return df
40
56
 
41
57
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hafez
3
- Version: 0.2.9
3
+ Version: 0.4.0
4
4
  Summary: Hafez Poems
5
5
  Author-email: Kaveh Bakhtiyari <kbakhtiyari@yahoo.com>
6
6
  Project-URL: Homepage, https://github.com/kavehbc/hafez
@@ -65,11 +65,12 @@ It returns the poem in a dictionary format (see Poem Data Structure)
65
65
  It returns a random poem in a dictionary format (see Poem Data Structure)
66
66
 
67
67
 
68
- - `hafez.search(qeury: str)` -> `list`
68
+ - `hafez.search(qeury: str, exact_match: bool = False)` -> `list`
69
69
  <br />
70
70
  It returns a list of poems in a dictionary format (see Poem Data Structure)
71
71
 
72
72
  - `query: str`: It is a string to search within the verses of the Divan Hafez
73
+ - `exact_match: bool': if True, it will search for exact match of the query
73
74
 
74
75
 
75
76
  - `hafez.download_all_audio(force: boolean = False)` -> `int`
@@ -99,6 +100,7 @@ It returns the absolute path of the audio file related to the given `poem`.
99
100
  {"id": 1,
100
101
  "poem": [],
101
102
  "interpretation": "",
103
+ "alt_interpretation": "",
102
104
  "mp3": "https://..."}
103
105
  ```
104
106
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "hafez"
3
- version = "0.2.9"
3
+ version = "0.4.0"
4
4
  authors = [
5
5
  { name = "Kaveh Bakhtiyari", email = "kbakhtiyari@yahoo.com" },
6
6
  ]
@@ -0,0 +1,4 @@
1
+ pandas>=1.5.3
2
+ numpy>=1.23.5
3
+ requests~=2.31.0
4
+ setuptools~=68.2.2
@@ -1,3 +0,0 @@
1
- pandas>=1.5.3
2
- requests~=2.31.0
3
- setuptools~=68.2.2
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes