forked from christophe-lejeune/cassandre_2_php
-
Notifications
You must be signed in to change notification settings - Fork 1
/
topic.php
40 lines (37 loc) · 1.18 KB
/
topic.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
<?php
include 'http.php';
header('content-type: application/json;charset=utf-8');
$viewpoint = $_GET['viewpoint'];
$topic = $_GET['topic'];
echo '{"rows":[', "\n";
$first = true;
$query = ($topic)
? 'key=["'.$viewpoint.'","'.$topic.'"]'
: 'startkey=["'.$viewpoint.'"]&endkey=["'.$viewpoint.'",{}]';
$rows = get('topic_pattern?'.$query)->rows;
foreach ($rows as $r) {
$corpus = $r->id;
$topic = $r->key[1];
$pattern = urlencode($r->value->text);
$kwic = get('kwic?startkey=["'.$corpus.'","'.$pattern
.'"]&endkey=["'.$corpus.'","'.$pattern.'\ufff0"]'
)->rows;
foreach ($kwic as $k) {
if ($first) {
$first = false;
} else {
echo ",\n";
}
$item = $k->id;
echo '{"key":["', $viewpoint, '","', $topic,
'"], "value":{"highlight":{"id":"', $r->value->highlight,
'|', $k->value->match,
'", "corpus":"', $corpus, '", "item":"', $item,
'", "coordinates":[', $k->value->begin, ',', $k->value->end,
'], "text":', json_encode($k->value->before.$k->key[1]),
($k->value->actor)?', "actor":'.json_encode($k->value->actor):'',
'}}}';
}
}
echo(']}');
?>