-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathvertere_reducer.php
More file actions
executable file
·35 lines (29 loc) · 931 Bytes
/
vertere_reducer.php
File metadata and controls
executable file
·35 lines (29 loc) · 931 Bytes
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
#!/usr/bin/env php
<?php
ini_set('memory_limit', '2048M');
define('LIB_DIR', dirname(__FILE__) . '/lib/');
define('MORIARTY_DIR', LIB_DIR.'moriarty/');
define('MORIARTY_ARC_DIR', LIB_DIR.'arc/');
include_once MORIARTY_DIR.'moriarty.inc.php';
include_once MORIARTY_DIR.'simplegraph.class.php';
$graph = new SimpleGraph();
$previous_subject = null;
while ($line = fgets(STDIN))
{
$line = trim($line);
if (empty($line)) { continue; }
$matched_as_triple = preg_match('%^<([^>]*)>[ \t]<([^>]*)> (.*)$%', $line, $matches);
if (!$matched_as_triple) {
die("The following line does not appear to be a triple:\n${line}\n\n");
}
$subject = $matches[1];
$property = $matches[2];
$remainder = $matches[3];
if ($subject != $previous_subject && $previous_subject != null) {
echo $graph->to_ntriples();
$graph->remove_all_triples();
}
$graph->add_turtle($line);
$previous_subject = $subject;
}
echo $graph->to_ntriples();