{"id":23462560,"url":"https://github.com/dnanhkhoa/python-vncorenlp","last_synced_at":"2025-04-14T06:55:09.071Z","repository":{"id":57477524,"uuid":"134885726","full_name":"dnanhkhoa/python-vncorenlp","owner":"dnanhkhoa","description":"A Python wrapper for VnCoreNLP using a bidirectional communication channel.","archived":false,"fork":false,"pushed_at":"2018-08-10T20:20:14.000Z","size":41,"stargazers_count":56,"open_issues_count":2,"forks_count":18,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-14T06:55:02.818Z","etag":null,"topics":["dependency-parser","named-entity-recognition","ner","nlp","parser","pos-tagger","postagger","python-vncorenlp","tokenizer","vietnamese-nlp","vncorenlp","word-segmentation"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dnanhkhoa.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-25T17:25:55.000Z","updated_at":"2025-03-27T14:48:59.000Z","dependencies_parsed_at":"2022-08-30T18:31:00.599Z","dependency_job_id":null,"html_url":"https://github.com/dnanhkhoa/python-vncorenlp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnanhkhoa%2Fpython-vncorenlp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnanhkhoa%2Fpython-vncorenlp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnanhkhoa%2Fpython-vncorenlp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnanhkhoa%2Fpython-vncorenlp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dnanhkhoa","download_url":"https://codeload.github.com/dnanhkhoa/python-vncorenlp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248837281,"owners_count":21169374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dependency-parser","named-entity-recognition","ner","nlp","parser","pos-tagger","postagger","python-vncorenlp","tokenizer","vietnamese-nlp","vncorenlp","word-segmentation"],"created_at":"2024-12-24T08:17:59.695Z","updated_at":"2025-04-14T06:55:09.032Z","avatar_url":"https://github.com/dnanhkhoa.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# python-vncorenlp\n\n[![PyPI](https://img.shields.io/pypi/v/vncorenlp.svg)]()\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/vncorenlp.svg)]()\n\nA Python wrapper for [VnCoreNLP](https://github.com/vncorenlp/VnCoreNLP) using a bidirectional communication channel.\n\n## Table Of Contents\n\n  * [Prerequisites](#prerequisites)\n  * [Installation](#installation)\n  * [Example Usage](#example-usage)\n  * [Use An Existing Server](#use-an-existing-server)\n  * [Debug](#debug)\n  * [Some Use Cases](#some-use-cases)\n  * [License](#license)\n\n## Prerequisites\n\n- Java 1.8+ ([JRE](http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html) or [JDK](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html))\n- VnCoreNLP ([Github](https://github.com/vncorenlp/VnCoreNLP) or [Download](https://github.com/vncorenlp/VnCoreNLP/archive/master.zip))\n\n## Installation\n\nYou can install this package from PyPI using [pip](http://www.pip-installer.org):\n\n```\n$ [sudo] pip install vncorenlp\n```\n\nFor Windows users, please ensure that you run the `Command Prompt` with **admin** privileges.\n\n## Example Usage\n\nA simple example of how to use `vncorenlp`:\n\n```python\n#!/usr/bin/python\n# -*- coding: utf-8 -*-\nimport logging\n\nfrom vncorenlp import VnCoreNLP\n\n\ndef simple_usage():\n    # Uncomment this line for debugging\n    # logging.basicConfig(level=logging.DEBUG)\n\n    vncorenlp_file = r'.../VnCoreNLP-1.0.1/VnCoreNLP-1.0.1.jar'\n\n    sentences = 'VTV đồng ý chia sẻ bản quyền World Cup 2018 cho HTV để khai thác. ' \\\n                'Nhưng cả hai nhà đài đều phải chờ sự đồng ý của FIFA mới thực hiện được điều này.'\n\n    # Use \"with ... as\" to close the server automatically\n    with VnCoreNLP(vncorenlp_file) as vncorenlp:\n        print('Tokenizing:', vncorenlp.tokenize(sentences))\n        print('POS Tagging:', vncorenlp.pos_tag(sentences))\n        print('Named-Entity Recognizing:', vncorenlp.ner(sentences))\n        print('Dependency Parsing:', vncorenlp.dep_parse(sentences))\n        print('Annotating:', vncorenlp.annotate(sentences))\n        print('Language:', vncorenlp.detect_language(sentences))\n\n    # In this way, you have to close the server manually by calling close function\n    vncorenlp = VnCoreNLP(vncorenlp_file)\n\n    print('Tokenizing:', vncorenlp.tokenize(sentences))\n    print('POS Tagging:', vncorenlp.pos_tag(sentences))\n    print('Named-Entity Recognizing:', vncorenlp.ner(sentences))\n    print('Dependency Parsing:', vncorenlp.dep_parse(sentences))\n    print('Annotating:', vncorenlp.annotate(sentences))\n    print('Language:', vncorenlp.detect_language(sentences))\n\n    # Do not forget to close the server\n    vncorenlp.close()\n\n\nif __name__ == '__main__':\n    simple_usage()\n```\n\nAnd here is the output:\n\n```\nTokenizing:\n[\n    ['VTV', 'đồng_ý', 'chia_sẻ', 'bản_quyền', 'World_Cup', '2018', 'cho', 'HTV', 'để', 'khai_thác', '.'],\n    ['Nhưng', 'cả', 'hai', 'nhà', 'đài', 'đều', 'phải', 'chờ', 'sự', 'đồng_ý', 'của', 'FIFA', 'mới', 'thực_hiện', 'được', 'điều', 'này', '.']\n]\n \n \nPOS Tagging:\n[\n    [('VTV', 'Ny'), ('đồng_ý', 'V'), ('chia_sẻ', 'V'), ('bản_quyền', 'N'), ('World_Cup', 'N'), ('2018', 'M'), ('cho', 'E'), ('HTV', 'Ny'), ('để', 'E'), ('khai_thác', 'V'), ('.', 'CH')],\n    [('Nhưng', 'C'), ('cả', 'P'), ('hai', 'M'), ('nhà', 'N'), ('đài', 'N'), ('đều', 'R'), ('phải', 'V'), ('chờ', 'V'), ('sự', 'Nc'), ('đồng_ý', 'V'), ('của', 'E'), ('FIFA', 'Np'), ('mới', 'R'), ('thực_hiện', 'V'), ('được', 'R'), ('điều', 'N'), ('này', 'P'), ('.', 'CH')]\n]\n \n \nNamed-Entity Recognizing:\n[\n    [('VTV', 'O'), ('đồng_ý', 'O'), ('chia_sẻ', 'O'), ('bản_quyền', 'O'), ('World_Cup', 'O'), ('2018', 'O'), ('cho', 'O'), ('HTV', 'O'), ('để', 'O'), ('khai_thác', 'O'), ('.', 'O')],\n    [('Nhưng', 'O'), ('cả', 'O'), ('hai', 'O'), ('nhà', 'O'), ('đài', 'O'), ('đều', 'O'), ('phải', 'O'), ('chờ', 'O'), ('sự', 'O'), ('đồng_ý', 'O'), ('của', 'O'), ('FIFA', 'B-ORG'), ('mới', 'O'), ('thực_hiện', 'O'), ('được', 'O'), ('điều', 'O'), ('này', 'O'), ('.', 'O')]\n]\n \n \nDependency Parsing:\n[\n    [('sub', 2, 1), ('root', 0, 2), ('vmod', 2, 3), ('dob', 3, 4), ('nmod', 4, 5), ('det', 5, 6), ('iob', 3, 7), ('pob', 7, 8), ('prp', 3, 9), ('vmod', 9, 10), ('punct', 2, 11)],\n    [('dep', 7, 1), ('nmod', 4, 2), ('det', 4, 3), ('sub', 7, 4), ('nmod', 4, 5), ('adv', 7, 6), ('root', 0, 7), ('vmod', 7, 8), ('dob', 8, 9), ('nmod', 9, 10), ('nmod', 9, 11), ('pob', 11, 12), ('adv', 14, 13), ('vmod', 7, 14), ('adv', 14, 15), ('dob', 14, 16), ('det', 16, 17), ('punct', 7, 18)]\n]\n \n \nAnnotating:\n{\n  \"sentences\": [\n    [\n      {\n        \"index\": 1,\n        \"form\": \"VTV\",\n        \"posTag\": \"Ny\",\n        \"nerLabel\": \"O\",\n        \"head\": 2,\n        \"depLabel\": \"sub\"\n      },\n      {\n        \"index\": 2,\n        \"form\": \"đồng_ý\",\n        \"posTag\": \"V\",\n        \"nerLabel\": \"O\",\n        \"head\": 0,\n        \"depLabel\": \"root\"\n      },\n      {\n        \"index\": 3,\n        \"form\": \"chia_sẻ\",\n        \"posTag\": \"V\",\n        \"nerLabel\": \"O\",\n        \"head\": 2,\n        \"depLabel\": \"vmod\"\n      },\n      {\n        \"index\": 4,\n        \"form\": \"bản_quyền\",\n        \"posTag\": \"N\",\n        \"nerLabel\": \"O\",\n        \"head\": 3,\n        \"depLabel\": \"dob\"\n      },\n      {\n        \"index\": 5,\n        \"form\": \"World_Cup\",\n        \"posTag\": \"N\",\n        \"nerLabel\": \"O\",\n        \"head\": 4,\n        \"depLabel\": \"nmod\"\n      },\n      {\n        \"index\": 6,\n        \"form\": \"2018\",\n        \"posTag\": \"M\",\n        \"nerLabel\": \"O\",\n        \"head\": 5,\n        \"depLabel\": \"det\"\n      },\n      {\n        \"index\": 7,\n        \"form\": \"cho\",\n        \"posTag\": \"E\",\n        \"nerLabel\": \"O\",\n        \"head\": 3,\n        \"depLabel\": \"iob\"\n      },\n      {\n        \"index\": 8,\n        \"form\": \"HTV\",\n        \"posTag\": \"Ny\",\n        \"nerLabel\": \"O\",\n        \"head\": 7,\n        \"depLabel\": \"pob\"\n      },\n      {\n        \"index\": 9,\n        \"form\": \"để\",\n        \"posTag\": \"E\",\n        \"nerLabel\": \"O\",\n        \"head\": 3,\n        \"depLabel\": \"prp\"\n      },\n      {\n        \"index\": 10,\n        \"form\": \"khai_thác\",\n        \"posTag\": \"V\",\n        \"nerLabel\": \"O\",\n        \"head\": 9,\n        \"depLabel\": \"vmod\"\n      },\n      {\n        \"index\": 11,\n        \"form\": \".\",\n        \"posTag\": \"CH\",\n        \"nerLabel\": \"O\",\n        \"head\": 2,\n        \"depLabel\": \"punct\"\n      }\n    ],\n    [\n      {\n        \"index\": 1,\n        \"form\": \"Nhưng\",\n        \"posTag\": \"C\",\n        \"nerLabel\": \"O\",\n        \"head\": 7,\n        \"depLabel\": \"dep\"\n      },\n      {\n        \"index\": 2,\n        \"form\": \"cả\",\n        \"posTag\": \"P\",\n        \"nerLabel\": \"O\",\n        \"head\": 4,\n        \"depLabel\": \"nmod\"\n      },\n      {\n        \"index\": 3,\n        \"form\": \"hai\",\n        \"posTag\": \"M\",\n        \"nerLabel\": \"O\",\n        \"head\": 4,\n        \"depLabel\": \"det\"\n      },\n      {\n        \"index\": 4,\n        \"form\": \"nhà\",\n        \"posTag\": \"N\",\n        \"nerLabel\": \"O\",\n        \"head\": 7,\n        \"depLabel\": \"sub\"\n      },\n      {\n        \"index\": 5,\n        \"form\": \"đài\",\n        \"posTag\": \"N\",\n        \"nerLabel\": \"O\",\n        \"head\": 4,\n        \"depLabel\": \"nmod\"\n      },\n      {\n        \"index\": 6,\n        \"form\": \"đều\",\n        \"posTag\": \"R\",\n        \"nerLabel\": \"O\",\n        \"head\": 7,\n        \"depLabel\": \"adv\"\n      },\n      {\n        \"index\": 7,\n        \"form\": \"phải\",\n        \"posTag\": \"V\",\n        \"nerLabel\": \"O\",\n        \"head\": 0,\n        \"depLabel\": \"root\"\n      },\n      {\n        \"index\": 8,\n        \"form\": \"chờ\",\n        \"posTag\": \"V\",\n        \"nerLabel\": \"O\",\n        \"head\": 7,\n        \"depLabel\": \"vmod\"\n      },\n      {\n        \"index\": 9,\n        \"form\": \"sự\",\n        \"posTag\": \"Nc\",\n        \"nerLabel\": \"O\",\n        \"head\": 8,\n        \"depLabel\": \"dob\"\n      },\n      {\n        \"index\": 10,\n        \"form\": \"đồng_ý\",\n        \"posTag\": \"V\",\n        \"nerLabel\": \"O\",\n        \"head\": 9,\n        \"depLabel\": \"nmod\"\n      },\n      {\n        \"index\": 11,\n        \"form\": \"của\",\n        \"posTag\": \"E\",\n        \"nerLabel\": \"O\",\n        \"head\": 9,\n        \"depLabel\": \"nmod\"\n      },\n      {\n        \"index\": 12,\n        \"form\": \"FIFA\",\n        \"posTag\": \"Np\",\n        \"nerLabel\": \"B-ORG\",\n        \"head\": 11,\n        \"depLabel\": \"pob\"\n      },\n      {\n        \"index\": 13,\n        \"form\": \"mới\",\n        \"posTag\": \"R\",\n        \"nerLabel\": \"O\",\n        \"head\": 14,\n        \"depLabel\": \"adv\"\n      },\n      {\n        \"index\": 14,\n        \"form\": \"thực_hiện\",\n        \"posTag\": \"V\",\n        \"nerLabel\": \"O\",\n        \"head\": 7,\n        \"depLabel\": \"vmod\"\n      },\n      {\n        \"index\": 15,\n        \"form\": \"được\",\n        \"posTag\": \"R\",\n        \"nerLabel\": \"O\",\n        \"head\": 14,\n        \"depLabel\": \"adv\"\n      },\n      {\n        \"index\": 16,\n        \"form\": \"điều\",\n        \"posTag\": \"N\",\n        \"nerLabel\": \"O\",\n        \"head\": 14,\n        \"depLabel\": \"dob\"\n      },\n      {\n        \"index\": 17,\n        \"form\": \"này\",\n        \"posTag\": \"P\",\n        \"nerLabel\": \"O\",\n        \"head\": 16,\n        \"depLabel\": \"det\"\n      },\n      {\n        \"index\": 18,\n        \"form\": \".\",\n        \"posTag\": \"CH\",\n        \"nerLabel\": \"O\",\n        \"head\": 7,\n        \"depLabel\": \"punct\"\n      }\n    ]\n  ]\n}\n \n \nLanguage: vi\n```\n\n## Use An Existing Server\n\n**I highly recommend you to use this approach to save your time when you are debugging your code.**\n\nFirst, you need to start the VnCoreNLPServer using this command:\n\n```\n$ vncorenlp -Xmx2g \u003cVnCoreNLP File\u003e -p 9000 -a \"wseg,pos,ner,parse\"\n```\n\nThe parameter `-Xmx2g` means that the VM can allocate a maximum of 2 GB for the Heap Space.\n\nAnd then connect to the server using this code:\n\n```python\n# Use the existing server\nwith VnCoreNLP(address='http://127.0.0.1', port=9000) as vncorenlp:\n    ...\n```\n\n## Debug\n\nThere are 3 ways to enable debugging:\n\n```python\n#!/usr/bin/python\n# -*- coding: utf-8 -*-\nimport logging\nimport sys\n\nfrom vncorenlp import VnCoreNLP\n\n\n# 1. Use the global logger\n# logging.basicConfig(level=logging.DEBUG)\n\ndef simple_usage():\n    vncorenlp_file = r'.../VnCoreNLP-1.0.1/VnCoreNLP-1.0.1.jar'\n\n    sentences = 'VTV đồng ý chia sẻ bản quyền World Cup 2018 cho HTV để khai thác. ' \\\n                'Nhưng cả hai nhà đài đều phải chờ sự đồng ý của FIFA mới thực hiện được điều này.'\n\n    # Use \"with ... as\" to close the server automatically\n    vncorenlp = VnCoreNLP(vncorenlp_file)\n\n    # 2. Set up the local logger here\n    logger = vncorenlp.logger\n    logger.setLevel(logging.DEBUG)\n    # Add stdout\n    ch = logging.StreamHandler(sys.stdout)\n    ch.setLevel(logging.DEBUG)\n    # Add formatter\n    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')\n    ch.setFormatter(formatter)\n    logger.addHandler(ch)\n\n    with vncorenlp:\n        print('Tokenizing:', vncorenlp.tokenize(sentences))\n        print('POS Tagging:', vncorenlp.pos_tag(sentences))\n        print('Named-Entity Recognizing:', vncorenlp.ner(sentences))\n        print('Dependency Parsing:', vncorenlp.dep_parse(sentences))\n        print('Annotating:', vncorenlp.annotate(sentences))\n        print('Language:', vncorenlp.detect_language(sentences))\n\n    # In this way, you have to close the server manually by calling close function\n    vncorenlp = VnCoreNLP(vncorenlp_file)\n\n    # 3. Set up the local logger here\n    logger = vncorenlp.logger\n    logger.setLevel(logging.DEBUG)\n    # Add stdout\n    ch = logging.StreamHandler(sys.stdout)\n    ch.setLevel(logging.DEBUG)\n    # Add formatter\n    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')\n    ch.setFormatter(formatter)\n    logger.addHandler(ch)\n\n    print('Tokenizing:', vncorenlp.tokenize(sentences))\n    print('POS Tagging:', vncorenlp.pos_tag(sentences))\n    print('Named-Entity Recognizing:', vncorenlp.ner(sentences))\n    print('Dependency Parsing:', vncorenlp.dep_parse(sentences))\n    print('Annotating:', vncorenlp.annotate(sentences))\n    print('Language:', vncorenlp.detect_language(sentences))\n\n    # Do not forget to close the server\n    vncorenlp.close()\n\n\nif __name__ == '__main__':\n    simple_usage()\n```\n\n## Some Use Cases\n\n```python\n#!/usr/bin/python\n# -*- coding: utf-8 -*-\nimport logging\n\nfrom vncorenlp import VnCoreNLP\n\nlogging.basicConfig(level=logging.DEBUG)\n\n\ndef simple_usage():\n    vncorenlp_file = r'.../VnCoreNLP-1.0.1/VnCoreNLP-1.0.1.jar'\n\n    sentences = 'VTV đồng ý chia sẻ bản quyền World Cup 2018 cho HTV để khai thác. ' \\\n                'Nhưng cả hai nhà đài đều phải chờ sự đồng ý của FIFA mới thực hiện được điều này.'\n\n    # Use only word segmentation\n    with VnCoreNLP(vncorenlp_file, annotators=\"wseg\") as vncorenlp:\n        print('Tokenizing:', vncorenlp.tokenize(sentences))\n\n    # Specify the maximum heap size\n    with VnCoreNLP(vncorenlp_file, annotators=\"wseg\", max_heap_size='-Xmx4g') as vncorenlp:\n        print('Tokenizing:', vncorenlp.tokenize(sentences))\n\n    # For debugging\n    with VnCoreNLP(vncorenlp_file, annotators=\"wseg\", max_heap_size='-Xmx4g', quiet=False) as vncorenlp:\n        print('Tokenizing:', vncorenlp.tokenize(sentences))\n\n\nif __name__ == '__main__':\n    simple_usage()\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdnanhkhoa%2Fpython-vncorenlp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdnanhkhoa%2Fpython-vncorenlp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdnanhkhoa%2Fpython-vncorenlp/lists"}