Giter Club home page Giter Club logo

dict's Introduction

SimpleDict

这是一个简单快速的词库工具,用来从一段文本中找出存在于词库的词语。

特点

  • 简单:纯 PHP 实现,无需安装扩展。
  • 快速:查找耗时跟词库大小关系不大(我的小破本上查询 40 万的词库轻轻松松),不会一次性加载整个词库,使用时内存占用小(就是生成词库的时候有点费内存)。

使用方法

准备文本格式的词库

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

词语<tab>值

生成 SimpleDict 专用词库

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

搜索

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

/* $result 的格式:
array(
  'word1' => array('value' => 'value1', 'count' => 'count1'),
  ...
)*/

替换

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

dict's People

Contributors

nowgoo avatar sillydong 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.