-
Notifications
You must be signed in to change notification settings - Fork 0
/
SKOS*normaal.php
46 lines (34 loc) · 1.3 KB
/
SKOS*normaal.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
require 'vendor/autoload.php';
//$client = elasticsearch\Clientbuilder::create()->build();
$client = \Elasticsearch\ClientBuilder::create()->build();
//index aanmaken,type declareren en id
$params = [
'index' => 'hzbwnature',
'type' => 'attachment',
"ids" => ["avwtbhmtdo33cilcv6ek"],
];
// multi termvectoren opvragen
$documents = $client->mtermvectors($params)['docs'];
//zet csv file om in array
$skostermen = array_map('str_getcsv', file('skos.csv'));
$result = [];
foreach ($documents as $document) {
//loopt over alle documenten heen en zoekt op termen op basis van resultaten in json
$termen_gevonden = $document['term_vectors']['content.content']['terms'];
// loopt over de skos termen heen
foreach ($skostermen as $skos_term) {
//gevonden termen tegenover de skos termen zetten
if (in_array(strtolower($skos_term[0]), array_keys($termen_gevonden)))
// loopt vervolgens weer over de gevonden zoektermen en voegt ze toe in de array om in de csv te zetten
foreach ($termen_gevonden as $term => $values) {
$result[] = [$skos_term[0], $term, $values['term_freq'], $document['_id']];
}
}
}
$file = fopen('file.csv', 'w');
foreach ($result as $fields) {
fputcsv($file, $fields, ';');
}
fclose($file);
?>