Php脚本,用于查找/识别域名中的单词


Php script to find/recognize words in the domain name

我正在寻找一个能够识别域名中单词的php代码/脚本。

例如,当用户查询域名snapnames.com时,此脚本将显示snapnames.com(识别此域中的2个单词:snapnames)

希望有人能帮助

感谢

恐怕没有完美的答案。。。arnold说,像"expertsexbhange.com"这样的域名可以评估为"Expert Sex Change.com"answers"Experts Exchange.com"

不仅如此,这样的函数在内存和处理能力上都会相当密集。你需要有巨大的文件才能识别所有的单词,等等。很高兴知道你为什么需要这个,以便尝试找到不同的解决方案。

如果你有某种显示网站信息的服务,那么显示"Snapnames.com"是完全可以接受的。没有必要将其大写或类似的东西。

然而,如果你对这种行为下定决心,即使它不是100%准确的,而且在你的服务器上相当激烈。。。

您首先需要找到一种方法来检查字符串是否为单词。这是一个完全独立的问题,有一个完全合理的答案。您需要单独询问,看看是否可以找到适用于PHP的词典库。

基本上,在字符串中向后迭代,直到它变成一个单词,从字符串中删除该单词,然后重复。例如:

expertsexchange.com,你可以这样查看:

第一个{}是你的单词表。第一个"是您要检查的所有字母最后一个"是您正在检查的当前字母子集

{} "expertsexchange" "expertsexchange" <-- not a word
{} "expertsexchange" "expertsexchang" <-- not a word
{} "expertsexchange" "expertsexchan" <-- not a word
{} "expertsexchange" "expertsexcha" <-- not a word
{} "expertsexchange" "expertsexch" <-- not a word
{} "expertsexchange" "expertsexc" <-- not a word
{} "expertsexchange" "expertsex" <-- not a word
{} "expertsexchange" "expertse" <-- not a word
{} "expertsexchange" "experts" <-- WORD! Add it to our list of words
{"experts"} "exchange" "exchange" <-- WORD! Add it to our list of words
{"experts", "exchange"} "" "" <-- No more letters to check, we have found all of our words.

让我们尝试一个不同的例子。。。

你好,小猫。这有一个字典无法识别的"单词"("wittle")。不幸的是,算法就是这样处理的:

{} "hellotherewittlekitty" "hellotherewittlekitty" <-- not a word
{} "hellotherewittlekitty" "hellotherewittlekitt" <-- not a word
{} "hellotherewittlekitty" "hellotherewittlekit" <-- not a word
{} "hellotherewittlekitty" "hellotherewittleki" <-- not a word
{} "hellotherewittlekitty" "hellotherewittlek" <-- not a word
{} "hellotherewittlekitty" "hellotherewittle" <-- not a word
{} "hellotherewittlekitty" "hellotherewittl" <-- not a word
{} "hellotherewittlekitty" "hellotherewitt" <-- not a word
{} "hellotherewittlekitty" "hellotherewit" <-- not a word
{} "hellotherewittlekitty" "hellotherewi" <-- not a word
{} "hellotherewittlekitty" "hellotherew" <-- not a word
{} "hellotherewittlekitty" "hellothere" <-- not a word
{} "hellotherewittlekitty" "hellother" <-- not a word
{} "hellotherewittlekitty" "hellothe" <-- not a word
{} "hellotherewittlekitty" "helloth" <-- not a word
{} "hellotherewittlekitty" "hellot" <-- not a word
{} "hellotherewittlekitty" "hello" <-- WORD! add it to list, and remove form main string!
{"hello"} "therewittlekitty" "therewittlekitty" <-- not a word
{"hello"} "therewittlekitty" "therewittlekitt" <-- not a word
{"hello"} "therewittlekitty" "therewittlekit" <-- not a word
{"hello"} "therewittlekitty" "therewittleki" <-- not a word
{"hello"} "therewittlekitty" "therewittlek" <-- not a word
{"hello"} "therewittlekitty" "therewittle" <-- not a word
{"hello"} "therewittlekitty" "therewittl" <-- not a word
{"hello"} "therewittlekitty" "therewitt" <-- not a word
{"hello"} "therewittlekitty" "therewit" <-- not a word
{"hello"} "therewittlekitty" "therew" <-- not a word
{"hello"} "therewittlekitty" "there" <-- WORD! add it to list, and remove from main string
{"hello", "there"} "wittlekitty" "wittlekitty" <-- not a word
{"hello", "there"} "wittlekitty" "wittlekitt" <-- not a word
{"hello", "there"} "wittlekitty" "wittlekit" <-- not a word
{"hello", "there"} "wittlekitty" "wittleki" <-- not a word
{"hello", "there"} "wittlekitty" "wittlek" <-- not a word
{"hello", "there"} "wittlekitty" "wittle" <-- not a word (even though humans read it as one)
{"hello", "there"} "wittlekitty" "wittl" <-- not a word
{"hello", "there"} "wittlekitty" "witt" <-- WORD! add to dictionary and remove from string
{"hello", "there", "witt"} "lekitty" "lekitty" <-- not a word
{"hello", "there", "witt"} "lekitty" "lekitt" <-- not a word
{"hello", "there", "witt"} "lekitty" "lekit" <-- not a word
{"hello", "there", "witt"} "lekitty" "leki" <-- WORD! (biology, wikipedia)
{"hello", "there", "witt", "leki"} "tty" "tty" <-- not a word
{"hello", "there", "witt", "leki"} "tty" "tt" <-- not a word
{"hello", "there", "witt", "leki"} "tty" "t" <-- not a word
{"hello", "there", "witt", "leki"} "tty" "" <-- No more letters, add it to the list!
{"hello", "there", "witt", "leki", "tty"} "" ""

因此,hellothewittlekitty会以hellotherewittlekitty的形式出现,这比只保留小写更糟糕。

还有更多的算法比这更耗费你的CPU,需要更多的数据,这可能会为你提供更高的准确性。但总的来说,对于所有的工作来说,只有30%的准确率是不值得的。特别是因为当算法失败时,它会打断你的话。这意味着添加这个会让你60%的网站被毁。