Skip to content

Commit 17fca17

Browse files
committed
makeup, fix
1 parent 2c692a5 commit 17fca17

File tree

2 files changed

+39
-46
lines changed

2 files changed

+39
-46
lines changed

public/index.php

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html lang="en">
33

4+
<title>Syntax tree</title>
45
<meta charset="utf-8">
56
<meta name="viewport" content="width=device-width, initial-scale=1">
67
<link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.min.css">
@@ -10,14 +11,29 @@
1011

1112
<body>
1213

14+
<div class="container-fluid">
15+
16+
<h1>Parser of syntax of russian sentences</h1>
17+
1318
<form method="post">
14-
<div class="form-group">
15-
<label for="text">Text</label>
16-
<textarea class="form-control" id="text" name="text" placeholder="Sentence"></textarea>
19+
<div class="row">
20+
<div class="col-md-1">
21+
<div class="form-group">
22+
<label for="text">Text</label>
23+
</div>
24+
</div>
25+
<div class="col-md-6">
26+
<div class="form-group">
27+
<textarea class="form-control" id="text" name="text" placeholder="Sentence"></textarea>
28+
</div>
29+
</div>
30+
<div class="col-md-2">
31+
<button type="submit" class="btn btn-primary">Submit</button>
32+
</div>
1733
</div>
18-
<button type="submit" class="btn btn-primary">Submit</button>
1934
</form>
2035

36+
<hr>
2137

2238

2339
<?php
@@ -29,23 +45,23 @@
2945

3046
$text = $_POST['text'] ?? null;
3147

32-
echo '<p><label>Text:</label></p>';
33-
echo "<p>$text</p>";
48+
echo '<p><label>Text:</label> ';
49+
echo "$text</p>";
3450

35-
$command = "/usr/local/tensorflow/models/syntaxnet/syntaxnet/models/parsey_universal/parse.sh /usr/local/tensorflow/Russian-SynTagRus 2>&1";
36-
$path = '/usr/local/tensorflow/models/syntaxnet/';
51+
$command = "syntaxnet/models/parsey_universal/parse.sh /home/tensor/tensorflow/Russian-SynTagRus";
52+
$path = '/home/tensor/tensorflow/models/syntaxnet/';
3753

3854
$descriptors = array(
3955
0 => array('pipe', 'r'), // stdin
4056
1 => array('pipe', 'w'), // stdout
4157
2 => array('pipe', 'w') // stderr
4258
);
4359

44-
// Here is problem
60+
// ! Sure what ~/.cache/bazel is acceseble for www-data !
4561
$process = proc_open($command, $descriptors, $pipes, $path);
4662

47-
echo '<p><label>Command:</label></p>';
48-
echo "<p>$command</p>";
63+
//echo '<p><label>Command:</label></p>';
64+
//echo "<p>$command</p>";
4965

5066
if (is_resource($process))
5167
{
@@ -54,50 +70,22 @@
5470
fclose($pipes[0]);
5571

5672
$csv = stream_get_contents($pipes[1]);
57-
echo '<p><label>csv:</label></p>';
58-
echo "<p>$csv</p>";
73+
echo '<p><label>Response &mdash; <a href="http://ilk.uvt.nl/conll/#dataformat">CoNLL-X</a> (CSV):</label></p>';
74+
echo "<pre>$csv</pre>";
5975

6076
$return_value = proc_close($process);
61-
echo '<p><label>Val:</label></p>';
62-
echo "<p>$return_value</p>";
77+
// echo '<p><label>Val:</label></p>';
78+
// echo "<p>$return_value</p>";
6379
}
6480

65-
66-
$csv = '1 Начальник _ NOUN _ Animacy=Anim|Case=Nom|Gender=Masc|Number=Sing|fPOS=NOUN++ 7 nsubj _ _
67-
2 Службы _ NOUN _ Animacy=Inan|Case=Gen|Gender=Fem|Number=Sing|fPOS=NOUN++ 1 dobj _ _
68-
3 безопасности _ NOUN _ Animacy=Inan|Case=Gen|Gender=Fem|Number=Sing|fPOS=NOUN++ 2 dobj _ _
69-
4 Украины _ NOUN _ Animacy=Inan|Case=Gen|Gender=Fem|Number=Sing|fPOS=NOUN++ 2 nmod _ _
70-
5 Владимир _ NOUN _ Animacy=Anim|Case=Nom|Gender=Masc|Number=Sing|fPOS=NOUN++ 1 appos _ _
71-
6 Путин _ NOUN _ Animacy=Anim|Case=Nom|Gender=Masc|Number=Sing|fPOS=NOUN++ 5 name _ _
72-
7 подтвердил, _ VERB _ Degree=Pos|fPOS=ADV++ 0 ROOT _ _
73-
8 что _ PRON _ fPOS=SCONJ++ 20 mark _ _
74-
9 двух _ NUM _ Case=Gen|fPOS=NUM++ 10 nummod _ _
75-
10 россиян, _ NOUN _ Animacy=Inan|Case=Gen|Gender=Fem|Number=Sing|fPOS=NOUN++ 20 nsubj _ _
76-
11 фигурирующих _ VERB _ Aspect=Imp|Case=Gen|Number=Plur|Tense=Pres|VerbForm=Part|Voice=Act|fPOS=VERB++ 10 nmod _ _
77-
12 в _ ADP _ fPOS=ADP++ 13 case _ _
78-
13 деле _ NOUN _ Animacy=Inan|Case=Loc|Gender=Neut|Number=Sing|fPOS=NOUN++ 11 nmod _ _
79-
14 о _ ADP _ fPOS=ADP++ 15 case _ _
80-
15 событиях _ NOUN _ Animacy=Inan|Case=Loc|Gender=Neut|Number=Plur|fPOS=NOUN++ 13 nmod _ _
81-
16 в _ ADP _ fPOS=ADP++ 17 case _ _
82-
17 Киеве _ NOUN _ Animacy=Inan|Case=Loc|Gender=Masc|Number=Sing|fPOS=NOUN++ 15 nmod _ _
83-
18 2 _ NUM _ fPOS=NUM++ 19 nummod _ _
84-
19 мая, _ NOUN _ Animacy=Inan|Case=Gen|Gender=Masc|Number=Sing|fPOS=NOUN++ 17 nmod _ _
85-
20 могут _ VERB _ Aspect=Imp|Mood=Ind|Number=Plur|Person=3|Tense=Pres|VerbForm=Fin|Voice=Act|fPOS=VERB++ 7 advcl _ _
86-
21 обменять _ VERB _ Aspect=Perf|VerbForm=Inf|fPOS=VERB++ 20 xcomp _ _
87-
22 на _ ADP _ fPOS=ADP++ 24 case _ _
88-
23 двух _ NUM _ Animacy=Anim|Case=Acc|Gender=Masc|fPOS=NUM++ 24 nummod _ _
89-
24 граждан _ NOUN _ Animacy=Anim|Case=Gen|Gender=Masc|Number=Plur|fPOS=NOUN++ 21 iobj _ _
90-
25 Украины, _ NOUN _ fPOS=CONJ++ 21 dobj _ _
91-
26 которые _ ADJ _ Case=Nom|Degree=Pos|Number=Plur|fPOS=ADJ++ 28 nsubj _ _
92-
27 сейчас _ ADV _ Degree=Pos|fPOS=ADV++ 28 advmod _ _
93-
28 находятся _ VERB _ Aspect=Imp|Mood=Ind|Number=Plur|Person=3|Tense=Pres|VerbForm=Fin|Voice=Act|fPOS=VERB++ 25 acl:relcl _ _
94-
29 в _ ADP _ fPOS=ADP++ 30 case _ _
95-
30 России. _ NOUN _ Animacy=Inan|Case=Loc|Gender=Fem|Number=Sing|fPOS=NOUN++ 28 nmod _ _';
9681
$syntaxTree = new \SyntaxTree\SyntaxTree();
9782
$tree = $syntaxTree->build($csv);
9883

9984
?>
10085

86+
<p><label>Processed response:</label></p>
87+
88+
</div>
10189

10290
<script>
10391

src/SyntaxTree/TensorFlowFactory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public static function create($csv, $delimiter = "\t", $enclosure = '"', $escape
2020

2121
foreach ($strings as $string)
2222
{
23+
if (!$string)
24+
{
25+
continue;
26+
}
27+
$string = str_replace('"', '\\"', $string);
2328
$array[] = str_getcsv($string, $delimiter, $enclosure, $escape);
2429
}
2530
$nodes = static::createNodes($array);

0 commit comments

Comments
 (0)