How to use hanlp in ubuntu

Preface

In the past, I used python's stuttering word segmentation tool for most of Chinese word segmentation. The word segmentation tool is to call API online. About the principle of this word segmentation tool, I recommend a good blog:

http://blog.csdn.net/daniel_ustc/article/details/48195287.

With the needs of the project, I need to use Stanford University's natural language processing package standford to build the dependency tree, but Standford is very mischievous to not let me do Chinese word segmentation (old error). In desperation, I can only use third-party word segmentation tools. Since the source code of Standford is java, I found a corresponding word segmentation tool, namely hanlp.

Installation and use of HanLP

One of the great benefits of HanLP is the offline open source toolkit. In other words, it not only provides free code to download for free, but also makes the hard-collected dictionaries public. This is a selfless act. When I install, I mainly refer to this blog:

http://m.blog.csdn.net/article/details?id=50938796

But this blog mainly introduces how to use hanlp in windows, and ubuntu is linux, so there will be differences. Below I mainly introduce the installation and use of unbuntu.

Install eclipse

Enter sudo get-apt install eclipse-platform in the terminal to achieve one-click installation, and then find eclipse in the application

Download hanlp

Visit the official website of hanlp: http://hanlp.linrunsoft.com/services.html

Download hanlp.jar (program package), data.zip (dictionary library), hanlp.properties (configuration file), and the following is the documentation, you don’t need to download it

When downloading data.zip, the download link is a bit obscure, click on the blue data-for-1.2.11.zip, and Baidu cloud link will appear.

Import the jar package

Import hanlp into eclipse, the specific process can refer to the website:

http://jingyan.baidu.com/article/ca41422fc76c4a1eae99ed9f.html

Import configuration file

Copy hanlp.propertie to the bin directory of the project and modify the path of the dictionary

Modify the path of root to the path where data is saved (remember to unzip data)

Programming code demonstration

import java.util.List;

import com.hankcs.hanlp.HanLP;

import com.hankcs.hanlp.seg.Segment;

import com.hankcs.hanlp.seg.common.Term;

public class DemoHanLP {

public static void main(String[] agrs){

String sentence = "Hello everyone, my name is Quincy.";

Segment segment = HanLP.newSegment();

List termList = segment.seg(sentence);

for(Term term : termList){

System.out.print(term+ " ");

    }

}

}

operation result:

The article comes from Quincy1994's blog

Recommended Posts

How to use hanlp in ubuntu
How to configure TensorFlow use environment in Ubuntu
How to use dpkg command in Ubuntu system
Introduction to the use of Hanlp in ubuntu
How to install Helm in Ubuntu
How to install mysql in Ubuntu 14.04
How to use Putty to log in to ubuntu installed in VirtualBox
How to install mysql in Ubuntu 14.04
How to use SQLite in Python
How to add swap partition in Ubuntu
How to easily compile openJDK in Ubuntu
How to use and and or in Python
How to install cuda10.1 driver in Ubuntu
How to add users to Sudoers in Ubuntu
How to delete redundant kernels in Ubuntu
How to delete redundant kernels in Ubuntu
How to use Samba server on Ubuntu 16.04
How to install ROS Noetic in Ubuntu20.04
How to set static IP in ubuntu14.04
How to modify software source in Ubuntu 7.10
How to open root account in Ubuntu20.04
How to hide applications in Ubuntu Dash?
How to upgrade to Ubuntu 20.04
Use supervisor in ubuntu
How to upgrade to Ubuntu 20.04
How to use Prometheus to monitor your Ubuntu 14.04 server
How to use the round function in python
How to modify time zone and time in ubuntu
How to use the zip function in Python
How to use Nginx's map module on Ubuntu 16.04
How to install and use Docker on Ubuntu 20.04
How to install python in ubuntu server environment
How to install and use Curl on Ubuntu 18.04
How to install and use Composer on Ubuntu 18.04
How to install and use Wine on Ubuntu 18.04
How to use the format function in python
How to use Docker data volumes on Ubuntu 14.04
How to open the ubuntu system in win10
How to use code running assistant in python
How to install and use Composer on Ubuntu 20.04
How to install and use BaasBox on Ubuntu 14.04
How to use Jenkins to build automatically on Ubuntu
How to install and use PostgreSQL on Ubuntu 16.04
How to configure /var/log/messages in Ubuntu system log
How to install and use Docker on Ubuntu 16.04
Use of Anaconda in Ubuntu
How to use python tuples
Use virtualbox to deploy ubuntu
How to upgrade to Ubuntu 16.04 LTS
How to install Hadoop in standalone mode on Ubuntu 18.04
How to use LVM to manage storage devices on Ubuntu 18.04
How to create and use MongoDB backups on Ubuntu 14.04
How to install and use MySQL Workbench on Ubuntu 18.04
How to view detailed network routing table in Ubuntu
How to modify time zone and time in ubuntu system
Example of how to modify ip address in Ubuntu20.04
How to create a Python virtual environment in Ubuntu 14.04
How to install Memcached on Ubuntu 20.04
How to use Python's filter function
How to use python's help function
How to install Java on Ubuntu 20.04