FDSRashid commited on
Commit
5d223db
·
verified ·
1 Parent(s): 9d719dc

added book and author information to Taraf

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -40,20 +40,27 @@ matn_info['taraf_ID'] = matn_info['taraf_ID'].replace('KeyAbsent', -1)
40
 
41
 
42
  matn_info['taraf_ID'] = matn_info['taraf_ID'].astype(int)
43
- matn_info = matn_info.sort_values('taraf_ID')
44
- tarafs = matn_info['taraf_ID'].unique()
45
- for i, taraf in enumerate(tarafs):
46
- matn_info.loc[matn_info['taraf_ID'] == taraf, 'taraf_ID_New'] = i + 1 # Replace 'a' with 'e' in column 'C' where the condition is met
47
- matn_info['taraf_ID_New'] = matn_info['taraf_ID_New'].astype(int)
48
 
49
 
50
 
51
  isnad_info = load_dataset('FDSRashid/hadith_info',token = Secret_token, data_files = 'isnad_info.csv', split = 'train').to_pandas()
52
  isnad_info['Hadiths Cleaned'] = isnad_info['Hadiths'].apply(lambda x: [re.findall(pattern, string)[0].split("_") for string in x[1:-1].split(',')])
53
 
54
- taraf_max = np.max(matn_info['taraf_ID_New'].unique())
55
 
56
  cmap = plt.colormaps['cool']
 
 
 
 
 
 
 
57
  def value_to_hex(value):
58
  rgba_color = cmap(value)
59
  return "#{:02X}{:02X}{:02X}".format(int(rgba_color[0] * 255), int(rgba_color[1] * 255), int(rgba_color[2] * 255))
@@ -61,9 +68,12 @@ def value_to_hex(value):
61
  #edge_info, matn_info, narrator_bios, isnad_info
62
 
63
  def visualize_isnad(taraf_num, yaxis):
64
- taraf_hadith = matn_info[matn_info['taraf_ID_New'] == taraf_num]['bookid_hadithid'].to_list()
65
- taraf_matns = matn_info[matn_info['taraf_ID_New'] == taraf_num]['matn'].to_list()
66
  taraf_hadith_split = [i.split('_') for i in taraf_hadith]
 
 
 
67
  lst_hadith = []
68
  for i in range(len(taraf_hadith_split)):
69
  isnad_in_hadith1 = isnad_info['Hadiths Cleaned'].apply(lambda x: taraf_hadith_split[i] in x )
@@ -72,7 +82,7 @@ def visualize_isnad(taraf_num, yaxis):
72
  node = [int(n) for n, d in G.out_degree() if d == 0][0]
73
  gen_node = narrator_bios[narrator_bios['Rawi ID']==node]['Generation'].iloc[0]
74
  name_node = narrator_bios[narrator_bios['Rawi ID']==node]['Famous Name'].iloc[0]
75
- lst_hadith.append([taraf_matns[i], gen_node, name_node])
76
  df = pd.DataFrame(lst_hadith, columns = ['Matn', 'Generation', 'Name'])
77
 
78
  hadith_cleaned = isnad_info['Hadiths Cleaned'].apply(lambda x: any(i in x for i in taraf_hadith_split) )
 
40
 
41
 
42
  matn_info['taraf_ID'] = matn_info['taraf_ID'].astype(int)
43
+ # matn_info = matn_info.sort_values('taraf_ID')
44
+ # tarafs = matn_info['taraf_ID'].unique()
45
+ # for i, taraf in enumerate(tarafs):
46
+ # matn_info.loc[matn_info['taraf_ID'] == taraf, 'taraf_ID_New'] = i + 1 # Replace 'a' with 'e' in column 'C' where the condition is met
47
+ # matn_info['taraf_ID_New'] = matn_info['taraf_ID_New'].astype(int)
48
 
49
 
50
 
51
  isnad_info = load_dataset('FDSRashid/hadith_info',token = Secret_token, data_files = 'isnad_info.csv', split = 'train').to_pandas()
52
  isnad_info['Hadiths Cleaned'] = isnad_info['Hadiths'].apply(lambda x: [re.findall(pattern, string)[0].split("_") for string in x[1:-1].split(',')])
53
 
54
+ taraf_max = np.max(matn_info['taraf_ID'].unique())
55
 
56
  cmap = plt.colormaps['cool']
57
+
58
+ books = load_dataset('FDSRashid/Hadith_info', data_files='Books.csv', token = Secret_token)['train'].to_pandas()
59
+
60
+ matn_info['Book'] = matn_info['bookid_hadithid'].apply(lambda x: books[books['Book_ID'] == int(x.split('_')[0])]['Book_Name'].to_list()[0])
61
+ matn_info['Author'] = matn_info['bookid_hadithid'].apply(lambda x: books[books['Book_ID'] == int(x.split('_')[0])]['Author'].to_list()[0])
62
+ matn_info['Hadith Number'] = matn_info['bookid_hadithid'].apply(lambda x: x.split('_')[1])
63
+
64
  def value_to_hex(value):
65
  rgba_color = cmap(value)
66
  return "#{:02X}{:02X}{:02X}".format(int(rgba_color[0] * 255), int(rgba_color[1] * 255), int(rgba_color[2] * 255))
 
68
  #edge_info, matn_info, narrator_bios, isnad_info
69
 
70
  def visualize_isnad(taraf_num, yaxis):
71
+ taraf_hadith = matn_info[matn_info['taraf_ID'] == taraf_num]['bookid_hadithid'].to_list()
72
+ taraf_matns = matn_info[matn_info['taraf_ID'] == taraf_num]['matn'].to_list()
73
  taraf_hadith_split = [i.split('_') for i in taraf_hadith]
74
+ taraf_book = matn_info[matn_info['taraf_ID'] == taraf_num]['Book'].to_list()
75
+ taraf_author = matn_info[matn_info['taraf_ID'] == taraf_num]['Author'].to_list()
76
+ taraf_hadith_number = taraf_book = matn_info[matn_info['taraf_ID'] == taraf_num]['Hadith Number'].to_list()
77
  lst_hadith = []
78
  for i in range(len(taraf_hadith_split)):
79
  isnad_in_hadith1 = isnad_info['Hadiths Cleaned'].apply(lambda x: taraf_hadith_split[i] in x )
 
82
  node = [int(n) for n, d in G.out_degree() if d == 0][0]
83
  gen_node = narrator_bios[narrator_bios['Rawi ID']==node]['Generation'].iloc[0]
84
  name_node = narrator_bios[narrator_bios['Rawi ID']==node]['Famous Name'].iloc[0]
85
+ lst_hadith.append([taraf_matns[i], gen_node, name_node, taraf_book[i], taraf_author[i], taraf_hadith_number[i]])
86
  df = pd.DataFrame(lst_hadith, columns = ['Matn', 'Generation', 'Name'])
87
 
88
  hadith_cleaned = isnad_info['Hadiths Cleaned'].apply(lambda x: any(i in x for i in taraf_hadith_split) )