unijoh commited on
Commit
5e8c89b
·
verified ·
1 Parent(s): fdcf728

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -13
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  import pandas as pd
 
3
 
4
  # Load and parse the CSV file from Hugging Face
5
  def load_data():
@@ -34,26 +35,37 @@ def load_data():
34
 
35
  lemmas = load_data()
36
 
 
 
 
 
 
 
 
 
 
 
37
  def create_noun_table(lemma, forms):
38
  table_data = {
39
- 'ncmsn==iuu': '', 'ncmsn==duu': '', 'ncfsn==iuu': '', 'ncfsn==duu': '', 'ncnsn==iuu': '', 'ncnsn==duu': '',
40
- 'ncmsa==iuu': '', 'ncmsa==duu': '', 'ncfsa==iuu': '', 'ncfsa==duu': '', 'ncnsa==iuu': '', 'ncnsa==duu': '',
41
- 'ncmsd==iuu': '', 'ncmsd==duu': '', 'ncfsd==iuu': '', 'ncfsd==duu': '', 'ncnsd==iuu': '', 'ncnsd==duu': '',
42
- 'ncmsg==iou': '', 'ncmsg==dou': '', 'ncfsg==iou': '', 'ncfsg==dou': '', 'ncnsg==iou': '', 'ncnsg==dou': '',
43
- 'ncmpn==iuu': '', 'ncmpn==duu': '', 'ncfnn==iuu': '', 'ncfnn==duu': '', 'ncnnn==iuu': '', 'ncnnn==duu': '',
44
- 'ncmpa==iuu': '', 'ncmpa==duu': '', 'ncfna==iuu': '', 'ncfna==duu': '', 'ncnna==iuu': '', 'ncnna==duu': '',
45
- 'ncmpd==iuu': '', 'ncmpd==duu': '', 'ncfnn==iuu': '', 'ncfnn==duu': '', 'ncnnn==iuu': '', 'ncnnn==duu': '',
46
- 'ncmpg==iou': '', 'ncmpg==dou': '', 'ncfnn==iou': '', 'ncfnn==dou': '', 'ncnnn==iou': '', 'ncnnn==dou': ''
47
  }
48
 
49
  for form in forms:
50
  ppos = form['PPOS'].lower() # Normalize to lowercase
51
  word = form['word']
52
- key = ppos # Use full PPOS for the key
53
- if key in table_data:
54
- table_data[key] = word
55
- else:
56
- print(f"Unmatched key: {key} for word: {word} with PPOS: {ppos}")
 
 
57
 
58
  print(f"Final table data for {lemma}: {table_data}") # Debugging output
59
 
 
1
  import gradio as gr
2
  import pandas as pd
3
+ import re
4
 
5
  # Load and parse the CSV file from Hugging Face
6
  def load_data():
 
35
 
36
  lemmas = load_data()
37
 
38
+ def expand_ppos(ppos):
39
+ matches = re.findall(r'\[([^\]]+)\]', ppos)
40
+ if matches:
41
+ expanded = []
42
+ for match in matches[0]:
43
+ expanded.append(ppos.replace(f'[{matches[0]}]', match))
44
+ return expanded
45
+ else:
46
+ return [ppos]
47
+
48
  def create_noun_table(lemma, forms):
49
  table_data = {
50
+ 'ncmsn==iuu': '', 'ncmsn==duu': 'hundurin', 'ncfsn==iuu': '', 'ncfsn==duu': '', 'ncnsn==iuu': '', 'ncnsn==duu': '',
51
+ 'ncmsa==iuu': '', 'ncmsa==duu': 'hundin', 'ncfsa==iuu': '', 'ncfsa==duu': '', 'ncnsa==iuu': '', 'ncnsa==duu': '',
52
+ 'ncmsd==iuu': '', 'ncmsd==duu': 'hundinum', 'ncfsd==iuu': '', 'ncfsd==duu': '', 'ncnsd==iuu': '', 'ncnsd==duu': '',
53
+ 'ncmsg==iou': '', 'ncmsg==dou': 'hundsins', 'ncfsg==iou': '', 'ncfsg==dou': '', 'ncnsg==iou': '', 'ncnsg==dou': '',
54
+ 'ncmpn==iuu': '', 'ncmpn==duu': 'hundarnir', 'ncfnn==iuu': '', 'ncfnn==duu': '', 'ncnnn==iuu': '', 'ncnnn==duu': '',
55
+ 'ncmpa==iuu': '', 'ncmpa==duu': 'hundarnar', 'ncfna==iuu': '', 'ncfna==duu': '', 'ncnna==iuu': '', 'ncnna==duu': '',
56
+ 'ncmpd==iuu': '', 'ncmpd==duu': 'hundunum', 'ncmpg==iou': '', 'ncmpg==dou': 'hundanna', 'ncfnn==iou': '', 'ncfnn==dou': '', 'ncnnn==iou': '', 'ncnnn==dou': ''
 
57
  }
58
 
59
  for form in forms:
60
  ppos = form['PPOS'].lower() # Normalize to lowercase
61
  word = form['word']
62
+ expanded_ppos_list = expand_ppos(ppos)
63
+ for expanded_ppos in expanded_ppos_list:
64
+ key = expanded_ppos
65
+ if key in table_data:
66
+ table_data[key] = word
67
+ else:
68
+ print(f"Unmatched key: {key} for word: {word} with PPOS: {ppos}")
69
 
70
  print(f"Final table data for {lemma}: {table_data}") # Debugging output
71