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.HashMap; 018 import java.util.Map; 019 020 import ch.uzh.ifi.attempto.acewiki.core.AbstractAceWikiEngine; 021 import ch.uzh.ifi.attempto.acewiki.core.AceWikiReasoner; 022 import ch.uzh.ifi.attempto.acewiki.core.Concept; 023 import ch.uzh.ifi.attempto.acewiki.core.DummyReasoner; 024 import ch.uzh.ifi.attempto.acewiki.core.Individual; 025 import ch.uzh.ifi.attempto.acewiki.core.LanguageHandler; 026 import ch.uzh.ifi.attempto.acewiki.core.Ontology; 027 import ch.uzh.ifi.attempto.acewiki.core.OntologyElement; 028 import ch.uzh.ifi.attempto.acewiki.core.Sentence; 029 030 /** 031 * This is an AceWiki engine using GF (Grammatical Framework). 032 * 033 * @author Tobias Kuhn 034 */ 035 public class GFEngine extends AbstractAceWikiEngine { 036 037 private Map<String, GFHandler> languageHandlers = new HashMap<String, GFHandler>(); 038 private AceWikiReasoner reasoner = new DummyReasoner(); 039 private GFGrammar gfGrammar; 040 private Ontology ontology; 041 042 /** 043 * Creates a new GF-based AceWiki engine. 044 */ 045 public GFEngine() { 046 } 047 048 public void init(Ontology ontology) { 049 this.ontology = ontology; 050 gfGrammar = new GFGrammar( 051 ontology.getParameter("pgf_file"), 052 getLanguages()[0] 053 ); 054 super.init(ontology); 055 } 056 057 public LanguageHandler getLanguageHandler(String language) { 058 GFHandler lh = languageHandlers.get(language); 059 if (lh == null) { 060 lh = new GFHandler(language, gfGrammar); 061 languageHandlers.put(language, lh); 062 } 063 return lh; 064 } 065 066 public String[] getLanguages() { 067 return ontology.getParameter("languages").split(","); 068 } 069 070 /** 071 * Returns the grammar object. 072 * 073 * @return The grammar object. 074 */ 075 public GFGrammar getGFGrammar() { 076 return gfGrammar; 077 } 078 079 public AceWikiReasoner getReasoner() { 080 return reasoner; 081 } 082 083 public OntologyElement createOntologyElement(String type) { 084 // TODO 085 return null; 086 } 087 088 public Sentence createSentence(String serialized) { 089 return new GFDeclaration(gfGrammar.deserialize(serialized), gfGrammar); 090 } 091 092 public Sentence createAssignmentSentence(Individual ind, Concept concept) { 093 // TODO 094 return null; 095 } 096 097 public Sentence createHierarchySentence(Concept subConcept, Concept superConcept) { 098 // TODO 099 return null; 100 } 101 102 }