-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_processor.php
51 lines (46 loc) · 1.48 KB
/
file_processor.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
$data=Array("category"=>Array(),"sentences"=>Array(),"sentence_category"=>Array());
if(strrchr($fails, '.')==".xml")
{
$saturs=file_get_contents($fails);
$DOMdoc = new DOMDocument();
$DOMdoc->loadXML($saturs);
$DOMPath = new DOMXPath( $DOMdoc );
$categories=$DOMPath->query("//CATEGORY");
foreach($categories AS $category)
{
$c=&$data['category'][$category->getAttribute("id")];
$c['id']=$category->getAttribute("id");
$c['name']=$category->nodeValue;
}
$sentence_categories=$DOMPath->query("//SENTENCE_CATEGORY");
foreach($sentence_categories AS $sentence_category)
{
$c=&$data['sentence_category'][$sentence_category->getAttribute("id")];
$c['id']=$sentence_category->getAttribute("id");
$c['name']=$sentence_category->nodeValue;
}
$sentences=$DOMPath->query("//SENTENCE");
foreach($sentences AS $sentence)
{
$s=&$data['sentences'][];
$s['text']=str_replace(Array("<TEXT>","</TEXT>"),"",str_replace("WORD","span",$DOMdoc->saveXML($DOMPath->query("TEXT",$sentence)->item(0))));
$s['comment']=$DOMPath->query("COMMENT",$sentence)->item(0)->nodeValue;
$s['category']=($sentence->getAttribute("CATEGORY") ? $sentence->getAttribute("CATEGORY") : "blank");
}
}
else
{
$lines=file($fails);
foreach($lines AS $line)
{
$s=&$data['sentences'][];
$s['comment']="";
$s['category']="blank";
$s['text']=htmlspecialchars(trim($line));
}
$c=&$data['category'][];
$c['id']="cFFFF00";
$c['name']="Agenss";
}
?>