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