Skip to content

Commit

Permalink
Rename gts functions
Browse files Browse the repository at this point in the history
  • Loading branch information
emreozcan committed Nov 9, 2024
1 parent 1924cee commit 9cb98d6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ import tdk

```python
import tdk
results = tdk.gts.search_sync("merkeziyetçilik")

results = tdk.dictionaries.gts.search_gts_sync("merkeziyetçilik")
print(results[0].meanings[0].meaning)
```
```{code-block}
Expand All @@ -51,9 +52,10 @@ is possible for there to be more than one word with the exact same spelling.

```python
import tdk
for number, entry in enumerate(tdk.gts.search_sync("bar")):

for number, entry in enumerate(tdk.dictionaries.gts.search_gts_sync("bar")):
for meaning in entry.meanings:
print(number+1, entry.entry, meaning.meaning)
print(number + 1, entry.entry, meaning.meaning)
```
```{code-block}
1 bar Anadolu'nun doğu ve kuzey bölgesinde, en çok Artvin ve Erzurum yörelerinde el ele tutuşularak oynanan, ağır ritimli bir halk oyunu
Expand All @@ -78,12 +80,12 @@ from difflib import get_close_matches
import tdk

# Calculate suggestions locally using the index:
suggestions = get_close_matches("feldispat", tdk.gts.get_index_sync())
# assert suggestions == ['feldspat', 'ispat', 'fesat']
words = get_close_matches("feldispat", tdk.dictionaries.gts.get_index_sync())
assert words == ['feldspat', 'ispat', 'fesat']

# Use the TDK API: (sometimes errors out)
suggestions = tdk.gts.get_suggestions_sync("feldispat")
# assert suggestions == ['feldspat', 'felekiyat', 'ispat']
words = tdk.dictionaries.gts.get_gts_suggestions_sync("feldispat")
assert words == ['feldspat', 'felekiyat', 'ispat']
```

### Performing complex analyses
Expand All @@ -94,7 +96,7 @@ of entries by the number of maximum consecutive consonants.
```python
import tdk
annotated_dict = {}
for entry in tdk.gts.get_index_sync():
for entry in tdk.dictionaries.gts.get_index_sync():
streaks = tdk.etc.tools.max_streak(entry)
if streaks not in annotated_dict:
annotated_dict[streaks] = [entry]
Expand Down
20 changes: 11 additions & 9 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ import tdk

```python
import tdk
results = tdk.gts.search_sync("merkeziyetçilik")

results = tdk.dictionaries.gts.search_gts_sync("merkeziyetçilik")
print(results[0].meanings[0].meaning)
```
```{code-block}
Expand All @@ -64,9 +65,10 @@ is possible for there to be more than one word with the exact same spelling.

```python
import tdk
for number, entry in enumerate(tdk.gts.search_sync("bar")):

for number, entry in enumerate(tdk.dictionaries.gts.search_gts_sync("bar")):
for meaning in entry.meanings:
print(number+1, entry.entry, meaning.meaning)
print(number + 1, entry.entry, meaning.meaning)
```
```{code-block}
:caption: Output
Expand All @@ -83,7 +85,7 @@ for number, entry in enumerate(tdk.gts.search_sync("bar")):
```

5 different words! One of them (#2) has multiple meanings!
z

### Generating suggestions

You can query suggestions for misspelt words or for other similar words.
Expand All @@ -93,12 +95,12 @@ from difflib import get_close_matches
import tdk

# Calculate suggestions locally using the index:
suggestions = get_close_matches("feldispat", tdk.gts.get_index_sync())
# assert suggestions == ['feldspat', 'ispat', 'fesat']
words = get_close_matches("feldispat", tdk.dictionaries.gts.get_index_sync())
assert words == ['feldspat', 'ispat', 'fesat']

# Use the TDK API: (sometimes errors out)
suggestions = tdk.gts.get_suggestions_sync("feldispat")
# assert suggestions == ['feldspat', 'felekiyat', 'ispat']
words = tdk.dictionaries.gts.get_gts_suggestions_sync("feldispat")
assert words == ['feldspat', 'felekiyat', 'ispat']
```

### Performing complex analyses
Expand All @@ -109,7 +111,7 @@ of entries by the number of maximum consecutive consonants.
```python
import tdk
annotated_dict = {}
for entry in tdk.gts.get_index_sync():
for entry in tdk.dictionaries.gts.get_index_sync():
streaks = tdk.etc.tools.max_streak(entry)
if streaks not in annotated_dict:
annotated_dict[streaks] = [entry]
Expand Down
18 changes: 9 additions & 9 deletions src/tdk/dictionaries/gts.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def get_circumflex_index_sync(): ...


@with_http_session
async def search(query: str, /, *, http_session: ClientSession) -> list[Entry]:
async def search_gts(query: str, /, *, http_session: ClientSession) -> list[Entry]:
query = lowercase(query, keep_unknown_characters=False)
async with http_session.get(
"https://sozluk.gov.tr/gts", params={"ara": query}
Expand All @@ -136,12 +136,12 @@ async def search(query: str, /, *, http_session: ClientSession) -> list[Entry]:
return []


@make_sync(search)
def search_sync(): ...
@make_sync(search_gts)
def search_gts_sync(): ...


@with_http_session
async def search_proverbs_and_phrases(
async def search_gts_proverbs_and_phrases(
query: str, /, *, http_session: ClientSession
) -> list[Entry]:
query = lowercase(query, keep_unknown_characters=False)
Expand All @@ -155,12 +155,12 @@ async def search_proverbs_and_phrases(
return []


@make_sync(search_proverbs_and_phrases)
def search_proverbs_and_phrases_sync(): ...
@make_sync(search_gts_proverbs_and_phrases)
def search_gts_proverbs_and_phrases_sync(): ...


@with_http_session
async def get_suggestions(
async def get_gts_suggestions(
query: str, /, *, http_session: ClientSession
) -> list[str]:
async with http_session.get(
Expand All @@ -181,5 +181,5 @@ async def get_suggestions(
) from e


@make_sync(get_suggestions)
def get_suggestions_sync(): ...
@make_sync(get_gts_suggestions)
def get_gts_suggestions_sync(): ...

0 comments on commit 9cb98d6

Please sign in to comment.