cstr commited on
Commit
9385557
·
verified ·
1 Parent(s): 95d2426

fix comprehensive de analysis

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -166,10 +166,14 @@ try:
166
  print("✓ Successfully imported pattern.de")
167
  except ImportError as e:
168
  PATTERN_DE_AVAILABLE = False
 
 
 
 
 
 
169
  print("="*70)
170
- print(f"CRITICAL WARNING: `pattern.de` library not found: {e}")
171
- print("The 'German Inflections' tab will not function.")
172
- print("="*70)
173
 
174
  # --- HanTa Tagger Import ---
175
  try:
@@ -2785,9 +2789,12 @@ def comprehensive_german_analysis(text: str, top_n_value: Optional[float] = 0) -
2785
  # provided by the encyclopedia for that POS.
2786
  data = entry_list[0]
2787
 
2788
- # Store all inflection blocks
2789
  inflection_analysis[f"{pos_key}_wiktionary"] = data.get("inflections_wiktionary")
2790
  inflection_analysis[f"{pos_key}_pattern"] = data.get("inflections_pattern")
 
 
 
2791
 
2792
  # --- Combine ALL senses (Wiktionary, OdeNet) for ranking ---
2793
  all_senses_for_pos = []
@@ -3800,14 +3807,13 @@ def _format_comprehensive_html(data: Dict[str, Any]) -> str:
3800
  else:
3801
  html += "<h3>Wort-für-Wort Analyse</h3>"
3802
  for lemma, details in deep_dive.items():
3803
- # Reconstruct a simplified data structure to reuse the word-formatter
3804
  html += f"<details><summary>{lemma}</summary>"
3805
 
3806
  inflections = details.get("inflection_analysis", {})
3807
  semantics = details.get("semantic_analysis", {})
3808
 
3809
  # Guess the POS keys present
3810
- all_keys = set([k.split('_')[0] for k in inflections.keys()])
3811
 
3812
  reconstructed_data = {"analysis": {}}
3813
 
@@ -3815,6 +3821,8 @@ def _format_comprehensive_html(data: Dict[str, Any]) -> str:
3815
  entry = {
3816
  "inflections_wiktionary": inflections.get(f"{pos}_wiktionary"),
3817
  "inflections_pattern": inflections.get(f"{pos}_pattern"),
 
 
3818
  "semantics_combined": {
3819
  "lemma": lemma,
3820
  "wiktionary_senses": [s for s in semantics.get(f"{pos}_senses", []) if s.get('source') == 'wiktionary'],
 
166
  print("✓ Successfully imported pattern.de")
167
  except ImportError as e:
168
  PATTERN_DE_AVAILABLE = False
169
+ # --- FIX: Define dummy constants to prevent NameError in other functions ---
170
+ MALE, FEMALE, NEUTRAL, PLURAL, SINGULAR = 1, 2, 3, "pl", "sg"
171
+ NOMINATIVE, ACCUSATIVE, DATIVE, GENITIVE = "nom", "acc", "dat", "gen"
172
+ INFINITIVE, PRESENT, PAST, PARTICIPLE = "inf", "pres", "pst", "part"
173
+ DEFINITE, INDEFINITE = "def", "indef"
174
+
175
  print("="*70)
176
+ print(f"WARNING: `pattern.de` library not found: {e}")
 
 
177
 
178
  # --- HanTa Tagger Import ---
179
  try:
 
2789
  # provided by the encyclopedia for that POS.
2790
  data = entry_list[0]
2791
 
2792
+ # Store all inflection blocks AND metadata
2793
  inflection_analysis[f"{pos_key}_wiktionary"] = data.get("inflections_wiktionary")
2794
  inflection_analysis[f"{pos_key}_pattern"] = data.get("inflections_pattern")
2795
+
2796
+ # --- Capture Metadata ---
2797
+ inflection_analysis[f"{pos_key}_metadata"] = data.get("wiktionary_metadata")
2798
 
2799
  # --- Combine ALL senses (Wiktionary, OdeNet) for ranking ---
2800
  all_senses_for_pos = []
 
3807
  else:
3808
  html += "<h3>Wort-für-Wort Analyse</h3>"
3809
  for lemma, details in deep_dive.items():
 
3810
  html += f"<details><summary>{lemma}</summary>"
3811
 
3812
  inflections = details.get("inflection_analysis", {})
3813
  semantics = details.get("semantic_analysis", {})
3814
 
3815
  # Guess the POS keys present
3816
+ all_keys = set([k.split('_')[0] for k in inflections.keys() if '_wiktionary' in k]) # Filter to avoid capturing 'metadata' as a pos key
3817
 
3818
  reconstructed_data = {"analysis": {}}
3819
 
 
3821
  entry = {
3822
  "inflections_wiktionary": inflections.get(f"{pos}_wiktionary"),
3823
  "inflections_pattern": inflections.get(f"{pos}_pattern"),
3824
+ # --- FIX: Inject Metadata back ---
3825
+ "wiktionary_metadata": inflections.get(f"{pos}_metadata"),
3826
  "semantics_combined": {
3827
  "lemma": lemma,
3828
  "wiktionary_senses": [s for s in semantics.get(f"{pos}_senses", []) if s.get('source') == 'wiktionary'],