Spaces:
Sleeping
Sleeping
fix entry_id / sense_id
Browse files
app.py
CHANGED
|
@@ -1804,13 +1804,13 @@ def _wiktionary_map_pos_key(wikt_pos: Optional[str]) -> str:
|
|
| 1804 |
|
| 1805 |
def _wiktionary_build_report_for_entry(entry_id: int, conn: sqlite3.Connection) -> Dict[str, Any]:
|
| 1806 |
"""
|
| 1807 |
-
(REVISED FOR FULL DB)
|
| 1808 |
-
Fetches ALL associated data for a single Wiktionary entry_id
|
| 1809 |
-
|
| 1810 |
"""
|
| 1811 |
report = {}
|
| 1812 |
|
| 1813 |
-
# 1. Get Base Entry Info
|
| 1814 |
entry_data = conn.execute(
|
| 1815 |
"SELECT word, title, redirect, pos, pos_title, lang, etymology_text FROM entries WHERE id = ?", (entry_id,)
|
| 1816 |
).fetchone()
|
|
@@ -1820,7 +1820,7 @@ def _wiktionary_build_report_for_entry(entry_id: int, conn: sqlite3.Connection)
|
|
| 1820 |
report["entry_id"] = entry_id
|
| 1821 |
report["lemma"] = entry_data["word"]
|
| 1822 |
|
| 1823 |
-
# 2. Get Senses (with Glosses, Tags, Topics, Categories,
|
| 1824 |
senses_q = conn.execute(
|
| 1825 |
"""
|
| 1826 |
SELECT
|
|
@@ -1840,28 +1840,14 @@ def _wiktionary_build_report_for_entry(entry_id: int, conn: sqlite3.Connection)
|
|
| 1840 |
sense_dict = dict(sense_row)
|
| 1841 |
sense_id = sense_dict["sense_id"]
|
| 1842 |
|
| 1843 |
-
# Get examples
|
| 1844 |
examples_q = conn.execute(
|
| 1845 |
"SELECT text, ref, author, title, year, url FROM examples WHERE sense_id = ?", (sense_id,)
|
| 1846 |
).fetchall()
|
| 1847 |
sense_dict["examples"] = [dict(ex) for ex in examples_q]
|
| 1848 |
|
| 1849 |
-
# --- NEW: Get expressions ---
|
| 1850 |
-
expr_q = conn.execute(
|
| 1851 |
-
"SELECT expression, sense_index FROM expressions WHERE sense_id = ?", (sense_id,)
|
| 1852 |
-
).fetchall()
|
| 1853 |
-
sense_dict["expressions"] = [dict(ex) for ex in expr_q]
|
| 1854 |
-
|
| 1855 |
-
# --- NEW: Get proverbs ---
|
| 1856 |
-
prov_q = conn.execute(
|
| 1857 |
-
"SELECT proverb, sense_index FROM proverbs WHERE sense_id = ?", (sense_id,)
|
| 1858 |
-
).fetchall()
|
| 1859 |
-
sense_dict["proverbs"] = [dict(p) for p in prov_q]
|
| 1860 |
-
|
| 1861 |
senses_list.append(sense_dict)
|
| 1862 |
report["senses"] = senses_list
|
| 1863 |
-
report["expressions_by_sense"] = [s["expressions"] for s in senses_list if s["expressions"]]
|
| 1864 |
-
report["proverbs_by_sense"] = [s["proverbs"] for s in senses_list if s["proverbs"]]
|
| 1865 |
|
| 1866 |
# 3. Get Inflected Forms (with Tags and Topics)
|
| 1867 |
forms_q = conn.execute(
|
|
@@ -1943,7 +1929,6 @@ def _wiktionary_build_report_for_entry(entry_id: int, conn: sqlite3.Connection)
|
|
| 1943 |
).fetchall()
|
| 1944 |
report["derived_terms"] = [dict(d) for d in derived_q]
|
| 1945 |
|
| 1946 |
-
# --- FIXED: Query related_terms with new columns ---
|
| 1947 |
related_q = conn.execute(
|
| 1948 |
"SELECT related_word, sense_index, raw_tags_json FROM related_terms WHERE entry_id = ?", (entry_id,)
|
| 1949 |
).fetchall()
|
|
@@ -1960,25 +1945,20 @@ def _wiktionary_build_report_for_entry(entry_id: int, conn: sqlite3.Connection)
|
|
| 1960 |
).fetchall()
|
| 1961 |
report["entry_categories"] = [c["category"] for c in entry_cats_q]
|
| 1962 |
|
| 1963 |
-
# --- 11. GET ALL NEW OMITTED FIELDS ---
|
| 1964 |
|
| 1965 |
-
# entry_notes
|
| 1966 |
notes_q = conn.execute("SELECT note FROM entry_notes WHERE entry_id = ?", (entry_id,)).fetchall()
|
| 1967 |
report["entry_notes"] = [n["note"] for n in notes_q]
|
| 1968 |
|
| 1969 |
-
# other_pos
|
| 1970 |
other_pos_q = conn.execute("SELECT pos_value FROM other_pos WHERE entry_id = ?", (entry_id,)).fetchall()
|
| 1971 |
report["other_pos"] = [p["pos_value"] for p in other_pos_q]
|
| 1972 |
|
| 1973 |
-
# entry_raw_tags
|
| 1974 |
raw_tags_q = conn.execute("SELECT raw_tag FROM entry_raw_tags WHERE entry_id = ?", (entry_id,)).fetchall()
|
| 1975 |
report["raw_tags"] = [t["raw_tag"] for t in raw_tags_q]
|
| 1976 |
|
| 1977 |
-
# descendants
|
| 1978 |
desc_q = conn.execute("SELECT lang, word, roman FROM descendants WHERE entry_id = ?", (entry_id,)).fetchall()
|
| 1979 |
report["descendants"] = [dict(d) for d in desc_q]
|
| 1980 |
|
| 1981 |
-
# Semantic relations
|
| 1982 |
hyper_q = conn.execute("SELECT hypernym_word, sense_index FROM hypernyms WHERE entry_id = ?", (entry_id,)).fetchall()
|
| 1983 |
report["hypernyms"] = [dict(h) for h in hyper_q]
|
| 1984 |
|
|
@@ -1991,7 +1971,6 @@ def _wiktionary_build_report_for_entry(entry_id: int, conn: sqlite3.Connection)
|
|
| 1991 |
mero_q = conn.execute("SELECT meronym_word, sense_index FROM meronyms WHERE entry_id = ?", (entry_id,)).fetchall()
|
| 1992 |
report["meronyms"] = [dict(m) for m in mero_q]
|
| 1993 |
|
| 1994 |
-
# Coordinate terms (with their tags)
|
| 1995 |
coord_q = conn.execute(
|
| 1996 |
"""
|
| 1997 |
SELECT
|
|
@@ -2004,6 +1983,17 @@ def _wiktionary_build_report_for_entry(entry_id: int, conn: sqlite3.Connection)
|
|
| 2004 |
).fetchall()
|
| 2005 |
report["coordinate_terms"] = [dict(c) for c in coord_q]
|
| 2006 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2007 |
return report
|
| 2008 |
|
| 2009 |
def _wiktionary_find_all_entries(word: str, conn: sqlite3.Connection) -> List[Dict[str, Any]]:
|
|
|
|
| 1804 |
|
| 1805 |
def _wiktionary_build_report_for_entry(entry_id: int, conn: sqlite3.Connection) -> Dict[str, Any]:
|
| 1806 |
"""
|
| 1807 |
+
(REVISED FOR FULL DB V3)
|
| 1808 |
+
Fetches ALL associated data for a single Wiktionary entry_id.
|
| 1809 |
+
This version correctly queries expressions/proverbs by entry_id.
|
| 1810 |
"""
|
| 1811 |
report = {}
|
| 1812 |
|
| 1813 |
+
# 1. Get Base Entry Info
|
| 1814 |
entry_data = conn.execute(
|
| 1815 |
"SELECT word, title, redirect, pos, pos_title, lang, etymology_text FROM entries WHERE id = ?", (entry_id,)
|
| 1816 |
).fetchone()
|
|
|
|
| 1820 |
report["entry_id"] = entry_id
|
| 1821 |
report["lemma"] = entry_data["word"]
|
| 1822 |
|
| 1823 |
+
# 2. Get Senses (with Glosses, Tags, Topics, Categories, and Examples)
|
| 1824 |
senses_q = conn.execute(
|
| 1825 |
"""
|
| 1826 |
SELECT
|
|
|
|
| 1840 |
sense_dict = dict(sense_row)
|
| 1841 |
sense_id = sense_dict["sense_id"]
|
| 1842 |
|
| 1843 |
+
# Get examples (linked to sense_id)
|
| 1844 |
examples_q = conn.execute(
|
| 1845 |
"SELECT text, ref, author, title, year, url FROM examples WHERE sense_id = ?", (sense_id,)
|
| 1846 |
).fetchall()
|
| 1847 |
sense_dict["examples"] = [dict(ex) for ex in examples_q]
|
| 1848 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1849 |
senses_list.append(sense_dict)
|
| 1850 |
report["senses"] = senses_list
|
|
|
|
|
|
|
| 1851 |
|
| 1852 |
# 3. Get Inflected Forms (with Tags and Topics)
|
| 1853 |
forms_q = conn.execute(
|
|
|
|
| 1929 |
).fetchall()
|
| 1930 |
report["derived_terms"] = [dict(d) for d in derived_q]
|
| 1931 |
|
|
|
|
| 1932 |
related_q = conn.execute(
|
| 1933 |
"SELECT related_word, sense_index, raw_tags_json FROM related_terms WHERE entry_id = ?", (entry_id,)
|
| 1934 |
).fetchall()
|
|
|
|
| 1945 |
).fetchall()
|
| 1946 |
report["entry_categories"] = [c["category"] for c in entry_cats_q]
|
| 1947 |
|
| 1948 |
+
# --- 11. GET ALL NEW OMITTED FIELDS (linked to entry_id) ---
|
| 1949 |
|
|
|
|
| 1950 |
notes_q = conn.execute("SELECT note FROM entry_notes WHERE entry_id = ?", (entry_id,)).fetchall()
|
| 1951 |
report["entry_notes"] = [n["note"] for n in notes_q]
|
| 1952 |
|
|
|
|
| 1953 |
other_pos_q = conn.execute("SELECT pos_value FROM other_pos WHERE entry_id = ?", (entry_id,)).fetchall()
|
| 1954 |
report["other_pos"] = [p["pos_value"] for p in other_pos_q]
|
| 1955 |
|
|
|
|
| 1956 |
raw_tags_q = conn.execute("SELECT raw_tag FROM entry_raw_tags WHERE entry_id = ?", (entry_id,)).fetchall()
|
| 1957 |
report["raw_tags"] = [t["raw_tag"] for t in raw_tags_q]
|
| 1958 |
|
|
|
|
| 1959 |
desc_q = conn.execute("SELECT lang, word, roman FROM descendants WHERE entry_id = ?", (entry_id,)).fetchall()
|
| 1960 |
report["descendants"] = [dict(d) for d in desc_q]
|
| 1961 |
|
|
|
|
| 1962 |
hyper_q = conn.execute("SELECT hypernym_word, sense_index FROM hypernyms WHERE entry_id = ?", (entry_id,)).fetchall()
|
| 1963 |
report["hypernyms"] = [dict(h) for h in hyper_q]
|
| 1964 |
|
|
|
|
| 1971 |
mero_q = conn.execute("SELECT meronym_word, sense_index FROM meronyms WHERE entry_id = ?", (entry_id,)).fetchall()
|
| 1972 |
report["meronyms"] = [dict(m) for m in mero_q]
|
| 1973 |
|
|
|
|
| 1974 |
coord_q = conn.execute(
|
| 1975 |
"""
|
| 1976 |
SELECT
|
|
|
|
| 1983 |
).fetchall()
|
| 1984 |
report["coordinate_terms"] = [dict(c) for c in coord_q]
|
| 1985 |
|
| 1986 |
+
# --- FIXED: Query expressions and proverbs by entry_id ---
|
| 1987 |
+
expr_q = conn.execute(
|
| 1988 |
+
"SELECT expression, sense_index FROM expressions WHERE entry_id = ?", (entry_id,)
|
| 1989 |
+
).fetchall()
|
| 1990 |
+
report["expressions"] = [dict(ex) for ex in expr_q]
|
| 1991 |
+
|
| 1992 |
+
prov_q = conn.execute(
|
| 1993 |
+
"SELECT proverb, sense_index FROM proverbs WHERE entry_id = ?", (entry_id,)
|
| 1994 |
+
).fetchall()
|
| 1995 |
+
report["proverbs"] = [dict(p) for p in prov_q]
|
| 1996 |
+
|
| 1997 |
return report
|
| 1998 |
|
| 1999 |
def _wiktionary_find_all_entries(word: str, conn: sqlite3.Connection) -> List[Dict[str, Any]]:
|