1 Star 0 Fork 0

Wang Ningkai / simple-dictionary

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

Simple Dictionary

一个简单快速的词库工具

特点:

  • 简单:纯 PHP 实现,无需安装扩展。
  • 快速:查找耗时跟词库大小关系不大,不会一次性加载整个词库,使用时内存占用小(生成词库比较耗费内存)。

使用方法

1.准备文本格式的词库

首先准备一个文本文件,每个词占一行。格式:

词语<tab>值
词语<tab>值
词语<tab>值
词语<tab>值

词语<tab>值
词语<tab>值

2.使用SimpleDictionary生成词库


composer require wangningkai\simple-dictionary dev-master
<?php

require 'vendow/autoload.php'

use WangNingkai\SimpleDictionary\SimpleDictionary;

SimpleDictionary::make("text_file_path", "output_dict_path");

搜索

<?php
require 'vendow/autoload.php'

use WangNingkai\SimpleDictionary\SimpleDictionary;

$dict = new SimpleDictionary("dict_path");
$result = $dict->search("some text here...");

# 返回结果
# $result = [
#  'word1' => ['value' => 'value1', 'count' => 'count1'],
#  ...
# ]
#

替换

<?php
require 'vendow/autoload.php'

use WangNingkai\SimpleDictionary\SimpleDictionary;

$dict = new SimpleDictionary("dict_path");
# 简单替换
$replaced = $dict->replace("some text here...", "**");

#高级替换
$replaced = $dict->replace("some text here...", function($word, $value) {
  return "[$word -> $value]";
});

Comments ( 0 )

Sign in for post a comment

About

一个简单快速的词库工具 spread retract
Cancel

Releases

No release

Contributors

All

Activities

load more
can not load any more
1
https://gitee.com/wangningkai/simple-dictionary.git
git@gitee.com:wangningkai/simple-dictionary.git
wangningkai
simple-dictionary
simple-dictionary
master

Search