comparison src/de/mpiwg/anteater/species/common/CommonNameFindController.java @ 3:ae96e4bc7fb2

save found species to analysis files
author jdamerow
date Mon, 22 Oct 2012 14:21:14 -0700
parents 1c2b4f5e2c05
children dcc35f89dce3
comparison
equal deleted inserted replaced
2:1c2b4f5e2c05 3:ae96e4bc7fb2
3 import java.io.File; 3 import java.io.File;
4 import java.util.ArrayList; 4 import java.util.ArrayList;
5 import java.util.List; 5 import java.util.List;
6 6
7 import de.mpiwg.anteater.AnteaterConfiguration; 7 import de.mpiwg.anteater.AnteaterConfiguration;
8 import de.mpiwg.anteater.species.common.impl.LinnaeusNameFinder;
9 import de.mpiwg.anteater.species.scientific.IScientificNamesFinder;
8 import de.mpiwg.anteater.species.scientific.ScientificNamesExtraction; 10 import de.mpiwg.anteater.species.scientific.ScientificNamesExtraction;
11 import de.mpiwg.anteater.species.scientific.impl.GNRDNameFinder;
9 import de.mpiwg.anteater.text.TextInformation; 12 import de.mpiwg.anteater.text.TextInformation;
13 import de.mpiwg.anteater.text.TextPart;
10 import de.mpiwg.anteater.xml.impl.AnalysisXMLManager; 14 import de.mpiwg.anteater.xml.impl.AnalysisXMLManager;
11 15
12 public class CommonNameFindController { 16 public class CommonNameFindController {
13 17
14 public final static String COMPONENT_NAME = CommonNameFindController.class.getSimpleName(); 18 public final static String COMPONENT_NAME = CommonNameFindController.class.getSimpleName();
17 21
18 public CommonNameFindController(AnteaterConfiguration configuration) { 22 public CommonNameFindController(AnteaterConfiguration configuration) {
19 this.configuration = configuration; 23 this.configuration = configuration;
20 } 24 }
21 25
22 public List<ScientificNamesExtraction> findCommonNamesInXML(TextInformation info) { 26 public List<CommonNamesExtraction> findCommonNamesInXML(TextInformation info) {
23 List<CommonNamesExtraction> results = new ArrayList<CommonNamesExtraction>(); 27 List<CommonNamesExtraction> results = new ArrayList<CommonNamesExtraction>();
24 List<String> summaryAnalysisResults = new ArrayList<String>(); 28 List<String> summaryAnalysisResults = new ArrayList<String>();
25 List<String> supplinfAnalysisResults = new ArrayList<String>(); 29 List<String> supplinfAnalysisResults = new ArrayList<String>();
26 30
27 // check if there are already stored results 31 // check if there are already stored results
38 configuration.getLogger().logMessageWithoutNewLine(COMPONENT_NAME, "Check analysis file for scientific names in supplementary information..."); 42 configuration.getLogger().logMessageWithoutNewLine(COMPONENT_NAME, "Check analysis file for scientific names in supplementary information...");
39 supplinfAnalysisResults = analysisManager.getSupplementaryInfoCommonNamesResults(); 43 supplinfAnalysisResults = analysisManager.getSupplementaryInfoCommonNamesResults();
40 configuration.getLogger().logMessage("found " + supplinfAnalysisResults.size() + " result(s)."); 44 configuration.getLogger().logMessage("found " + supplinfAnalysisResults.size() + " result(s).");
41 } 45 }
42 46
47 ICommonNameFinder nameFinder = new LinnaeusNameFinder(configuration.getLogger());
48
49 // if there are no results for summaries, ask GNRD name finding service.
50 if (summaryAnalysisResults.size() == 0) {
51 configuration.getLogger().logMessage(COMPONENT_NAME, "No results found for summaries, so will ask LinnaeusNameFinder.");
52
53 for (TextPart sum : info.getSummaries()) {
54 String sumResult = nameFinder.findCommonNames(sum.getText());
55 if (sumResult != null) {
56 summaryAnalysisResults.add(sumResult);
57
58 // if there is an analysis folder, add result to analysis file
59 if (analysisManager != null)
60 analysisManager.addSummaryCommonNamesResult(sumResult);
61 }
62 }
63 }
64
65 // if there are no results for supplementary information, ask GNRD name fining service
66 if (supplinfAnalysisResults.size() == 0) {
67 configuration.getLogger().logMessage(COMPONENT_NAME, "No results found for supplementary information, so will ask LinnaeusNameFinder.");
68
69 for (TextPart sInf : info.getSupplInfos()) {
70 String supinfResult = nameFinder.findCommonNames(sInf.getText());
71 if (supinfResult != null) {
72 supplinfAnalysisResults.add(supinfResult);
73
74 // if there is an analysis folder, add result to analysis file
75 if (analysisManager != null)
76 analysisManager.addSupplInfCommonNamesResult(supinfResult);
77 }
78 }
79 }
80
43 return null; 81 return null;
44 } 82 }
45 83
46 } 84 }