diff --git a/docs/api/corpus.rst b/docs/api/corpus.rst index 8f5a98188..09243f944 100644 --- a/docs/api/corpus.rst +++ b/docs/api/corpus.rst @@ -122,15 +122,6 @@ pythainlp.corpus.th_en_translit.get_transliteration_dict .. autofunction:: pythainlp.corpus.th_en_translit.get_transliteration_dict :noindex: -ConceptNet ----------- - -ConceptNet is an open, multilingual knowledge graph used for various natural language understanding tasks. For more information, refer to the `ConceptNet documentation `_. - -pythainlp.corpus.conceptnet.edges -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. autofunction:: pythainlp.corpus.conceptnet.edges - :noindex: TNC (Thai National Corpus) --- diff --git a/pythainlp/corpus/conceptnet.py b/pythainlp/corpus/conceptnet.py deleted file mode 100644 index 33b01d3d6..000000000 --- a/pythainlp/corpus/conceptnet.py +++ /dev/null @@ -1,115 +0,0 @@ -# -*- coding: utf-8 -*- -# SPDX-FileCopyrightText: 2016-2025 PyThaiNLP Project -# SPDX-FileType: SOURCE -# SPDX-License-Identifier: Apache-2.0 -""" -Get data from ConceptNet API at http://conceptnet.io -""" -import requests - - -def edges(word: str, lang: str = "th"): - """ - Get edges from `ConceptNet `_ API. - ConceptNet is a public semantic network, designed to help computers - understand the meanings of words that people use. - - For example, the term "ConceptNet" is a "knowledge graph", and - "knowledge graph" has "common sense knowledge" which is a part of - "artificial intelligence". Also, "ConcepNet" is used for - "natural language understanding" which is a part of - "artificial intelligence". - - | "ConceptNet" --is a--> "knowledge graph" --has--> "common sense"\ - --a part of--> "artificial intelligence" - | "ConceptNet" --used for--> "natural language understanding"\ - --a part of--> "artificial intelligence" - - With this illustration, it shows relationships (represented as *Edge*) - between the terms (represented as *Node*). - - This function requires an internet connection to access the ConceptNet API. - Please use it considerately. It will timeout after 10 seconds. - - :param str word: word to be sent to ConceptNet API - :param str lang: abbreviation of language (i.e. *th* for Thai, *en* for - English, or *ja* for Japan). By default, it is *th* - (Thai). - - :return: return edges of the given word according to the - ConceptNet network. - :rtype: list[dict] - - :Example: - :: - - from pythainlp.corpus.conceptnet import edges - - edges('hello', lang='en') - # output: - # [{ - # '@id': '/a/[/r/IsA/,/c/en/hello/,/c/en/greeting/]', - # '@type': 'Edge', - # 'dataset': '/d/conceptnet/4/en', - # 'end': {'@id': '/c/en/greeting', - # '@type': 'Node', - # 'label': 'greeting', - # 'language': 'en', - # 'term': '/c/en/greeting'}, - # 'license': 'cc:by/4.0', - # 'rel': {'@id': '/r/IsA', '@type': 'Relation', 'label': 'IsA'}, - # 'sources': [ - # { - # '@id': '/and/[/s/activity/omcs/vote/,/s/contributor/omcs/bmsacr/]', - # '@type': 'Source', - # 'activity': '/s/activity/omcs/vote', - # 'contributor': '/s/contributor/omcs/bmsacr' - # }, - # { - # '@id': '/and/[/s/activity/omcs/vote/,/s/contributor/omcs/test/]', - # '@type': 'Source', - # 'activity': '/s/activity/omcs/vote', - # 'contributor': '/s/contributor/omcs/test'} - # ], - # 'start': {'@id': '/c/en/hello', - # '@type': 'Node', - # 'label': 'Hello', - # 'language': 'en', - # 'term': '/c/en/hello'}, - # 'surfaceText': '[[Hello]] is a kind of [[greeting]]', - # 'weight': 3.4641016151377544 - # }, ...] - - edges('สวัสดี', lang='th') - # output: - # [{ - # '@id': '/a/[/r/RelatedTo/,/c/th/สวัสดี/n/,/c/en/prosperity/]', - # '@type': 'Edge', - # 'dataset': '/d/wiktionary/en', - # 'end': {'@id': '/c/en/prosperity', - # '@type': 'Node', - # 'label': 'prosperity', - # 'language': 'en', - # 'term': '/c/en/prosperity'}, - # 'license': 'cc:by-sa/4.0', - # 'rel': { - # '@id': '/r/RelatedTo', '@type': 'Relation', - # 'label': 'RelatedTo'}, - # 'sources': [{ - # '@id': '/and/[/s/process/wikiparsec/2/,/s/resource/wiktionary/en/]', - # '@type': 'Source', - # 'contributor': '/s/resource/wiktionary/en', - # 'process': '/s/process/wikiparsec/2'}], - # 'start': {'@id': '/c/th/สวัสดี/n', - # '@type': 'Node', - # 'label': 'สวัสดี', - # 'language': 'th', - # 'sense_label': 'n', - # 'term': '/c/th/สวัสดี'}, - # 'surfaceText': None, - # 'weight': 1.0 - # }, ...] - """ - - obj = requests.get(f"https://api.conceptnet.io/c/{lang}/{word}", timeout=10).json() - return obj["edges"] diff --git a/tests/core/test_corpus.py b/tests/core/test_corpus.py index 33d53fff6..dfb13e7bf 100644 --- a/tests/core/test_corpus.py +++ b/tests/core/test_corpus.py @@ -9,7 +9,6 @@ from requests import Response from pythainlp.corpus import ( - conceptnet, countries, download, find_synonyms, @@ -39,9 +38,6 @@ class CorpusTestCase(unittest.TestCase): - def test_conceptnet(self): - self.assertIsNotNone(conceptnet.edges("รัก")) - def test_corpus(self): self.assertIsInstance(thai_negations(), frozenset) self.assertGreater(len(thai_negations()), 0)