Git Product home page Git Product logo

text-segment's Introduction

分詞系統 (Segment System)

  • using simple Trie data structure
  • maximum matching

Dependency Intallation

  • Python 3.5
# we using virtuel environment
$ virtuelenv -p python3.5 env
$ source env/bin/activate
(env)$ pip install -r requirements.txt

Example

import segment

# 創建你的字典或是載入先前的字典
dictionary = dictionary.Dictionary()
dictionary.load([optional_path])

# 建立斷詞系統,並且可以搭配不同的字典來使用
segments_agent = segment.SegmentSystem()
segments_agent.use_dictionary(dictionary)

context = '''勞神勞力又勞心勞費的勞什骨子喜歡勞什子嗎?'''
segment_list = segments_agent.segments(context)
print(segment_list)
# result: ['勞神', '勞力', '又', '勞心', '勞費', '的', '勞什骨子', '喜歡', '勞什子', '嗎', '?']

How to use?

  1. clone this project
  2. cd /src
  3. initialize dictionary: python build_dictionary.py
  4. enjoy it!
1. Simple input:
(env)$ python main.py -s '今天天氣好冷,這種天氣就想睡覺。睡眠不足的話,會氣噗噗'
# ['今天', '天氣', '好', '冷', ',', '這', '種', '天氣', '就', '想', '睡覺', '。', '睡眠', '不足', '的', '話', ',', '會', '氣', '噗', '噗']

2. File Input:
(env)$ python main.py -f context.txt
# ['今天', '早上', '在', '操場', '看', '到', '一個', '身形', '疲累', '的', '人', ',', '被', '別人', '稱', '作', '勞什骨子', '。', '到底', '勞什骨子', '是', '什麼', '呢', '?']

text-segment's People

Contributors

jielite avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.