PHP code example of survos / followthemoney

1. Go to this page and download the library: Download survos/followthemoney 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/ */

    

survos / followthemoney example snippets


use Survos\FollowTheMoney\Model;

$model = Model::bundled();
$emily = $model->create('Person', 'rappnews-emily-berry');
$emily->name = 'Emily Armstead Berry'; // virtual property hook
$emily->add('alias', 'Emily A. Berry');
$emily->add('deathDate', '1953'); // precision is retained
$emily->add('country', 'United States'); // us

$lucy = $model->create('Person', 'rappnews-lucy-berry');
$lucy->name = 'Lucy Barr Berry';
$family = $model->create('Family', 'rappnews-emily-lucy');
$family->add('person', $emily);
$family->add('relative', $lucy);
$family->add('relationship', 'mother'); // Lucy is Emily's mother

echo json_encode($emily, JSON_THROW_ON_ERROR);

use Survos\JsonlBundle\IO\JsonlReader;
use Survos\JsonlBundle\IO\JsonlWriter;

$writer = JsonlWriter::open('/path/to/output.jsonl');
try {
    foreach (JsonlReader::open('/path/to/input.jsonl') as $row) {
        $entity = $model->fromArray($row);
        $writer->write($entity); // Entity implements JsonSerializable
    }
    $writer->finish();
} finally {
    $writer->close();
}

$errors = $family->validate(fn (string $id) => $entitiesById[$id] ?? null);

$model = $model->withSchemas([
    'HistoricalPerson' => [
        'extends' => ['Person'],
        'label' => 'Historical person',
        'properties' => ['localKey' => ['type' => 'identifier']],
    ],
]);

$projection = new Survos\FollowTheMoney\Search\ElasticsearchProjection();
$createIndexBody = ['mappings' => $projection->mapping()];
$bulkLines = $projection->bulk($entities, 'newspaper-entities-v1');