Changeset 52

Show
Ignore:
Timestamp:
01/01/07 20:53:29 (2 years ago)
Author:
chris
Message:

- Removed requirement to know chart width beforehand

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lex/trunk/src/com/qwirx/lex/parser/Chart.java

    r30 r52  
    77public class Chart 
    88{ 
    9     private int  m_Width = 0; 
    109    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     } 
    2110     
    2211    public List getEdges() 
     
    5443    } 
    5544     
    56     public String toString() { return m_Width + ": " + m_Edges; } 
     45    public String toString() { return m_Edges.toString(); } 
    5746} 
  • lex/trunk/src/com/qwirx/lex/parser/Edge.java

    r30 r52  
    3131     
    3232    boolean isAt(int pos); 
     33    boolean includes(Edge other); 
    3334} 
  • lex/trunk/src/com/qwirx/lex/parser/MorphEdge.java

    r48 r52  
    9191        return m_Position == position; 
    9292    } 
     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    } 
    93101} 
  • lex/trunk/src/com/qwirx/lex/parser/Parser.java

    r47 r52  
    6767        public Chart parse(List input)  
    6868    { 
    69         Chart chart = new Chart(input.size()); 
     69        Chart chart = new Chart(); 
    7070         
    7171                for (int i = 0; i < input.size(); i++) 
     
    119119            boolean hasHoles = false; 
    120120             
    121             for (int j = 0; j < chart.getWidth(); j++
     121            for (Iterator j = input.iterator(); j.hasNext();
    122122            { 
    123                 if (! edge.isAt(j)) 
     123                Edge other = (Edge)( j.next() ); 
     124                if (!edge.includes(other)) 
    124125                { 
    125126                    hasHoles = true; 
     127                    if (m_Verbose) 
     128                    { 
     129                        System.out.println("Rejected edge: " + edge + 
     130                            ": does not contain " + other); 
     131                    } 
    126132                    break; 
    127133                } 
     
    130136            if (hasHoles) 
    131137            { 
    132                 if (m_Verbose) 
    133                 { 
    134                     System.out.println("Rejected edge with holes: " + edge); 
    135                 }    
    136138                continue; 
    137139            } 
  • lex/trunk/src/com/qwirx/lex/parser/Rule.java

    r30 r52  
    555555            // check that the edge doesn't overlap any previously chosen ones 
    556556            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++) 
    559558            { 
    560559                if (edge.isAt(j)) 
  • lex/trunk/src/com/qwirx/lex/parser/RuleEdge.java

    r30 r52  
    343343        return false; 
    344344    } 
     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    } 
    345357} 
  • lex/trunk/src/com/qwirx/lex/parser/WordEdge.java

    r30 r52  
    105105        return m_Position == position; 
    106106    } 
     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    } 
    107114} 
  • lex/trunk/test/com/qwirx/lex/ParserTest.java

    r51 r52  
    4747    public void testAddToChart() 
    4848    { 
    49         Chart chart = new Chart(2); 
     49        Chart chart = new Chart(); 
    5050        List edges = chart.getEdges(); 
    5151        assertEquals(0, edges.size()); 
     
    7777    public void testApplyRuleToChartReturnsEdge() 
    7878    { 
    79         Chart chart = new Chart(2); 
     79        Chart chart = new Chart(); 
    8080        chart.add(new WordEdge("the", 0)); 
    8181        chart.add(new WordEdge("cat", 1)); 
     
    314314                 
    315315                Parser p = new Parser(rules); 
     316        p.setVerbose(true); 
    316317                List results = p.parseFor("the cat sat on the mat by the door", "SENTENCE"); 
    317318                 
     
    578579        Rule test = Rule.makeFromString(3, "maybe_CATs_maybe_DOGs", "# {CAT}* {DOG}*"); 
    579580         
    580         Chart chart = new Chart(2); 
     581        Chart chart = new Chart(); 
    581582        chart.add(new RuleEdge(cat, new Edge[]{ 
    582583            new WordEdge("cat", 0, cat.part(0))