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.util.ArrayList; 018 import java.util.Collection; 019 import java.util.List; 020 021 import ch.uzh.ifi.attempto.acewiki.owl.OWLRelation; 022 import ch.uzh.ifi.attempto.ape.LexiconEntry; 023 import ch.uzh.ifi.attempto.chartparser.LexicalRule; 024 025 /** 026 * This class stands for relations that are represented by transitive verbs in ACE and object 027 * properties in OWL. Transitive verbs have three word forms: a third singular form, a bare 028 * infinitive form, and a passive form. The bare infinitive form is used in the case of negation 029 * and plural. The passive form always ends with the word "by". 030 *<p> 031 * 0: third singular form. 032 * 1: bare infinitive form. 033 * 2: passive form. 034 *<p> 035 * Examples: ["gives", "give", "given by"]; ["knows", "know", "known by"]. 036 * 037 * @author Tobias Kuhn 038 */ 039 public class VerbRelation extends OWLRelation implements ACEOWLOntoElement { 040 041 private String thirdSg, inf, passive; 042 043 /** 044 * Creates a new verb relation. 045 */ 046 public VerbRelation() { 047 } 048 049 public String[] getWords() { 050 return new String[] {thirdSg, inf, passive}; 051 } 052 053 public void setWords(String serializedWords) { 054 String[] words = serializedWords.split(";"); 055 thirdSg = words[0]; 056 inf = words[1]; 057 if (words.length < 3 || words[2] == null) { 058 passive = null; 059 } else if (words[2].endsWith(" by")) { 060 passive = words[2]; 061 } else { 062 passive = words[2] + " by"; 063 } 064 if (passive != null && passive.length() == 0) { 065 passive = null; 066 } 067 } 068 069 public String serializeWords() { 070 return thirdSg + ";" + inf + ";" + (passive == null ? "" : passive) + ";"; 071 } 072 073 /** 074 * Returns the past participle which is the passive form without the "by". 075 * E.g. for the passive form "given by", the past participle is "given". 076 * 077 * @return The past participle form. 078 */ 079 public String getPastPart() { 080 String s = getWord(2); 081 if (s == null) { 082 return null; 083 } else if (s.endsWith(" by")) { 084 return s.substring(0, s.length()-3); 085 } else { 086 throw new RuntimeException("Illegal passive word form: " + s); 087 } 088 } 089 090 public String getIRISuffix() { 091 return getWord(1); 092 } 093 094 public List<LexiconEntry> getLexiconEntries() { 095 List<LexiconEntry> entries = new ArrayList<LexiconEntry>(); 096 entries.add(LexiconEntry.createTrVerbThirdEntry(thirdSg, inf)); 097 entries.add(LexiconEntry.createTrVerbInfEntry(inf, inf)); 098 if (passive != null) { 099 entries.add(LexiconEntry.createTrVerbPPEntry(getPastPart(), inf)); 100 } 101 return entries; 102 } 103 104 public String getType() { 105 return "Verb"; 106 } 107 108 public String getInternalType() { 109 return "trverb"; 110 } 111 112 public void collectLexicalRules(String catName, Collection<LexicalRule> lexRules) { 113 if (catName == null || catName.equals("verbsg")) { 114 lexRules.add(new LexicalRule("verbsg", getWord(0))); 115 } 116 if (catName == null || catName.equals("verbinf")) { 117 lexRules.add(new LexicalRule("verbinf", getWord(1))); 118 } 119 if (catName == null || catName.equals("pverb")) { 120 if (getWord(2) != null) { 121 lexRules.add(new LexicalRule("pverb", getWord(2))); 122 } 123 } 124 } 125 126 }