dd/php-library-ddtextcompare 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dd/php-library-ddtextcompare

Composer 安装命令:

composer require dd/php-library-ddtextcompare

包简介

A simple tool allowing to compare two texts

README 文档

README

A simple tool allowing to compare two strings. The library works only with UTF-8 strings for now.

What this library is

ddTextCompare can be used in situations when it is not possible to make the native string comparison in PHP. The library relies on chars number and their position, therefore, it's suitable for a comparison of strings containing typos or having different word order but the same words.

What this library isn't

ddTextCompare has nothing to do with morphological or any other analysis you would expect from an intelligent search engine. The main purpose for the library is to stay simple.

How it works

By default ddTextCompare performs a simple analysis. Each string being compared is represented as two n-dimensional vectors, where n is the number of unique chars used in both strings. The firs vector v1 shows what chars are in its string and their total number. The other vector v2 shows where those unique chars are. When those two vectors are found for each string, cosine similarity will be found for the vector pairs. Once calculated, cos(v1,1v1,2) and cos(v2,1v2,2) are multiplied by their wights respectively and the result is modified to make it belong to a range between 0 and 1.

Installation

Composer

Just add the package to your composer.json.

composer require dd/php-library-ddtextcompare

Manually

Though it's convenient to use Composer, it is also possible to place the library wherever you want and include all the classes inside the “src” folder manually.

Basic usage

Here are some examples.

Comparing strings with typos

$compare = new DDTextCompare();
$similarity = $compare->compare("Text without any typos", "Text wihtout ayn typoes");
// $similarity = 0.99076390557741

Adjusting weights

By default, the weights for all criteria are equal, but it can be changed. When a wight is changed the another weight will be adjusted automatically to make their sum equal to 1.

$compare = new DDTextCompare();
$comparator = new Comparator\Cosine();

//Change the char total criterion weight
$comparator->setCharTotalWeight(0.8)

$similarity = $compare->compare("Text without any typos", "Txet wihtout ayn typoes", $comparator);
// $similarity = 0.99310343750374

Extending

A custom comparator class can be created by implementing the DDTextCompare\Comparator interface.

$compare = new DDTextCompare();
$comparator = new Comparator\YourCustomComparator();

$similarity = $compare->compare("Text without any typos", "Txet wihtout ayn typoes", $comparator);

Changelog

Version 0.9 (2015-11-07)

  • + The first release.

dd/php-library-ddtextcompare 适用场景与选型建议

dd/php-library-ddtextcompare 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 11 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「text compare」 「dd」 「divan design」 「ddtextcompare」 「string compare」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 dd/php-library-ddtextcompare 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dd/php-library-ddtextcompare 我们能提供哪些服务?
定制开发 / 二次开发

基于 dd/php-library-ddtextcompare 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 19
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-11-07