Changeset 473

Show
Ignore:
Timestamp:
01/24/11 12:50:33 (16 months ago)
Author:
martijn
Message:

Alternative freeAttributeSearch method, Patch by Ferry

Location:
trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/org.bridgedb.rdb/src/org/bridgedb/rdb/SimpleGdbImplCommon.java

    r459 r473  
    1717import org.bridgedb.IDMapperException; 
    1818import org.bridgedb.Xref; 
     19import org.bridgedb.impl.InternalUtils; 
    1920 
    2021/** 
     
    321322                } 
    322323        } 
     324         
     325        public Map<Xref, Set<String>> freeAttributeSearchEx (String query, String attrType, int limit) throws IDMapperException 
     326        { 
     327                Map<Xref, Set<String>> result = new HashMap<Xref, Set<String>>(); 
     328                final QueryLifeCycle pst = (MATCH_ID.equals (attrType)) ?  
     329                                qIdSearchWithAttributes : qAttributeSearch; 
     330                synchronized (pst) {  
     331                        try { 
     332                                pst.init(limit); 
     333                                pst.setString(1, attrType); 
     334                                pst.setString(2, "%" + query.toLowerCase() + "%"); 
     335                                ResultSet r = pst.executeQuery(); 
     336         
     337                                while(r.next())  
     338                                { 
     339                                        String id = r.getString("id"); 
     340                                        String code = r.getString("code"); 
     341                                        String symbol = r.getString("attrValue"); 
     342                                        Xref ref = new Xref (id, DataSource.getBySystemCode(code)); 
     343                                        InternalUtils.multiMapPut(result, ref, symbol); 
     344                                } 
     345                        } catch (SQLException e) { 
     346                                throw new IDMapperException (e); 
     347                        } 
     348                        finally { pst.cleanup(); } 
     349                        return result; 
     350                } 
     351        } 
    323352 
    324353        /** {@inheritDoc} */ 
  • trunk/org.bridgedb.webservice.biomart/src/org/bridgedb/webservice/biomart/IDMapperBiomart.java

    r308 r473  
    388388     * {@inheritDoc} 
    389389     */ 
     390    public Map<Xref, Set<String>> freeAttributeSearchEx (String query, String attrType, int limit) throws IDMapperException { 
     391        throw new UnsupportedOperationException("Free attribute search not supported."); 
     392    } 
     393 
     394    /** 
     395     * {@inheritDoc} 
     396     */ 
    390397    public Set<String> getAttributeSet() throws IDMapperException { 
    391398        return stub.availableTgtAttributes(mart, dataset); 
  • trunk/org.bridgedb.webservice.bridgerest/src/org/bridgedb/webservice/bridgerest/BridgeRest.java

    r347 r473  
    513513                }  
    514514        } 
     515 
     516        @Override 
     517        public Map<Xref, Set<String>> freeAttributeSearchEx(String query, String attrType, int limit) 
     518                        throws IDMapperException 
     519        { 
     520                try { 
     521                        Map<Xref, Set<String>> result = new HashMap<Xref, Set<String>>(); 
     522                         
     523                        BufferedReader in = new UrlBuilder("attributeSearch") 
     524                                .ordered (query).named("limit", "" + limit) 
     525                                .named ("attrName", attrType) 
     526                                .openReader(); 
     527                        String line; 
     528                        while ((line = in.readLine()) != null) { 
     529                                String[] cols = line.split("\t", -1); 
     530                                Xref x = new Xref (cols[0], DataSource.getByFullName(cols[1])); 
     531                                String value = cols[2]; 
     532                                InternalUtils.multiMapPut(result, x, value); 
     533                        } 
     534                        in.close(); 
     535                        return result; 
     536                } catch (IOException ex) { 
     537                        throw new IDMapperException (ex); 
     538                }  
     539        } 
    515540         
    516541} 
  • trunk/org.bridgedb.webservice.picr/src/org/bridgedb/webservice/picr/IDMapperPicr.java

    r308 r473  
    272272                return result; 
    273273        } 
     274 
     275        @Override 
     276        public Map<Xref, Set<String>> freeAttributeSearchEx(String query, String attrType, int limit) 
     277                        throws IDMapperException 
     278        { 
     279                throw new UnsupportedOperationException(); 
     280        } 
    274281} 
  • trunk/org.bridgedb/src/org/bridgedb/AttributeMapper.java

    r308 r473  
    5151 
    5252        /** 
    53          * free text search for matching symbols. 
     53         * free text search for matching attributes. 
    5454         * @return map references and attribute values that match the query 
    5555         * @param query The text to search for 
     
    6161        public Map<Xref, String> freeAttributeSearch (String query, String attrType, int limit) throws IDMapperException; 
    6262 
     63        /** 
     64         * Improved version of free text search for matching attributes. 
     65         * Unlike freeAttributeSearch, this method may return multiple results per xref. 
     66         * @return map of references and attribute values that match the query 
     67         * @param query The text to search for 
     68         * @param attrType the attribute to look for, e.g. 'Symbol' or 'Description'.  
     69         *      If you use the special MATCH_ID constant, it will query the identifier instead. 
     70         * @param limit The number of results to limit the search to 
     71         * @throws IDMapperException if the mapping service is (temporarily) unavailable  
     72         */ 
     73        public Map<Xref, Set<String>> freeAttributeSearchEx (String query, String attrType, int limit) throws IDMapperException; 
     74         
    6375        /** use this magic constant as the attrType parameter to also search for identifiers. */ 
    6476        public static final String MATCH_ID = "org.bridgedb.MATCH_ID"; 
  • trunk/org.bridgedb/src/org/bridgedb/IDMapperStack.java

    r337 r473  
    386386        } 
    387387         
     388        public Map<Xref, Set<String>> freeAttributeSearchEx (String query, String attrType, int limit) throws IDMapperException 
     389        { 
     390                Map<Xref, Set<String>> result = new HashMap<Xref, Set<String>>(); 
     391                for (IDMapper child : gdbs) 
     392                { 
     393                        if (child != null && child instanceof AttributeMapper && child.isConnected() 
     394                                && ((AttributeMapper)child).isFreeAttributeSearchSupported()) 
     395                        { 
     396                                Map<Xref, Set<String>> childResult =  
     397                                        ((AttributeMapper)child).freeAttributeSearchEx(query, attrType, limit); 
     398                                if (result == null)  
     399                                        result = childResult; 
     400                                else 
     401                                { 
     402                                        for (Xref ref : childResult.keySet()) 
     403                                        { 
     404                                                if (!result.containsKey(ref)) 
     405                                                        result.put (ref, childResult.get(ref)); 
     406                                        } 
     407                                } 
     408                        } 
     409                } 
     410                return result; 
     411        } 
     412         
    388413        /** @return concatenation of toString of each child */ 
    389414        @Override public String toString() 
     
    533558                return result; 
    534559        } 
    535          
    536560}