├── .gitignore ├── AUTHORS.md ├── LANGUAGES.md ├── LICENSE.txt ├── README.md ├── SYNSET-RELATIONS.md ├── cfilt-dark-vec.png ├── examples └── example.ipynb ├── pyiwn ├── __init__.py ├── constants.py ├── helpers.py └── iwn.py ├── requirements.txt ├── setup.cfg └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | *.egg 6 | build/ 7 | dist/ 8 | pyiwn.egg-info/ 9 | web/_build 10 | 11 | # iPython notebooks 12 | .ipynb_checkpoints 13 | 14 | # pyenv files 15 | .python-version 16 | 17 | # pycharm files 18 | .idea -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | pyiwn: A Python based API to access Indian language WordNets Authors 2 | 3 | - Ritesh Panjwani riteshp@cse.iitb.ac.in 4 | - Diptesh Kanojia diptesh@cse.iitb.ac.in 5 | - Pushpak Bhattacharyya pb@cse.iitb.ac.in -------------------------------------------------------------------------------- /LANGUAGES.md: -------------------------------------------------------------------------------- 1 | pyiwn provides access to the WordNets of the following languages: 2 | 3 | - hindi 4 | - english 5 | - assamese 6 | - bengali 7 | - bodo 8 | - gujarati 9 | - kannada 10 | - kashmiri 11 | - konkani 12 | - malayalam 13 | - meitei 14 | - marathi 15 | - nepali 16 | - sanskrit 17 | - tamil 18 | - telugu 19 | - punjabi 20 | - urdu 21 | - oriya -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Attribution-ShareAlike 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More_considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution-ShareAlike 4.0 International Public 58 | License 59 | 60 | By exercising the Licensed Rights (defined below), You accept and agree 61 | to be bound by the terms and conditions of this Creative Commons 62 | Attribution-ShareAlike 4.0 International Public License ("Public 63 | License"). To the extent this Public License may be interpreted as a 64 | contract, You are granted the Licensed Rights in consideration of Your 65 | acceptance of these terms and conditions, and the Licensor grants You 66 | such rights in consideration of benefits the Licensor receives from 67 | making the Licensed Material available under these terms and 68 | conditions. 69 | 70 | 71 | Section 1 -- Definitions. 72 | 73 | a. Adapted Material means material subject to Copyright and Similar 74 | Rights that is derived from or based upon the Licensed Material 75 | and in which the Licensed Material is translated, altered, 76 | arranged, transformed, or otherwise modified in a manner requiring 77 | permission under the Copyright and Similar Rights held by the 78 | Licensor. For purposes of this Public License, where the Licensed 79 | Material is a musical work, performance, or sound recording, 80 | Adapted Material is always produced where the Licensed Material is 81 | synched in timed relation with a moving image. 82 | 83 | b. Adapter's License means the license You apply to Your Copyright 84 | and Similar Rights in Your contributions to Adapted Material in 85 | accordance with the terms and conditions of this Public License. 86 | 87 | c. BY-SA Compatible License means a license listed at 88 | creativecommons.org/compatiblelicenses, approved by Creative 89 | Commons as essentially the equivalent of this Public License. 90 | 91 | d. Copyright and Similar Rights means copyright and/or similar rights 92 | closely related to copyright including, without limitation, 93 | performance, broadcast, sound recording, and Sui Generis Database 94 | Rights, without regard to how the rights are labeled or 95 | categorized. For purposes of this Public License, the rights 96 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 97 | Rights. 98 | 99 | e. Effective Technological Measures means those measures that, in the 100 | absence of proper authority, may not be circumvented under laws 101 | fulfilling obligations under Article 11 of the WIPO Copyright 102 | Treaty adopted on December 20, 1996, and/or similar international 103 | agreements. 104 | 105 | f. Exceptions and Limitations means fair use, fair dealing, and/or 106 | any other exception or limitation to Copyright and Similar Rights 107 | that applies to Your use of the Licensed Material. 108 | 109 | g. License Elements means the license attributes listed in the name 110 | of a Creative Commons Public License. The License Elements of this 111 | Public License are Attribution and ShareAlike. 112 | 113 | h. Licensed Material means the artistic or literary work, database, 114 | or other material to which the Licensor applied this Public 115 | License. 116 | 117 | i. Licensed Rights means the rights granted to You subject to the 118 | terms and conditions of this Public License, which are limited to 119 | all Copyright and Similar Rights that apply to Your use of the 120 | Licensed Material and that the Licensor has authority to license. 121 | 122 | j. Licensor means the individual(s) or entity(ies) granting rights 123 | under this Public License. 124 | 125 | k. Share means to provide material to the public by any means or 126 | process that requires permission under the Licensed Rights, such 127 | as reproduction, public display, public performance, distribution, 128 | dissemination, communication, or importation, and to make material 129 | available to the public including in ways that members of the 130 | public may access the material from a place and at a time 131 | individually chosen by them. 132 | 133 | l. Sui Generis Database Rights means rights other than copyright 134 | resulting from Directive 96/9/EC of the European Parliament and of 135 | the Council of 11 March 1996 on the legal protection of databases, 136 | as amended and/or succeeded, as well as other essentially 137 | equivalent rights anywhere in the world. 138 | 139 | m. You means the individual or entity exercising the Licensed Rights 140 | under this Public License. Your has a corresponding meaning. 141 | 142 | 143 | Section 2 -- Scope. 144 | 145 | a. License grant. 146 | 147 | 1. Subject to the terms and conditions of this Public License, 148 | the Licensor hereby grants You a worldwide, royalty-free, 149 | non-sublicensable, non-exclusive, irrevocable license to 150 | exercise the Licensed Rights in the Licensed Material to: 151 | 152 | a. reproduce and Share the Licensed Material, in whole or 153 | in part; and 154 | 155 | b. produce, reproduce, and Share Adapted Material. 156 | 157 | 2. Exceptions and Limitations. For the avoidance of doubt, where 158 | Exceptions and Limitations apply to Your use, this Public 159 | License does not apply, and You do not need to comply with 160 | its terms and conditions. 161 | 162 | 3. Term. The term of this Public License is specified in Section 163 | 6(a). 164 | 165 | 4. Media and formats; technical modifications allowed. The 166 | Licensor authorizes You to exercise the Licensed Rights in 167 | all media and formats whether now known or hereafter created, 168 | and to make technical modifications necessary to do so. The 169 | Licensor waives and/or agrees not to assert any right or 170 | authority to forbid You from making technical modifications 171 | necessary to exercise the Licensed Rights, including 172 | technical modifications necessary to circumvent Effective 173 | Technological Measures. For purposes of this Public License, 174 | simply making modifications authorized by this Section 2(a) 175 | (4) never produces Adapted Material. 176 | 177 | 5. Downstream recipients. 178 | 179 | a. Offer from the Licensor -- Licensed Material. Every 180 | recipient of the Licensed Material automatically 181 | receives an offer from the Licensor to exercise the 182 | Licensed Rights under the terms and conditions of this 183 | Public License. 184 | 185 | b. Additional offer from the Licensor -- Adapted Material. 186 | Every recipient of Adapted Material from You 187 | automatically receives an offer from the Licensor to 188 | exercise the Licensed Rights in the Adapted Material 189 | under the conditions of the Adapter's License You apply. 190 | 191 | c. No downstream restrictions. You may not offer or impose 192 | any additional or different terms or conditions on, or 193 | apply any Effective Technological Measures to, the 194 | Licensed Material if doing so restricts exercise of the 195 | Licensed Rights by any recipient of the Licensed 196 | Material. 197 | 198 | 6. No endorsement. Nothing in this Public License constitutes or 199 | may be construed as permission to assert or imply that You 200 | are, or that Your use of the Licensed Material is, connected 201 | with, or sponsored, endorsed, or granted official status by, 202 | the Licensor or others designated to receive attribution as 203 | provided in Section 3(a)(1)(A)(i). 204 | 205 | b. Other rights. 206 | 207 | 1. Moral rights, such as the right of integrity, are not 208 | licensed under this Public License, nor are publicity, 209 | privacy, and/or other similar personality rights; however, to 210 | the extent possible, the Licensor waives and/or agrees not to 211 | assert any such rights held by the Licensor to the limited 212 | extent necessary to allow You to exercise the Licensed 213 | Rights, but not otherwise. 214 | 215 | 2. Patent and trademark rights are not licensed under this 216 | Public License. 217 | 218 | 3. To the extent possible, the Licensor waives any right to 219 | collect royalties from You for the exercise of the Licensed 220 | Rights, whether directly or through a collecting society 221 | under any voluntary or waivable statutory or compulsory 222 | licensing scheme. In all other cases the Licensor expressly 223 | reserves any right to collect such royalties. 224 | 225 | 226 | Section 3 -- License Conditions. 227 | 228 | Your exercise of the Licensed Rights is expressly made subject to the 229 | following conditions. 230 | 231 | a. Attribution. 232 | 233 | 1. If You Share the Licensed Material (including in modified 234 | form), You must: 235 | 236 | a. retain the following if it is supplied by the Licensor 237 | with the Licensed Material: 238 | 239 | i. identification of the creator(s) of the Licensed 240 | Material and any others designated to receive 241 | attribution, in any reasonable manner requested by 242 | the Licensor (including by pseudonym if 243 | designated); 244 | 245 | ii. a copyright notice; 246 | 247 | iii. a notice that refers to this Public License; 248 | 249 | iv. a notice that refers to the disclaimer of 250 | warranties; 251 | 252 | v. a URI or hyperlink to the Licensed Material to the 253 | extent reasonably practicable; 254 | 255 | b. indicate if You modified the Licensed Material and 256 | retain an indication of any previous modifications; and 257 | 258 | c. indicate the Licensed Material is licensed under this 259 | Public License, and include the text of, or the URI or 260 | hyperlink to, this Public License. 261 | 262 | 2. You may satisfy the conditions in Section 3(a)(1) in any 263 | reasonable manner based on the medium, means, and context in 264 | which You Share the Licensed Material. For example, it may be 265 | reasonable to satisfy the conditions by providing a URI or 266 | hyperlink to a resource that includes the required 267 | information. 268 | 269 | 3. If requested by the Licensor, You must remove any of the 270 | information required by Section 3(a)(1)(A) to the extent 271 | reasonably practicable. 272 | 273 | b. ShareAlike. 274 | 275 | In addition to the conditions in Section 3(a), if You Share 276 | Adapted Material You produce, the following conditions also apply. 277 | 278 | 1. The Adapter's License You apply must be a Creative Commons 279 | license with the same License Elements, this version or 280 | later, or a BY-SA Compatible License. 281 | 282 | 2. You must include the text of, or the URI or hyperlink to, the 283 | Adapter's License You apply. You may satisfy this condition 284 | in any reasonable manner based on the medium, means, and 285 | context in which You Share Adapted Material. 286 | 287 | 3. You may not offer or impose any additional or different terms 288 | or conditions on, or apply any Effective Technological 289 | Measures to, Adapted Material that restrict exercise of the 290 | rights granted under the Adapter's License You apply. 291 | 292 | 293 | Section 4 -- Sui Generis Database Rights. 294 | 295 | Where the Licensed Rights include Sui Generis Database Rights that 296 | apply to Your use of the Licensed Material: 297 | 298 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 299 | to extract, reuse, reproduce, and Share all or a substantial 300 | portion of the contents of the database; 301 | 302 | b. if You include all or a substantial portion of the database 303 | contents in a database in which You have Sui Generis Database 304 | Rights, then the database in which You have Sui Generis Database 305 | Rights (but not its individual contents) is Adapted Material, 306 | 307 | including for purposes of Section 3(b); and 308 | c. You must comply with the conditions in Section 3(a) if You Share 309 | all or a substantial portion of the contents of the database. 310 | 311 | For the avoidance of doubt, this Section 4 supplements and does not 312 | replace Your obligations under this Public License where the Licensed 313 | Rights include other Copyright and Similar Rights. 314 | 315 | 316 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 317 | 318 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 319 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 320 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 321 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 322 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 323 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 324 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 325 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 326 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 327 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 328 | 329 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 330 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 331 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 332 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 333 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 334 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 335 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 336 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 337 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 338 | 339 | c. The disclaimer of warranties and limitation of liability provided 340 | above shall be interpreted in a manner that, to the extent 341 | possible, most closely approximates an absolute disclaimer and 342 | waiver of all liability. 343 | 344 | 345 | Section 6 -- Term and Termination. 346 | 347 | a. This Public License applies for the term of the Copyright and 348 | Similar Rights licensed here. However, if You fail to comply with 349 | this Public License, then Your rights under this Public License 350 | terminate automatically. 351 | 352 | b. Where Your right to use the Licensed Material has terminated under 353 | Section 6(a), it reinstates: 354 | 355 | 1. automatically as of the date the violation is cured, provided 356 | it is cured within 30 days of Your discovery of the 357 | violation; or 358 | 359 | 2. upon express reinstatement by the Licensor. 360 | 361 | For the avoidance of doubt, this Section 6(b) does not affect any 362 | right the Licensor may have to seek remedies for Your violations 363 | of this Public License. 364 | 365 | c. For the avoidance of doubt, the Licensor may also offer the 366 | Licensed Material under separate terms or conditions or stop 367 | distributing the Licensed Material at any time; however, doing so 368 | will not terminate this Public License. 369 | 370 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 371 | License. 372 | 373 | 374 | Section 7 -- Other Terms and Conditions. 375 | 376 | a. The Licensor shall not be bound by any additional or different 377 | terms or conditions communicated by You unless expressly agreed. 378 | 379 | b. Any arrangements, understandings, or agreements regarding the 380 | Licensed Material not stated herein are separate from and 381 | independent of the terms and conditions of this Public License. 382 | 383 | 384 | Section 8 -- Interpretation. 385 | 386 | a. For the avoidance of doubt, this Public License does not, and 387 | shall not be interpreted to, reduce, limit, restrict, or impose 388 | conditions on any use of the Licensed Material that could lawfully 389 | be made without permission under this Public License. 390 | 391 | b. To the extent possible, if any provision of this Public License is 392 | deemed unenforceable, it shall be automatically reformed to the 393 | minimum extent necessary to make it enforceable. If the provision 394 | cannot be reformed, it shall be severed from this Public License 395 | without affecting the enforceability of the remaining terms and 396 | conditions. 397 | 398 | c. No term or condition of this Public License will be waived and no 399 | failure to comply consented to unless expressly agreed to by the 400 | Licensor. 401 | 402 | d. Nothing in this Public License constitutes or may be interpreted 403 | as a limitation upon, or waiver of, any privileges and immunities 404 | that apply to the Licensor or You, including from the legal 405 | processes of any jurisdiction or authority. 406 | 407 | 408 | ======================================================================= 409 | 410 | Creative Commons is not a party to its public 411 | licenses. Notwithstanding, Creative Commons may elect to apply one of 412 | its public licenses to material it publishes and in those instances 413 | will be considered the “Licensor.” The text of the Creative Commons 414 | public licenses is dedicated to the public domain under the CC0 Public 415 | Domain Dedication. Except for the limited purpose of indicating that 416 | material is shared under a Creative Commons public license or as 417 | otherwise permitted by the Creative Commons policies published at 418 | creativecommons.org/policies, Creative Commons does not authorize the 419 | use of the trademark "Creative Commons" or any other trademark or logo 420 | of Creative Commons without its prior written consent including, 421 | without limitation, in connection with any unauthorized modifications 422 | to any of its public licenses or any other arrangements, 423 | understandings, or agreements concerning use of licensed material. For 424 | the avoidance of doubt, this paragraph does not form part of the 425 | public licenses. 426 | 427 | Creative Commons may be contacted at creativecommons.org. 428 | 429 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

logo

2 | 3 | # A Python based API to access Indian language WordNets (pyiwn) 4 | [![PyPI](https://img.shields.io/pypi/v/pyiwn.svg)](https://pypi.python.org/pypi/pyiwn) 5 | [![GitHub issues](https://img.shields.io/github/issues/cfiltnlp/pyiwn?style=flat-square)](https://github.com/cfiltnlp/pyiwn/issues) 6 | [![GitHub forks](https://img.shields.io/github/forks/cfiltnlp/pyiwn?style=flat-square)](https://github.com/cfiltnlp/pyiwn/network) 7 | [![GitHub stars](https://img.shields.io/github/stars/cfiltnlp/pyiwn?style=flat-square)](https://github.com/cfiltnlp/pyiwn/stargazers) 8 | [![GitHub license](https://img.shields.io/github/license/cfiltnlp/pyiwn?style=flat-square)](https://github.com/cfiltnlp/pyiwn/blob/master/LICENSE.txt) 9 | [![Twitter Follow](https://img.shields.io/twitter/follow/cfiltnlp?color=1DA1F2&logo=twitter&style=flat-square)](https://twitter.com/cfiltnlp) 10 | [![Twitter Follow](https://img.shields.io/twitter/follow/PeopleCentredAI?color=1DA1F2&logo=twitter&style=flat-square)](https://twitter.com/PeopleCentredAI) 11 | 12 | pyIWN -- A Python based API to access Indian language WordNets -- This API gives access to synsets, glosses, examples, lexico-semantic relations between synsets, ontology nodes for 18 Indian languages, see [LANGUAGES.md](LANGUAGES.md) for the complete list of supported languages. In future, it will also provide access to speech data for words, glosses examples in Hindi WordNet. 13 | 14 | ## Prerequisite 15 | Python 3.5+ 16 | 17 | ## Installation 18 | 19 | pyiwn can be installed using pip 20 | 21 | ```bash 22 | pip install --upgrade pyiwn 23 | ``` 24 | 25 | or install it from the source 26 | 27 | ```bash 28 | git clone https://github.com/riteshpanjwani/pyiwn.git 29 | cd pyiwn 30 | python setup.py install 31 | ``` 32 | 33 | Please see examples/ for further instructions and usage. 34 | 35 | ## Citing 36 | 37 | If you publish work that uses pyiwn, please cite the pyiwn paper, as follows: 38 | 39 | ```latex 40 | @inproceedings{panjwani-etal-2018-pyiwn, 41 | title = "pyiwn: A Python based {API} to access {I}ndian Language {W}ord{N}ets", 42 | author = "Panjwani, Ritesh and 43 | Kanojia, Diptesh and 44 | Bhattacharyya, Pushpak", 45 | booktitle = "Proceedings of the 9th Global Wordnet Conference", 46 | month = jan, 47 | year = "2018", 48 | address = "Nanyang Technological University (NTU), Singapore", 49 | publisher = "Global Wordnet Association", 50 | url = "https://aclanthology.org/2018.gwc-1.47", 51 | pages = "378--383", 52 | abstract = "Indian language WordNets have their individual web-based browsing interfaces along with a common interface for IndoWordNet. These interfaces prove to be useful for language learners and in an educational domain, however, they do not provide the functionality of connecting to them and browsing their data through a lucid application programming interface or an API. In this paper, we present our work on creating such an easy-to-use framework which is bundled with the data for Indian language WordNets and provides NLTK WordNet interface like core functionalities in Python. Additionally, we use a pre-built speech synthesis system for Hindi language and augment Hindi data with audios for words, glosses, and example sentences. We provide a detailed usage of our API and explain the functions for ease of the user. Also, we package the IndoWordNet data along with the source code and provide it openly for the purpose of research. We aim to provide all our work as an open source framework for further development.", 53 | } 54 | ``` 55 | 56 | 57 | ## Copyright 58 | 59 | Copyright (C) 2017 pyiwn Project 60 | 61 | For license information, see [LICENSE.txt](LICENSE.txt). 62 | 63 | [AUTHORS.md](AUTHORS.md) have a list of everyone contributed to pyiwn. 64 | -------------------------------------------------------------------------------- /SYNSET-RELATIONS.md: -------------------------------------------------------------------------------- 1 | Synset Relations 2 | 3 | - ability_verb 4 | - attributes 5 | - capability_verb 6 | - function_verb 7 | - holo_component_object 8 | - holo_member_collection 9 | - holo_phase_state 10 | - holo_place_area 11 | - holo_portion_mass 12 | - holo_position_area 13 | - holo_resource_process 14 | - holo_stuff_object 15 | - mero_component_object 16 | - mero_feature_activity 17 | - mero_member_collection 18 | - mero_phase_state 19 | - mero_place_area 20 | - mero_portion_mass 21 | - mero_position_area 22 | - mero_resource_process 23 | - mero_stuff_object 24 | - modifies_noun 25 | - similar 26 | - also_see 27 | - modifies_verb 28 | - causative 29 | - compounding 30 | - conjunction 31 | - entailment 32 | - troponymy -------------------------------------------------------------------------------- /cfilt-dark-vec.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cfiltnlp/pyiwn/d968ac1a8b2ebb4244f6ec3eed38b95321723880/cfilt-dark-vec.png -------------------------------------------------------------------------------- /examples/example.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "import pyiwn" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "### Supported Languages" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 2, 22 | "metadata": {}, 23 | "outputs": [ 24 | { 25 | "data": { 26 | "text/plain": [ 27 | "['Language.ASSAMESE',\n", 28 | " 'Language.BENGALI',\n", 29 | " 'Language.BODO',\n", 30 | " 'Language.GUJARATI',\n", 31 | " 'Language.HINDI',\n", 32 | " 'Language.KANNADA',\n", 33 | " 'Language.KASHMIRI',\n", 34 | " 'Language.KONKANI',\n", 35 | " 'Language.MALAYALAM',\n", 36 | " 'Language.MARATHI',\n", 37 | " 'Language.MEITEI',\n", 38 | " 'Language.NEPALI',\n", 39 | " 'Language.ORIYA',\n", 40 | " 'Language.PUNJABI',\n", 41 | " 'Language.SANSKRIT',\n", 42 | " 'Language.TAMIL',\n", 43 | " 'Language.TELUGU',\n", 44 | " 'Language.URDU']" 45 | ] 46 | }, 47 | "execution_count": 2, 48 | "metadata": {}, 49 | "output_type": "execute_result" 50 | } 51 | ], 52 | "source": [ 53 | "list(map(str, pyiwn.Language))" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": {}, 59 | "source": [ 60 | "### Create a IndoWordNet class instance" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 3, 66 | "metadata": {}, 67 | "outputs": [ 68 | { 69 | "name": "stderr", 70 | "output_type": "stream", 71 | "text": [ 72 | "2019-09-29:05:26:12,502 INFO [iwn.py:43] Loading hindi language synsets...\n" 73 | ] 74 | } 75 | ], 76 | "source": [ 77 | "# language defaults to Hindi\n", 78 | "iwn = pyiwn.IndoWordNet()\n", 79 | "\n", 80 | "# to use other language wordnet(s), use:\n", 81 | "# iwn = pyiwn.IndoWordNet(lang=pyiwn.Language.KANNADA)" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "metadata": {}, 87 | "source": [ 88 | "### Words\n", 89 | "\n", 90 | "Look up a word using synsets(); this function has an optional pos argument which lets you constrain the part of speech of the word:" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 4, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "aam_all_synsets = iwn.synsets('आम')" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 5, 105 | "metadata": {}, 106 | "outputs": [ 107 | { 108 | "data": { 109 | "text/plain": [ 110 | "[Synset('कच्चा.adjective.2283'),\n", 111 | " Synset('अधपका.adjective.2697'),\n", 112 | " Synset('आम.noun.3462'),\n", 113 | " Synset('आम.noun.3463'),\n", 114 | " Synset('सामान्य.adjective.3468'),\n", 115 | " Synset('सामूहिक.adjective.3469'),\n", 116 | " Synset('आँव.noun.6253'),\n", 117 | " Synset('आँव.noun.8446'),\n", 118 | " Synset('आम.adjective.39736')]" 119 | ] 120 | }, 121 | "execution_count": 5, 122 | "metadata": {}, 123 | "output_type": "execute_result" 124 | } 125 | ], 126 | "source": [ 127 | "aam_all_synsets" 128 | ] 129 | }, 130 | { 131 | "cell_type": "markdown", 132 | "metadata": {}, 133 | "source": [ 134 | "### Lookup synsets with POS tag" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 6, 140 | "metadata": {}, 141 | "outputs": [ 142 | { 143 | "data": { 144 | "text/plain": [ 145 | "['PosTag.NOUN', 'PosTag.VERB', 'PosTag.ADVERB', 'PosTag.ADJECTIVE']" 146 | ] 147 | }, 148 | "execution_count": 6, 149 | "metadata": {}, 150 | "output_type": "execute_result" 151 | } 152 | ], 153 | "source": [ 154 | "# POS\n", 155 | "list(map(str, pyiwn.PosTag))" 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": 7, 161 | "metadata": {}, 162 | "outputs": [], 163 | "source": [ 164 | "aam_synsets = iwn.synsets('आम', pos=pyiwn.PosTag.NOUN)" 165 | ] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "execution_count": 8, 170 | "metadata": {}, 171 | "outputs": [ 172 | { 173 | "data": { 174 | "text/plain": [ 175 | "[Synset('आम.noun.3462'),\n", 176 | " Synset('आम.noun.3463'),\n", 177 | " Synset('आँव.noun.6253'),\n", 178 | " Synset('आँव.noun.8446')]" 179 | ] 180 | }, 181 | "execution_count": 8, 182 | "metadata": {}, 183 | "output_type": "execute_result" 184 | } 185 | ], 186 | "source": [ 187 | "aam_synsets" 188 | ] 189 | }, 190 | { 191 | "cell_type": "markdown", 192 | "metadata": {}, 193 | "source": [ 194 | "### Synsets" 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": 9, 200 | "metadata": {}, 201 | "outputs": [], 202 | "source": [ 203 | "# let's select the first synset of 'आम'\n", 204 | "aam = aam_synsets[0]" 205 | ] 206 | }, 207 | { 208 | "cell_type": "code", 209 | "execution_count": 10, 210 | "metadata": {}, 211 | "outputs": [ 212 | { 213 | "data": { 214 | "text/plain": [ 215 | "Synset('आम.noun.3462')" 216 | ] 217 | }, 218 | "execution_count": 10, 219 | "metadata": {}, 220 | "output_type": "execute_result" 221 | } 222 | ], 223 | "source": [ 224 | "aam" 225 | ] 226 | }, 227 | { 228 | "cell_type": "code", 229 | "execution_count": 11, 230 | "metadata": {}, 231 | "outputs": [ 232 | { 233 | "data": { 234 | "text/plain": [ 235 | "3462" 236 | ] 237 | }, 238 | "execution_count": 11, 239 | "metadata": {}, 240 | "output_type": "execute_result" 241 | } 242 | ], 243 | "source": [ 244 | "# Synset ID\n", 245 | "aam.synset_id()" 246 | ] 247 | }, 248 | { 249 | "cell_type": "code", 250 | "execution_count": 12, 251 | "metadata": {}, 252 | "outputs": [ 253 | { 254 | "data": { 255 | "text/plain": [ 256 | "'आम'" 257 | ] 258 | }, 259 | "execution_count": 12, 260 | "metadata": {}, 261 | "output_type": "execute_result" 262 | } 263 | ], 264 | "source": [ 265 | "# Head word of the synset\n", 266 | "aam.head_word()" 267 | ] 268 | }, 269 | { 270 | "cell_type": "code", 271 | "execution_count": 13, 272 | "metadata": {}, 273 | "outputs": [ 274 | { 275 | "data": { 276 | "text/plain": [ 277 | "['आम',\n", 278 | " 'आम्र',\n", 279 | " 'अंब',\n", 280 | " 'अम्ब',\n", 281 | " 'आँब',\n", 282 | " 'आंब',\n", 283 | " 'रसाल',\n", 284 | " 'च्यूत',\n", 285 | " 'प्रियांबु',\n", 286 | " 'प्रियाम्बु',\n", 287 | " 'केशवायुध',\n", 288 | " 'कामायुध',\n", 289 | " 'कामशर',\n", 290 | " 'कामांग']" 291 | ] 292 | }, 293 | "execution_count": 13, 294 | "metadata": {}, 295 | "output_type": "execute_result" 296 | } 297 | ], 298 | "source": [ 299 | "# list of string lemmas in the synset\n", 300 | "aam.lemma_names()" 301 | ] 302 | }, 303 | { 304 | "cell_type": "code", 305 | "execution_count": 14, 306 | "metadata": {}, 307 | "outputs": [ 308 | { 309 | "data": { 310 | "text/plain": [ 311 | "[Lemma('आम.noun.3462.आम'),\n", 312 | " Lemma('आम.noun.3462.आम्र'),\n", 313 | " Lemma('आम.noun.3462.अंब'),\n", 314 | " Lemma('आम.noun.3462.अम्ब'),\n", 315 | " Lemma('आम.noun.3462.आँब'),\n", 316 | " Lemma('आम.noun.3462.आंब'),\n", 317 | " Lemma('आम.noun.3462.रसाल'),\n", 318 | " Lemma('आम.noun.3462.च्यूत'),\n", 319 | " Lemma('आम.noun.3462.प्रियांबु'),\n", 320 | " Lemma('आम.noun.3462.प्रियाम्बु'),\n", 321 | " Lemma('आम.noun.3462.केशवायुध'),\n", 322 | " Lemma('आम.noun.3462.कामायुध'),\n", 323 | " Lemma('आम.noun.3462.कामशर'),\n", 324 | " Lemma('आम.noun.3462.कामांग')]" 325 | ] 326 | }, 327 | "execution_count": 14, 328 | "metadata": {}, 329 | "output_type": "execute_result" 330 | } 331 | ], 332 | "source": [ 333 | "# list of Lemma type in the synset\n", 334 | "aam.lemmas()" 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": 15, 340 | "metadata": {}, 341 | "outputs": [ 342 | { 343 | "data": { 344 | "text/plain": [ 345 | "'noun'" 346 | ] 347 | }, 348 | "execution_count": 15, 349 | "metadata": {}, 350 | "output_type": "execute_result" 351 | } 352 | ], 353 | "source": [ 354 | "# POS tag of the synset\n", 355 | "aam.pos()" 356 | ] 357 | }, 358 | { 359 | "cell_type": "code", 360 | "execution_count": 16, 361 | "metadata": {}, 362 | "outputs": [ 363 | { 364 | "data": { 365 | "text/plain": [ 366 | "'एक फल जो खाया या चूसा जाता है'" 367 | ] 368 | }, 369 | "execution_count": 16, 370 | "metadata": {}, 371 | "output_type": "execute_result" 372 | } 373 | ], 374 | "source": [ 375 | "# gloss / definition of the synset\n", 376 | "aam.gloss()" 377 | ] 378 | }, 379 | { 380 | "cell_type": "code", 381 | "execution_count": 17, 382 | "metadata": {}, 383 | "outputs": [ 384 | { 385 | "data": { 386 | "text/plain": [ 387 | "['तोता पेड़ पर बैठकर आम खा रहा है ।',\n", 388 | " 'शास्त्रों ने आम को इंद्रासनी फल की संज्ञा दी है ।']" 389 | ] 390 | }, 391 | "execution_count": 17, 392 | "metadata": {}, 393 | "output_type": "execute_result" 394 | } 395 | ], 396 | "source": [ 397 | "# examples of the synset\n", 398 | "aam.examples()" 399 | ] 400 | }, 401 | { 402 | "cell_type": "markdown", 403 | "metadata": {}, 404 | "source": [ 405 | "### Lemma" 406 | ] 407 | }, 408 | { 409 | "cell_type": "code", 410 | "execution_count": 18, 411 | "metadata": {}, 412 | "outputs": [], 413 | "source": [ 414 | "# let's select first lemma of the 'aam' synset\n", 415 | "aam_lemma = aam.lemmas()[0]" 416 | ] 417 | }, 418 | { 419 | "cell_type": "code", 420 | "execution_count": 19, 421 | "metadata": {}, 422 | "outputs": [ 423 | { 424 | "data": { 425 | "text/plain": [ 426 | "Lemma('आम.noun.3462.आम')" 427 | ] 428 | }, 429 | "execution_count": 19, 430 | "metadata": {}, 431 | "output_type": "execute_result" 432 | } 433 | ], 434 | "source": [ 435 | "aam_lemma" 436 | ] 437 | }, 438 | { 439 | "cell_type": "code", 440 | "execution_count": 20, 441 | "metadata": {}, 442 | "outputs": [ 443 | { 444 | "data": { 445 | "text/plain": [ 446 | "'आम'" 447 | ] 448 | }, 449 | "execution_count": 20, 450 | "metadata": {}, 451 | "output_type": "execute_result" 452 | } 453 | ], 454 | "source": [ 455 | "aam_lemma.name()" 456 | ] 457 | }, 458 | { 459 | "cell_type": "code", 460 | "execution_count": 21, 461 | "metadata": {}, 462 | "outputs": [ 463 | { 464 | "data": { 465 | "text/plain": [ 466 | "Synset('आम.noun.3462')" 467 | ] 468 | }, 469 | "execution_count": 21, 470 | "metadata": {}, 471 | "output_type": "execute_result" 472 | } 473 | ], 474 | "source": [ 475 | "aam_lemma.synset()" 476 | ] 477 | }, 478 | { 479 | "cell_type": "markdown", 480 | "metadata": {}, 481 | "source": [ 482 | "### All synsets" 483 | ] 484 | }, 485 | { 486 | "cell_type": "code", 487 | "execution_count": 22, 488 | "metadata": {}, 489 | "outputs": [], 490 | "source": [ 491 | "synsets = iwn.all_synsets()" 492 | ] 493 | }, 494 | { 495 | "cell_type": "code", 496 | "execution_count": 23, 497 | "metadata": {}, 498 | "outputs": [ 499 | { 500 | "data": { 501 | "text/plain": [ 502 | "40360" 503 | ] 504 | }, 505 | "execution_count": 23, 506 | "metadata": {}, 507 | "output_type": "execute_result" 508 | } 509 | ], 510 | "source": [ 511 | "len(synsets)" 512 | ] 513 | }, 514 | { 515 | "cell_type": "code", 516 | "execution_count": 24, 517 | "metadata": {}, 518 | "outputs": [ 519 | { 520 | "data": { 521 | "text/plain": [ 522 | "[Synset('अजन्मा.adjective.1'),\n", 523 | " Synset('स्वयंभू.adjective.30168'),\n", 524 | " Synset('अशुभ.adjective.2'),\n", 525 | " Synset('अप्रविष्ट.adjective.3'),\n", 526 | " Synset('पवित्र स्थान.noun.4')]" 527 | ] 528 | }, 529 | "execution_count": 24, 530 | "metadata": {}, 531 | "output_type": "execute_result" 532 | } 533 | ], 534 | "source": [ 535 | "synsets[:5]" 536 | ] 537 | }, 538 | { 539 | "cell_type": "markdown", 540 | "metadata": {}, 541 | "source": [ 542 | "### All synsets filtered with POS tag" 543 | ] 544 | }, 545 | { 546 | "cell_type": "code", 547 | "execution_count": 25, 548 | "metadata": {}, 549 | "outputs": [], 550 | "source": [ 551 | "noun_synsets = iwn.all_synsets(pos=pyiwn.PosTag.NOUN)" 552 | ] 553 | }, 554 | { 555 | "cell_type": "code", 556 | "execution_count": 26, 557 | "metadata": {}, 558 | "outputs": [ 559 | { 560 | "data": { 561 | "text/plain": [ 562 | "29846" 563 | ] 564 | }, 565 | "execution_count": 26, 566 | "metadata": {}, 567 | "output_type": "execute_result" 568 | } 569 | ], 570 | "source": [ 571 | "len(noun_synsets)" 572 | ] 573 | }, 574 | { 575 | "cell_type": "code", 576 | "execution_count": 27, 577 | "metadata": {}, 578 | "outputs": [ 579 | { 580 | "data": { 581 | "text/plain": [ 582 | "[Synset('पवित्र स्थान.noun.4'),\n", 583 | " Synset('शिवालय.noun.5'),\n", 584 | " Synset('अपवित्र स्थान.noun.6'),\n", 585 | " Synset('नैतिक कार्य.noun.9'),\n", 586 | " Synset('दुश्चरित्रता.noun.11')]" 587 | ] 588 | }, 589 | "execution_count": 27, 590 | "metadata": {}, 591 | "output_type": "execute_result" 592 | } 593 | ], 594 | "source": [ 595 | "noun_synsets[:5]" 596 | ] 597 | }, 598 | { 599 | "cell_type": "markdown", 600 | "metadata": {}, 601 | "source": [ 602 | "### Words in a language's WordNet" 603 | ] 604 | }, 605 | { 606 | "cell_type": "code", 607 | "execution_count": 28, 608 | "metadata": {}, 609 | "outputs": [], 610 | "source": [ 611 | "words = iwn.all_words()" 612 | ] 613 | }, 614 | { 615 | "cell_type": "code", 616 | "execution_count": 29, 617 | "metadata": {}, 618 | "outputs": [ 619 | { 620 | "data": { 621 | "text/plain": [ 622 | "105458" 623 | ] 624 | }, 625 | "execution_count": 29, 626 | "metadata": {}, 627 | "output_type": "execute_result" 628 | } 629 | ], 630 | "source": [ 631 | "len(words)" 632 | ] 633 | }, 634 | { 635 | "cell_type": "code", 636 | "execution_count": 30, 637 | "metadata": {}, 638 | "outputs": [ 639 | { 640 | "data": { 641 | "text/plain": [ 642 | "['अजन्मा', 'अजात', 'अनुत्पन्न', 'अनुद्भूत', 'अप्रादुर्भूत']" 643 | ] 644 | }, 645 | "execution_count": 30, 646 | "metadata": {}, 647 | "output_type": "execute_result" 648 | } 649 | ], 650 | "source": [ 651 | "words[:5]" 652 | ] 653 | }, 654 | { 655 | "cell_type": "markdown", 656 | "metadata": {}, 657 | "source": [ 658 | "### Words filtered by POS Tag" 659 | ] 660 | }, 661 | { 662 | "cell_type": "code", 663 | "execution_count": 31, 664 | "metadata": {}, 665 | "outputs": [], 666 | "source": [ 667 | "noun_words = iwn.all_words(pos=pyiwn.PosTag.NOUN)" 668 | ] 669 | }, 670 | { 671 | "cell_type": "code", 672 | "execution_count": 32, 673 | "metadata": {}, 674 | "outputs": [ 675 | { 676 | "data": { 677 | "text/plain": [ 678 | "82747" 679 | ] 680 | }, 681 | "execution_count": 32, 682 | "metadata": {}, 683 | "output_type": "execute_result" 684 | } 685 | ], 686 | "source": [ 687 | "len(noun_words)" 688 | ] 689 | }, 690 | { 691 | "cell_type": "code", 692 | "execution_count": 33, 693 | "metadata": {}, 694 | "outputs": [ 695 | { 696 | "data": { 697 | "text/plain": [ 698 | "['बड़', 'गी', 'अभिक्रिया कारक', 'गर्मजोशी', 'कनकी']" 699 | ] 700 | }, 701 | "execution_count": 33, 702 | "metadata": {}, 703 | "output_type": "execute_result" 704 | } 705 | ], 706 | "source": [ 707 | "noun_words[:5]" 708 | ] 709 | }, 710 | { 711 | "cell_type": "markdown", 712 | "metadata": {}, 713 | "source": [ 714 | "### Synset Relations" 715 | ] 716 | }, 717 | { 718 | "cell_type": "code", 719 | "execution_count": 34, 720 | "metadata": {}, 721 | "outputs": [], 722 | "source": [ 723 | "hyponyms = iwn.synset_relation(aam, pyiwn.SynsetRelations.HYPONYMY)" 724 | ] 725 | }, 726 | { 727 | "cell_type": "code", 728 | "execution_count": 35, 729 | "metadata": {}, 730 | "outputs": [ 731 | { 732 | "data": { 733 | "text/plain": [ 734 | "95" 735 | ] 736 | }, 737 | "execution_count": 35, 738 | "metadata": {}, 739 | "output_type": "execute_result" 740 | } 741 | ], 742 | "source": [ 743 | "len(hyponyms)" 744 | ] 745 | }, 746 | { 747 | "cell_type": "code", 748 | "execution_count": 36, 749 | "metadata": {}, 750 | "outputs": [ 751 | { 752 | "data": { 753 | "text/plain": [ 754 | "[Synset('सफेदा.noun.1294'),\n", 755 | " Synset('अंबिया.noun.2888'),\n", 756 | " Synset('सिंदूरिया.noun.8636'),\n", 757 | " Synset('जरदालू.noun.4724'),\n", 758 | " Synset('तोतापरी.noun.6892')]" 759 | ] 760 | }, 761 | "execution_count": 36, 762 | "metadata": {}, 763 | "output_type": "execute_result" 764 | } 765 | ], 766 | "source": [ 767 | "hyponyms[:5]" 768 | ] 769 | }, 770 | { 771 | "cell_type": "markdown", 772 | "metadata": {}, 773 | "source": [ 774 | "### Supported Synset Relations" 775 | ] 776 | }, 777 | { 778 | "cell_type": "code", 779 | "execution_count": 37, 780 | "metadata": {}, 781 | "outputs": [ 782 | { 783 | "data": { 784 | "text/plain": [ 785 | "['SynsetRelations.MERO_MEMBER_COLLECTION',\n", 786 | " 'SynsetRelations.ABILITY_VERB',\n", 787 | " 'SynsetRelations.CAUSATIVE',\n", 788 | " 'SynsetRelations.CAPABILITY_VERB',\n", 789 | " 'SynsetRelations.MERO_COMPONENT_OBJECT',\n", 790 | " 'SynsetRelations.HOLO_PORTION_MASS',\n", 791 | " 'SynsetRelations.FUNCTION_VERB',\n", 792 | " 'SynsetRelations.HOLO_COMPONENT_OBJECT',\n", 793 | " 'SynsetRelations.HYPERNYMY',\n", 794 | " 'SynsetRelations.ENTAILMENT',\n", 795 | " 'SynsetRelations.ALSO_SEE',\n", 796 | " 'SynsetRelations.MERO_FEATURE_ACTIVITY',\n", 797 | " 'SynsetRelations.HOLO_PLACE_AREA',\n", 798 | " 'SynsetRelations.MODIFIES_VERB',\n", 799 | " 'SynsetRelations.ATTRIBUTES',\n", 800 | " 'SynsetRelations.MERO_PORTION_MASS',\n", 801 | " 'SynsetRelations.MODIFIES_NOUN',\n", 802 | " 'SynsetRelations.HOLO_FEATURE_ACTIVITY',\n", 803 | " 'SynsetRelations.MERO_STUFF_OBJECT',\n", 804 | " 'SynsetRelations.TROPONYMY',\n", 805 | " 'SynsetRelations.MERO_PLACE_AREA',\n", 806 | " 'SynsetRelations.HOLO_MEMBER_COLLECTION',\n", 807 | " 'SynsetRelations.HYPONYMY',\n", 808 | " 'SynsetRelations.SIMILAR',\n", 809 | " 'SynsetRelations.MERO_POSITION_AREA',\n", 810 | " 'SynsetRelations.HOLO_POSITION_AREA',\n", 811 | " 'SynsetRelations.HOLO_STUFF_OBJECT']" 812 | ] 813 | }, 814 | "execution_count": 37, 815 | "metadata": {}, 816 | "output_type": "execute_result" 817 | } 818 | ], 819 | "source": [ 820 | "list(map(str, pyiwn.SynsetRelations))" 821 | ] 822 | }, 823 | { 824 | "cell_type": "markdown", 825 | "metadata": {}, 826 | "source": [ 827 | "### Other language WordNet" 828 | ] 829 | }, 830 | { 831 | "cell_type": "code", 832 | "execution_count": 38, 833 | "metadata": {}, 834 | "outputs": [ 835 | { 836 | "name": "stderr", 837 | "output_type": "stream", 838 | "text": [ 839 | "2019-09-29:05:26:18,912 INFO [iwn.py:43] Loading kannada language synsets...\n" 840 | ] 841 | } 842 | ], 843 | "source": [ 844 | "kannada_iwn = pyiwn.IndoWordNet(lang=pyiwn.Language.KANNADA)" 845 | ] 846 | }, 847 | { 848 | "cell_type": "code", 849 | "execution_count": 39, 850 | "metadata": {}, 851 | "outputs": [ 852 | { 853 | "name": "stdout", 854 | "output_type": "stream", 855 | "text": [ 856 | "[Synset('ಮನುಷ್ಯ.noun.196'), Synset('ಮಾನವ.noun.858'), Synset('ಮಾನವ.noun.3389'), Synset('ಮನುಷ್ಯ.noun.22862')]\n" 857 | ] 858 | } 859 | ], 860 | "source": [ 861 | "print(kannada_iwn.synsets('ಮಾನವ'))" 862 | ] 863 | }, 864 | { 865 | "cell_type": "code", 866 | "execution_count": 40, 867 | "metadata": {}, 868 | "outputs": [ 869 | { 870 | "name": "stdout", 871 | "output_type": "stream", 872 | "text": [ 873 | "[Synset('ಗುಡುಗುಡು.noun.37371')]\n" 874 | ] 875 | } 876 | ], 877 | "source": [ 878 | "print(kannada_iwn.synsets('ಗುಡುಗುಡು'))" 879 | ] 880 | } 881 | ], 882 | "metadata": { 883 | "kernelspec": { 884 | "display_name": "Python 3", 885 | "language": "python", 886 | "name": "python3" 887 | }, 888 | "language_info": { 889 | "codemirror_mode": { 890 | "name": "ipython", 891 | "version": 3 892 | }, 893 | "file_extension": ".py", 894 | "mimetype": "text/x-python", 895 | "name": "python", 896 | "nbconvert_exporter": "python", 897 | "pygments_lexer": "ipython3", 898 | "version": "3.7.4" 899 | } 900 | }, 901 | "nbformat": 4, 902 | "nbformat_minor": 4 903 | } 904 | -------------------------------------------------------------------------------- /pyiwn/__init__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import logging 3 | 4 | from .helpers import download 5 | 6 | 7 | logging.basicConfig(format='[%(filename)s:%(lineno)d] %(message)s', 8 | datefmt='%Y-%m-%d:%H:%M:%S', 9 | level=logging.INFO) 10 | logger = logging.getLogger(__name__) 11 | 12 | 13 | if not download(): 14 | logger.error('Could not download IndoWordNet data.') 15 | sys.exit(1) 16 | 17 | 18 | from .iwn import Language 19 | from .iwn import PosTag 20 | from .iwn import SynsetRelations 21 | from .iwn import IndoWordNet 22 | -------------------------------------------------------------------------------- /pyiwn/constants.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pathlib import Path 3 | 4 | 5 | IWN_DATA_URL = 'https://www.dropbox.com/s/t29eqq19nt5eygs/iwn_data.tar.gz?dl=1' 6 | USER_HOME = str(Path.home()) 7 | IWN_DATA_TEMP_PATH = os.path.join(USER_HOME, 'iwn_data.tar.gz') 8 | IWN_DATA_PATH = os.path.join(*[USER_HOME, 'iwn_data']) 9 | -------------------------------------------------------------------------------- /pyiwn/helpers.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import requests 4 | import logging 5 | import tarfile 6 | 7 | import pyiwn.constants as constants 8 | 9 | 10 | logging.basicConfig(format='%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s', 11 | datefmt='%Y-%m-%d:%H:%M:%S', 12 | level=logging.INFO) 13 | logger = logging.getLogger(__name__) 14 | 15 | 16 | def download(): 17 | if os.path.exists(constants.IWN_DATA_PATH): 18 | return True 19 | 20 | logger.info('Downloading IndoWordNet data of size ~31 MB...') 21 | with open(constants.IWN_DATA_TEMP_PATH, 'wb') as f: 22 | try: 23 | response = requests.get(constants.IWN_DATA_URL, stream=True) 24 | except Exception as e: 25 | logger.error(e) 26 | return False 27 | 28 | total = response.headers.get('content-length') 29 | 30 | if total is None: 31 | f.write(response.content) 32 | else: 33 | downloaded = 0 34 | total = int(total) 35 | for data in response.iter_content(chunk_size=max(int(total / 1000), 1024 * 1024)): 36 | downloaded += len(data) 37 | f.write(data) 38 | done = int(50 * downloaded / total) 39 | sys.stdout.write('\r[{}{}]'.format('█' * done, '.' * (50 - done))) 40 | sys.stdout.flush() 41 | sys.stdout.write('\n') 42 | 43 | logger.info(f'Extracting {constants.IWN_DATA_TEMP_PATH} into {constants.USER_HOME}...') 44 | tar = tarfile.open(constants.IWN_DATA_TEMP_PATH) 45 | tar.extractall(constants.USER_HOME) 46 | tar.close() 47 | 48 | logger.info(f'Removing temporary zip file from {constants.IWN_DATA_TEMP_PATH}') 49 | os.remove(constants.IWN_DATA_TEMP_PATH) 50 | 51 | logger.info(f'IndoWordNet data successfully downloaded at {constants.IWN_DATA_PATH}') 52 | 53 | return True 54 | -------------------------------------------------------------------------------- /pyiwn/iwn.py: -------------------------------------------------------------------------------- 1 | from enum import Enum, unique 2 | import re 3 | import logging 4 | import glob 5 | import ntpath 6 | import os 7 | 8 | import pandas as pd 9 | 10 | import pyiwn.constants as constants 11 | 12 | 13 | logging.basicConfig(format='[%(filename)s:%(lineno)d] %(message)s', 14 | datefmt='%Y-%m-%d:%H:%M:%S', 15 | level=logging.INFO) 16 | logger = logging.getLogger(__name__) 17 | 18 | 19 | @unique 20 | class Language(Enum): 21 | ASSAMESE = 'assamese' 22 | BENGALI = 'bengali' 23 | BODO = 'bodo' 24 | GUJARATI = 'gujarati' 25 | HINDI = 'hindi' 26 | KANNADA = 'kannada' 27 | KASHMIRI = 'kashmiri' 28 | KONKANI = 'konkani' 29 | MALAYALAM = 'malayalam' 30 | MARATHI = 'marathi' 31 | MEITEI = 'meitei' 32 | NEPALI = 'nepali' 33 | ORIYA = 'oriya' 34 | PUNJABI = 'punjabi' 35 | SANSKRIT = 'sanskrit' 36 | TAMIL = 'tamil' 37 | TELUGU = 'telugu' 38 | URDU = 'urdu' 39 | 40 | 41 | class IndoWordNet: 42 | def __init__(self, lang=Language.HINDI): 43 | logger.info(f'Loading {lang.value} language synsets...') 44 | self._synset_idx_map = {} 45 | self._synset_df = self._load_synset_file(lang.value) 46 | self._synset_relations_dict = self._load_synset_relations() 47 | 48 | def _load_synset_file(self, lang): 49 | filename = os.path.join( 50 | *[constants.IWN_DATA_PATH, 'synsets', 'all.{}'.format(lang)]) 51 | f = open(filename, encoding='utf8') 52 | synsets = list( 53 | map(lambda line: self._load_synset(line), f.readlines())) 54 | synset_df = pd.DataFrame( 55 | synsets, columns=['synset_id', 'synsets', 'pos']) 56 | synset_df = synset_df.dropna() 57 | synset_df = synset_df.set_index('synset_id') 58 | return synset_df 59 | 60 | def _load_synset_relations(self): 61 | relations_dict = {} 62 | for file_path, relation_name in self._relation_list(): 63 | relations_dict[relation_name] = [] 64 | d = {} 65 | for line in open(file_path): 66 | line_parts = line.split('\t') 67 | synset_id, synset_ids = line_parts 68 | synset_id = int(synset_id) 69 | synset_ids = list(map(int, synset_ids.split(','))) 70 | synset_ids = list( 71 | filter(lambda x: True if x in self._synset_df.index else False, synset_ids)) 72 | if synset_id in d: 73 | d[synset_id].extend(synset_ids) 74 | else: 75 | if synset_ids: 76 | d[synset_id] = synset_ids 77 | relations_dict[relation_name] = d 78 | return relations_dict 79 | 80 | def _relation_list(self, type='synset_relations'): 81 | relations = [] 82 | path_parts = '{},{},*'.format(constants.IWN_DATA_PATH, type).split(',') 83 | for file_path in glob.glob(os.path.join(*path_parts)): 84 | file_name = ntpath.basename(file_path) 85 | file_name_parts = file_name.split('.') 86 | if len(file_name_parts) != 2: 87 | continue 88 | relation_name, pos_tag = file_name_parts 89 | relations.append((file_path, relation_name)) 90 | return relations 91 | 92 | def _update_synset_idx_map(self, synset): 93 | synset_id = synset.synset_id() 94 | for word in synset.lemma_names(): 95 | if word in self._synset_idx_map: 96 | self._synset_idx_map[word].append(synset_id) 97 | else: 98 | self._synset_idx_map[word] = [synset_id] 99 | return True 100 | 101 | def _load_synset(self, synset_string): 102 | if 'null' in synset_string: 103 | return None, None, None 104 | 105 | synset_string = synset_string.replace('\n', '').strip() 106 | synset_pattern = '([0-9]+)\t(.+)\t(.+)\t([a-zA-Z]+)' 107 | try: 108 | matches = re.findall(synset_pattern, synset_string) 109 | synset_id, synset_words, gloss_examples, pos = matches[0] 110 | except Exception as e: 111 | return None, None, None 112 | 113 | synset_id = int(synset_id) 114 | synset_words = list(filter(lambda x: False if x == 115 | '' else True, synset_words.split(','))) 116 | if not synset_words: 117 | return None, None, None 118 | head_word = synset_words[0] 119 | if gloss_examples != '': 120 | if ':"' in gloss_examples: 121 | ge_list = gloss_examples.split(':') 122 | gloss = ge_list[0] 123 | if len(ge_list) > 1: 124 | examples = ''.join(ge_list[1:]) 125 | examples = re.sub('["]', '', examples) 126 | examples = examples.split(' / ') 127 | else: 128 | examples = [] 129 | else: 130 | gloss = gloss_examples 131 | examples = [] 132 | else: 133 | return None, None, None 134 | synset = Synset(synset_id, head_word, 135 | synset_words, pos, gloss, examples) 136 | 137 | self._update_synset_idx_map(synset) 138 | 139 | return synset_id, synset, pos 140 | 141 | def all_synsets(self, pos=None): 142 | if pos is None: 143 | result = self._synset_df 144 | else: 145 | mask = (self._synset_df.pos == pos.value) 146 | result = self._synset_df[mask] 147 | return list(result['synsets'].values) 148 | 149 | def synsets(self, word, pos=None): 150 | try: 151 | synset_id_list = self._synset_idx_map[word] 152 | except: 153 | return [] 154 | 155 | synsets = [] 156 | if pos is not None: 157 | for synset_id in synset_id_list: 158 | synset = self._synset_df.loc[[synset_id]]['synsets'].values[0] 159 | if synset.pos() == pos.value: 160 | synsets.append(synset) 161 | else: 162 | for synset_id in synset_id_list: 163 | synset = self._synset_df.loc[[synset_id]]['synsets'].values[0] 164 | synsets.append(synset) 165 | 166 | return synsets 167 | 168 | def all_words(self, pos=None): 169 | if pos is None: 170 | return list(self._synset_idx_map.keys()) 171 | 172 | words = set() 173 | mask = (self._synset_df.pos == pos.value) 174 | for synset in self._synset_df[mask]['synsets'].values: 175 | for word in synset.lemma_names(): 176 | words.add(word) 177 | words = list(words) 178 | return words 179 | 180 | def synset_relation(self, synset, relation): 181 | return list(self._synset_df[self._synset_df.index.isin(self._synset_relations_dict[relation.value].get(synset.synset_id(), []))]['synsets']) 182 | 183 | 184 | class Synset: 185 | def __init__(self, synset_id, head_word, lemma_names, pos, gloss, examples): 186 | self._synset_id = synset_id 187 | self._head_word = head_word 188 | self._lemma_names = lemma_names 189 | self._pos = pos 190 | self._gloss = gloss 191 | self._examples = examples 192 | 193 | def __repr__(self): 194 | return 'Synset(\'{}.{}.{}\')'.format(self._head_word, self._pos, self._synset_id) 195 | 196 | def synset_id(self): 197 | return self._synset_id 198 | 199 | def head_word(self): 200 | return self._head_word 201 | 202 | def lemma_names(self): 203 | return self._lemma_names 204 | 205 | def lemmas(self): 206 | return [Lemma(self, lemma) for lemma in self._lemma_names] 207 | 208 | def pos(self): 209 | return self._pos 210 | 211 | def gloss(self): 212 | return self._gloss 213 | 214 | def examples(self): 215 | return self._examples 216 | 217 | def ontology_nodes(self): 218 | raise NotImplementedError("This method will be implemented soon.") 219 | 220 | 221 | class Lemma: 222 | def __init__(self, synset, name): 223 | self._synset = synset 224 | self._name = name 225 | 226 | def __repr__(self): 227 | return 'Lemma(\'{}.{}.{}.{}\')'.format(self._synset.head_word(), self._synset.pos(), self._synset.synset_id(), self._name) 228 | 229 | def name(self): 230 | return self._name 231 | 232 | def synset(self): 233 | return self._synset 234 | 235 | def gradation(self): 236 | raise NotImplementedError("This method will be implemented soon.") 237 | 238 | def antonym(self): 239 | raise NotImplementedError("This method will be implemented soon.") 240 | 241 | 242 | @unique 243 | class PosTag(Enum): 244 | NOUN = 'noun' 245 | VERB = 'verb' 246 | ADVERB = 'adverb' 247 | ADJECTIVE = 'adjective' 248 | 249 | 250 | class IndoWordNetError(Exception): 251 | """ An exception class for IndoWordNet-related errors. """ 252 | 253 | 254 | @unique 255 | class SynsetRelations(Enum): 256 | MERO_MEMBER_COLLECTION = 'mero_member_collection' 257 | ABILITY_VERB = 'ability_verb' 258 | CAUSATIVE = 'causative' 259 | CAPABILITY_VERB = 'capability_verb' 260 | MERO_COMPONENT_OBJECT = 'mero_component_object' 261 | HOLO_PORTION_MASS = 'holo_portion_mass' 262 | FUNCTION_VERB = 'function_verb' 263 | HOLO_COMPONENT_OBJECT = 'holo_component_object' 264 | HYPERNYMY = 'hypernymy' 265 | ENTAILMENT = 'entailment' 266 | ALSO_SEE = 'also_see' 267 | MERO_FEATURE_ACTIVITY = 'mero_feature_activity' 268 | HOLO_PLACE_AREA = 'holo_place_area' 269 | MODIFIES_VERB = 'modifies_verb' 270 | ATTRIBUTES = 'attributes' 271 | MERO_PORTION_MASS = 'mero_portion_mass' 272 | MODIFIES_NOUN = 'modifies_noun' 273 | HOLO_FEATURE_ACTIVITY = 'holo_feature_activity' 274 | MERO_STUFF_OBJECT = 'mero_stuff_object' 275 | TROPONYMY = 'troponymy' 276 | MERO_PLACE_AREA = 'mero_place_area' 277 | HOLO_MEMBER_COLLECTION = 'holo_member_collection' 278 | HYPONYMY = 'hyponymy' 279 | SIMILAR = 'similar' 280 | MERO_POSITION_AREA = 'mero_position_area' 281 | HOLO_POSITION_AREA = 'holo_position_area' 282 | HOLO_STUFF_OBJECT = 'holo_stuff_object' 283 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pandas 2 | requests -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.md -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | setup(name='pyiwn', 4 | version='0.0.5', 5 | description='pyiwn -- A Python based API to access Indian language WordNets -- This API gives access to synsets, glosses, examples, lexico-semantic relations between synsets, ontology nodes for 18 Indian languages, viz., Assamese, Bangla, Bodo, Gujarati, Hindi, Kannada, Kashmiri, Konkani, Malayalam, Meitei (Manipuri), Marathi, Nepali, Odia, Punjabi, Sanskrit, Tamil, Telugu and Urdu. In future, it will also provide access to speech data for words, glosses examples in Hindi WordNet.', 6 | url='https://github.com/riteshpanjwani/pyiwn', 7 | author='Ritesh Panjwani', 8 | author_email='riteshpanjwani@gmail.com', 9 | license='MIT', 10 | packages=['pyiwn'], 11 | zip_safe=False, 12 | keywords = ['wordnet', 'IndoWordNet', 'nlp', 'python', 'API'], 13 | install_requires=[line.replace('\n', '') for line in open('requirements.txt').readlines()] 14 | ) --------------------------------------------------------------------------------