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.acewiki.gf;
016    
017    import java.util.ArrayList;
018    import java.util.List;
019    
020    import ch.uzh.ifi.attempto.acewiki.core.AbstractLanguageHandler;
021    import ch.uzh.ifi.attempto.acewiki.core.EditorController;
022    import ch.uzh.ifi.attempto.acewiki.core.Ontology;
023    import ch.uzh.ifi.attempto.acewiki.core.Sentence;
024    import ch.uzh.ifi.attempto.base.DefaultTextOperator;
025    import ch.uzh.ifi.attempto.base.PredictiveParser;
026    import ch.uzh.ifi.attempto.base.TextContainer;
027    import ch.uzh.ifi.attempto.base.TextOperator;
028    
029    /**
030     * This is a language handler for languages written in GF.
031     * 
032     * @author Tobias Kuhn
033     */
034    public class GFHandler extends AbstractLanguageHandler {
035            
036            private String language;
037            private TextOperator textOperator = new DefaultTextOperator();
038            private EditorController editorController = new EditorController();
039            private GFGrammar gfGrammar;
040            
041            /**
042             * Creates a new GF handler for the given language.
043             * 
044             * @param language The name of the language.
045             * @param gfGrammar The grammar object.
046             */
047            public GFHandler(String language, GFGrammar gfGrammar) {
048                    this.language = language;
049                    this.gfGrammar = gfGrammar;
050            }
051    
052            public String getLanguage() {
053                    return language;
054            }
055    
056            public void init(Ontology ontology) {
057            }
058            
059            public TextOperator getTextOperator() {
060                    return textOperator;
061            }
062            
063            public List<Sentence> extractSentences(TextContainer tc, PredictiveParser parser) {
064                    List<Sentence> l = new ArrayList<Sentence>();
065                    l.add(new GFDeclaration(tc.getText(), language, gfGrammar));
066                    return l;
067            }
068            
069            public PredictiveParser getPredictiveParser() {
070                    return new GFPredictiveParser(gfGrammar, language);
071            }
072            
073            public EditorController getEditorController() {
074                    return editorController;
075            }
076    
077    }