From: <mg...@us...> - 2006-10-13 19:09:00
|
Revision: 158 http://svn.sourceforge.net/obo/?rev=158&view=rev Author: mgibson Date: 2006-10-13 12:08:49 -0700 (Fri, 13 Oct 2006) Log Message: ----------- now comp list sorts by exat term startsWith term contains term exact/startswith syn contains syn definitions obsoletes CompletionTerm now holds state of how it matched - startsWith, syn, defintion - which makes sorting this easier Modified Paths: -------------- phenote/trunk/src/java/phenote/datamodel/Ontology.java phenote/trunk/src/java/phenote/gui/field/CompListSearcher.java phenote/trunk/src/java/phenote/gui/field/CompletionTerm.java phenote/trunk/src/java/phenote/servlet/PhenoteServlet.java Modified: phenote/trunk/src/java/phenote/datamodel/Ontology.java =================================================================== --- phenote/trunk/src/java/phenote/datamodel/Ontology.java 2006-10-12 18:33:48 UTC (rev 157) +++ phenote/trunk/src/java/phenote/datamodel/Ontology.java 2006-10-13 19:08:49 UTC (rev 158) @@ -79,6 +79,96 @@ return true; // no exception - it has it } + + public List<OBOProperty> getSortedRelations() { + if (sortedRelations == null) { + //sortedRelations=new ArrayList<OBOProperty>(); not Comparable! + List sorRel = new ArrayList(); + // if (oboSession == null) ? shouldnt happen + sorRel.addAll(oboSession.getRelationshipTypes()); + Collections.sort(sorRel,new RelComparator()); + sortedRelations = sorRel; // ? + } + return sortedRelations; + } + + private class RelComparator<OBOProperty> implements Comparator<OBOProperty> { + public int compare(OBOProperty r1, OBOProperty r2) { + return r1.toString().compareTo(r2.toString()); + } + public boolean equals(OBOProperty r1, OBOProperty r2) { + return r1.toString().equals(r2.toString()); + } + } + + + /** non obsolete terms - sorted */ + public List<OBOClass> getSortedTerms() { + return sortedTerms; + } + + public List<OBOClass> getSortedObsoleteTerms() { + return sortedObsoleteTerms; + } + + + private OBOSession getOboSession() { return oboSession; } + + public List<OBOClass> getSortedTerms(Set terms) { + List<OBOClass> sortedTerms = new ArrayList<OBOClass>(); + sortedTerms.addAll(terms); + Collections.sort(sortedTerms); + return sortedTerms; + } + + /** moght move this elsewhere - subclass? data adap specific wrapper? */ + public void setTimestamp(long t) { ontologyTimestamp = t; } + public long getTimestamp() { return ontologyTimestamp; } + /** for obo files this is the filename */ + public void setSource(String s) { source = s; } + public String getSource() { return source; } + + + + + public void setFilter(String filterOutString) { + this.filterOutString = filterOutString; + } + + private boolean haveFilter() { + //return filterOutString != null; + // minimally filter out obo: obo edit internal terms + return true; + } + + /** This is not generic - this looks for ids that have the filterOut string + as a prefix and tosses them - for example "ZFS" filters out all zf stage + terms - can add more flexibility as needed - this is all thats needed for now*/ + private List<OBOClass> filterList(List<OBOClass> list, String filterOut) { + List<OBOClass> filteredList = new ArrayList<OBOClass>(); + for (OBOClass term : list) { + // or could do remove on list? + // also filter out obo: terms as they are internal obo edit thingies it seems + // funny logic but more efficient to do in one pass - refactor somehow? + if (term.getName().startsWith("obo:")) + continue; // filter our obo: + if (filterOut != null && term.getID().startsWith(filterOut)) + continue; + filteredList.add(term); // passed 2 filters above - add it + } + return filteredList; + } + + private Logger log; + private Logger log() { + if (log == null) log = Logger.getLogger(getClass()); + return log; + } +} + + + +// GARBAGE // /** Returns a Vector of OBOClass from ontology that contain input string // constrained by compParams. compParams specifies syns,terms,defs,& obs // should input be just part of search params? @@ -167,87 +257,6 @@ // } // return matches; // } - - public List<OBOProperty> getSortedRelations() { - if (sortedRelations == null) { - //sortedRelations=new ArrayList<OBOProperty>(); not Comparable! - List sorRel = new ArrayList(); - // if (oboSession == null) ? shouldnt happen - sorRel.addAll(oboSession.getRelationshipTypes()); - Collections.sort(sorRel,new RelComparator()); - sortedRelations = sorRel; // ? - } - return sortedRelations; - } - - private class RelComparator<OBOProperty> implements Comparator<OBOProperty> { - public int compare(OBOProperty r1, OBOProperty r2) { - return r1.toString().compareTo(r2.toString()); - } - public boolean equals(OBOProperty r1, OBOProperty r2) { - return r1.toString().equals(r2.toString()); - } - } - - - /** non obsolete terms - sorted */ - public List<OBOClass> getSortedTerms() { - return sortedTerms; - } - - public List<OBOClass> getSortedObsoleteTerms() { - return sortedObsoleteTerms; - } - - - private OBOSession getOboSession() { return oboSession; } - - public List<OBOClass> getSortedTerms(Set terms) { - List<OBOClass> sortedTerms = new ArrayList<OBOClass>(); - sortedTerms.addAll(terms); - Collections.sort(sortedTerms); - return sortedTerms; - } - - /** moght move this elsewhere - subclass? data adap specific wrapper? */ - public void setTimestamp(long t) { ontologyTimestamp = t; } - public long getTimestamp() { return ontologyTimestamp; } - /** for obo files this is the filename */ - public void setSource(String s) { source = s; } - public String getSource() { return source; } - - - - - public void setFilter(String filterOutString) { - this.filterOutString = filterOutString; - } - - private boolean haveFilter() { return filterOutString != null; } - - /** This is not generic - this looks for ids that have the filterOut string - as a prefix and tosses them - for example "ZFS" filters out all zf stage - terms - can add more flexibility as needed - this is all thats needed for now*/ - private List<OBOClass> filterList(List<OBOClass> list, String filterOut) { - List<OBOClass> filteredList = new ArrayList<OBOClass>(); - for (OBOClass term : list) { - // or could do remove on list? - if (!term.getID().startsWith(filterOut)) - filteredList.add(term); - } - return filteredList; - } - - private Logger log; - private Logger log() { - if (log == null) log = Logger.getLogger(getClass()); - return log; - } -} - - - -// GARBAGE // /** User input is already lower cased, this potentially adds oboClass to // * searchTerms if input & compareTerm match. Puts it first if exact. // * for term names comp = obo, for syns comp is the syn. Modified: phenote/trunk/src/java/phenote/gui/field/CompListSearcher.java =================================================================== --- phenote/trunk/src/java/phenote/gui/field/CompListSearcher.java 2006-10-12 18:33:48 UTC (rev 157) +++ phenote/trunk/src/java/phenote/gui/field/CompListSearcher.java 2006-10-13 19:08:49 UTC (rev 158) @@ -1,6 +1,7 @@ package phenote.gui.field; // complist package? field package? +import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Set; @@ -68,51 +69,44 @@ private Vector<CompletionTerm> getSearchTerms(String input, List<OBOClass> ontologyTermList) { SearchTermList searchTermList = new SearchTermList(); - //Vector searchTerms = new Vector(); if (ontologyTermList == null) - return searchTermList.getVector();//searchTerms; + return searchTermList.getVector(); - boolean ignoreCase = true; // param? - if (ignoreCase) - input = input.toLowerCase(); + //boolean ignoreCase = true; // param? //if (ignoreCase) + //input = input.toLowerCase(); // done in CompletionTerm // i think iterators are more efficient than get(i) ?? Iterator<OBOClass> iter = ontologyTermList.iterator(); while (iter.hasNext()) { - // toString extracts name from OBOClass + OBOClass oboClass = iter.next(); - String originalTerm = oboClass.getName();//toString(); - - boolean termAdded = false; - if (searchParams.searchTerms()) { - // adds originalTerm to searchTerms if match (1st if exact) - termAdded = compareAndAddTerm(input,originalTerm,oboClass,searchTermList); - if (termAdded) - continue; + CompletionTerm ct = new CompletionTerm(oboClass); + if (ct.matches(input,searchParams)) { + searchTermList.addTerm(ct); } - - if (searchParams.searchSynonyms()) { - Set synonyms = oboClass.getSynonyms(); - for (Iterator i = synonyms.iterator(); i.hasNext() &&!termAdded; ) { - String syn = i.next().toString(); - //log().debug("syn "+syn+" for "+originalTerm); - termAdded = compareAndAddTerm(input,syn,oboClass,searchTermList); - //if (termAdded) continue; // woops continues this for not the outer! - } - } - if (termAdded) continue; - - - if (searchParams.searchDefinitions()) { - String definition = oboClass.getDefinition(); - if (definition != null & !definition.equals("")) - termAdded = compareAndAddTerm(input,definition,oboClass,searchTermList); - if (termAdded) - continue; // not really necesary as its last - } - +// String originalTerm = oboClass.getName();//toString(); +// boolean termAdded = false; +// if (searchParams.searchTerms()) { +// // adds originalTerm to searchTerms if match (1st if exact) +// termAdded = compareAndAddTerm(input,originalTerm,oboClass,searchTermList); +// if (termAdded) continue;} +// if (searchParams.searchSynonyms()) { +// Set synonyms = oboClass.getSynonyms(); +// for (Iterator i = synonyms.iterator(); i.hasNext() &&!termAdded; ) { +// String syn = i.next().toString(); +// //log().debug("syn "+syn+" for "+originalTerm); +// termAdded = compareAndAddTerm(input,syn,oboClass,searchTermList); +// //if (termAdded) continue; // woops continues this for not the outer! +// } +// } +// if (termAdded) continue; +// if (searchParams.searchDefinitions()) { +// String definition = oboClass.getDefinition(); +// if (definition != null & !definition.equals("")) +// termAdded = compareAndAddTerm(input,definition,oboClass,searchTermList); +// if (termAdded) continue; // not really necesary as its last } } return searchTermList.getVector(); } @@ -135,74 +129,108 @@ can be syn obs term or def and its lost here i think these methods need to be moved to gui.TermSearcher that utilizes Ontology but produces CompListTerms */ - private boolean compareAndAddTerm(String input, String compareTerm, OBOClass oboClass, - SearchTermList searchTermList) { +// private boolean compareAndAddTerm(String input, String compareTerm, OBOClass oboClass, +// SearchTermList searchTermList) { - String oboTerm = oboClass.getName(); +// //String oboTerm = oboClass.getName(); - String lowerComp = compareTerm; - boolean ignoreCase = true; // discard? param for? - if (ignoreCase) - lowerComp = compareTerm.toLowerCase(); +// String lowerComp = compareTerm; +// boolean ignoreCase = true; // discard? param for? +// if (ignoreCase) +// lowerComp = compareTerm.toLowerCase(); - //boolean doContains = true; // discard? param for? - // exact match goes first in list - if (lowerComp.equals(input)) { - searchTermList.addTermFirst(oboClass); // adds if not present - return true; - } - // new paradigm - put starts with first - else if (lowerComp.startsWith(input)) { - searchTermList.addTerm(oboClass); - return true; - } - // Contains - else if (contains(lowerComp,input) && !termFilter(lowerComp)) { - searchTermList.addContainsTerm(oboClass); - return true; - } - return false; - } +// //boolean doContains = true; // discard? param for? +// // exact match goes first in list +// if (lowerComp.equals(input)) { +// searchTermList.addTermFirst(oboClass); // adds if not present +// return true; +// } +// // new paradigm - put starts with first +// else if (lowerComp.startsWith(input)) { +// searchTermList.addTerm(oboClass); +// return true; +// } +// // Contains +// else if (contains(lowerComp,input)) { // && !termFilter(lowerComp) -> Ont +// searchTermList.addContainsTerm(oboClass); +// return true; +// } +// return false; +// } // 1.5 has a contains! use when we shift private boolean contains(String term, String input) { return term.contains(input); // 1.5!! //return term.indexOf(input) != -1; } - /** Oboedit getTerms returns some terms with obo: prefix that should be filtered - * out. Returns true if starts with obo: */ - private boolean termFilter(String term) { - return term.startsWith("obo:"); - } + // now done in Ontology.filterList() so dont have to check every time +// /** Oboedit getTerms returns some terms with obo: prefix that should be filtered +// * out. Returns true if starts with obo: */ +// private boolean termFilter(String term) { +// return term.startsWith("obo:"); // take these out of ontology? +// } /** this data structure is handy for putting starts with before contains! UniqueTermList -> SearchTermList*/ private class SearchTermList { - private Vector<CompletionTerm> searchTerms = new Vector<CompletionTerm>(); + private List<CompletionTerm> startsWithTerms = new ArrayList<CompletionTerm>(); //private Map<OBOClass,OBOClass> uniqueCheck = new HashMap<OBOClass,OBOClass>(); // list of terms that are contained but NOT startsWith - private Vector<CompletionTerm> containTerms = new Vector<CompletionTerm>(); - private void addTerm(OBOClass oboClass) { - addTerm(oboClass,false); + private List<CompletionTerm> containTerms = new ArrayList<CompletionTerm>(); + private List<CompletionTerm> startsWithSyns = new ArrayList<CompletionTerm>(); + private List<CompletionTerm> containSyns = new ArrayList<CompletionTerm>(); + private List<CompletionTerm> obsoletes = new ArrayList<CompletionTerm>(); + private List<CompletionTerm> definitions = new ArrayList<CompletionTerm>(); + + private void addTerm(CompletionTerm ct) { + if (ct.isObsolete()) + obsoletes.add(ct); // start with/contains? + else if (ct.isTermMatch()) + addTerm(ct,startsWithTerms,containTerms); + else if (ct.isSynMatch()) + addTerm(ct,startsWithSyns,containSyns); + else if (ct.isDefinitionMatch()) + definitions.add(ct); // start with/contains? } - private void addTermFirst(OBOClass oboClass) { - addTerm(oboClass,true); + + private void addTerm(CompletionTerm ct, List startsWith, List contains) { + if (ct.isExactMatch()) // for syns as well? sure why not? + startsWith.add(0); + else if (ct.isStartsWithMatch()) + startsWith.add(ct); + else + contains.add(ct); } - private void addTerm(OBOClass oboClass,boolean first) { - //if (uniqueCheck.containsKey(oboClass)) { - //log().debug("dup term in search "+oboClass); - // new Throwable().printStackTrace(); return; } - CompletionTerm t = new CompletionTerm(oboClass); - if (first) searchTerms.add(0,t); - else searchTerms.add(t); - //uniqueCheck.put(oboClass,null); // dont need value - } - /** Add term thats not startsWith but contains */ - private void addContainsTerm(OBOClass oboClass) { - containTerms.add(new CompletionTerm(oboClass)); - } + private Vector<CompletionTerm> getVector() { - searchTerms.addAll(containTerms); - return searchTerms; + //startsWithTerms.addAll(containTerms); return startsWithTerms; + Vector<CompletionTerm> sortedTerms = new Vector<CompletionTerm>(); + sortedTerms.addAll(startsWithTerms); + sortedTerms.addAll(containTerms); + sortedTerms.addAll(startsWithSyns); + sortedTerms.addAll(containSyns); + sortedTerms.addAll(definitions); + sortedTerms.addAll(obsoletes); + return sortedTerms; } } } + +// private void addTerm(OBOClass oboClass) { +// addTerm(oboClass,false); +// } +// private void addTermFirst(OBOClass oboClass) { +// addTerm(oboClass,true); +// } +// private void addTerm(OBOClass oboClass,boolean first) { +// //if (uniqueCheck.containsKey(oboClass)) { +// //log().debug("dup term in search "+oboClass); +// // new Throwable().printStackTrace(); return; } +// CompletionTerm t = new CompletionTerm(oboClass); +// if (first) startsWithTerms.add(0,t); +// else startsWithTerms.add(t); +// //uniqueCheck.put(oboClass,null); // dont need value +// } +// /** Add term thats not startsWith but contains */ +// private void addContainsTerm(OBOClass oboClass) { +// containTerms.add(new CompletionTerm(oboClass)); +// } Modified: phenote/trunk/src/java/phenote/gui/field/CompletionTerm.java =================================================================== --- phenote/trunk/src/java/phenote/gui/field/CompletionTerm.java 2006-10-12 18:33:48 UTC (rev 157) +++ phenote/trunk/src/java/phenote/gui/field/CompletionTerm.java 2006-10-13 19:08:49 UTC (rev 158) @@ -1,18 +1,34 @@ package phenote.gui.field; // completion package? +import java.util.Set; + import org.geneontology.oboedit.datamodel.OBOClass; /** This is basically a view object for the auto completer for terms/OBOClass */ public class CompletionTerm { OBOClass term; + boolean termMatch = false; + boolean synonymMatch = false; + boolean definitionMatch = false; + boolean exactMatch = false; + boolean startsWith = false; + boolean contains = false; // do we need this? + CompletionTerm(OBOClass term) { this.term = term; } OBOClass getOboClass() { return term; } + boolean isTermMatch() { return termMatch; } + boolean isSynMatch() { return synonymMatch; } + boolean isDefinitionMatch() { return definitionMatch; } + + boolean isExactMatch() { return exactMatch; } + boolean isStartsWithMatch() { return startsWith; } + public String toString() { return compListDisplayString(); } @@ -26,5 +42,59 @@ public String getID() { return term.getID(); } public String getName() { return term.getName(); } + private Set getSyns() { return term.getSynonyms(); } + private boolean hasDefinition() { + return getDefinition() != null && !getDefinition().equals(""); + } + private String getDefinition() { return term.getDefinition(); } + boolean isObsolete() { return term.isObsolete(); } + /** Returns true if term matches input according to searchParams. has + side effect of recording the kind of match - term, syn, desc... */ + boolean matches(String input, SearchParamsI searchParams) { + // TERMS + if (searchParams.searchTerms()) { + if (stringMatches(input,getName())) { + termMatch = true; // is this needed? + return true; + } + } + // SYNS + if (searchParams.searchSynonyms()) { + for (Object o : getSyns()) { + String syn = o.toString(); + if (stringMatches(input,syn)) { + synonymMatch = true; + return true; + } + } + } + // DEFS + if (searchParams.searchDefinitions() && hasDefinition()) { + if (stringMatches(input,getDefinition())) { + definitionMatch = true; + return true; + } + } + return false; + } + + private boolean stringMatches(String input, String item) { + input = input.toLowerCase().trim(); + item = item.toLowerCase().trim(); + if (input.equals(item)) { + exactMatch = true; + return true; + } + else if (item.startsWith(input)) { + startsWith = true; + return true; + } + else if (item.contains(input)) { + contains = true; + return true; + } + return false; // all above failed - no match + } + } Modified: phenote/trunk/src/java/phenote/servlet/PhenoteServlet.java =================================================================== --- phenote/trunk/src/java/phenote/servlet/PhenoteServlet.java 2006-10-12 18:33:48 UTC (rev 157) +++ phenote/trunk/src/java/phenote/servlet/PhenoteServlet.java 2006-10-13 19:08:49 UTC (rev 158) @@ -259,11 +259,11 @@ } public boolean searchSynonyms() { - return false; + return false; // --> true } public boolean searchDefinitions() { - return false; + return false; // ?? w [def]?? } /** @@ -271,7 +271,7 @@ * This should be in conjunction with the other 3 */ public boolean searchObsoletes() { - return false; + return false; // --> true w [obs], disallow selection } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |