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.aceowl;
016    
017    import java.io.IOException;
018    import java.util.ArrayList;
019    import java.util.Collections;
020    import java.util.List;
021    
022    import ch.uzh.ifi.attempto.acewiki.core.OntologyElement;
023    import ch.uzh.ifi.attempto.acewiki.core.OntologyExporter;
024    import ch.uzh.ifi.attempto.ape.LexiconEntry;
025    
026    /**
027     * This exporter generates a lexicon file in the ACE lexicon format containing all the words used
028     * in the knowledge base.
029     * 
030     * @author Tobias Kuhn
031     */
032    public class ACELexiconExporter extends OntologyExporter {
033            
034            protected void writeContent() throws IOException {
035                    List<String> lexiconEntries = new ArrayList<String>();
036                    for (OntologyElement oe : getOntologyElements()) {
037                            if (oe instanceof ACEOWLOntoElement) {
038                                    for (LexiconEntry le : ((ACEOWLOntoElement) oe).getLexiconEntries()) {
039                                            if (!lexiconEntries.contains(le.toString())) {
040                                                    lexiconEntries.add(le.toString());
041                                            }
042                                    }
043                            }
044                    }
045                    Collections.sort(lexiconEntries, String.CASE_INSENSITIVE_ORDER);
046                    for (String s : lexiconEntries) {
047                            write(s + ".\n");
048                    }
049            }
050            
051            public String getName() {
052                    return "ACE Lexicon";
053            }
054            
055            public boolean isApplicable() {
056                    return true;
057            }
058            
059            public String getFileSuffix() {
060                    return ".lex.pl";
061            }
062            
063            public String getContentType() {
064                    return "text/plain";
065            }
066    
067    }