如何在 Ruby 中进行高级字符串比较? [英] How to do advanced string comparison in Ruby?

查看:49
本文介绍了如何在 Ruby 中进行高级字符串比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试比较 2 段字符串,其输出必须是相似度的百分比.

I am trying to compare 2 paragraphs of strings the output of which has to be the percentage of similarity.

我尝试使用 diff 方法和一些 自然语言处理工具

I have tried doing this using the diff method and some Natural Language Processing tools

在 ruby​​ 中有更好的方法吗?

Is there a better way of doing this in ruby?

推荐答案

您可能想为此尝试 Levenshtein 字符串距离算法.http://rubygems.org/gems/text 有一个实现以及其他有用的字符串比较实用程序.

You may want to try the Levenshtein string distance algorithm for this. http://rubygems.org/gems/text has an implementation of this along with other helpful string comparison utils.

这篇关于如何在 Ruby 中进行高级字符串比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆