Skip to content

Commit 89ea62e

Browse files
authored
Add timeout to conceptnet edges()
Also add notes to the docstring to use the function considerately.
1 parent 515fe7c commit 89ea62e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pythainlp/corpus/conceptnet.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ def edges(word: str, lang: str = "th"):
2525
--a part of--> "artificial intelligence"
2626
2727
With this illustration, it shows relationships (represented as *Edge*)
28-
between the terms (represented as *Node*)
28+
between the terms (represented as *Node*).
29+
30+
This function requires an internet connection to access the ConceptNet API.
31+
Please use it considerately. It will timeout after 10 seconds.
2932
3033
:param str word: word to be sent to ConceptNet API
3134
:param str lang: abbreviation of language (i.e. *th* for Thai, *en* for
@@ -107,5 +110,5 @@ def edges(word: str, lang: str = "th"):
107110
# }, ...]
108111
"""
109112

110-
obj = requests.get(f"https://api.conceptnet.io/c/{lang}/{word}").json()
113+
obj = requests.get(f"https://api.conceptnet.io/c/{lang}/{word}", timeout=10).json()
111114
return obj["edges"]

0 commit comments

Comments
 (0)