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.core; 016 017 import java.io.IOException; 018 import java.util.List; 019 020 /** 021 * This exporter generates a table of the wiki statements in CSV (comma separated values) format. 022 * 023 * @author Tobias Kuhn 024 */ 025 public class StatementTableExporter extends OntologyExporter { 026 027 private String language; 028 029 /** 030 * Creates a statement table exporter in the given language. 031 * 032 * @param language The language. 033 */ 034 public StatementTableExporter(String language) { 035 this.language = language; 036 } 037 038 protected void writeContent() throws IOException { 039 write("PAGE,TYPE,TEXT\n"); 040 List<OntologyElement> elements = getOntologyElements(); 041 LanguageUtils.sortOntologyElements(elements); 042 for (OntologyElement oe : elements) { 043 for (Statement s : oe.getArticle().getStatements()) { 044 write(LanguageUtils.getHeading(oe) + ","); 045 write(getStatementType(s) + ","); 046 write("\"" + s.getText(language).replaceAll("\"", "\"\"").replaceAll("\\s+", " ") + "\""); 047 write("\n"); 048 } 049 } 050 } 051 052 public boolean isApplicable() { 053 return true; 054 } 055 056 public String getName() { 057 return "Statement Table"; 058 } 059 060 public String getFileSuffix() { 061 return "-st.csv"; 062 } 063 064 public String getContentType() { 065 return "text/plain"; 066 } 067 068 private static String getStatementType(Statement statement) { 069 if (statement instanceof Comment) { 070 return "comment"; 071 } else if (statement instanceof Question) { 072 return "question"; 073 } else if (statement instanceof Declaration) { 074 Declaration declaration = (Declaration) statement; 075 if (declaration.getArticle() == null) { 076 return "inferred"; 077 } else if (declaration.isIntegrated()) { 078 return "asserted"; 079 } else { 080 return "unasserted"; 081 } 082 } else { 083 throw new RuntimeException("Unknown statement class"); 084 } 085 } 086 087 }