001/** 002 * 003 */ 004package org.biopax.paxtools.util; 005 006import java.util.Set; 007 008import org.apache.lucene.document.Document; 009import org.biopax.paxtools.model.level3.BioSource; 010import org.biopax.paxtools.model.level3.UnificationXref; 011import org.biopax.paxtools.model.level3.Xref; 012import org.hibernate.search.bridge.FieldBridge; 013import org.hibernate.search.bridge.LuceneOptions; 014 015/** 016 * A FieldBridge implementation 017 * for including organism (BioSource) names, ids, terms 018 * to parent BioPAX element's index. 019 * 020 * @author rodche 021 * @deprecated Hibernate ORM/Search will be removed in v5 022 */ 023public final class OrganismFieldBridge implements FieldBridge { 024 025 @Override 026 public void set(String searchFieldName, Object value, Document document, LuceneOptions luceneOptions) { 027 if (value instanceof Set) { 028 for (BioSource o : (Set<BioSource>) value) { 029 if(o != null) 030 setOrganism(searchFieldName, o, document, luceneOptions); 031 } 032 } else { 033 throw new AssertionError("bug!"); 034 } 035 } 036 037 038 private void setOrganism(String searchFieldName, BioSource bs, 039 Document document, LuceneOptions luceneOptions) 040 { 041 // put id (e.g., urn:miriam:taxonomy:9606, if normalized...) 042 // do not do .toLowerCase()! 043 FieldBridgeUtils.addFieldToDocumentAsIs(luceneOptions, searchFieldName, bs.getRDFId(), document); 044 045 // add organism names 046 for(String s : bs.getName()) { 047 FieldBridgeUtils.addFieldToDocument(luceneOptions, searchFieldName, s, document); 048 } 049 // add taxonomy 050 for(UnificationXref x : 051 new ClassFilterSet<Xref,UnificationXref>(bs.getXref(), UnificationXref.class)) { 052 if(x.getId() != null) 053 FieldBridgeUtils.addFieldToDocument(luceneOptions, searchFieldName, x.getId(), document); 054 } 055 // include tissue type terms 056 if (bs.getTissue() != null) { 057 for (String s : bs.getTissue().getTerm()) { 058 FieldBridgeUtils.addFieldToDocument(luceneOptions, searchFieldName, s, document); 059 } 060 } 061 // include cell type terms 062 if (bs.getCellType() != null) { 063 for (String s : bs.getCellType().getTerm()) { 064 FieldBridgeUtils.addFieldToDocument(luceneOptions, searchFieldName, s, document); 065 } 066 } 067 } 068 069}