如何在 MySQL 中标记字符串?

发布于 2024-12-21 06:04:45 字数 803 浏览 1 评论 0原文

我的项目正在从平面 Excel 文件导入超过 50 万行数据的大量数据,这些文件是由团队手动创建的。现在的问题是,这一切都需要标准化,以便客户搜索。例如,公司字段将有多个公司拼写并包括分支机构,例如“IBM”,然后是“IBM Inc.”。此外,我还有字母数字的产品名称,例如“A46-Rhizonme Pentahol”,单独使用 SOUNDEX 无法处理

从长远来看,我可以通过使用 AJAX 自动建议通过 Web 表单输入所有数据来解决该问题。但在那之前,我仍然需要处理大量现有数据。根据我在这里读到的内容,这让我相信这是一个很好的过程:

http://msdn.microsoft.com/en-us/magazine/cc163731.aspx

创建自定义模糊逻辑查找和模糊逻辑分组列表

  1. 将字符串标记化 的步骤关键字
  2. 计算关键字 TF-IDF(总频率 - 逆文档频率)
  3. 计算关键字之间的编辑距离 计算
  4. 可用 alpha 字符串的 Soundex
  5. 确定关键字的上下文
  6. 根据上下文将关键字放入单独的数据库表中,例如“公司”、“产品” ,“成分”

我一直在谷歌搜索、搜索 StackOverflow、阅读 MySQL.com 上关于这个问题的讨论等,试图找到一个预先构建的解决方案。有什么想法吗?

My project is importing a sizable collection +500K rows of data from flat Excel files, which are manually created by a team of people. Now the problem is that it all needs to be normalized, for client searching. For example, the company field will have multiple company spellings and include branches, such as "IBM" and then "IBM Inc." and "IBM Japan" etc. Additionally, I have product names that alphanumeric, such as "A46-Rhizonme Pentahol", which SOUNDEX alone cannot handle.

I can solve the issue in the long term by having all the data input be through a web form, with an AJAX auto-suggest. Until then however, I still need to deal with the massive collection of existing data. This brings me to what I believe is a good process, based on what I've read here:

http://msdn.microsoft.com/en-us/magazine/cc163731.aspx

Steps to create a custom Fuzzy Logic Lookup, and Fuzzy Logic Grouping

  1. List item
  2. tokenize strings into keywords
  3. calculate keyword TF-IDF (total frequency - inverse document frequecy)
  4. calculate levenshtein distance between keywords
  5. calculate Soundex on available alpha strings
  6. determine context of keywords
  7. place keywords, based on context, into separate DB tables, such as "Companies", "Products", "Ingredients"

I've been Googling, searching StackOverflow, reading over MySQL.com discussions, etc. about this issue, to attempt to find a prebuilt solution. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浮光之海 2024-12-28 06:04:45

所以,我放弃了,只是为mysql做了一个字符串标记化函数。代码如下:

CREATE DEFINER = `root`@`localhost` FUNCTION `NewProc`(in_string VARCHAR(255), delims VARCHAR(255), str_replace VARCHAR(255))
 RETURNS varchar(255)
    DETERMINISTIC
BEGIN
    DECLARE str_len, delim_len, a, b, is_delim INT;
    DECLARE z, y VARBINARY(1);
    DECLARE str_out VARBINARY(256);
    SET str_len = CHAR_LENGTH(in_string), delim_len = CHAR_LENGTH(delims),a = 1, b = 1, is_delim = 0, str_out = '';

    -- get each CHARACTER
    WHILE a <= str_len DO
        SET z = SUBSTRING(in_string, a, 1);
        -- loop through the deliminators
        WHILE b <= delim_len AND is_delim < 1 DO
            SET y = SUBSTRING(delims, b, 1);
            -- search for each deliminator
            IF z = y THEN
                SET is_delim = 1;
            END IF;
            SET b = b + 1;
        END WHILE;

        IF is_delim = 1 THEN
            SET str_out = CONCAT(str_out, str_replace);
        ELSE
            SET str_out = CONCAT(str_out, z);
        END IF;

        SET b = 0;
        SET is_delim = 0;
        SET a = a + 1;
    END WHILE;
    RETURN str_out;
END;

它的调用方式如下:

strtok("this.is.my.input.string",".,:;"," | ")

并将返回

“this | is | my | input | string”

我希望其他人发现这很有用。干杯!

So, I gave up and just made a string tokenizing function for mysql. Here's the code:

CREATE DEFINER = `root`@`localhost` FUNCTION `NewProc`(in_string VARCHAR(255), delims VARCHAR(255), str_replace VARCHAR(255))
 RETURNS varchar(255)
    DETERMINISTIC
BEGIN
    DECLARE str_len, delim_len, a, b, is_delim INT;
    DECLARE z, y VARBINARY(1);
    DECLARE str_out VARBINARY(256);
    SET str_len = CHAR_LENGTH(in_string), delim_len = CHAR_LENGTH(delims),a = 1, b = 1, is_delim = 0, str_out = '';

    -- get each CHARACTER
    WHILE a <= str_len DO
        SET z = SUBSTRING(in_string, a, 1);
        -- loop through the deliminators
        WHILE b <= delim_len AND is_delim < 1 DO
            SET y = SUBSTRING(delims, b, 1);
            -- search for each deliminator
            IF z = y THEN
                SET is_delim = 1;
            END IF;
            SET b = b + 1;
        END WHILE;

        IF is_delim = 1 THEN
            SET str_out = CONCAT(str_out, str_replace);
        ELSE
            SET str_out = CONCAT(str_out, z);
        END IF;

        SET b = 0;
        SET is_delim = 0;
        SET a = a + 1;
    END WHILE;
    RETURN str_out;
END;

It's called like this:

strtok("this.is.my.input.string",".,:;"," | ")

and will return

"this | is | my | input | string"

I hope someone else finds this useful. Cheers!

嗫嚅 2024-12-28 06:04:45

您应该查看 Google Refine

Google Refine 是一款强大的工具,用于处理和清理杂乱的数据
向上,将其从一种格式转换为另一种格式,用
Web 服务,并将其链接到 Freebase 等数据库。

You should check out Google Refine.

Google Refine is a power tool for working with messy data, cleaning it
up, transforming it from one format into another, extending it with
web services, and linking it to databases like Freebase.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文