| 1 |
<%@ include file="include/setup.jsp" %> |
|---|
| 2 |
<%@ include file="include/auth.jsp" %> |
|---|
| 3 |
|
|---|
| 4 |
<% String pageTitle = "Parser Testing"; %> |
|---|
| 5 |
<%@ include file="include/header.jsp" %> |
|---|
| 6 |
|
|---|
| 7 |
<%@ page import="java.util.*" %> |
|---|
| 8 |
<%@ page import="jemdros.*" %> |
|---|
| 9 |
<%@ page import="com.qwirx.lex.hebrew.*" %> |
|---|
| 10 |
<%@ page import="com.qwirx.lex.morph.*" %> |
|---|
| 11 |
<%@ page import="com.qwirx.lex.ontology.*" %> |
|---|
| 12 |
<%@ page import="com.qwirx.lex.parser.*" %> |
|---|
| 13 |
<%@ page import="com.qwirx.lex.wordnet.*" %> |
|---|
| 14 |
|
|---|
| 15 |
<%@ include file="include/navclause_head.jsp" %> |
|---|
| 16 |
<%@ include file="include/navclause_body.jsp" %> |
|---|
| 17 |
|
|---|
| 18 |
<script language="javascript" src="js/parsetree.js"></script> |
|---|
| 19 |
|
|---|
| 20 |
<% |
|---|
| 21 |
ParseController controller = new ParseController(request, emdros, sql, |
|---|
| 22 |
navigator); |
|---|
| 23 |
MatchedObject clause = controller.getClause(); |
|---|
| 24 |
|
|---|
| 25 |
if (clause == null) |
|---|
| 26 |
{ |
|---|
| 27 |
%><p>Selected clause not found or access denied.</p><% |
|---|
| 28 |
} |
|---|
| 29 |
else |
|---|
| 30 |
{ |
|---|
| 31 |
%> |
|---|
| 32 |
<p> |
|---|
| 33 |
Hebrew text: |
|---|
| 34 |
<span class="hebrew"><%= controller.getHebrewText() %></span> |
|---|
| 35 |
</p> |
|---|
| 36 |
<% |
|---|
| 37 |
|
|---|
| 38 |
if (request.getParameter("rule_add") != null) |
|---|
| 39 |
{ |
|---|
| 40 |
String symbol = request.getParameter("new_rule_sym"); |
|---|
| 41 |
String parts = request.getParameter("new_rule_parts"); |
|---|
| 42 |
|
|---|
| 43 |
if (symbol == null || symbol.equals("") || |
|---|
| 44 |
parts == null || parts.equals("")) |
|---|
| 45 |
{ |
|---|
| 46 |
%> |
|---|
| 47 |
<h2>Error: some required parameters were missing or empty</h2> |
|---|
| 48 |
<% |
|---|
| 49 |
} |
|---|
| 50 |
else |
|---|
| 51 |
{ |
|---|
| 52 |
Change ch = sql.createChange(SqlChange.INSERT, |
|---|
| 53 |
"lexicon_entries", null); |
|---|
| 54 |
ch.setString("Symbol", symbol); |
|---|
| 55 |
ch.setString("Lexeme", parts); |
|---|
| 56 |
ch.execute(); |
|---|
| 57 |
} |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
{ |
|---|
| 61 |
Parser p = new Parser(sql); |
|---|
| 62 |
p.setVerbose(true); |
|---|
| 63 |
List<MorphEdge> morphEdges = controller.getMorphEdges(); |
|---|
| 64 |
Chart chart = p.parse(morphEdges); |
|---|
| 65 |
List sentences = chart.filter("SENTENCE", morphEdges, false); |
|---|
| 66 |
|
|---|
| 67 |
if (sentences.size() == 0) |
|---|
| 68 |
{ |
|---|
| 69 |
%> |
|---|
| 70 |
<h3>Parse failed</h3> |
|---|
| 71 |
<% |
|---|
| 72 |
} |
|---|
| 73 |
else |
|---|
| 74 |
{ |
|---|
| 75 |
%> |
|---|
| 76 |
<h3>Parse succeeded</h3> |
|---|
| 77 |
<% |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
%> |
|---|
| 81 |
<p>Complete sentences found: <%= sentences.size() %></p> |
|---|
| 82 |
<p>The edges found were:</p> |
|---|
| 83 |
<form name="rulecmd" method="post"> |
|---|
| 84 |
<% |
|---|
| 85 |
|
|---|
| 86 |
Map edgeIds = new Hashtable(); |
|---|
| 87 |
Map idEdges = new Hashtable(); |
|---|
| 88 |
Map fakeChild = new Hashtable(); |
|---|
| 89 |
List fakeEdges = new ArrayList(); |
|---|
| 90 |
List depths = new ArrayList(); |
|---|
| 91 |
List edges = chart.getEdges(); |
|---|
| 92 |
int maxDepth = 0; |
|---|
| 93 |
|
|---|
| 94 |
for (ListIterator i = edges.listIterator(); i.hasNext(); ) |
|---|
| 95 |
{ |
|---|
| 96 |
Edge e = (Edge)( i.next() ); |
|---|
| 97 |
|
|---|
| 98 |
int depth = e.getDepth(); |
|---|
| 99 |
|
|---|
| 100 |
if (maxDepth < depth) |
|---|
| 101 |
{ |
|---|
| 102 |
maxDepth = depth; |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
if (e instanceof MorphEdge) |
|---|
| 106 |
{ |
|---|
| 107 |
MorphEdge me = (MorphEdge)e; |
|---|
| 108 |
WordEdge we = new WordEdge(me.getHtmlSurface(), |
|---|
| 109 |
me.getLeftPosition()); |
|---|
| 110 |
i.add(we); |
|---|
| 111 |
fakeChild.put(me, we); |
|---|
| 112 |
fakeEdges.add(we); |
|---|
| 113 |
} |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
for (ListIterator i = edges.listIterator(); i.hasNext(); ) |
|---|
| 117 |
{ |
|---|
| 118 |
Edge e = (Edge)( i.next() ); |
|---|
| 119 |
|
|---|
| 120 |
int uniqueNum = 1; |
|---|
| 121 |
String base = e.symbol().replaceAll("[^A-Za-z0-9]","_"); |
|---|
| 122 |
String id = base + "_" + uniqueNum; |
|---|
| 123 |
|
|---|
| 124 |
while (idEdges.get(id) != null) |
|---|
| 125 |
{ |
|---|
| 126 |
uniqueNum++; |
|---|
| 127 |
id = base + "_" + uniqueNum; |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
edgeIds.put(e, id); |
|---|
| 131 |
idEdges.put(id, e); |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
/* |
|---|
| 135 |
%> |
|---|
| 136 |
<ul> |
|---|
| 137 |
<% |
|---|
| 138 |
|
|---|
| 139 |
for (Iterator i = edges.iterator(); i.hasNext(); ) |
|---|
| 140 |
{ |
|---|
| 141 |
Edge e = (Edge)( i.next() ); |
|---|
| 142 |
%> |
|---|
| 143 |
<ul> |
|---|
| 144 |
[<%= e.getDepth() %>] <%= edgeIds.get(e) %> |
|---|
| 145 |
<%= e.toString() %> |
|---|
| 146 |
</ul> |
|---|
| 147 |
<% |
|---|
| 148 |
} |
|---|
| 149 |
|
|---|
| 150 |
%> |
|---|
| 151 |
</ul> |
|---|
| 152 |
<% |
|---|
| 153 |
*/ |
|---|
| 154 |
|
|---|
| 155 |
for (int i = 0; i <= maxDepth; i++) |
|---|
| 156 |
{ |
|---|
| 157 |
depths.add(new ArrayList()); |
|---|
| 158 |
} |
|---|
| 159 |
|
|---|
| 160 |
for (Iterator i = edges.iterator(); i.hasNext(); ) |
|---|
| 161 |
{ |
|---|
| 162 |
Edge e = (Edge)( i.next() ); |
|---|
| 163 |
int depth = e.getDepth(); |
|---|
| 164 |
List edgesAtDepth = (List)( depths.get(depth) ); |
|---|
| 165 |
edgesAtDepth.add(e); |
|---|
| 166 |
} |
|---|
| 167 |
|
|---|
| 168 |
%> |
|---|
| 169 |
<table border> |
|---|
| 170 |
<% |
|---|
| 171 |
|
|---|
| 172 |
class EdgeComparator implements Comparator |
|---|
| 173 |
{ |
|---|
| 174 |
public int compare(Object o1, Object o2) |
|---|
| 175 |
{ |
|---|
| 176 |
Edge e1 = (Edge)o1; |
|---|
| 177 |
Edge e2 = (Edge)o2; |
|---|
| 178 |
int diff = e1.getLeftPosition() - e2.getLeftPosition(); |
|---|
| 179 |
if (diff != 0) return diff; |
|---|
| 180 |
return e2.getRightPosition() - e1.getRightPosition(); |
|---|
| 181 |
} |
|---|
| 182 |
} |
|---|
| 183 |
|
|---|
| 184 |
Comparator comp = new EdgeComparator(); |
|---|
| 185 |
|
|---|
| 186 |
for (int i = maxDepth; i >= 0; i--) |
|---|
| 187 |
{ |
|---|
| 188 |
List edgesAtDepth = (List)( depths.get(i) ); |
|---|
| 189 |
List remaining = new ArrayList(); |
|---|
| 190 |
remaining.addAll(edgesAtDepth); |
|---|
| 191 |
Collections.sort(remaining, comp); |
|---|
| 192 |
|
|---|
| 193 |
if (remaining.size() != edgesAtDepth.size()) |
|---|
| 194 |
{ |
|---|
| 195 |
throw new AssertionError("lost elements"); |
|---|
| 196 |
} |
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
while (remaining.size() > 0) |
|---|
| 201 |
{ |
|---|
| 202 |
List added = new ArrayList(); |
|---|
| 203 |
List leftOver = new ArrayList(); |
|---|
| 204 |
|
|---|
| 205 |
%> |
|---|
| 206 |
<tr> |
|---|
| 207 |
<% |
|---|
| 208 |
|
|---|
| 209 |
int pos = 0; |
|---|
| 210 |
|
|---|
| 211 |
for (Iterator n = remaining.iterator(); n.hasNext(); ) |
|---|
| 212 |
{ |
|---|
| 213 |
Edge next = (Edge)( n.next() ); |
|---|
| 214 |
boolean overlaps = false; |
|---|
| 215 |
|
|---|
| 216 |
for (Iterator a = added.iterator(); a.hasNext(); ) |
|---|
| 217 |
{ |
|---|
| 218 |
Edge addedEdge = (Edge)( a.next() ); |
|---|
| 219 |
if (next.overlaps(addedEdge)) |
|---|
| 220 |
{ |
|---|
| 221 |
overlaps = true; |
|---|
| 222 |
break; |
|---|
| 223 |
} |
|---|
| 224 |
} |
|---|
| 225 |
|
|---|
| 226 |
if (overlaps) |
|---|
| 227 |
{ |
|---|
| 228 |
leftOver.add(next); |
|---|
| 229 |
continue; |
|---|
| 230 |
} |
|---|
| 231 |
|
|---|
| 232 |
int left = next.getLeftPosition(); |
|---|
| 233 |
if (pos < left) |
|---|
| 234 |
{ |
|---|
| 235 |
%> |
|---|
| 236 |
<td colspan="<%= left - pos %>" /> |
|---|
| 237 |
<% |
|---|
| 238 |
pos = left; |
|---|
| 239 |
} |
|---|
| 240 |
|
|---|
| 241 |
int right = next.getRightPosition(); |
|---|
| 242 |
int colspan = right - left + 1; |
|---|
| 243 |
|
|---|
| 244 |
%> |
|---|
| 245 |
<td <%= colspan>1 ? "colspan="+colspan : "" %> |
|---|
| 246 |
id="<%= edgeIds.get(next) %>" |
|---|
| 247 |
onMouseOver="return highlight (this);" |
|---|
| 248 |
onMouseOut=" return unhighlight_all();" |
|---|
| 249 |
> |
|---|
| 250 |
|
|---|
| 251 |
<% /* %> |
|---|
| 252 |
[<%= edgeIds.get(next) %>] |
|---|
| 253 |
<% */ |
|---|
| 254 |
|
|---|
| 255 |
if (!fakeEdges.contains(next)) |
|---|
| 256 |
{ |
|---|
| 257 |
%> |
|---|
| 258 |
<span class="cb"> |
|---|
| 259 |
<input name="<%= edgeIds.get(next) %>" |
|---|
| 260 |
type="checkbox" |
|---|
| 261 |
onClick="return on_checkbox_click(this);" /> |
|---|
| 262 |
</span> |
|---|
| 263 |
<% |
|---|
| 264 |
} |
|---|
| 265 |
|
|---|
| 266 |
if (next instanceof RuleEdge) |
|---|
| 267 |
{ |
|---|
| 268 |
RuleEdge re = (RuleEdge)next; |
|---|
| 269 |
%><a href="rules.jsp?erid=<%= |
|---|
| 270 |
re.rule().id() |
|---|
| 271 |
%>#rule_<%= |
|---|
| 272 |
re.rule().id() |
|---|
| 273 |
%>"><%= |
|---|
| 274 |
next.getHtmlLabel() |
|---|
| 275 |
%></a><% |
|---|
| 276 |
} |
|---|
| 277 |
else |
|---|
| 278 |
{ |
|---|
| 279 |
%><%= next.getHtmlLabel() %><% |
|---|
| 280 |
} |
|---|
| 281 |
|
|---|
| 282 |
%> |
|---|
| 283 |
</td> |
|---|
| 284 |
<% |
|---|
| 285 |
|
|---|
| 286 |
added.add(next); |
|---|
| 287 |
pos += colspan; |
|---|
| 288 |
} |
|---|
| 289 |
|
|---|
| 290 |
remaining = leftOver; |
|---|
| 291 |
} |
|---|
| 292 |
|
|---|
| 293 |
%> |
|---|
| 294 |
</tr> |
|---|
| 295 |
<% |
|---|
| 296 |
} |
|---|
| 297 |
|
|---|
| 298 |
Map parentEdges = new Hashtable(); |
|---|
| 299 |
|
|---|
| 300 |
%> |
|---|
| 301 |
</table> |
|---|
| 302 |
<script><!-- |
|---|
| 303 |
var children_by_id = Array(); |
|---|
| 304 |
<% |
|---|
| 305 |
|
|---|
| 306 |
for (Iterator i = edges.iterator(); i.hasNext(); ) |
|---|
| 307 |
{ |
|---|
| 308 |
Edge e = (Edge)( i.next() ); |
|---|
| 309 |
%>children_by_id["<%= edgeIds.get(e) %>"] = new Array(<% |
|---|
| 310 |
Edge [] children = e.parts(); |
|---|
| 311 |
List childList = new ArrayList(); |
|---|
| 312 |
for (int j = 0; j < children.length; j++) |
|---|
| 313 |
{ |
|---|
| 314 |
childList.add(children[j].getUnboundOriginal()); |
|---|
| 315 |
} |
|---|
| 316 |
if (fakeChild.get(e) != null) |
|---|
| 317 |
{ |
|---|
| 318 |
childList.add(fakeChild.get(e)); |
|---|
| 319 |
} |
|---|
| 320 |
for (Iterator j = childList.iterator(); j.hasNext(); ) |
|---|
| 321 |
{ |
|---|
| 322 |
Edge child = (Edge)( j.next() ); |
|---|
| 323 |
String id = (String)( edgeIds.get(child) ); |
|---|
| 324 |
%>"<%= id %>"<% |
|---|
| 325 |
if (j.hasNext()) |
|---|
| 326 |
{ |
|---|
| 327 |
%>, <% |
|---|
| 328 |
} |
|---|
| 329 |
|
|---|
| 330 |
List parentEdgeList = (List)( parentEdges.get(id) ); |
|---|
| 331 |
if (parentEdgeList == null) |
|---|
| 332 |
{ |
|---|
| 333 |
parentEdgeList = new ArrayList(); |
|---|
| 334 |
} |
|---|
| 335 |
parentEdgeList.add(e); |
|---|
| 336 |
parentEdges.put(id, parentEdgeList); |
|---|
| 337 |
} |
|---|
| 338 |
%>); |
|---|
| 339 |
<% |
|---|
| 340 |
} |
|---|
| 341 |
|
|---|
| 342 |
%> |
|---|
| 343 |
var parents_by_id = Array(); |
|---|
| 344 |
<% |
|---|
| 345 |
for (Iterator i = parentEdges.keySet().iterator(); i.hasNext(); ) |
|---|
| 346 |
{ |
|---|
| 347 |
String childId = (String)( i.next() ); |
|---|
| 348 |
List parentList = (List)( parentEdges.get(childId) ); |
|---|
| 349 |
|
|---|
| 350 |
%>parents_by_id["<%= childId %>"] = new Array(<% |
|---|
| 351 |
for (Iterator j = parentList.iterator(); j.hasNext(); ) |
|---|
| 352 |
{ |
|---|
| 353 |
Edge parent = (Edge)( j.next() ); |
|---|
| 354 |
String id = (String)( edgeIds.get(parent) ); |
|---|
| 355 |
%>"<%= id %>"<% |
|---|
| 356 |
if (j.hasNext()) |
|---|
| 357 |
{ |
|---|
| 358 |
%>, <% |
|---|
| 359 |
} |
|---|
| 360 |
} |
|---|
| 361 |
%>); |
|---|
| 362 |
<% |
|---|
| 363 |
} |
|---|
| 364 |
%> |
|---|
| 365 |
|
|---|
| 366 |
var edges = Array( |
|---|
| 367 |
<% |
|---|
| 368 |
for (Iterator i = edges.iterator(); i.hasNext(); ) |
|---|
| 369 |
{ |
|---|
| 370 |
Edge e = (Edge)( i.next() ); |
|---|
| 371 |
String id = (String)( edgeIds.get(e) ); |
|---|
| 372 |
%> |
|---|
| 373 |
new edge("<%= id %>", <%= |
|---|
| 374 |
e.getLeftPosition() %>, <%= |
|---|
| 375 |
e.getRightPosition() %>, "<%= |
|---|
| 376 |
e.symbol() %>", <%= |
|---|
| 377 |
e.isTerminal() %>, <%= |
|---|
| 378 |
fakeEdges.contains(e) %>)<% |
|---|
| 379 |
if (i.hasNext()) |
|---|
| 380 |
{ |
|---|
| 381 |
%>, |
|---|
| 382 |
<% |
|---|
| 383 |
} |
|---|
| 384 |
} |
|---|
| 385 |
%> |
|---|
| 386 |
); |
|---|
| 387 |
|
|---|
| 388 |
//--></script> |
|---|
| 389 |
|
|---|
| 390 |
<p></p> |
|---|
| 391 |
|
|---|
| 392 |
<table> |
|---|
| 393 |
<tr bgcolor="#ffcccc"> |
|---|
| 394 |
<th colspan="3">Create a new rule</th> |
|---|
| 395 |
</tr> |
|---|
| 396 |
<tr bgcolor="#ffeeee"> |
|---|
| 397 |
<td>Top node name (symbol)</td> |
|---|
| 398 |
<td>Component node names (parts)</td> |
|---|
| 399 |
<td>Command</td> |
|---|
| 400 |
</tr> |
|---|
| 401 |
<tr bgcolor="#ffcccc"> |
|---|
| 402 |
<td> |
|---|
| 403 |
<input name="new_rule_sym" /> |
|---|
| 404 |
</td> |
|---|
| 405 |
<td> |
|---|
| 406 |
<input name="new_rule_parts" size="30"/> |
|---|
| 407 |
</td> |
|---|
| 408 |
<td> |
|---|
| 409 |
<input name="rule_add" type="submit" value="Create" |
|---|
| 410 |
onClick="return on_rule_add_click()" /> |
|---|
| 411 |
</td> |
|---|
| 412 |
</tr> |
|---|
| 413 |
</table> |
|---|
| 414 |
|
|---|
| 415 |
</form> |
|---|
| 416 |
|
|---|
| 417 |
<% |
|---|
| 418 |
} |
|---|
| 419 |
} |
|---|
| 420 |
|
|---|
| 421 |
%> |
|---|
| 422 |
|
|---|
| 423 |
<%@ include file="include/footer.jsp" %> |
|---|