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 ch.uzh.ifi.attempto.acewiki.core.AceWikiReasoner;
018 import ch.uzh.ifi.attempto.acewiki.core.Concept;
019 import ch.uzh.ifi.attempto.acewiki.core.Individual;
020 import ch.uzh.ifi.attempto.acewiki.core.LanguageHandler;
021 import ch.uzh.ifi.attempto.acewiki.core.MonolingualEngine;
022 import ch.uzh.ifi.attempto.acewiki.core.OntologyElement;
023 import ch.uzh.ifi.attempto.acewiki.core.Sentence;
024 import ch.uzh.ifi.attempto.acewiki.owl.AceWikiOWLReasoner;
025 import ch.uzh.ifi.attempto.acewiki.owl.OWLXMLExporter;
026
027 /**
028 * This is the AceWiki language engine for ACE/OWL. It delivers the grammar, the lexicon, the
029 * language factory, the reasoner, and more.
030 *
031 * @author Tobias Kuhn
032 */
033 public class ACEOWLEngine extends MonolingualEngine {
034
035 private ACEHandler languageHandler = new ACEHandler();
036 private AceWikiOWLReasoner reasoner = new AceWikiOWLReasoner();
037
038 /**
039 * Creates a new language engine for ACE/OWL.
040 */
041 public ACEOWLEngine() {
042 addExporter(new OWLXMLExporter(true));
043 addExporter(new OWLXMLExporter(false));
044 addExporter(new ACETextExporter(true));
045 addExporter(new ACETextExporter(false));
046 addExporter(new ACELexiconExporter());
047
048 setLexicalTypes("propername", "noun", "nounof", "trverb", "tradj");
049 }
050
051 public LanguageHandler getLanguageHandler() {
052 return languageHandler;
053 }
054
055 public AceWikiReasoner getReasoner() {
056 return reasoner;
057 }
058
059 public OntologyElement createOntologyElement(String type) {
060 if (type.equals("propername")) {
061 return new ProperNameIndividual();
062 } else if (type.equals("noun")) {
063 return new NounConcept();
064 } else if (type.equals("nounof")) {
065 return new OfRelation();
066 } else if (type.equals("trverb")) {
067 return new VerbRelation();
068 } else if (type.equals("tradj")) {
069 return new TrAdjRelation();
070 }
071 return null;
072 }
073
074 public Sentence createSentence(String serialized) {
075 // remove leading and trailing blank spaces.
076 String s = serialized.replaceFirst("^\\s+", "").replaceFirst("\\s+$", "");
077 if (s.substring(s.length()-1).equals("?")) {
078 return new ACEQuestion(s);
079 } else {
080 return new ACEDeclaration(s);
081 }
082 }
083
084 public Sentence createAssignmentSentence(Individual ind, Concept concept) {
085 return createSentence(ind.getWord(2) + " is a " + concept.getWord() + ".");
086 }
087
088 public Sentence createHierarchySentence(Concept subConcept, Concept superConcept) {
089 return createSentence("Every " + subConcept.getWord() + " is a " +
090 superConcept.getWord() + ".");
091 }
092
093 }