PHP code example of mathsgod / semantic-splitter-php
1. Go to this page and download the library: Download mathsgod/semantic-splitter-php library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mathsgod / semantic-splitter-php example snippets
$splitter = new TextSplitter\SemanticTextSplitter(new MyEmbeddingRetriever());
$sentences= $splitter->split("I am a sentence.
I am another sentence.
I am a sentence that is a question?
這是一個中文句子。
這是另一個中文句子。
如果句子意思接近, 這個工具會把他們放在一起。");
print_r($sentences);
class MyEmbeddingRetriever implements TextSplitter\EmbeddingRetrieverInterface
{
public function getEmbedding(string $text): array
{
// Implement your own embedding retriever here
// for example, you can use OpenAI to get the embedding of the text
return [0.1, 0.2, 0.3];
}
}
bash
composer