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.List;
019
020 import ch.uzh.ifi.attempto.acewiki.core.LanguageUtils;
021 import ch.uzh.ifi.attempto.acewiki.core.OntologyElement;
022 import ch.uzh.ifi.attempto.acewiki.core.OntologyExporter;
023 import ch.uzh.ifi.attempto.acewiki.core.Sentence;
024
025 /**
026 * This exporter generates a file that contains the complete ontology as one ACE text.
027 *
028 * @author Tobias Kuhn
029 */
030 public class ACETextExporter extends OntologyExporter {
031
032 private final boolean consistent;
033
034 /**
035 * Creates a new ACE text exporter.
036 *
037 * @param consistent Defines if only the consistent part of the ontology should be considered.
038 */
039 public ACETextExporter(boolean consistent) {
040 this.consistent = consistent;
041 }
042
043 protected void writeContent() throws IOException {
044 List<OntologyElement> elements = getOntologyElements();
045 LanguageUtils.sortOntologyElements(elements);
046 for (OntologyElement oe : elements) {
047 String heading = "\n# " + LanguageUtils.getHeading(oe) + "\n\n";
048 for (Sentence sentence : oe.getArticle().getSentences()) {
049 ACESentence s = (ACESentence) sentence;
050 if (!consistent || (s.isIntegrated() && s.isReasonable()) ) {
051 if (heading != null) {
052 write(heading);
053 heading = null;
054 }
055 write(s.getText() + "\n\n");
056 }
057 }
058 }
059 }
060
061 public String getName() {
062 return "ACE Text, " + (consistent ? "consistent" : "full");
063 }
064
065 public boolean isApplicable() {
066 return true;
067 }
068
069 public String getFileSuffix() {
070 return ".ace.txt";
071 }
072
073 public String getContentType() {
074 return "text/plain";
075 }
076
077 }