Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use pycharm to call Hanlp Natural language processing package under ubuntu

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to use pycharm to call Hanlp natural language processing package under ubuntu". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

First click File, select Settings, click Project Interpreter under Project, and click the plus sign on the right:

Search JPype and select the JPype version you want to install based on the python version.

After that, in https://github.com/hankcs/HanLP/releases

Download hanlp.jar package, model data package, configuration file hanlp.properties, and create a new folder Hanlp

Put hanlp.jar and hanlp.properties in:

After that, you need to create a new folder hanlp and put data in it:

Modify the path under Hanlp to the path of the current data, because I put data under / home/javawork/hanlp, so: root=/home/javawork/hanlp/

Next, create a new file demo_hanlp.py with the following code:

#! / usr/bin/env python2.7

# coding=utf-8

From jpype import *

# startJVM (getDefaultJVMPath (), "- Djava.class.path=home/javawork/Hanlp/hanlp-1.2.7.jar;home/javawork/Hanlp/", "- Xms1g", "- Xmx1g")

StartJVM (getDefaultJVMPath (), "- Djava.class.path=/home/qinghua/javawork/Hanlp/hanlp-1.2.7.jar:/home/qinghua/javawork/Hanlp")

HanLP = JClass ('com.hankcs.hanlp.HanLP')

# Chinese word Segmentation

Print (HanLP.segment ('Hello, welcome to call HanLP's API' in Python))

TestCases = [

"goods and services"

"married and unmarried do interfere with participle."

"buy fruit, then come to the Expo Park and finally go to the World Expo"]

For sentence in testCases: print (HanLP.segment (sentence))

# named entity recognition and part of speech tagging

NLPTokenizer = JClass ('com.hankcs.hanlp.tokenizer.NLPTokenizer')

Print (NLPTokenizer.segment ('Professor Zong Chengqing of the Institute of Computing Technology of the Chinese Academy of Sciences is teaching natural language processing')

# keyword extraction

Document = "Chen Mingzhong, director of the Water Resources Department of the Ministry of Water Resources, revealed at a press conference held by the Information Office on September 29th,"

"according to the assessment of the water resources management system that has just been completed, some provinces are close to the red line target."

"some provinces exceed the index of the red line. For some places that exceed the red line, Chen Mingzhong said that regional restrictions should be imposed on some water intake projects."

"the demonstration of water resources and the approval of water intake permits shall be carried out strictly."

Print (HanLP.extractKeyword (document, 2))

# automatic summary

Print (HanLP.extractSummary (document, 3))

# dependency parsing

Print ("Mr. Xu also specifically helped him identify the painting of eagles, squirrels and sparrows as his main target."))

ShutdownJVM ()

It should be noted that the path separator for ubuntu is ":" and window is ";"

This is the end of the content of "how to use pycharm to call the Hanlp natural language processing package under ubuntu". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report