2
|
1 package de.mpiwg.anteater.species.common;
|
|
2
|
|
3 import java.io.File;
|
|
4 import java.util.ArrayList;
|
|
5 import java.util.List;
|
|
6
|
|
7 import de.mpiwg.anteater.AnteaterConfiguration;
|
3
|
8 import de.mpiwg.anteater.species.common.impl.LinnaeusNameFinder;
|
|
9 import de.mpiwg.anteater.species.scientific.IScientificNamesFinder;
|
2
|
10 import de.mpiwg.anteater.species.scientific.ScientificNamesExtraction;
|
3
|
11 import de.mpiwg.anteater.species.scientific.impl.GNRDNameFinder;
|
2
|
12 import de.mpiwg.anteater.text.TextInformation;
|
3
|
13 import de.mpiwg.anteater.text.TextPart;
|
2
|
14 import de.mpiwg.anteater.xml.impl.AnalysisXMLManager;
|
|
15
|
|
16 public class CommonNameFindController {
|
|
17
|
|
18 public final static String COMPONENT_NAME = CommonNameFindController.class.getSimpleName();
|
|
19
|
|
20 private AnteaterConfiguration configuration;
|
|
21
|
|
22 public CommonNameFindController(AnteaterConfiguration configuration) {
|
|
23 this.configuration = configuration;
|
|
24 }
|
|
25
|
3
|
26 public List<CommonNamesExtraction> findCommonNamesInXML(TextInformation info) {
|
2
|
27 List<CommonNamesExtraction> results = new ArrayList<CommonNamesExtraction>();
|
|
28 List<String> summaryAnalysisResults = new ArrayList<String>();
|
|
29 List<String> supplinfAnalysisResults = new ArrayList<String>();
|
|
30
|
|
31 // check if there are already stored results
|
|
32 AnalysisXMLManager analysisManager = null;
|
|
33 if (configuration.getAnalysisPath() != null && !configuration.getAnalysisPath().isEmpty()) {
|
|
34 File file = new File(info.getFilepath());
|
|
35
|
|
36 analysisManager = new AnalysisXMLManager(configuration.getAnalysisPath() + File.separator + file.getName());
|
|
37
|
|
38 configuration.getLogger().logMessageWithoutNewLine(COMPONENT_NAME, "Check analysis file for scientific names in summaries...");
|
|
39 summaryAnalysisResults = analysisManager.getSummaryCommonNamesResults();
|
|
40 configuration.getLogger().logMessage("found " + summaryAnalysisResults.size() + " result(s).");
|
|
41
|
|
42 configuration.getLogger().logMessageWithoutNewLine(COMPONENT_NAME, "Check analysis file for scientific names in supplementary information...");
|
|
43 supplinfAnalysisResults = analysisManager.getSupplementaryInfoCommonNamesResults();
|
|
44 configuration.getLogger().logMessage("found " + supplinfAnalysisResults.size() + " result(s).");
|
|
45 }
|
|
46
|
3
|
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
|
2
|
81 return null;
|
|
82 }
|
|
83
|
|
84 }
|