001    // This file is part of AceWiki.
002    // Copyright 2008-2012, AceWiki developers.
003    // 
004    // AceWiki is free software: you can redistribute it and/or modify it under the terms of the GNU
005    // Lesser General Public License as published by the Free Software Foundation, either version 3 of
006    // the License, or (at your option) any later version.
007    // 
008    // AceWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009    // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
010    // Lesser General Public License for more details.
011    // 
012    // You should have received a copy of the GNU Lesser General Public License along with AceWiki. If
013    // not, see http://www.gnu.org/licenses/.
014    
015    package ch.uzh.ifi.attempto.chartparser;
016    
017    import java.util.Collection;
018    import java.util.HashMap;
019    import java.util.List;
020    import java.util.Set;
021    
022    /**
023     * This class stands for a terminal category. Terminal categories consists only of a name and
024     * cannot have features. The names of terminal categories correspond to the tokens in the text
025     * to be parsed.
026     * 
027     * @author Tobias Kuhn
028     */
029    public class Terminal extends Category {
030    
031            /**
032             * Creates a new terminal category.
033             * 
034             * @param name The name of the terminal category.
035             */
036            public Terminal(String name) {
037                    this.name = name;
038            }
039            
040            protected String getType() {
041                    return "term";
042            }
043            
044            public void unify(Category c) throws UnificationFailedException {
045                    if (!name.equals(c.name) || !getType().equals(c.getType())) {
046                            throw new UnificationFailedException();
047                    }
048            }
049            
050            public void tryToUnify(Category c) throws UnificationFailedException {
051                    if (!name.equals(c.name) || !getType().equals(c.getType())) {
052                            throw new UnificationFailedException();
053                    }
054            }
055            
056            public boolean canUnify(Category c) {
057                    if (!name.equals(c.name) || !getType().equals(c.getType())) {
058                            return false;
059                    } else {
060                            return true;
061                    }
062            }
063            
064            public boolean isSimilar(Category c) {
065                    if (!name.equals(c.name) || !getType().equals(c.getType())) {
066                            return false;
067                    } else {
068                            return true;
069                    }
070            }
071            
072            public boolean subsumes(Category c) {
073                    if (!name.equals(c.name) || !getType().equals(c.getType())) {
074                            return false;
075                    } else {
076                            return true;
077                    }
078            }
079            
080            public void skolemize() {
081            }
082            
083            public Set<String> getFeatureNames() {
084                    return null;
085            }
086            
087            public Collection<StringRef> getFeatureValues() {
088                    return null;
089            }
090            
091            String getIdentifier(List<Integer> mvars, String[] usedFeatureNames) {
092                    return toString();
093            }
094            
095            public Category deepCopy() {
096                    return new Terminal(name);
097            }
098            
099            Category deepCopy(HashMap<Integer, StringObject> stringObjs) {
100                    return new Terminal(name);
101            }
102            
103            public int hashCode() {
104                    return name.hashCode();
105            }
106            
107            public boolean equals(Object obj) {
108                    if (!(obj instanceof Terminal)) return false;
109                    return toString().equals(obj.toString());
110            }
111            
112            public String toString() {
113                    return "'" + name + "'";
114            }
115    
116    }