39 |
39 |
40 private function addWordInfo($wNode, &$annotation) { |
40 private function addWordInfo($wNode, &$annotation) { |
41 if(!array_key_exists('words',$annotation['content']['data'])) { |
41 if(!array_key_exists('words',$annotation['content']['data'])) { |
42 $annotation['content']['data']['words'] = []; |
42 $annotation['content']['data']['words'] = []; |
43 } |
43 } |
44 $content = ""; |
44 $wLang = $wNode->getAttribute('xml:lang'); |
45 $formNodes = $wNode->getElementsByTagName('FORM'); |
45 |
46 if(count($formNodes) !== 0 ) { |
46 $content = null; |
47 $content = $formNodes[0]->textContent; |
47 $transl = null ; |
|
48 $morphenes = []; |
|
49 $wbegin = null; |
|
50 $wend = null; |
|
51 |
|
52 foreach ($wNode->childNodes as $node) { |
|
53 if($node->nodeName === "FORM" && is_null($content)) { |
|
54 $content = $this->buildTextvalue($node->textContent, $wLang); |
|
55 } elseif($node->nodeName === "TRANSL" && is_null($transl)) { |
|
56 $transl = $this->buildTextvalue($node->textContent, $node->getAttribute('xml:lang')); |
|
57 } elseif($node->nodeName === "M") { |
|
58 $morphInfo = $this->getMorpheneInfo($node,$wLang); |
|
59 if(!is_null($morphInfo)) { |
|
60 array_push($morphenes, $morphInfo); |
|
61 } |
|
62 } elseif($node->nodeName === 'AUDIO') { |
|
63 $wbegin = $audio->getAttribute('start'); |
|
64 $wend = $audio->getAttribute('end'); |
|
65 } |
48 } |
66 } |
49 $transl = ""; |
67 |
50 $translNodes = $wNode->getElementsByTagName('TRANSL'); |
68 $wDef = ['content' => $content, 'transl' => $transl, 'morphenes' => $morphenes]; |
51 if(count($translNodes) !== 0) { |
69 |
52 $transl = $this->buildTextvalue($translNodes[0]->textContent, $translNodes[0]->getAttribute('xml:lang')); |
70 if(!empty($wbegin) && !empty($wend)) { |
|
71 $wDef['begin'] = intval($wbegin); |
|
72 $wDef['end'] = intval($wend); |
53 } |
73 } |
54 array_push($annotation['content']['data']['words'], ['content' => $content, 'transl' => $transl]); |
74 array_push($annotation['content']['data']['words'], $wDef); |
|
75 } |
|
76 |
|
77 private function getMorpheneInfo($mNode, $wLang) { |
|
78 $mLang = $mNode->getAttribute('xml:lang'); |
|
79 if(empty($mLang)) { |
|
80 $mLang = $wLang; |
|
81 } |
|
82 $content = null; |
|
83 $transl = null; |
|
84 $mbegin = null; |
|
85 $mend = null; |
|
86 |
|
87 foreach ($mNode->childNodes as $node) { |
|
88 if($node->nodeName === "FORM" && is_null($content)) { |
|
89 $content = $this->buildTextvalue($node->textContent, $mLang); |
|
90 } elseif($node->nodeName === "TRANSL" && is_null($transl)) { |
|
91 $transl = $this->buildTextvalue($node->textContent, $node->getAttribute('xml:lang')); |
|
92 } elseif($node->nodeName === 'AUDIO') { |
|
93 $mbegin = $node->getAttribute('start'); |
|
94 $mend = $node->getAttribute('end'); |
|
95 } |
|
96 } |
|
97 $mDef = ['content' => $content, 'transl' => $transl]; |
|
98 |
|
99 if(!empty($mbegin) && !empty($mend)) { |
|
100 $mDef['begin'] = intval($mbegin); |
|
101 $mDef['end'] = intval($mend); |
|
102 } |
|
103 |
|
104 $mClass = $mNode->getAttribute('class'); |
|
105 if(!empty($mClass)) { |
|
106 $mDef['class'] = $mClass; |
|
107 } |
|
108 $mSclass = $mNode->getAttribute('sclass'); |
|
109 if(!empty($mSclass)) { |
|
110 $mDef['sclass'] = $mSclass; |
|
111 } |
|
112 |
|
113 return $mDef; |
55 } |
114 } |
56 |
115 |
57 |
116 |
58 public function buildAnnotations() { |
117 public function buildAnnotations() { |
59 $xpath = new \DOMXPath($this->source); |
118 $xpath = new \DOMXPath($this->source); |