unijoh commited on
Commit
4095e7a
·
verified ·
1 Parent(s): 413b7fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -23
app.py CHANGED
@@ -16,6 +16,7 @@ def load_data():
16
  lemmas[current_lemma] = []
17
  else:
18
  lemma_data = {
 
19
  'PPOS': row['#PPOS'].replace("PPOS:", "") if pd.notna(row['#PPOS']) else "",
20
  'PHON1': row['#PHON1'].replace("PHON:", "") if pd.notna(row['#PHON1']) else "",
21
  'PHON2': row['#PHON2'].replace("PHON:", "") if pd.notna(row['#PHON2']) else "",
@@ -28,6 +29,22 @@ def load_data():
28
  lemmas = load_data()
29
 
30
  def create_noun_table(lemma, forms):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  table = f"""
32
  <table border="1">
33
  <thead>
@@ -44,28 +61,28 @@ def create_noun_table(lemma, forms):
44
  </thead>
45
  <tbody>
46
  <tr>
47
- <td>{forms.get('Nsns', '')}</td>
48
- <td>{forms.get('Nsnst', '')}</td>
49
- <td>{forms.get('Npns', '')}</td>
50
- <td>{forms.get('Npnst', '')}</td>
51
  </tr>
52
  <tr>
53
- <td>{forms.get('Nsas', '')}</td>
54
- <td>{forms.get('Nsast', '')}</td>
55
- <td>{forms.get('Npas', '')}</td>
56
- <td>{forms.get('Npast', '')}</td>
57
  </tr>
58
  <tr>
59
- <td>{forms.get('Nsds', '')}</td>
60
- <td>{forms.get('Nsdst', '')}</td>
61
- <td>{forms.get('Npds', '')}</td>
62
- <td>{forms.get('Npdt', '')}</td>
63
  </tr>
64
  <tr>
65
- <td>{forms.get('Nsgs', '')}</td>
66
- <td>{forms.get('Nsgst', '')}</td>
67
- <td>{forms.get('Npgs', '')}</td>
68
- <td>{forms.get('Npgst', '')}</td>
69
  </tr>
70
  </tbody>
71
  </table>
@@ -77,14 +94,8 @@ def search_lemma(lemma):
77
  if not results:
78
  return f"No results found for {lemma}"
79
 
80
- forms = {}
81
- for result in results:
82
- ppos = result['PPOS']
83
- key = ppos[1:5] # Extracting relevant part of PPOS
84
- forms[key] = result['PPOS']
85
-
86
  if 'N' in results[0]['PPOS']:
87
- table = create_noun_table(lemma, forms)
88
  else:
89
  table = "Only noun tables are currently supported."
90
 
 
16
  lemmas[current_lemma] = []
17
  else:
18
  lemma_data = {
19
+ 'word': row['#ORTO'].replace("ORTO:", "") if pd.notna(row['#ORTO']) else "",
20
  'PPOS': row['#PPOS'].replace("PPOS:", "") if pd.notna(row['#PPOS']) else "",
21
  'PHON1': row['#PHON1'].replace("PHON:", "") if pd.notna(row['#PHON1']) else "",
22
  'PHON2': row['#PHON2'].replace("PHON:", "") if pd.notna(row['#PHON2']) else "",
 
29
  lemmas = load_data()
30
 
31
  def create_noun_table(lemma, forms):
32
+ # Initialize the table structure
33
+ table_data = {
34
+ 'Nsns': '', 'Nsnst': '', 'Nsas': '', 'Nsast': '',
35
+ 'Nsds': '', 'Nsdst': '', 'Nsgs': '', 'Nsgst': '',
36
+ 'Npns': '', 'Npnst': '', 'Npas': '', 'Npast': '',
37
+ 'Npds': '', 'Npdt': '', 'Npgs': '', 'Npgst': ''
38
+ }
39
+
40
+ # Fill the table data based on PPOS
41
+ for form in forms:
42
+ ppos = form['PPOS']
43
+ word = form['word']
44
+ if ppos[1:5] in table_data:
45
+ table_data[ppos[1:5]] = word
46
+
47
+ # Create the HTML table
48
  table = f"""
49
  <table border="1">
50
  <thead>
 
61
  </thead>
62
  <tbody>
63
  <tr>
64
+ <td>{table_data['Nsns']}</td>
65
+ <td>{table_data['Nsnst']}</td>
66
+ <td>{table_data['Npns']}</td>
67
+ <td>{table_data['Npnst']}</td>
68
  </tr>
69
  <tr>
70
+ <td>{table_data['Nsas']}</td>
71
+ <td>{table_data['Nsast']}</td>
72
+ <td>{table_data['Npas']}</td>
73
+ <td>{table_data['Npast']}</td>
74
  </tr>
75
  <tr>
76
+ <td>{table_data['Nsds']}</td>
77
+ <td>{table_data['Nsdst']}</td>
78
+ <td>{table_data['Npds']}</td>
79
+ <td>{table_data['Npdt']}</td>
80
  </tr>
81
  <tr>
82
+ <td>{table_data['Nsgs']}</td>
83
+ <td>{table_data['Nsgst']}</td>
84
+ <td>{table_data['Npgs']}</td>
85
+ <td>{table_data['Npgst']}</td>
86
  </tr>
87
  </tbody>
88
  </table>
 
94
  if not results:
95
  return f"No results found for {lemma}"
96
 
 
 
 
 
 
 
97
  if 'N' in results[0]['PPOS']:
98
+ table = create_noun_table(lemma, results)
99
  else:
100
  table = "Only noun tables are currently supported."
101