Changeset 52
- Timestamp:
- 01/01/07 20:53:29 (2 years ago)
- Files:
-
- lex/trunk/src/com/qwirx/lex/parser/Chart.java (modified) (2 diffs)
- lex/trunk/src/com/qwirx/lex/parser/Edge.java (modified) (1 diff)
- lex/trunk/src/com/qwirx/lex/parser/MorphEdge.java (modified) (1 diff)
- lex/trunk/src/com/qwirx/lex/parser/Parser.java (modified) (3 diffs)
- lex/trunk/src/com/qwirx/lex/parser/Rule.java (modified) (1 diff)
- lex/trunk/src/com/qwirx/lex/parser/RuleEdge.java (modified) (1 diff)
- lex/trunk/src/com/qwirx/lex/parser/WordEdge.java (modified) (1 diff)
- lex/trunk/test/com/qwirx/lex/ParserTest.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
lex/trunk/src/com/qwirx/lex/parser/Chart.java
r30 r52 7 7 public class Chart 8 8 { 9 private int m_Width = 0;10 9 private List m_Edges = new ArrayList(); 11 12 public Chart(int width)13 {14 m_Width = width;15 }16 17 public int getWidth()18 {19 return m_Width;20 }21 10 22 11 public List getEdges() … … 54 43 } 55 44 56 public String toString() { return m_ Width + ": " + m_Edges; }45 public String toString() { return m_Edges.toString(); } 57 46 } lex/trunk/src/com/qwirx/lex/parser/Edge.java
r30 r52 31 31 32 32 boolean isAt(int pos); 33 boolean includes(Edge other); 33 34 } lex/trunk/src/com/qwirx/lex/parser/MorphEdge.java
r48 r52 91 91 return m_Position == position; 92 92 } 93 public boolean includes(Edge other) 94 { 95 if (!(other instanceof MorphEdge)) return false; 96 MorphEdge m = (MorphEdge)other; 97 return this.m_Surface.equals(m.m_Surface) && 98 this.m_Symbol.equals(m.m_Symbol) && 99 this.m_Position == m.m_Position; 100 } 93 101 } lex/trunk/src/com/qwirx/lex/parser/Parser.java
r47 r52 67 67 public Chart parse(List input) 68 68 { 69 Chart chart = new Chart( input.size());69 Chart chart = new Chart(); 70 70 71 71 for (int i = 0; i < input.size(); i++) … … 119 119 boolean hasHoles = false; 120 120 121 for ( int j = 0; j < chart.getWidth(); j++)121 for (Iterator j = input.iterator(); j.hasNext(); ) 122 122 { 123 if (! edge.isAt(j)) 123 Edge other = (Edge)( j.next() ); 124 if (!edge.includes(other)) 124 125 { 125 126 hasHoles = true; 127 if (m_Verbose) 128 { 129 System.out.println("Rejected edge: " + edge + 130 ": does not contain " + other); 131 } 126 132 break; 127 133 } … … 130 136 if (hasHoles) 131 137 { 132 if (m_Verbose)133 {134 System.out.println("Rejected edge with holes: " + edge);135 }136 138 continue; 137 139 } lex/trunk/src/com/qwirx/lex/parser/Rule.java
r30 r52 555 555 // check that the edge doesn't overlap any previously chosen ones 556 556 boolean overlaps = false; 557 for (int j = rightmostEmptyPos + 1; 558 j < m_CurrentChart.getWidth(); j++) 557 for (int j = rightmostEmptyPos + 1; j < m_PositionsUsed.length; j++) 559 558 { 560 559 if (edge.isAt(j)) lex/trunk/src/com/qwirx/lex/parser/RuleEdge.java
r30 r52 343 343 return false; 344 344 } 345 public boolean includes(Edge other) 346 { 347 for (int i = 0; i < parts.length; i++) 348 { 349 if (parts[i].includes(other)) 350 { 351 return true; 352 } 353 } 354 355 return false; 356 } 345 357 } lex/trunk/src/com/qwirx/lex/parser/WordEdge.java
r30 r52 105 105 return m_Position == position; 106 106 } 107 public boolean includes(Edge other) 108 { 109 if (!(other instanceof WordEdge)) return false; 110 WordEdge w = (WordEdge)other; 111 return this.surface.equals(w.surface) && 112 this.m_Position == w.m_Position; 113 } 107 114 } lex/trunk/test/com/qwirx/lex/ParserTest.java
r51 r52 47 47 public void testAddToChart() 48 48 { 49 Chart chart = new Chart( 2);49 Chart chart = new Chart(); 50 50 List edges = chart.getEdges(); 51 51 assertEquals(0, edges.size()); … … 77 77 public void testApplyRuleToChartReturnsEdge() 78 78 { 79 Chart chart = new Chart( 2);79 Chart chart = new Chart(); 80 80 chart.add(new WordEdge("the", 0)); 81 81 chart.add(new WordEdge("cat", 1)); … … 314 314 315 315 Parser p = new Parser(rules); 316 p.setVerbose(true); 316 317 List results = p.parseFor("the cat sat on the mat by the door", "SENTENCE"); 317 318 … … 578 579 Rule test = Rule.makeFromString(3, "maybe_CATs_maybe_DOGs", "# {CAT}* {DOG}*"); 579 580 580 Chart chart = new Chart( 2);581 Chart chart = new Chart(); 581 582 chart.add(new RuleEdge(cat, new Edge[]{ 582 583 new WordEdge("cat", 0, cat.part(0))
