001 /* 002 * The contents of this file are subject to the Mozilla Public 003 * License Version 1.1 (the "License"); you may not use this file 004 * except in compliance with the License. You may obtain a copy of 005 * the License at http://www.mozilla.org/MPL/ 006 * 007 * Software distributed under the License is distributed on an "AS 008 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 009 * implied. See the License for the specific language governing 010 * rights and limitations under the License. 011 * 012 * The Original Code is Knowtator. 013 * 014 * The Initial Developer of the Original Code is University of Colorado. 015 * Copyright (C) 2005 - 2008. All Rights Reserved. 016 * 017 * Knowtator was developed by the Center for Computational Pharmacology 018 * (http://compbio.uchcs.edu) at the University of Colorado Health 019 * Sciences Center School of Medicine with support from the National 020 * Library of Medicine. 021 * 022 * Current information about Knowtator can be obtained at 023 * http://knowtator.sourceforge.net/ 024 * 025 * Contributor(s): 026 * Philip V. Ogren <philip@ogren.info> (Original Author) 027 */ 028 029 package edu.uchsc.ccp.knowtator.textsource; 030 031 import java.awt.Component; 032 import java.util.ArrayList; 033 034 import edu.stanford.smi.protege.model.Cls; 035 import edu.stanford.smi.protege.model.KnowledgeBase; 036 import edu.stanford.smi.protege.model.Project; 037 import edu.uchsc.ccp.knowtator.KnowtatorProjectUtil; 038 039 /** 040 * Authors: Philip V. Ogren Created: October, 2004 Description: 041 * 042 * Every extension of this class should have a corresponding extension of 043 * TextSource. Both extensions should be built together in parallel. 044 * 045 */ 046 047 public abstract class TextSourceCollection { 048 049 /** 050 * Corresponds to the Protege class name of the text sources that are 051 * retrieved by this collection. 052 */ 053 public static String CLS_NAME = KnowtatorProjectUtil.TEXT_SOURCE_CLS_NAME; 054 055 /** 056 * This is the name that is displayed when users are asked what type of text 057 * source collection they would like to access. 058 */ 059 public static String DISPLAY_NAME; 060 061 /** 062 * provides an easy way for a script to iterate through all TextSources in a 063 * collection. 064 */ 065 public abstract TextSourceIterator iterator(); 066 067 /** 068 * @return The name of the text source collection. Might correspond to the 069 * name of the directory, database or file that the text source 070 * collection accesses to get text sources. 071 */ 072 public abstract String getName(); 073 074 public abstract int size(); 075 076 public abstract TextSource get(int index) throws TextSourceAccessException; 077 078 /** 079 * @return the text source that has the given name. A text source collection 080 * should have no name collisions. 081 */ 082 public abstract TextSource get(String textSourceName) throws TextSourceAccessException; 083 084 /** 085 * @return -1 if text source does not exist. 086 */ 087 public abstract int getIndex(TextSource textSource); 088 089 /** 090 * @return a TextSource selected by a human user through a user interface. 091 * Implementations of this method might provide a dialog with a list 092 * of available text sources. 093 */ 094 public abstract TextSource select(Component parent); 095 096 /** 097 * @return a TextSource selected by a human user through a user interface. 098 * Implementations of this method might provide a dialog with a text 099 * field that requires the user to enter the name of a text source 100 * or some text that s/he is looking for. 101 */ 102 public abstract TextSource find(Component parent); 103 104 /** 105 * This method saves information about this text source collection to the 106 * Protege project. The information saved should be sufficient to 107 * reinstantiate this text source collection the next time Protege is 108 * started. 109 * 110 */ 111 public abstract void save(Project project); 112 113 /** 114 * This method should return the text source collection most recently opened 115 * by the provided project. This method is called when Knowtator is 116 * initiated. This method eliminates the need for the user to open the same 117 * text source collection every time s/he opens Knowtator. 118 * 119 * @return null if recent text source collection cannot be opened. 120 * 121 */ 122 123 public static TextSourceCollection open(Project project) { 124 return null; 125 } 126 127 /** 128 * @return a text source collection chosen by a human user through a user 129 * interface. Implementations of this method might provide a 130 * FileChooser, a dialog with database connection settings, etc. 131 */ 132 public static TextSourceCollection open(Project project, Component parent) { 133 return null; 134 } 135 136 /** 137 * This method ensures that the Protege cls definition corresponding to the 138 * text sources in this collection does exist. If not, it creates the 139 * appropriate cls. Implementors of this class should first check the kb to 140 * make sure that the class does not already exist. 141 * 142 */ 143 144 public static void createCls(KnowledgeBase kb) { 145 if (kb.getCls(CLS_NAME) == null) { 146 Cls textSourceParent = kb.getCls(KnowtatorProjectUtil.TEXT_SOURCE_CLS_NAME); 147 ArrayList parents = new ArrayList(); 148 parents.add(textSourceParent); 149 kb.createCls(CLS_NAME, parents); 150 } 151 return; 152 } 153 154 }