nlptoolkit-annotatedtree 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/README.md +6 -1
  2. package/dist/Layer/DependencyLayer.d.ts +4 -0
  3. package/dist/Layer/DependencyLayer.js +4 -0
  4. package/dist/Layer/DependencyLayer.js.map +1 -1
  5. package/dist/Layer/EnglishPropbankLayer.d.ts +9 -0
  6. package/dist/Layer/EnglishPropbankLayer.js +9 -0
  7. package/dist/Layer/EnglishPropbankLayer.js.map +1 -1
  8. package/dist/Layer/EnglishSemanticLayer.d.ts +5 -0
  9. package/dist/Layer/EnglishSemanticLayer.js +5 -0
  10. package/dist/Layer/EnglishSemanticLayer.js.map +1 -1
  11. package/dist/Layer/EnglishWordLayer.d.ts +4 -0
  12. package/dist/Layer/EnglishWordLayer.js +4 -0
  13. package/dist/Layer/EnglishWordLayer.js.map +1 -1
  14. package/dist/Layer/MetaMorphemeLayer.d.ts +19 -0
  15. package/dist/Layer/MetaMorphemeLayer.js +19 -0
  16. package/dist/Layer/MetaMorphemeLayer.js.map +1 -1
  17. package/dist/Layer/MetaMorphemesMovedLayer.d.ts +20 -0
  18. package/dist/Layer/MetaMorphemesMovedLayer.js +20 -0
  19. package/dist/Layer/MetaMorphemesMovedLayer.js.map +1 -1
  20. package/dist/Layer/MorphologicalAnalysisLayer.d.ts +32 -0
  21. package/dist/Layer/MorphologicalAnalysisLayer.js +32 -0
  22. package/dist/Layer/MorphologicalAnalysisLayer.js.map +1 -1
  23. package/dist/Layer/MultiWordLayer.d.ts +9 -0
  24. package/dist/Layer/MultiWordLayer.js +9 -0
  25. package/dist/Layer/MultiWordLayer.js.map +1 -1
  26. package/dist/Layer/NERLayer.d.ts +14 -0
  27. package/dist/Layer/NERLayer.js +14 -0
  28. package/dist/Layer/NERLayer.js.map +1 -1
  29. package/dist/Layer/PersianWordLayer.d.ts +4 -0
  30. package/dist/Layer/PersianWordLayer.js +4 -0
  31. package/dist/Layer/PersianWordLayer.js.map +1 -1
  32. package/dist/Layer/ShallowParseLayer.d.ts +11 -0
  33. package/dist/Layer/ShallowParseLayer.js +11 -0
  34. package/dist/Layer/ShallowParseLayer.js.map +1 -1
  35. package/dist/Layer/SingleWordLayer.d.ts +4 -0
  36. package/dist/Layer/SingleWordLayer.js +4 -0
  37. package/dist/Layer/SingleWordLayer.js.map +1 -1
  38. package/dist/Layer/SourceLanguageWordLayer.d.ts +4 -0
  39. package/dist/Layer/SourceLanguageWordLayer.js +4 -0
  40. package/dist/Layer/SourceLanguageWordLayer.js.map +1 -1
  41. package/dist/Layer/TargetLanguageWordLayer.d.ts +10 -1
  42. package/dist/Layer/TargetLanguageWordLayer.js +9 -0
  43. package/dist/Layer/TargetLanguageWordLayer.js.map +1 -1
  44. package/dist/Layer/TurkishPropbankLayer.d.ts +18 -0
  45. package/dist/Layer/TurkishPropbankLayer.js +18 -0
  46. package/dist/Layer/TurkishPropbankLayer.js.map +1 -1
  47. package/dist/Layer/TurkishSemanticLayer.d.ts +11 -0
  48. package/dist/Layer/TurkishSemanticLayer.js +11 -0
  49. package/dist/Layer/TurkishSemanticLayer.js.map +1 -1
  50. package/dist/Layer/TurkishWordLayer.d.ts +4 -0
  51. package/dist/Layer/TurkishWordLayer.js +4 -0
  52. package/dist/Layer/TurkishWordLayer.js.map +1 -1
  53. package/dist/Layer/WordLayer.d.ts +12 -0
  54. package/dist/Layer/WordLayer.js +12 -0
  55. package/dist/Layer/WordLayer.js.map +1 -1
  56. package/dist/LayerInfo.d.ts +188 -0
  57. package/dist/LayerInfo.js +229 -63
  58. package/dist/LayerInfo.js.map +1 -1
  59. package/dist/ParseNodeDrawable.d.ts +102 -0
  60. package/dist/ParseNodeDrawable.js +102 -0
  61. package/dist/ParseNodeDrawable.js.map +1 -1
  62. package/dist/ParseTreeDrawable.d.ts +134 -0
  63. package/dist/ParseTreeDrawable.js +153 -16
  64. package/dist/ParseTreeDrawable.js.map +1 -1
  65. package/dist/Processor/Condition/IsDoubleNode.d.ts +6 -0
  66. package/dist/Processor/Condition/IsDoubleNode.js +6 -0
  67. package/dist/Processor/Condition/IsDoubleNode.js.map +1 -1
  68. package/dist/Processor/Condition/IsDoubleNodeWithDifferentTags.d.ts +6 -0
  69. package/dist/Processor/Condition/IsDoubleNodeWithDifferentTags.js +6 -0
  70. package/dist/Processor/Condition/IsDoubleNodeWithDifferentTags.js.map +1 -1
  71. package/dist/Processor/Condition/IsEnglishLeafNode.d.ts +5 -0
  72. package/dist/Processor/Condition/IsEnglishLeafNode.js +5 -0
  73. package/dist/Processor/Condition/IsEnglishLeafNode.js.map +1 -1
  74. package/dist/Processor/Condition/IsLeafNode.d.ts +5 -0
  75. package/dist/Processor/Condition/IsLeafNode.js +5 -0
  76. package/dist/Processor/Condition/IsLeafNode.js.map +1 -1
  77. package/dist/Processor/Condition/IsNodeWithPredicate.d.ts +11 -0
  78. package/dist/Processor/Condition/IsNodeWithPredicate.js +11 -0
  79. package/dist/Processor/Condition/IsNodeWithPredicate.js.map +1 -1
  80. package/dist/Processor/Condition/IsNodeWithSymbol.d.ts +9 -0
  81. package/dist/Processor/Condition/IsNodeWithSymbol.js +9 -0
  82. package/dist/Processor/Condition/IsNodeWithSymbol.js.map +1 -1
  83. package/dist/Processor/Condition/IsNodeWithSynSetId.d.ts +9 -0
  84. package/dist/Processor/Condition/IsNodeWithSynSetId.js +9 -0
  85. package/dist/Processor/Condition/IsNodeWithSynSetId.js.map +1 -1
  86. package/dist/Processor/Condition/IsNoneNode.d.ts +5 -0
  87. package/dist/Processor/Condition/IsNoneNode.js +5 -0
  88. package/dist/Processor/Condition/IsNoneNode.js.map +1 -1
  89. package/dist/Processor/Condition/IsNullElement.d.ts +6 -0
  90. package/dist/Processor/Condition/IsNullElement.js +6 -0
  91. package/dist/Processor/Condition/IsNullElement.js.map +1 -1
  92. package/dist/Processor/Condition/IsNumber.d.ts +6 -0
  93. package/dist/Processor/Condition/IsNumber.js +6 -0
  94. package/dist/Processor/Condition/IsNumber.js.map +1 -1
  95. package/dist/Processor/Condition/IsPredicateVerbNode.d.ts +11 -0
  96. package/dist/Processor/Condition/IsPredicateVerbNode.js +11 -0
  97. package/dist/Processor/Condition/IsPredicateVerbNode.js.map +1 -1
  98. package/dist/Processor/Condition/IsProperNoun.d.ts +5 -0
  99. package/dist/Processor/Condition/IsProperNoun.js +5 -0
  100. package/dist/Processor/Condition/IsProperNoun.js.map +1 -1
  101. package/dist/Processor/Condition/IsPunctuationNode.d.ts +5 -0
  102. package/dist/Processor/Condition/IsPunctuationNode.js +5 -0
  103. package/dist/Processor/Condition/IsPunctuationNode.js.map +1 -1
  104. package/dist/Processor/Condition/IsTransferable.d.ts +5 -0
  105. package/dist/Processor/Condition/IsTransferable.js +5 -0
  106. package/dist/Processor/Condition/IsTransferable.js.map +1 -1
  107. package/dist/Processor/Condition/IsTurkishLeafNode.d.ts +5 -0
  108. package/dist/Processor/Condition/IsTurkishLeafNode.js +5 -0
  109. package/dist/Processor/Condition/IsTurkishLeafNode.js.map +1 -1
  110. package/dist/Processor/Condition/IsVPNode.d.ts +5 -0
  111. package/dist/Processor/Condition/IsVPNode.js +5 -0
  112. package/dist/Processor/Condition/IsVPNode.js.map +1 -1
  113. package/dist/Processor/Condition/IsVerbNode.d.ts +10 -0
  114. package/dist/Processor/Condition/IsVerbNode.js +10 -0
  115. package/dist/Processor/Condition/IsVerbNode.js.map +1 -1
  116. package/dist/Processor/LayerExist/ContainsLayerInformation.d.ts +9 -0
  117. package/dist/Processor/LayerExist/ContainsLayerInformation.js +9 -0
  118. package/dist/Processor/LayerExist/ContainsLayerInformation.js.map +1 -1
  119. package/dist/Processor/LayerExist/NotContainsLayerInformation.d.ts +9 -0
  120. package/dist/Processor/LayerExist/NotContainsLayerInformation.js +9 -0
  121. package/dist/Processor/LayerExist/NotContainsLayerInformation.js.map +1 -1
  122. package/dist/Processor/LayerExist/SemiContainsLayerInformation.d.ts +10 -0
  123. package/dist/Processor/LayerExist/SemiContainsLayerInformation.js +10 -0
  124. package/dist/Processor/LayerExist/SemiContainsLayerInformation.js.map +1 -1
  125. package/dist/Processor/LeafConverter/LeafToEnglish.d.ts +3 -0
  126. package/dist/Processor/LeafConverter/LeafToEnglish.js +3 -0
  127. package/dist/Processor/LeafConverter/LeafToEnglish.js.map +1 -1
  128. package/dist/Processor/LeafConverter/LeafToLanguageConverter.d.ts +7 -0
  129. package/dist/Processor/LeafConverter/LeafToLanguageConverter.js +7 -0
  130. package/dist/Processor/LeafConverter/LeafToLanguageConverter.js.map +1 -1
  131. package/dist/Processor/LeafConverter/LeafToPersian.d.ts +3 -0
  132. package/dist/Processor/LeafConverter/LeafToPersian.js +3 -0
  133. package/dist/Processor/LeafConverter/LeafToPersian.js.map +1 -1
  134. package/dist/Processor/LeafConverter/LeafToRootFormConverter.d.ts +7 -0
  135. package/dist/Processor/LeafConverter/LeafToRootFormConverter.js +7 -0
  136. package/dist/Processor/LeafConverter/LeafToRootFormConverter.js.map +1 -1
  137. package/dist/Processor/LeafConverter/LeafToTurkish.d.ts +3 -0
  138. package/dist/Processor/LeafConverter/LeafToTurkish.js +3 -0
  139. package/dist/Processor/LeafConverter/LeafToTurkish.js.map +1 -1
  140. package/dist/Processor/NodeDrawableCollector.d.ts +16 -0
  141. package/dist/Processor/NodeDrawableCollector.js +16 -0
  142. package/dist/Processor/NodeDrawableCollector.js.map +1 -1
  143. package/dist/Processor/TreeToStringConverter.d.ts +15 -0
  144. package/dist/Processor/TreeToStringConverter.js +15 -0
  145. package/dist/Processor/TreeToStringConverter.js.map +1 -1
  146. package/dist/TreeBankDrawable.d.ts +20 -0
  147. package/dist/TreeBankDrawable.js +20 -0
  148. package/dist/TreeBankDrawable.js.map +1 -1
  149. package/package.json +14 -12
  150. package/source/Layer/DependencyLayer.ts +4 -0
  151. package/source/Layer/EnglishPropbankLayer.ts +9 -0
  152. package/source/Layer/EnglishSemanticLayer.ts +5 -0
  153. package/source/Layer/EnglishWordLayer.ts +4 -0
  154. package/source/Layer/MetaMorphemeLayer.ts +19 -0
  155. package/source/Layer/MetaMorphemesMovedLayer.ts +20 -0
  156. package/source/Layer/MorphologicalAnalysisLayer.ts +32 -0
  157. package/source/Layer/MultiWordLayer.ts +9 -0
  158. package/source/Layer/NERLayer.ts +14 -0
  159. package/source/Layer/PersianWordLayer.ts +4 -0
  160. package/source/Layer/ShallowParseLayer.ts +11 -0
  161. package/source/Layer/SingleWordLayer.ts +4 -0
  162. package/source/Layer/SourceLanguageWordLayer.ts +4 -0
  163. package/source/Layer/TargetLanguageWordLayer.ts +10 -1
  164. package/source/Layer/TurkishPropbankLayer.ts +18 -0
  165. package/source/Layer/TurkishSemanticLayer.ts +11 -0
  166. package/source/Layer/TurkishWordLayer.ts +4 -0
  167. package/source/Layer/WordLayer.ts +12 -0
  168. package/source/LayerInfo.ts +333 -155
  169. package/source/ParseNodeDrawable.ts +102 -0
  170. package/source/ParseTreeDrawable.ts +158 -16
  171. package/source/Processor/Condition/IsDoubleNode.ts +6 -0
  172. package/source/Processor/Condition/IsDoubleNodeWithDifferentTags.ts +6 -0
  173. package/source/Processor/Condition/IsEnglishLeafNode.ts +5 -0
  174. package/source/Processor/Condition/IsLeafNode.ts +5 -0
  175. package/source/Processor/Condition/IsNodeWithPredicate.ts +11 -0
  176. package/source/Processor/Condition/IsNodeWithSymbol.ts +9 -0
  177. package/source/Processor/Condition/IsNodeWithSynSetId.ts +9 -0
  178. package/source/Processor/Condition/IsNoneNode.ts +5 -0
  179. package/source/Processor/Condition/IsNullElement.ts +6 -0
  180. package/source/Processor/Condition/IsNumber.ts +6 -0
  181. package/source/Processor/Condition/IsPredicateVerbNode.ts +11 -0
  182. package/source/Processor/Condition/IsProperNoun.ts +5 -0
  183. package/source/Processor/Condition/IsPunctuationNode.ts +5 -0
  184. package/source/Processor/Condition/IsTransferable.ts +5 -0
  185. package/source/Processor/Condition/IsTurkishLeafNode.ts +5 -0
  186. package/source/Processor/Condition/IsVPNode.ts +5 -0
  187. package/source/Processor/Condition/IsVerbNode.ts +10 -0
  188. package/source/Processor/LayerExist/ContainsLayerInformation.ts +9 -0
  189. package/source/Processor/LayerExist/NotContainsLayerInformation.ts +9 -0
  190. package/source/Processor/LayerExist/SemiContainsLayerInformation.ts +10 -0
  191. package/source/Processor/LeafConverter/LeafToEnglish.ts +3 -0
  192. package/source/Processor/LeafConverter/LeafToLanguageConverter.ts +7 -0
  193. package/source/Processor/LeafConverter/LeafToPersian.ts +3 -0
  194. package/source/Processor/LeafConverter/LeafToRootFormConverter.ts +7 -0
  195. package/source/Processor/LeafConverter/LeafToTurkish.ts +3 -0
  196. package/source/Processor/NodeDrawableCollector.ts +16 -0
  197. package/source/Processor/TreeToStringConverter.ts +15 -0
  198. package/source/TreeBankDrawable.ts +20 -0
@@ -10,6 +10,14 @@ export class ParseNodeDrawable extends ParseNode{
10
10
  protected depth: number
11
11
  protected inOrderTraversalIndex: number
12
12
 
13
+ /**
14
+ * Constructs a ParseNodeDrawable from a single line. If the node is a leaf node, it only sets the data. Otherwise,
15
+ * splits the line w.r.t. spaces and parenthesis and calls itself recursively to generate its child parseNodes.
16
+ * @param parentOrLeftOrSymbol The parent node of this node.
17
+ * @param lineOrRightOrData The input line to create this parseNode.
18
+ * @param dataOrIsleaf True, if this node is a leaf node; false otherwise.
19
+ * @param depth Depth of the node.
20
+ */
13
21
  constructor(parentOrLeftOrSymbol?: any, lineOrRightOrData?: any, dataOrIsleaf?: any, depth?: number) {
14
22
  super();
15
23
  if (parentOrLeftOrSymbol == null || lineOrRightOrData != undefined){
@@ -66,10 +74,19 @@ export class ParseNodeDrawable extends ParseNode{
66
74
  }
67
75
  }
68
76
 
77
+ /**
78
+ * Accessor for layers attribute
79
+ * @return Layers attribute
80
+ */
69
81
  getLayerInfo(): LayerInfo{
70
82
  return this.layers
71
83
  }
72
84
 
85
+ /**
86
+ * Returns the data. Either the node is a leaf node, in which case English word layer is returned; or the node is
87
+ * a nonleaf node, in which case the node tag is returned.
88
+ * @return English word for leaf node, constituency tag for non-leaf node.
89
+ */
73
90
  getData(): Symbol{
74
91
  if (this.layers == null){
75
92
  return super.getData()
@@ -78,10 +95,17 @@ export class ParseNodeDrawable extends ParseNode{
78
95
  }
79
96
  }
80
97
 
98
+ /**
99
+ * Clears the layers hash map.
100
+ */
81
101
  clearLayers(){
82
102
  this.layers = new LayerInfo()
83
103
  }
84
104
 
105
+ /**
106
+ * Recursive method to clear a given layer.
107
+ * @param layerType Name of the layer to be cleared
108
+ */
85
109
  clearLayer(layerType: ViewLayerType){
86
110
  if (this.children.length == 0 && this.layerExists(layerType)){
87
111
  this.layers.removeLayer(layerType)
@@ -91,15 +115,27 @@ export class ParseNodeDrawable extends ParseNode{
91
115
  }
92
116
  }
93
117
 
118
+ /**
119
+ * Clears the node tag.
120
+ */
94
121
  clearData(){
95
122
  this.data = null
96
123
  }
97
124
 
125
+ /**
126
+ * Setter for the data attribute and also clears all layers.
127
+ * @param data New data field.
128
+ */
98
129
  setDataAndClearLayers(data: Symbol){
99
130
  super.setData(data)
100
131
  this.layers = null
101
132
  }
102
133
 
134
+ /**
135
+ * Mutator for the data field. If the layers is null, its sets the data field, otherwise it sets the English layer
136
+ * to the given value.
137
+ * @param data Data to be set.
138
+ */
103
139
  setData(data: Symbol) {
104
140
  if (this.layers == null){
105
141
  super.setData(data);
@@ -108,6 +144,11 @@ export class ParseNodeDrawable extends ParseNode{
108
144
  }
109
145
  }
110
146
 
147
+ /**
148
+ * Returns the layer value of the head child of this node.
149
+ * @param viewLayerType Layer name
150
+ * @return Layer value of the head child of this node.
151
+ */
111
152
  headWord(viewLayerType: ViewLayerType): string{
112
153
  if (this.children.length > 0){
113
154
  return (<ParseNodeDrawable> this.headChild()).headWord(viewLayerType);
@@ -116,6 +157,11 @@ export class ParseNodeDrawable extends ParseNode{
116
157
  }
117
158
  }
118
159
 
160
+ /**
161
+ * Returns the layer value of a given layer.
162
+ * @param viewLayer Layer name
163
+ * @return Value of the given layer
164
+ */
119
165
  getLayerData(viewLayer?: ViewLayerType): string{
120
166
  if (viewLayer == undefined){
121
167
  if (this.data != null){
@@ -130,16 +176,29 @@ export class ParseNodeDrawable extends ParseNode{
130
176
  }
131
177
  }
132
178
 
179
+ /**
180
+ * Accessor for the depth attribute
181
+ * @return Depth attribute
182
+ */
133
183
  getDepth(): number{
134
184
  return this.depth
135
185
  }
136
186
 
187
+ /**
188
+ * Replaces a given old child with the given new child.
189
+ * @param oldChild Old child to be replaced
190
+ * @param newChild New child which replaces old child
191
+ */
137
192
  replaceChild(oldChild: ParseNodeDrawable, newChild: ParseNodeDrawable){
138
193
  newChild.updateDepths(this.depth + 1);
139
194
  newChild.parent = this;
140
195
  this.children[this.children.indexOf(oldChild)] = newChild;
141
196
  }
142
197
 
198
+ /**
199
+ * Recursive method which updates the depth attribute
200
+ * @param depth Current depth to set.
201
+ */
143
202
  updateDepths(depth: number){
144
203
  this.depth = depth;
145
204
  for (let aChildren of this.children){
@@ -148,6 +207,10 @@ export class ParseNodeDrawable extends ParseNode{
148
207
  }
149
208
  }
150
209
 
210
+ /**
211
+ * Calculates the maximum depth of the subtree rooted from this node.
212
+ * @return The maximum depth of the subtree rooted from this node.
213
+ */
151
214
  maxDepth(): number{
152
215
  let depth = this.depth;
153
216
  for (let aChildren of this.children) {
@@ -158,6 +221,13 @@ export class ParseNodeDrawable extends ParseNode{
158
221
  return depth;
159
222
  }
160
223
 
224
+ /**
225
+ * Recursive method that checks if all nodes in the subtree rooted with this node has the annotation in the given
226
+ * layer.
227
+ * @param viewLayerType Layer name
228
+ * @return True if all nodes in the subtree rooted with this node has the annotation in the given layer, false
229
+ * otherwise.
230
+ */
161
231
  layerExists(viewLayerType: ViewLayerType): boolean{
162
232
  if (this.children.length == 0){
163
233
  if (this.getLayerData(viewLayerType) != null){
@@ -173,6 +243,11 @@ export class ParseNodeDrawable extends ParseNode{
173
243
  return false;
174
244
  }
175
245
 
246
+ /**
247
+ * Checks if the current node is a dummy node or not. A node is a dummy node if its data contains '*', or its
248
+ * data is '0' and its parent is '-NONE-'.
249
+ * @return True if the current node is a dummy node, false otherwise.
250
+ */
176
251
  isDummyNode(): boolean {
177
252
  let data = this.getLayerData(ViewLayerType.ENGLISH_WORD);
178
253
  let parentData = (<ParseNodeDrawable> this.parent).getLayerData(ViewLayerType.ENGLISH_WORD);
@@ -187,6 +262,12 @@ export class ParseNodeDrawable extends ParseNode{
187
262
  }
188
263
  }
189
264
 
265
+ /**
266
+ * Checks if all nodes in the subtree rooted with this node has annotation with the given layer.
267
+ * @param viewLayerType Layer name
268
+ * @return True if all nodes in the subtree rooted with this node has annotation with the given layer, false
269
+ * otherwise.
270
+ */
190
271
  layerAll(viewLayerType: ViewLayerType): boolean{
191
272
  if (this.children.length == 0){
192
273
  if (this.getLayerData(viewLayerType) == null && !this.isDummyNode()){
@@ -202,6 +283,11 @@ export class ParseNodeDrawable extends ParseNode{
202
283
  return true;
203
284
  }
204
285
 
286
+ /**
287
+ * Recursive method to convert the subtree rooted with this node to a string. All parenthesis types are converted to
288
+ * their regular forms.
289
+ * @return String version of the subtree rooted with this node.
290
+ */
205
291
  toTurkishSentence(): string{
206
292
  if (this.children.length == 0){
207
293
  if (this.getLayerData(ViewLayerType.TURKISH_WORD) != null && this.getLayerData(ViewLayerType.TURKISH_WORD) != "*NONE*"){
@@ -230,6 +316,12 @@ export class ParseNodeDrawable extends ParseNode{
230
316
  }
231
317
  }
232
318
 
319
+ /**
320
+ * Sets the NER layer according to the tag of the parent node and the word in the node. The word is searched in the
321
+ * gazetteer, if it exists, the NER info is replaced with the NER tag in the gazetter.
322
+ * @param gazetteer Gazetteer where we search the word
323
+ * @param word Word to be searched in the gazetteer
324
+ */
233
325
  checkGazetteer(gazetteer: Gazetteer, word: string){
234
326
  if (gazetteer.contains(word) && this.getParent().getData().getName() == "NNP"){
235
327
  this.getLayerInfo().setLayerData(ViewLayerType.NER, gazetteer.getName());
@@ -239,6 +331,12 @@ export class ParseNodeDrawable extends ParseNode{
239
331
  }
240
332
  }
241
333
 
334
+ /**
335
+ * Recursive method that sets the tag information of the given parse node with all descendants with respect to the
336
+ * morphological annotation of the current node with all descendants.
337
+ * @param parseNode Parse node whose tag information will be changed.
338
+ * @param surfaceForm If true, tag will be replaced with the surface form annotation.
339
+ */
242
340
  generateParseNode(parseNode: ParseNode, surfaceForm: boolean){
243
341
  if (this.numberOfChildren() == 0){
244
342
  if (surfaceForm){
@@ -256,6 +354,10 @@ export class ParseNodeDrawable extends ParseNode{
256
354
  }
257
355
  }
258
356
 
357
+ /**
358
+ * Recursive method to convert the subtree rooted with this node to a string.
359
+ * @return String version of the subtree rooted with this node.
360
+ */
259
361
  toString(): string{
260
362
  if (this.children.length < 2){
261
363
  if (this.children.length < 1){
@@ -15,54 +15,115 @@ export class ParseTreeDrawable extends ParseTree{
15
15
 
16
16
  private fileDescription: FileDescription
17
17
 
18
+ /**
19
+ * Another constructor for the ParseTreeDrawable. Sets the file description and reads the tree from the file
20
+ * description.
21
+ * @param fileDescription File description that contains the path, index and extension information.
22
+ */
23
+ constructor1(fileDescription: FileDescription){
24
+ this.fileDescription = fileDescription
25
+ this.readFromFile(fileDescription.getPath())
26
+ }
27
+
28
+ /**
29
+ * Another constructor for the ParseTreeDrawable. Sets the file description and reads the tree from the file
30
+ * description.
31
+ * @param path Path of the tree
32
+ */
33
+ constructor2(path: string){
34
+ this.readFromFile(path)
35
+ }
36
+
37
+ /**
38
+ * Another constructor for the ParseTreeDrawable. Sets the file description and reads the tree from the file
39
+ * description.
40
+ * @param path Path of the tree
41
+ * @param fileDescription File description that contains the path, index and extension information.
42
+ */
43
+ constructor3(path: string, fileDescription: FileDescription){
44
+ this.fileDescription = new FileDescription(path, fileDescription.getExtension(), fileDescription.getIndex())
45
+ this.readFromFile(this.fileDescription.getPath())
46
+ }
47
+
48
+ /**
49
+ * Constructor for the ParseTreeDrawable. Sets the file description and reads the tree from the file description.
50
+ * @param path Path of the tree
51
+ * @param rawFileName File name of the tree such as 0123.train.
52
+ */
53
+ constructor4(path: string, rawFileName: string){
54
+ this.fileDescription = new FileDescription(path, rawFileName)
55
+ this.readFromFile(this.fileDescription.getPath())
56
+ }
57
+
58
+ /**
59
+ * Another constructor for the ParseTreeDrawable. Sets the file description and reads the tree from the file
60
+ * description.
61
+ * @param path Path of the tree
62
+ * @param extension Extension of the file such as train, test or dev.
63
+ * @param index Index of the file such as 1235.
64
+ */
65
+ constructor5(path: string, extension: string, index: number){
66
+ this.fileDescription = new FileDescription(path, extension, index)
67
+ this.readFromFile(this.fileDescription.getPath())
68
+ }
69
+
18
70
  constructor(fileDescriptionOrPath?: any, fileDescriptionOrFileName?: any, index?: number) {
19
71
  super();
20
72
  if (fileDescriptionOrPath instanceof FileDescription){
21
- this.fileDescription = fileDescriptionOrPath
22
- this.readFromFile(fileDescriptionOrPath.getPath())
73
+ this.constructor1(fileDescriptionOrPath)
23
74
  } else {
24
75
  if (fileDescriptionOrFileName == undefined){
25
- let path: string = fileDescriptionOrPath
26
- this.readFromFile(path)
76
+ this.constructor2(fileDescriptionOrPath)
27
77
  } else {
28
78
  if (fileDescriptionOrFileName instanceof FileDescription){
29
- let path: string = fileDescriptionOrPath
30
- let fileDescription: FileDescription = fileDescriptionOrFileName
31
- this.fileDescription = new FileDescription(path, fileDescription.getExtension(), fileDescription.getIndex())
32
- this.readFromFile(this.fileDescription.getPath())
79
+ this.constructor3(fileDescriptionOrPath, fileDescriptionOrFileName)
33
80
  } else {
34
81
  if (index == undefined){
35
- let path: string = fileDescriptionOrPath
36
- let rawFileName: string = fileDescriptionOrFileName
37
- this.fileDescription = new FileDescription(path, rawFileName)
38
- this.readFromFile(this.fileDescription.getPath())
82
+ this.constructor4(fileDescriptionOrPath, fileDescriptionOrFileName)
39
83
  } else {
40
- let path: string = fileDescriptionOrPath
41
- let extension: string = fileDescriptionOrFileName
42
- this.fileDescription = new FileDescription(path, extension, index)
43
- this.readFromFile(this.fileDescription.getPath())
84
+ this.constructor5(fileDescriptionOrPath, fileDescriptionOrFileName, index)
44
85
  }
45
86
  }
46
87
  }
47
88
  }
48
89
  }
49
90
 
91
+ /**
92
+ * Mutator method for the fileDescription attribute.
93
+ * @param fileDescription New fileDescription value.
94
+ */
50
95
  setFileDescription(fileDescription: FileDescription){
51
96
  this.fileDescription = fileDescription
52
97
  }
53
98
 
99
+ /**
100
+ * Accessor method for the fileDescription attribute.
101
+ * @return FileDescription attribute.
102
+ */
54
103
  getFileDescription(){
55
104
  return this.fileDescription
56
105
  }
57
106
 
107
+ /**
108
+ * Reloads the tree from the input file.
109
+ */
58
110
  reload(){
59
111
  this.readFromFile(this.fileDescription.getPath());
60
112
  }
61
113
 
114
+ /**
115
+ * Mutator for the root attribute.
116
+ * @param newRootNode New root node.
117
+ */
62
118
  setRoot(newRootNode: ParseNode){
63
119
  this.root = newRootNode
64
120
  }
65
121
 
122
+ /**
123
+ * Reads the parse tree from the given file description with path replaced with the currentPath. It sets the root
124
+ * node which calls ParseNodeDrawable constructor recursively.
125
+ * @param currentPath Path of the tree
126
+ */
66
127
  readFromFile(currentPath: string) {
67
128
  let data = fs.readFileSync(currentPath, 'utf8')
68
129
  let line = data.split("\n")[0]
@@ -72,6 +133,12 @@ export class ParseTreeDrawable extends ParseTree{
72
133
  }
73
134
  }
74
135
 
136
+ /**
137
+ * Loads the next tree according to the index of the parse tree. For example, if the current
138
+ * tree fileName is 0123.train, after the call of nextTree(3), the method will load 0126.train. If the next tree
139
+ * does not exist, nothing will happen.
140
+ * @param count Number of trees to go forward
141
+ */
75
142
  nextTree(count: number){
76
143
  if (this.fileDescription.nextFileExists(count)){
77
144
  this.fileDescription.addToIndex(count);
@@ -79,6 +146,12 @@ export class ParseTreeDrawable extends ParseTree{
79
146
  }
80
147
  }
81
148
 
149
+ /**
150
+ * Loads the previous tree according to the index of the parse tree. For example, if the current
151
+ * tree fileName is 0123.train, after the call of previousTree(4), the method will load 0119.train. If the
152
+ * previous tree does not exist, nothing will happen.
153
+ * @param count Number of trees to go backward
154
+ */
82
155
  previousTree(count: number){
83
156
  if (this.fileDescription.previousFileExists(count)){
84
157
  this.fileDescription.addToIndex(-count);
@@ -86,22 +159,42 @@ export class ParseTreeDrawable extends ParseTree{
86
159
  }
87
160
  }
88
161
 
162
+ /**
163
+ * Calculates the maximum depth of the tree.
164
+ * @return The maximum depth of the tree.
165
+ */
89
166
  maxDepth(): number{
90
167
  return (<ParseNodeDrawable> this.root).maxDepth()
91
168
  }
92
169
 
170
+ /**
171
+ * Swaps the given child node of this node with the previous sibling of that given node. If the given node is the
172
+ * leftmost child, it swaps with the last node.
173
+ * @param node Node to be swapped.
174
+ */
93
175
  moveLeft(node: ParseNode){
94
176
  if (this.root != node){
95
177
  this.root.moveLeft(node);
96
178
  }
97
179
  }
98
180
 
181
+ /**
182
+ * Swaps the given child node of this node with the next sibling of that given node. If the given node is the
183
+ * rightmost child, it swaps with the first node.
184
+ * @param node Node to be swapped.
185
+ */
99
186
  moveRight(node: ParseNode){
100
187
  if (this.root != node){
101
188
  this.root.moveRight(node);
102
189
  }
103
190
  }
104
191
 
192
+ /**
193
+ * Divides the given node into multiple parse nodes if it contains more than one word. The parent node will be
194
+ * the same for the new nodes, original node is deleted from the children, the pos tags of the new parse nodes will
195
+ * be determined according to their morphological parses.
196
+ * @param parseNode Parse node to be divided
197
+ */
105
198
  divideIntoWords(parseNode: ParseNodeDrawable) {
106
199
  let layers = parseNode.getLayerInfo().divideIntoWords();
107
200
  parseNode.getParent().removeChild(parseNode);
@@ -120,6 +213,12 @@ export class ParseTreeDrawable extends ParseTree{
120
213
  }
121
214
  }
122
215
 
216
+ /**
217
+ * Moves the subtree rooted at fromNode as a child to the node toNode at position childIndex.
218
+ * @param fromNode Subtree root node to be moved.
219
+ * @param toNode Node to which a new subtree will be added.
220
+ * @param childIndex New child index of the toNode.
221
+ */
123
222
  moveNode(fromNode: ParseNode, toNode: ParseNode, childIndex?: number){
124
223
  if (this.root != fromNode){
125
224
  let parent = fromNode.getParent();
@@ -129,6 +228,11 @@ export class ParseTreeDrawable extends ParseTree{
129
228
  }
130
229
  }
131
230
 
231
+ /**
232
+ * Removed the first child of the parent node and adds the given child node as a child to that node.
233
+ * @param parent Parent node.
234
+ * @param child New child node to be added.
235
+ */
132
236
  combineWords(parent: ParseNodeDrawable, child: ParseNodeDrawable){
133
237
  while (parent.numberOfChildren() > 0){
134
238
  parent.removeChild(parent.firstChild());
@@ -137,20 +241,39 @@ export class ParseTreeDrawable extends ParseTree{
137
241
  (<ParseNodeDrawable> this.root).updateDepths(0);
138
242
  }
139
243
 
244
+ /**
245
+ * The method checks if all nodes in the tree has the annotation in the given layer.
246
+ * @param viewLayerType Layer name
247
+ * @return True if all nodes in the tree has the annotation in the given layer, false otherwise.
248
+ */
140
249
  layerExists(viewLayerType: ViewLayerType): boolean{
141
250
  return (<ParseNodeDrawable>(this.root)).layerExists(viewLayerType);
142
251
  }
143
252
 
253
+ /**
254
+ * Checks if all nodes in the tree has annotation with the given layer.
255
+ * @param viewLayerType Layer name
256
+ * @return True if all nodes in the tree has annotation with the given layer, false otherwise.
257
+ */
144
258
  layerAll(viewLayerType: ViewLayerType): boolean{
145
259
  return (<ParseNodeDrawable>(this.root)).layerAll(viewLayerType);
146
260
  }
147
261
 
262
+ /**
263
+ * Clears the given layer for all nodes in the tree
264
+ * @param layerType Layer name
265
+ */
148
266
  clearLayer(layerType: ViewLayerType){
149
267
  if (this.root != null){
150
268
  (<ParseNodeDrawable>this.root).clearLayer(layerType);
151
269
  }
152
270
  }
153
271
 
272
+ /**
273
+ * Returns the leaf node that comes one after the given parse node according to the inorder traversal.
274
+ * @param parseNode Input parse node.
275
+ * @return The leaf node that comes one after the given parse node according to the inorder traversal.
276
+ */
154
277
  nextLeafNode(parseNode: ParseNodeDrawable): ParseNodeDrawable {
155
278
  let nodeDrawableCollector = new NodeDrawableCollector(<ParseNodeDrawable>this.root, new IsTurkishLeafNode());
156
279
  let leafList = nodeDrawableCollector.collect();
@@ -162,6 +285,11 @@ export class ParseTreeDrawable extends ParseTree{
162
285
  return null;
163
286
  }
164
287
 
288
+ /**
289
+ * Returns the leaf node that comes one before the given parse node according to the inorder traversal.
290
+ * @param parseNode Input parse node.
291
+ * @return The leaf node that comes one before the given parse node according to the inorder traversal.
292
+ */
165
293
  previousLeafNode(parseNode: ParseNodeDrawable): ParseNodeDrawable {
166
294
  let nodeDrawableCollector = new NodeDrawableCollector(<ParseNodeDrawable>this.root, new IsTurkishLeafNode());
167
295
  let leafList = nodeDrawableCollector.collect();
@@ -173,6 +301,12 @@ export class ParseTreeDrawable extends ParseTree{
173
301
  return null;
174
302
  }
175
303
 
304
+ /**
305
+ * Constructs an AnnotatedSentence object from the Turkish tree. Collects all leaf nodes, then for each leaf node
306
+ * converts layer info of all words at that node to AnnotatedWords. Layers are converted to the counterparts in the
307
+ * AnnotatedWord.
308
+ * @return AnnotatedSentence counterpart of the Turkish tree
309
+ */
176
310
  generateAnnotatedSentence(language?: string): AnnotatedSentence{
177
311
  if (language == undefined){
178
312
  let sentence = new AnnotatedSentence();
@@ -198,6 +332,14 @@ export class ParseTreeDrawable extends ParseTree{
198
332
  }
199
333
  }
200
334
 
335
+ /**
336
+ * Recursive method that generates a new parse tree by replacing the tag information of the all parse nodes (with all
337
+ * its descendants) with respect to the morphological annotation of all parse nodes (with all its descendants)
338
+ * of the current parse tree.
339
+ * @param surfaceForm If true, tag will be replaced with the surface form annotation.
340
+ * @return A new parse tree by replacing the tag information of the all parse nodes with respect to the
341
+ * morphological annotation of all parse nodes of the current parse tree.
342
+ */
201
343
  generateParseTree(surfaceForm: boolean): ParseTree{
202
344
  let rootNode = <ParseNodeDrawable> this.root
203
345
  let result = new ParseTree(new ParseNode(rootNode.getData()))
@@ -3,6 +3,12 @@ import {ParseNodeDrawable} from "../../ParseNodeDrawable";
3
3
 
4
4
  export class IsDoubleNode implements NodeDrawableCondition{
5
5
 
6
+ /**
7
+ * Checks if the parse node is a double node, i.e., it has one child and his child has one or more children; its
8
+ * tag equals to its child tag.
9
+ * @param parseNode Parse node to check
10
+ * @return True if the tag of the parse node is equal to the tag of its child node, false otherwise.
11
+ */
6
12
  satisfies(parseNode: ParseNodeDrawable): boolean {
7
13
  return parseNode.numberOfChildren() == 1
8
14
  && parseNode.getChild(0).numberOfChildren() >= 1
@@ -3,6 +3,12 @@ import {ParseNodeDrawable} from "../../ParseNodeDrawable";
3
3
 
4
4
  export class IsDoubleNodeWithDifferentTags implements NodeDrawableCondition{
5
5
 
6
+ /**
7
+ * Checks if the parse node is a double node, i.e., it has one child and his child has one or more children; and its
8
+ * tag is not equal to its child tag.
9
+ * @param parseNode Parse node to check
10
+ * @return True if the tag of the parse node is not equal to the tag of its child node, false otherwise.
11
+ */
6
12
  satisfies(parseNode: ParseNodeDrawable): boolean {
7
13
  return parseNode.numberOfChildren() == 1
8
14
  && parseNode.getChild(0).numberOfChildren() >= 1
@@ -4,6 +4,11 @@ import {IsNullElement} from "./IsNullElement";
4
4
 
5
5
  export class IsEnglishLeafNode extends IsLeafNode{
6
6
 
7
+ /**
8
+ * Checks if the parse node is a leaf node and contains a valid English word in its data.
9
+ * @param parseNode Parse node to check.
10
+ * @return True if the parse node is a leaf node and contains a valid English word in its data; false otherwise.
11
+ */
7
12
  satisfies(parseNode: ParseNodeDrawable): boolean {
8
13
  if (super.satisfies(parseNode)) {
9
14
  return !new IsNullElement().satisfies(parseNode);
@@ -3,6 +3,11 @@ import {ParseNodeDrawable} from "../../ParseNodeDrawable";
3
3
 
4
4
  export class IsLeafNode implements NodeDrawableCondition{
5
5
 
6
+ /**
7
+ * Checks if the parse node is a leaf node, i.e., it has no child.
8
+ * @param parseNode Parse node to check.
9
+ * @return True if the parse node is a leaf node, false otherwise.
10
+ */
6
11
  satisfies(parseNode: ParseNodeDrawable): boolean {
7
12
  return parseNode.numberOfChildren() == 0;
8
13
  }
@@ -4,10 +4,21 @@ import {ViewLayerType} from "nlptoolkit-annotatedsentence/dist/ViewLayerType";
4
4
 
5
5
  export class IsNodeWithPredicate extends IsNodeWithSynSetId{
6
6
 
7
+ /**
8
+ * Stores the synset id to check.
9
+ * @param id Synset id to check
10
+ */
7
11
  constructor(id: string) {
8
12
  super(id);
9
13
  }
10
14
 
15
+ /**
16
+ * Checks if at least one of the semantic ids of the parse node is equal to the given id and also the node is
17
+ * annotated as PREDICATE with semantic role.
18
+ * @param parseNode Parse node to check.
19
+ * @return True if at least one of the semantic ids of the parse node is equal to the given id and also the node is
20
+ * annotated as PREDICATE with semantic role, false otherwise.
21
+ */
11
22
  satisfies(parseNode: ParseNodeDrawable): boolean {
12
23
  let layerInfo = parseNode.getLayerInfo();
13
24
  return super.satisfies(parseNode)
@@ -5,10 +5,19 @@ export class IsNodeWithSymbol implements NodeDrawableCondition{
5
5
 
6
6
  private symbol: string
7
7
 
8
+ /**
9
+ * Stores the symbol to check.
10
+ * @param symbol Symbol to check
11
+ */
8
12
  constructor(symbol: string) {
9
13
  this.symbol = symbol
10
14
  }
11
15
 
16
+ /**
17
+ * Checks if the tag of the parse node is equal to the given symbol.
18
+ * @param parseNode Parse node to check.
19
+ * @return True if the tag of the parse node is equal to the given symbol, false otherwise.
20
+ */
12
21
  satisfies(parseNode: ParseNodeDrawable): boolean {
13
22
  if (parseNode.numberOfChildren() > 0){
14
23
  return parseNode.getData().toString() == this.symbol;
@@ -5,11 +5,20 @@ export class IsNodeWithSynSetId extends IsLeafNode{
5
5
 
6
6
  private id: string
7
7
 
8
+ /**
9
+ * Stores the synset id to check.
10
+ * @param id Synset id to check
11
+ */
8
12
  constructor(id: string) {
9
13
  super();
10
14
  this.id = id
11
15
  }
12
16
 
17
+ /**
18
+ * Checks if at least one of the semantic ids of the parse node is equal to the given id.
19
+ * @param parseNode Parse node to check.
20
+ * @return True if at least one of the semantic ids of the parse node is equal to the given id, false otherwise.
21
+ */
13
22
  satisfies(parseNode: ParseNodeDrawable): boolean {
14
23
  if (super.satisfies(parseNode)){
15
24
  let layerInfo = parseNode.getLayerInfo();
@@ -11,6 +11,11 @@ export class IsNoneNode extends IsLeafNode{
11
11
  this.secondLanguage = secondLanguage
12
12
  }
13
13
 
14
+ /**
15
+ * Checks if the data of the parse node is '*NONE*'.
16
+ * @param parseNode Parse node to check.
17
+ * @return True if the data of the parse node is '*NONE*', false otherwise.
18
+ */
14
19
  satisfies(parseNode: ParseNodeDrawable): boolean {
15
20
  if (super.satisfies(parseNode)){
16
21
  let data = parseNode.getLayerData(this.secondLanguage);
@@ -4,6 +4,12 @@ import {ViewLayerType} from "nlptoolkit-annotatedsentence/dist/ViewLayerType";
4
4
 
5
5
  export class IsNullElement extends IsLeafNode{
6
6
 
7
+ /**
8
+ * Checks if the parse node is a leaf node and its data is '*' and its parent's data is '-NONE-'.
9
+ * @param parseNode Parse node to check.
10
+ * @return True if the parse node is a leaf node and its data is '*' and its parent's data is '-NONE-', false
11
+ * otherwise.
12
+ */
7
13
  satisfies(parseNode: ParseNodeDrawable): boolean {
8
14
  if (super.satisfies(parseNode)){
9
15
  let data = parseNode.getLayerData(ViewLayerType.ENGLISH_WORD);