From: <ba...@us...> - 2009-10-28 19:54:31
|
Revision: 2891 http://obo.svn.sourceforge.net/obo/?rev=2891&view=rev Author: balhoff Date: 2009-10-28 19:54:19 +0000 (Wed, 28 Oct 2009) Log Message: ----------- Exposed configuration of autocomplete content via OBO-Edit term filters, loaded from files. Modified Paths: -------------- phenex/trunk/src/org/phenoscape/main/PhenexStartupTask.java phenex/trunk/src/org/phenoscape/model/OntologyController.java phenex/trunk/src/org/phenoscape/model/TermSet.java Added Paths: ----------- phenex/trunk/src/org/phenoscape/filters/ phenex/trunk/src/org/phenoscape/filters/entities.xml phenex/trunk/src/org/phenoscape/filters/museums.xml phenex/trunk/src/org/phenoscape/filters/qualities.xml phenex/trunk/src/org/phenoscape/filters/relations.xml phenex/trunk/src/org/phenoscape/filters/taxa.xml phenex/trunk/src/org/phenoscape/filters/units.xml Added: phenex/trunk/src/org/phenoscape/filters/entities.xml =================================================================== --- phenex/trunk/src/org/phenoscape/filters/entities.xml (rev 0) +++ phenex/trunk/src/org/phenoscape/filters/entities.xml 2009-10-28 19:54:19 UTC (rev 2891) @@ -0,0 +1,124 @@ +<?xml version="1.0" encoding="UTF-8"?> +<java version="1.6.0_15" class="java.beans.XMLDecoder"> + <object class="org.obo.filters.CompoundFilterImpl"> + <void property="filters"> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="criterion"> + <object class="org.obo.filters.IsClassCriterion"/> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="criterion"> + <object class="org.obo.filters.IsObsoleteCriterion"/> + </void> + <void property="negate"> + <boolean>true</boolean> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.CompoundFilterImpl"> + <void property="booleanOperation"> + <int>1</int> + </void> + <void property="filters"> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="comparison"> + <object id="EqualsComparison0" class="org.obo.filters.EqualsComparison"/> + </void> + <void property="criterion"> + <object id="NamespaceSearchCriterion0" class="org.obo.filters.NamespaceSearchCriterion"/> + </void> + <void property="value"> + <string>teleost_anatomy</string> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="comparison"> + <object idref="EqualsComparison0"/> + </void> + <void property="criterion"> + <object idref="NamespaceSearchCriterion0"/> + </void> + <void property="value"> + <string>spatial</string> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="comparison"> + <object idref="EqualsComparison0"/> + </void> + <void property="criterion"> + <object idref="NamespaceSearchCriterion0"/> + </void> + <void property="value"> + <string>quality</string> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="comparison"> + <object idref="EqualsComparison0"/> + </void> + <void property="criterion"> + <object idref="NamespaceSearchCriterion0"/> + </void> + <void property="value"> + <string>molecular_function</string> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="comparison"> + <object idref="EqualsComparison0"/> + </void> + <void property="criterion"> + <object idref="NamespaceSearchCriterion0"/> + </void> + <void property="value"> + <string>cellular_component</string> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="comparison"> + <object idref="EqualsComparison0"/> + </void> + <void property="criterion"> + <object idref="NamespaceSearchCriterion0"/> + </void> + <void property="value"> + <string>biological_process</string> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="comparison"> + <object idref="EqualsComparison0"/> + </void> + <void property="criterion"> + <object idref="NamespaceSearchCriterion0"/> + </void> + <void property="value"> + <string>gene_ontology</string> + </void> + </object> + </void> + </void> + </object> + </void> + </void> + </object> +</java> Added: phenex/trunk/src/org/phenoscape/filters/museums.xml =================================================================== --- phenex/trunk/src/org/phenoscape/filters/museums.xml (rev 0) +++ phenex/trunk/src/org/phenoscape/filters/museums.xml 2009-10-28 19:54:19 UTC (rev 2891) @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<java version="1.6.0_15" class="java.beans.XMLDecoder"> + <object class="org.obo.filters.CompoundFilterImpl"> + <void property="filters"> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="criterion"> + <object class="org.obo.filters.NamespaceSearchCriterion"/> + </void> + <void property="value"> + <string>museum</string> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="criterion"> + <object class="org.obo.filters.IsClassCriterion"/> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="criterion"> + <object class="org.obo.filters.IsObsoleteCriterion"/> + </void> + <void property="negate"> + <boolean>true</boolean> + </void> + </object> + </void> + </void> + </object> +</java> Added: phenex/trunk/src/org/phenoscape/filters/qualities.xml =================================================================== --- phenex/trunk/src/org/phenoscape/filters/qualities.xml (rev 0) +++ phenex/trunk/src/org/phenoscape/filters/qualities.xml 2009-10-28 19:54:19 UTC (rev 2891) @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<java version="1.6.0_15" class="java.beans.XMLDecoder"> + <object class="org.obo.filters.CompoundFilterImpl"> + <void property="filters"> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="criterion"> + <object class="org.obo.filters.IsClassCriterion"/> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="criterion"> + <object class="org.obo.filters.IsObsoleteCriterion"/> + </void> + <void property="negate"> + <boolean>true</boolean> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="comparison"> + <object class="org.obo.filters.EqualsComparison"/> + </void> + <void property="criterion"> + <object class="org.obo.filters.NamespaceSearchCriterion"/> + </void> + <void property="value"> + <string>quality</string> + </void> + </object> + </void> + </void> + </object> +</java> Added: phenex/trunk/src/org/phenoscape/filters/relations.xml =================================================================== --- phenex/trunk/src/org/phenoscape/filters/relations.xml (rev 0) +++ phenex/trunk/src/org/phenoscape/filters/relations.xml 2009-10-28 19:54:19 UTC (rev 2891) @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<java version="1.6.0_15" class="java.beans.XMLDecoder"> + <object class="org.obo.filters.CompoundFilterImpl"> + <void property="filters"> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="comparison"> + <object id="EqualsComparison0" class="org.obo.filters.EqualsComparison"/> + </void> + <void property="criterion"> + <object class="org.obo.filters.IsPropertyCriterion"/> + </void> + <void property="value"> + <string>quality</string> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="criterion"> + <object class="org.obo.filters.IsObsoleteCriterion"/> + </void> + <void property="negate"> + <boolean>true</boolean> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="comparison"> + <object idref="EqualsComparison0"/> + </void> + <void property="criterion"> + <object class="org.obo.filters.IDSearchCriterion"/> + </void> + <void property="negate"> + <boolean>true</boolean> + </void> + <void property="value"> + <string>part_of</string> + </void> + </object> + </void> + </void> + </object> +</java> Added: phenex/trunk/src/org/phenoscape/filters/taxa.xml =================================================================== --- phenex/trunk/src/org/phenoscape/filters/taxa.xml (rev 0) +++ phenex/trunk/src/org/phenoscape/filters/taxa.xml 2009-10-28 19:54:19 UTC (rev 2891) @@ -0,0 +1,84 @@ +<?xml version="1.0" encoding="UTF-8"?> +<java version="1.6.0_15" class="java.beans.XMLDecoder"> + <object class="org.obo.filters.CompoundFilterImpl"> + <void property="filters"> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="criterion"> + <object class="org.obo.filters.NamespaceSearchCriterion"/> + </void> + <void property="value"> + <string>teleost-taxonomy</string> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="criterion"> + <object class="org.obo.filters.IsClassCriterion"/> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="criterion"> + <object class="org.obo.filters.IsObsoleteCriterion"/> + </void> + <void property="negate"> + <boolean>true</boolean> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="aspect"> + <object class="org.obo.filters.ParentSearchAspect"/> + </void> + <void property="comparison"> + <object id="EqualsComparison0" class="org.obo.filters.EqualsComparison"/> + </void> + <void property="criterion"> + <object id="IDSearchCriterion0" class="org.obo.filters.IDSearchCriterion"/> + </void> + <void property="negate"> + <boolean>true</boolean> + </void> + <void property="traversalFilter"> + <object class="org.obo.filters.LinkFilterImpl"> + <void property="filter"> + <void property="comparison"> + <object class="org.obo.filters.EqualsComparison"/> + </void> + <void property="criterion"> + <object class="org.obo.filters.IDSearchCriterion"/> + </void> + <void property="value"> + <string>OBO_REL:is_a</string> + </void> + </void> + </object> + </void> + <void property="value"> + <string>TTO:taxonomic_rank</string> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="comparison"> + <object idref="EqualsComparison0"/> + </void> + <void property="criterion"> + <object idref="IDSearchCriterion0"/> + </void> + <void property="negate"> + <boolean>true</boolean> + </void> + <void property="value"> + <string>TTO:taxonomic_rank</string> + </void> + </object> + </void> + </void> + </object> +</java> Added: phenex/trunk/src/org/phenoscape/filters/units.xml =================================================================== --- phenex/trunk/src/org/phenoscape/filters/units.xml (rev 0) +++ phenex/trunk/src/org/phenoscape/filters/units.xml 2009-10-28 19:54:19 UTC (rev 2891) @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<java version="1.6.0_15" class="java.beans.XMLDecoder"> + <object class="org.obo.filters.CompoundFilterImpl"> + <void property="filters"> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="criterion"> + <object class="org.obo.filters.IsClassCriterion"/> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="criterion"> + <object class="org.obo.filters.IsObsoleteCriterion"/> + </void> + <void property="negate"> + <boolean>true</boolean> + </void> + </object> + </void> + <void method="add"> + <object class="org.obo.filters.ObjectFilterImpl"> + <void property="comparison"> + <object class="org.obo.filters.EqualsComparison"/> + </void> + <void property="criterion"> + <object class="org.obo.filters.NamespaceSearchCriterion"/> + </void> + <void property="value"> + <string>unit.ontology</string> + </void> + </object> + </void> + </void> + </object> +</java> Modified: phenex/trunk/src/org/phenoscape/main/PhenexStartupTask.java =================================================================== --- phenex/trunk/src/org/phenoscape/main/PhenexStartupTask.java 2009-10-28 18:14:19 UTC (rev 2890) +++ phenex/trunk/src/org/phenoscape/main/PhenexStartupTask.java 2009-10-28 19:54:19 UTC (rev 2891) @@ -52,188 +52,188 @@ * @author Jim Balhoff */ public class PhenexStartupTask extends DefaultGUIStartupTask { - - private PhenexController controller; - - @Override - protected Collection<GUIComponentFactory<?>> getDefaultComponentFactories() { - Collection<GUIComponentFactory<?>> factories = new ArrayList<GUIComponentFactory<?>>(); - factories.add(new DataSetComponentFactory(this.controller)); - factories.add(new CharacterTableComponentFactory(this.controller)); - factories.add(new StateTableComponentFactory(this.controller)); - factories.add(new PhenotypeTableComponentFactory(this.controller)); - factories.add(new TaxonTableComponentFactory(this.controller)); - factories.add(new SpecimenTableComponentFactory(this.controller)); - factories.add(new CharacterMatrixComponentFactory(this.controller)); - //factories.add(new OntologyPreferencesComponentFactory()); - factories.add(new SessionTermInfoFactory()); - factories.add(new PhenoteOntologyTreeEditorFactory()); - factories.add(new PhenoteGraphViewFactory()); - factories.add(new SearchComponentFactory() { - public FactoryCategory getCategory() { - return FactoryCategory.ONTOLOGY; - } - }); - factories.add(new SearchResultsComponentFactory()); - factories.add(new LogViewComponentFactory()); - return factories; - } - - @Override - protected void configureLogging() { - //TODO should the desired level be set in the configuration file? - final Logger rl = LogManager.getRootLogger(); - rl.setLevel(Level.DEBUG); - } - @Override - protected void configureUI() { - try { - final String lookAndFeelClassName = UIManager.getSystemLookAndFeelClassName(); - if (lookAndFeelClassName.equals("apple.laf.AquaLookAndFeel")) { - // We are running on Mac OS X - use the Quaqua look and feel - System.setProperty("apple.laf.useScreenMenuBar", "true"); - UIManager.setLookAndFeel("ch.randelshofer.quaqua.QuaquaLookAndFeel"); - } else { - // We are on some other platform, use the system look and feel - UIManager.setLookAndFeel(lookAndFeelClassName); - } - } catch (ClassNotFoundException e) { - log().error("Look and feel class not found", e); - } catch (InstantiationException e) { - log().error("Could not instantiate look and feel", e); - } catch (IllegalAccessException e) { - log().error("Error setting look and feel", e); - } catch (UnsupportedLookAndFeelException e) { - log().error("Look and feel not supported", e); + private PhenexController controller; + + @Override + protected Collection<GUIComponentFactory<?>> getDefaultComponentFactories() { + Collection<GUIComponentFactory<?>> factories = new ArrayList<GUIComponentFactory<?>>(); + factories.add(new DataSetComponentFactory(this.controller)); + factories.add(new CharacterTableComponentFactory(this.controller)); + factories.add(new StateTableComponentFactory(this.controller)); + factories.add(new PhenotypeTableComponentFactory(this.controller)); + factories.add(new TaxonTableComponentFactory(this.controller)); + factories.add(new SpecimenTableComponentFactory(this.controller)); + factories.add(new CharacterMatrixComponentFactory(this.controller)); + //factories.add(new OntologyPreferencesComponentFactory()); + factories.add(new SessionTermInfoFactory()); + factories.add(new PhenoteOntologyTreeEditorFactory()); + factories.add(new PhenoteGraphViewFactory()); + factories.add(new SearchComponentFactory() { + public FactoryCategory getCategory() { + return FactoryCategory.ONTOLOGY; + } + }); + factories.add(new SearchResultsComponentFactory()); + factories.add(new LogViewComponentFactory()); + return factories; } - } - - @Override - protected void configureSystem() { - super.configureSystem(); - final SwingWorker<OntologyController, Void> ontologyLoader = new SwingWorker<OntologyController, Void>() { - @Override - protected OntologyController doInBackground() { - return new OntologyController(); + + @Override + protected void configureLogging() { + //TODO should the desired level be set in the configuration file? + final Logger rl = LogManager.getRootLogger(); + rl.setLevel(Level.DEBUG); + } + + @Override + protected void configureUI() { + try { + final String lookAndFeelClassName = UIManager.getSystemLookAndFeelClassName(); + if (lookAndFeelClassName.equals("apple.laf.AquaLookAndFeel")) { + // We are running on Mac OS X - use the Quaqua look and feel + System.setProperty("apple.laf.useScreenMenuBar", "true"); + UIManager.setLookAndFeel("ch.randelshofer.quaqua.QuaquaLookAndFeel"); + } else { + // We are on some other platform, use the system look and feel + UIManager.setLookAndFeel(lookAndFeelClassName); + } + } catch (ClassNotFoundException e) { + log().error("Look and feel class not found", e); + } catch (InstantiationException e) { + log().error("Could not instantiate look and feel", e); + } catch (IllegalAccessException e) { + log().error("Error setting look and feel", e); + } catch (UnsupportedLookAndFeelException e) { + log().error("Look and feel not supported", e); } - }; - // you would expect that displaying the progress dialog would make the splash screen go away, but it doesn't - this.flashJFrameToMakeSplashScreenGoAway(); - final BlockingProgressDialog<OntologyController, Void> dialog = new BlockingProgressDialog<OntologyController, Void>(ontologyLoader, "Phenex is checking for ontology updates. It may take some time to download and configure ontologies."); - dialog.setTitle("Launching " + this.getAppName()); - dialog.setSize(400, 150); - dialog.setLocationRelativeTo(null); - dialog.run(); - try { - this.controller = new PhenexController(ontologyLoader.get()); - } catch (InterruptedException e) { - log().fatal("Failed to create ontology controller", e); - GUIManager.exit(1); - } catch (ExecutionException e) { - log().fatal("Failed to create ontology controller", e); - GUIManager.exit(1); } - this.controller.setAppName(this.getAppName()); - } - - @Override - protected String getAppID() { - return "Phenex"; - } - - @Override - protected String getAppName() { - return "Phenex"; - } - - @Override - protected Action getAboutAction() { - //TODO make an about panel - return new AbstractAction() { - public void actionPerformed(ActionEvent e) { - } - }; - } - @Override - protected JFrame createFrame() { - final JFrame frame = super.createFrame(); - frame.setTitle(getAppName()); - // the window prefs saver is not currently working because the BBOP MainFrame is trying to be too smart - new WindowSizePrefsSaver(frame, this.getClass().getName() + "mainwindow"); - return frame; - } - - @Override - protected void showFrame() { - // BBOP centers and makes frame a certain size - we are overriding this - GUIManager.getManager().getFrame().setVisible(true); - } + @Override + protected void configureSystem() { + super.configureSystem(); + final SwingWorker<OntologyController, Void> ontologyLoader = new SwingWorker<OntologyController, Void>() { + @Override + protected OntologyController doInBackground() { + return new OntologyController(); + } + }; + // you would expect that displaying the progress dialog would make the splash screen go away, but it doesn't + this.flashJFrameToMakeSplashScreenGoAway(); + final BlockingProgressDialog<OntologyController, Void> dialog = new BlockingProgressDialog<OntologyController, Void>(ontologyLoader, "Phenex is checking for ontology updates. It may take some time to download and configure ontologies."); + dialog.setTitle("Launching " + this.getAppName()); + dialog.setSize(400, 150); + dialog.setLocationRelativeTo(null); + dialog.run(); + try { + this.controller = new PhenexController(ontologyLoader.get()); + } catch (InterruptedException e) { + log().fatal("Failed to create ontology controller", e); + GUIManager.exit(1); + } catch (ExecutionException e) { + log().fatal("Failed to create ontology controller", e); + GUIManager.exit(1); + } + this.controller.setAppName(this.getAppName()); + } - @Override - protected LayoutDriver createLayoutDriver() { - final LayoutDriver driver = super.createLayoutDriver(); - if (driver instanceof IDWDriver) { - ((IDWDriver)driver).setCustomTheme(new PhenoteDockingTheme()); + @Override + protected String getAppID() { + return "Phenex"; } - driver.setSaveLayoutOnExit(false); - return driver; - } - - @Override - protected String getPerspectiveResourceDir() { - return "org/phenoscape/view/layouts"; - } - @Override - protected String getDefaultPerspectiveResourcePath() { - if (getPerspectiveResourceDir() != null) - return getPerspectiveResourceDir() + "/default.idw"; - else - return null; - } + @Override + protected String getAppName() { + return "Phenex"; + } - @Override - public File getPrefsDir() { - return CrossPlatform.getUserPreferencesFolder(this.getAppID()); - } - - @Override - protected void installSystemListeners() { - GUIManager.addVetoableShutdownListener(new VetoableShutdownListener() { - public boolean willShutdown() { - return controller.canCloseDocument(); + @Override + protected Action getAboutAction() { + //TODO make an about panel + return new AbstractAction() { + public void actionPerformed(ActionEvent e) { + } + }; + } + + @Override + protected JFrame createFrame() { + final JFrame frame = super.createFrame(); + frame.setTitle(getAppName()); + // the window prefs saver is not currently working because the BBOP MainFrame is trying to be too smart + new WindowSizePrefsSaver(frame, this.getClass().getName() + "mainwindow"); + return frame; + } + + @Override + protected void showFrame() { + // BBOP centers and makes frame a certain size - we are overriding this + GUIManager.getManager().getFrame().setVisible(true); + } + + @Override + protected LayoutDriver createLayoutDriver() { + final LayoutDriver driver = super.createLayoutDriver(); + if (driver instanceof IDWDriver) { + ((IDWDriver)driver).setCustomTheme(new PhenoteDockingTheme()); } - }); - } - - @Override - protected void doOtherInstallations() { - super.doOtherInstallations(); - new SelectionBridge().install(); - } + driver.setSaveLayoutOnExit(false); + return driver; + } - @Override - protected Collection<? extends JMenuItem> getDefaultMenus() { - return (new MenuFactory(this.controller)).createMenus(); - } - - @Override - protected Collection<GUITask> getDefaultTasks() { - // OBO-Edit startup task adds some things we don't want - // hopefully none of these tasks are needed for operations in Phenex - return new ArrayList<GUITask>(); - } - - private void flashJFrameToMakeSplashScreenGoAway() { - final JFrame frame = new JFrame(); - frame.setVisible(true); - frame.setVisible(false); - } + @Override + protected String getPerspectiveResourceDir() { + return "org/phenoscape/view/layouts"; + } - private Logger log() { - return Logger.getLogger(this.getClass()); - } - + @Override + protected String getDefaultPerspectiveResourcePath() { + if (getPerspectiveResourceDir() != null) + return getPerspectiveResourceDir() + "/default.idw"; + else + return null; + } + + @Override + public File getPrefsDir() { + return CrossPlatform.getUserPreferencesFolder(this.getAppID()); + } + + @Override + protected void installSystemListeners() { + GUIManager.addVetoableShutdownListener(new VetoableShutdownListener() { + public boolean willShutdown() { + return controller.canCloseDocument(); + } + }); + } + + @Override + protected void doOtherInstallations() { + super.doOtherInstallations(); + new SelectionBridge().install(); + } + + @Override + protected Collection<? extends JMenuItem> getDefaultMenus() { + return (new MenuFactory(this.controller)).createMenus(); + } + + @Override + protected Collection<GUITask> getDefaultTasks() { + // OBO-Edit startup task adds some things we don't want + // hopefully none of these tasks are needed for operations in Phenex + return new ArrayList<GUITask>(); + } + + private void flashJFrameToMakeSplashScreenGoAway() { + final JFrame frame = new JFrame(); + frame.setVisible(true); + frame.setVisible(false); + } + + private Logger log() { + return Logger.getLogger(this.getClass()); + } + } Modified: phenex/trunk/src/org/phenoscape/model/OntologyController.java =================================================================== --- phenex/trunk/src/org/phenoscape/model/OntologyController.java 2009-10-28 18:14:19 UTC (rev 2890) +++ phenex/trunk/src/org/phenoscape/model/OntologyController.java 2009-10-28 19:54:19 UTC (rev 2891) @@ -1,22 +1,25 @@ package org.phenoscape.model; +import java.beans.XMLDecoder; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import org.apache.log4j.Logger; import org.bbop.dataadapter.DataAdapterException; import org.bbop.framework.GUIManager; import org.obo.dataadapter.OBOAdapter; import org.obo.dataadapter.OBOFileAdapter; -import org.obo.dataadapter.OBOMetaData; -import org.obo.datamodel.Namespace; +import org.obo.datamodel.IdentifiedObject; import org.obo.datamodel.OBOSession; +import org.obo.filters.Filter; import org.oboedit.controller.SessionManager; +import org.phenoscape.app.CrossPlatform; import org.phenoscape.io.URLProxy; /** @@ -25,9 +28,6 @@ */ public class OntologyController { - private final OBOFileAdapter fileAdapter; - private final OBOMetaData metadata; - private String TTO = ""; private String COLLECTION = ""; private String TAO = ""; @@ -38,6 +38,13 @@ private String REL_PROPOSED = ""; private String GO = ""; private String CHARACTER_SLIM = ""; + private static final String ENTITY_FILTER = "entities"; + private static final String QUALITY_FILTER = "qualities"; + private static final String RELATION_FILTER = "relations"; + private static final String UNIT_FILTER = "units"; + private static final String TAXON_FILTER = "taxa"; + private static final String MUSEUM_FILTER = "museums"; + private File overridingFiltersFolder = new File(CrossPlatform.getUserPreferencesFolder("Phenex"), "Filters"); //FIXME should set this from outside this class private TermSet entityTermSet = null; private TermSet qualityTermSet = null; @@ -47,18 +54,17 @@ private TermSet relationsTermSet = null; public OntologyController() { - this.fileAdapter = new OBOFileAdapter(); + final OBOFileAdapter fileAdapter = new OBOFileAdapter(); OBOFileAdapter.OBOAdapterConfiguration config = new OBOFileAdapter.OBOAdapterConfiguration(); config.setReadPaths(Arrays.asList(this.getPaths())); config.setBasicSave(false); config.setAllowDangling(true); config.setFollowImports(false); // this is required because OBO currently fails if it tries to follow an import and there is no network connection try { - SessionManager.getManager().setSession(this.fileAdapter.doOperation(OBOAdapter.READ_ONTOLOGY, config, null)); + SessionManager.getManager().setSession(fileAdapter.doOperation(OBOAdapter.READ_ONTOLOGY, config, null)); } catch (DataAdapterException e) { log().fatal("Failed to load ontologies", e); } - this.metadata = this.fileAdapter.getMetaData(); this.prefetchTermSets(); } @@ -79,8 +85,8 @@ String[] paths = { TTO, COLLECTION, TAO, PATO, SPATIAL, UNIT, REL, REL_PROPOSED, GO, CHARACTER_SLIM }; return paths; } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + //TODO alert user somehow + log().fatal("Unable to read one or more ontologies", e); } catch (IOException e) { //TODO alert user somehow log().fatal("Unable to read one or more ontologies", e); @@ -94,32 +100,39 @@ public TermSet getTaxonTermSet() { if (this.taxonTermSet == null) { - this.taxonTermSet = this.getTermSet(TTO); + final TermSet terms = new TermSet(); + terms.setOBOSession(this.getOBOSession()); + terms.setTermFilter(this.loadFilterWithName(TAXON_FILTER)); + this.taxonTermSet = terms; } return this.taxonTermSet; } public TermSet getCollectionTermSet() { if (this.collectionTermSet == null) { - this.collectionTermSet = this.getTermSet(COLLECTION); + final TermSet terms = new TermSet(); + terms.setOBOSession(this.getOBOSession()); + terms.setTermFilter(this.loadFilterWithName(MUSEUM_FILTER)); + this.collectionTermSet = terms; } return this.collectionTermSet; } public TermSet getEntityTermSet() { if (this.entityTermSet == null) { - final TermSet terms = this.getTermSet(TAO, SPATIAL, PATO, GO); - //terms.setTermFilter(new AnatomyTermFilter(this.getOBOSession())); + final TermSet terms = new TermSet(); + terms.setOBOSession(this.getOBOSession()); + terms.setTermFilter(this.loadFilterWithName(ENTITY_FILTER)); this.entityTermSet = terms; } - return this.entityTermSet; } public TermSet getQualityTermSet() { if (this.qualityTermSet == null) { - final TermSet terms = this.getTermSet(PATO); - //terms.setTermFilter(new AnatomyTermFilter(this.getOBOSession())); + final TermSet terms = new TermSet(); + terms.setOBOSession(this.getOBOSession()); + terms.setTermFilter(this.loadFilterWithName(QUALITY_FILTER)); this.qualityTermSet = terms; } return this.qualityTermSet; @@ -131,32 +144,32 @@ public TermSet getUnitTermSet() { if (this.unitTermSet == null) { - this.unitTermSet = this.getTermSet(UNIT); + final TermSet terms = new TermSet(); + terms.setOBOSession(this.getOBOSession()); + terms.setTermFilter(this.loadFilterWithName(UNIT_FILTER)); + this.unitTermSet = terms; } return this.unitTermSet; } public TermSet getRelationsTermSet() { - if (this.relationsTermSet == null) { - final TermSet set = this.getTermSet(); - set.setTermFilter(new RelationTermFilter(this.getOBOSession())); - set.setIncludesProperties(true); + if (this.relationsTermSet == null) {; + final TermSet set = new TermSet(); + set.setOBOSession(this.getOBOSession()); + set.setTermFilter(this.loadFilterWithName(RELATION_FILTER)); this.relationsTermSet = set; } return this.relationsTermSet; } - private TermSet getTermSet(String... urls) { - final Collection<Namespace> namespaces = new ArrayList<Namespace>(); - for (String url : urls) { - namespaces.addAll(this.metadata.getNamespaces(url)); - } - final TermSet terms = new TermSet(); - terms.setOBOSession(this.getOBOSession()); - terms.setNamespaces(namespaces); - return terms; + public File getOverridingFiltersFolder() { + return this.overridingFiltersFolder; } + public void setOverridingFiltersFolder(File folder) { + this.overridingFiltersFolder = folder; + } + /** * This is just a startup "optimization" - it makes the term searches * happen while the ontology loading panel is displayed. This reduces @@ -169,7 +182,40 @@ this.getCollectionTermSet().getTerms(); this.getUnitTermSet().getTerms(); this.getRelationsTermSet().getTerms(); + this.getQualityTermSet().getTerms(); + this.getRelatedEntityTermSet().getTerms(); } + + private Filter<IdentifiedObject> loadFilterWithName(String filterName) { + final String filename = filterName + ".xml"; + final File filterFile = new File(this.getOverridingFiltersFolder(), filename); + if (filterFile.exists()) { + return this.loadFilter(filterFile); + } else { + return this.loadFilterFromResource("/org/phenoscape/filters/" + filename); + } + } + + private Filter<IdentifiedObject> loadFilterFromResource(String resourcePath) { + return this.loadFilter(this.getClass().getResourceAsStream(resourcePath)); + } + + private Filter<IdentifiedObject> loadFilter(File xmlFile) { + try { + return this.loadFilter(new FileInputStream(xmlFile)); + } catch (FileNotFoundException e) { + log().error("Could not find specified filter file", e); + } + return null; + } + + @SuppressWarnings("unchecked") + private Filter<IdentifiedObject> loadFilter(InputStream stream) { + final XMLDecoder d = new XMLDecoder(stream); + final Filter<IdentifiedObject> result = (Filter<IdentifiedObject>) d.readObject(); + d.close(); + return result; + } private Logger log() { return Logger.getLogger(this.getClass()); Modified: phenex/trunk/src/org/phenoscape/model/TermSet.java =================================================================== --- phenex/trunk/src/org/phenoscape/model/TermSet.java 2009-10-28 18:14:19 UTC (rev 2890) +++ phenex/trunk/src/org/phenoscape/model/TermSet.java 2009-10-28 19:54:19 UTC (rev 2891) @@ -4,12 +4,15 @@ import java.util.Collection; import java.util.List; -import org.obo.datamodel.Namespace; +import org.apache.log4j.Logger; +import org.obo.datamodel.IdentifiedObject; import org.obo.datamodel.OBOObject; import org.obo.datamodel.OBOSession; +import org.obo.filters.Filter; import org.obo.query.QueryEngine; -import org.obo.query.impl.CategoryObjQuery; -import org.obo.query.impl.NamespaceObjQuery; +import org.obo.query.impl.FilterQuery; +import org.obo.query.impl.SearchHit; +import org.oboedit.controller.SessionManager; /** * A TermSet is used to define a collection of ontology terms. Currently the collection @@ -18,109 +21,58 @@ */ public class TermSet { - private OBOSession session; - private Collection<Namespace> namespaces = new ArrayList<Namespace>(); - private Collection<String> categories = new ArrayList<String>(); - private Collection<OBOObject> cachedTerms = null; - private boolean includesProperties = false; - private TermFilter filter = null; + private OBOSession session; + private Collection<OBOObject> cachedTerms = null; + private Filter<IdentifiedObject> filter = null; - /** - * @return The OBOSession from which this TermSet draws its terms. - */ - public OBOSession getOBOSession() { - return this.session; - } - - /** - * @param oboSession The OBOSession from which this TermSet should draw its terms. - */ - public void setOBOSession(OBOSession oboSession) { - this.session = oboSession; - this.invalidateTerms(); - } - - /** - * @return The terms returned by this TermSet are a union of all terms in the given Namespaces. - */ - public Collection<Namespace> getNamespaces() { - return this.namespaces; - } + /** + * @return The OBOSession from which this TermSet draws its terms. + */ + public OBOSession getOBOSession() { + return this.session; + } - /** - * @param namespaces The Namespaces from which this TermSet should draw its terms. - */ - public void setNamespaces(Collection<Namespace> namespaces) { - this.namespaces = namespaces; - this.invalidateTerms(); - } - - /** - * @return The terms returned by this TermSet are a union of all terms in the given categories. - */ - public Collection<String> getCategories() { - return this.categories; - } - - /** - * @param categories The categories from which this TermSet should draw its terms. - */ - public void setCategories(Collection<String> categories) { - this.categories = categories; - this.invalidateTerms(); - } + /** + * @param oboSession The OBOSession from which this TermSet should draw its terms. + */ + public void setOBOSession(OBOSession oboSession) { + this.session = oboSession; + this.invalidateTerms(); + } - public boolean includesProperties() { - return this.includesProperties; - } + public Filter<IdentifiedObject> getTermFilter() { + return this.filter; + } - public void setIncludesProperties(boolean includeProperties) { - this.includesProperties = includeProperties; - this.invalidateTerms(); - } - - public TermFilter getTermFilter() { - return this.filter; - } - - public void setTermFilter(TermFilter filter) { - this.filter = filter; - } - - /** - * @return All terms matching the search criteria of this TermSet, such as its namespaces and categories. - */ - public Collection<OBOObject> getTerms() { - if (this.cachedTerms != null) { - return this.cachedTerms; + public void setTermFilter(Filter<IdentifiedObject> filter) { + this.filter = filter; } - final QueryEngine engine = new QueryEngine(this.getOBOSession()); - final List<String> namespaceIDs = new ArrayList<String>(); - for (Namespace ns : this.getNamespaces()) { namespaceIDs.add(ns.getID()); } - final NamespaceObjQuery query = new NamespaceObjQuery(namespaceIDs, false, true); - query.setJustTerms(!this.includesProperties()); - final Collection<OBOObject> termsInNamespaces = engine.query(query); - if (this.hasAnyCategory()) { - this.cachedTerms = engine.subquery(termsInNamespaces, new CategoryObjQuery(this.getCategories())).getResults(); - } else { - this.cachedTerms = termsInNamespaces; + + /** + * @return All terms matching the search criteria of this TermSet, such as its namespaces and categories. + */ + public Collection<OBOObject> getTerms() { + if (this.cachedTerms != null) { + return this.cachedTerms; + } + final QueryEngine engine = new QueryEngine(this.getOBOSession()); + final FilterQuery<IdentifiedObject> query = new FilterQuery<IdentifiedObject>(this.getTermFilter(), IdentifiedObject.class, SessionManager.getManager().getReasoner()); + final Collection<SearchHit<IdentifiedObject>> termHits = engine.query(query); + final List<OBOObject> terms = new ArrayList<OBOObject>(); + for (SearchHit<IdentifiedObject> hit : termHits) { + terms.add((OBOObject)hit.getHit()); //TODO fix need for this cast + } + this.cachedTerms = terms; + return this.cachedTerms; } - if (this.filter != null) { - final List<OBOObject> keeps = new ArrayList<OBOObject>(); - for (OBOObject term : this.cachedTerms) { - if (this.filter.include(term)) { keeps.add(term); } - } - this.cachedTerms = keeps; + + private void invalidateTerms() { + this.cachedTerms = null; } - return this.cachedTerms; - } - - private boolean hasAnyCategory() { - return !this.getCategories().isEmpty(); - } - - private void invalidateTerms() { - this.cachedTerms = null; - } - + + @SuppressWarnings("unused") + private Logger log() { + return Logger.getLogger(this.getClass()); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |