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.util.List; 018 019 import ch.uzh.ifi.attempto.base.PredictiveParser; 020 import ch.uzh.ifi.attempto.base.TextContainer; 021 022 /** 023 * This factory class is used to generate different kind of statements (declarations, questions and 024 * comments). 025 * 026 * @author Tobias Kuhn 027 */ 028 public class StatementFactory { 029 030 private Ontology ontology; 031 032 StatementFactory(Ontology ontology) { 033 this.ontology = ontology; 034 } 035 036 /** 037 * Creates a new comment. Comments must be part of an article. 038 * 039 * @param text The comment text. 040 * @param article The article. 041 * @return The new comment. 042 */ 043 public Comment createComment(String text, Article article) { 044 Comment c = new Comment(text); 045 c.init(ontology, article); 046 return c; 047 } 048 049 /** 050 * Creates a new sentence object with the given article. 051 * 052 * @param serialized The serialized representation of the sentence. 053 * @param article The article. 054 * @return A new sentence object. 055 */ 056 public Sentence createSentence(String serialized, Article article) { 057 Sentence s = ontology.getEngine().createSentence(serialized); 058 s.init(ontology, article); 059 return s; 060 } 061 062 /** 063 * Extracts sentence objects out of a text container and/or a parser state. 064 * 065 * @param tc The text container. 066 * @param languageHandler The language handler. 067 * @param parser The parser object with the parsed text. 068 * @param article The article of the sentences. 069 * @return A list of sentences. 070 */ 071 public List<Sentence> extractSentences(LanguageHandler languageHandler, TextContainer tc, 072 PredictiveParser parser, Article article) { 073 List<Sentence> l = languageHandler.extractSentences(tc, parser); 074 for (Sentence s : l) { 075 s.init(ontology, article); 076 } 077 return l; 078 } 079 080 /** 081 * Creates an assignment sentence. 082 * 083 * @param ind The individual. 084 * @param conc The concept. 085 * @return A new assignement sentence. 086 */ 087 public Sentence createAssignmentSentence(Individual ind, Concept conc) { 088 Sentence s = ontology.getEngine().createAssignmentSentence(ind, conc); 089 s.init(ontology, null); 090 return s; 091 } 092 093 /** 094 * Creates a hierarchy sentence. 095 * 096 * @param subConc The sub-concept. 097 * @param superConc The super-concept. 098 * @return A new hierarchy sentence. 099 */ 100 public Sentence createHierarchySentence(Concept subConc, Concept superConc) { 101 Sentence s = ontology.getEngine().createHierarchySentence(subConc, superConc); 102 s.init(ontology, null); 103 return s; 104 } 105 106 }