【问题标题】:How to count word of sentence from database with PHP如何使用 PHP 从数据库中计算句子中的单词
【发布时间】:2019-05-23 08:39:12
【问题描述】:

我在数据库中有一个表

|ID| Sentence        |  
|1 | I have a Rabbit |     
|2 | I have a Turtle |

如何计算该表中的每个单词(或者这是一个 TF-IDF Raw 方法)?

I  = 2 
have = 2
a = 2 
Rabbit = 1 
Turtle = 1 

有人帮我写PHP代码吗?

【问题讨论】:

标签: php information-retrieval tf-idf cosine-similarity


【解决方案1】:

您需要将所有字符串连接到一个变量,然后这样做

$words = 'Word count count';
print_r( array_count_values(str_word_count($words, 1)) );

http://sandbox.onlinephpfunctions.com/code/e7820275a94fbcf6fa814d4886167e201ce03de3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-04
    • 2015-08-18
    • 2018-01-21
    • 2020-04-25
    • 2015-01-03
    • 2015-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多