How to calculate DF in TF-IDF with PHP

51
January 12, 2019, at 1:30 PM

I have a pseudocode about TF IDF, and i'm still confused how to calculate document frequency.

Example :

D1 : I have a box inside big box

D2 : I have box

Goal :

tf of "box" in D1 = 2

tf off "box" in D2 = 1

and
df of "box"= 1

Here is my pseudocode: documents = read_documents()

all_words = []
idf = []
tf = [][]

for (document in documents) {
    words = document.split()
    for (word in words) {
        tf[document][word] += 1 / words.count
    }
    for (word in tf[document]) {
        all_words[word] += 1
    }
    print(tf)
}

I've already tried but still failed

Here is my code :

$sql = "SELECT * FROM tbl_judul";
$N = $connection->query($sql)->num_rows;
echo "Jumlah dokumen = ".$N."<br>";
$result = $connection->query($sql)->fetch_all(MYSQLI_ASSOC);
$Dokumen = array_column($result, "judul_prepros");
//print_r($Dokumen);
$all_word = array();
$count = array();
$tf = array();
$df = array();
echo "Nilai tf tiap term : <br>";
foreach ($Dokumen as $docID => $doc) {
    $words = explode(" ", $doc);
    $tf  = array_count_values($words);
    // print_r($tf)."</br>";
    foreach ($tf as $word => $value) {
        echo $word.":".$value."<br>";
    }
    foreach ($words as $key) {
        $all_word[$key]=+1;
        echo $key." ".$all_word[$key];
    }
    echo "----------------------------<br>";      
}
READ ALSO
Laravel working with collection filter and map

Laravel working with collection filter and map

I have a method where I can return the upcoming payment dateIn the below example, getNextDate() will return a Carbon date, like so:

64
How to make query-selector work inside php and calculate?

How to make query-selector work inside php and calculate?

I took a look at this job pricing calculator I found on Codepen and I made it work exactly how it's shown on the pen but I wanted to take it one step furtherI wanted to tie this in with phpmailer but the issue I am having is that the query selector script...

46