Project

General

Profile

« Previous | Next » 

Revision 5174bd4c

Added by Patrick Plitzner about 9 years ago

  • optimized name matching for terms in ABCD import

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/UnitsGatheringArea.java
11 11

  
12 12
import java.awt.Dimension;
13 13
import java.util.ArrayList;
14
import java.util.Arrays;
15 14
import java.util.HashMap;
16 15
import java.util.HashSet;
17 16
import java.util.List;
......
26 25

  
27 26
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
28 27
import eu.etaxonomy.cdm.api.service.ITermService;
28
import eu.etaxonomy.cdm.api.service.pager.Pager;
29 29
import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
30 30
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
31 31
import eu.etaxonomy.cdm.io.specimen.excel.in.SpecimenSynthesysExcelImportConfigurator;
......
33 33
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
34 34
import eu.etaxonomy.cdm.model.location.Country;
35 35
import eu.etaxonomy.cdm.model.location.NamedArea;
36
import eu.etaxonomy.cdm.persistence.query.MatchMode;
36 37

  
37 38
/**
38 39
 * @author p.kelbert
......
90 91
        HashSet<String> areaToAdd= new HashSet<String>();
91 92
        HashSet<UUID> areaSet = new HashSet<UUID>();
92 93

  
93
        HashMap<String, UUID> matchingTerms = new HashMap<String, UUID>();
94
        HashMap<String, UUID> matchingTermsToUuid = new HashMap<String, UUID>();
94 95
        for (String namedAreaStr : namedAreas){
95
            for (DefinedTermBase na:termsList){
96
            	if (na != null && namedAreas != null){
97
	                if (na.getTitleCache().toLowerCase().indexOf(namedAreaStr.toLowerCase()) != -1) {
98
	                    if (na.getClass().toString().indexOf("eu.etaxonomy.cdm.model.location.") != -1) {
99
	                        matchingTerms.put(na.getTitleCache()+" ("+na.getClass().toString().split("eu.etaxonomy.cdm.model.location.")[1]+")",na.getUuid());
100
	                    }
101
	                }
102
            	}else{
103
            		logger.debug("This should not happen.");
104
            	}
96
            Pager<DefinedTermBase> matchingTerms = termService.findByTitle(DefinedTermBase.class, namedAreaStr, MatchMode.ANYWHERE, null, null, null, null, null);
97
            for (DefinedTermBase matchingTerm : matchingTerms.getRecords()) {
98
                matchingTermsToUuid
99
                        .put(matchingTerm.getTitleCache() + " ("
100
                                + matchingTerm.getClass().toString().split("eu.etaxonomy.cdm.model.location.")[1] + ")",
101
                                matchingTerm.getUuid());
105 102
            }
106
            //            logger.info("matchingterms: "+matchingTerms.keySet().toString());
107 103
            UUID areaUUID = null;
108 104
            areaUUID = getNamedAreaDecision(namedAreaStr,config);
109 105

  
110 106
            if (areaUUID == null && config.isInteractWithUser()){
111
                areaUUID = askForArea(namedAreaStr, matchingTerms, "area");
107
                areaUUID = askForArea(namedAreaStr, matchingTermsToUuid, "area");
112 108
            }
113 109
            if (DEBUG) {
114 110
                logger.info("selected area: "+areaUUID);
......
138 134

  
139 135
    private UUID askForArea(String namedAreaStr, HashMap<String, UUID> matchingTerms, String areaType){
140 136
//        matchingTerms.put("Nothing matches, create a new area",null);
141
        
137

  
142 138
        //FIXME names with same label will not make it to the map
143 139
        JTextArea textArea = new JTextArea("Several CDM-areas could match the current '"+namedAreaStr+"'");
144 140
        JScrollPane scrollPane = new JScrollPane(textArea);
......
148 144
        String s=null;
149 145
        List<String> list = new ArrayList<String>(matchingTerms.keySet());
150 146
        list.add("Nothing matches, create a new area");
151
        
147

  
152 148
        if (list.size() <= 1){
153 149
        	return null;
154 150
        }
......
177 173
     */
178 174
    public void setCountry(String iso, String fullName, ImportConfiguratorBase<?, ?> config, ITermService termService,
179 175
            IOccurrenceService occurrenceService){
180
  
181
       
176

  
177

  
182 178
        if (!StringUtils.isEmpty(iso)){
183 179
            wbc = occurrenceService.getCountryByIso(iso);
184 180
        }
......
190 186
                UUID areaUUID = null;
191 187
                //TODO Critical, should be a country decision
192 188
                areaUUID = getNamedAreaDecision(fullName,config);
193
                 
189

  
194 190
                if (areaUUID == null){
195 191
                	List<UUID> countryUuids = new ArrayList<UUID>();
196 192
                	HashMap<String, UUID> matchingTerms = new HashMap<String, UUID>();
197
                		 
193

  
198 194
                	List<Country> countryList = termService.list(Country.class, 0, 0, null, null);
199 195
                	for (NamedArea na:countryList){
200 196
	                   	if (na.getTitleCache().equalsIgnoreCase(fullName)) {
......
206 202
	                }
207 203
                	if (countryUuids.isEmpty()){
208 204
                		List<NamedArea> namedAreaList = termService.list(NamedArea.class,0,0,null,null);
209
                		
205

  
210 206
                		for (NamedArea na:namedAreaList){
211 207
                			if (! na.getClass().isAssignableFrom(Country.class) && na.getTitleCache().toLowerCase().indexOf(fullName.toLowerCase()) != -1) {
212 208
                				matchingTerms.put(na.getTitleCache()+" ("+na.getType().getLabel() + ")",na.getUuid());
......
223 219
                    		logger.warn("Non interaction not yet implemented correctly");
224 220
                    	}
225 221
                	}
226
                    
222

  
227 223
                }
228 224
                if (areaUUID == null){
229 225
                    NamedArea ar = NamedArea.NewInstance();

Also available in: Unified diff