0
|
1 package de.mpiwg.anteater.places;
|
|
2
|
|
3 import java.io.File;
|
|
4 import java.util.ArrayList;
|
|
5 import java.util.List;
|
|
6
|
|
7 import de.mpiwg.anteater.AnteaterConfiguration;
|
|
8 import de.mpiwg.anteater.places.impl.PlacemakerPlaceFinder;
|
|
9 import de.mpiwg.anteater.text.TextInformation;
|
|
10 import de.mpiwg.anteater.text.TextPart;
|
|
11 import de.mpiwg.anteater.text.TextType;
|
|
12 import de.mpiwg.anteater.xml.IPlaceFinderParser;
|
|
13 import de.mpiwg.anteater.xml.impl.AnalysisXMLManager;
|
|
14 import de.mpiwg.anteater.xml.impl.PlacemakerXMLParser;
|
|
15
|
|
16 public class PlaceFinderController {
|
|
17
|
|
18 public final static String COMPONENT_NAME = PlaceFinderController.class.getSimpleName();
|
|
19
|
|
20 private AnteaterConfiguration configuration;
|
|
21
|
|
22 public PlaceFinderController(AnteaterConfiguration configuration) {
|
|
23 this.configuration = configuration;
|
|
24 }
|
|
25
|
|
26 public List<PlacesExtraction> findPlacesInXML(TextInformation info) {
|
|
27 List<PlacesExtraction> results = new ArrayList<PlacesExtraction>();
|
|
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 places in summaries...");
|
|
39 summaryAnalysisResults = analysisManager.getSummaryPlacesResults();
|
|
40 configuration.getLogger().logMessage("found " + summaryAnalysisResults.size() + " result(s).");
|
|
41
|
|
42 configuration.getLogger().logMessageWithoutNewLine(COMPONENT_NAME, "Check analysis file for places in supplementary information...");
|
|
43 supplinfAnalysisResults = analysisManager.getSupplementaryInfoPlacesResults();
|
|
44 configuration.getLogger().logMessage("found " + supplinfAnalysisResults.size() + " result(s).");
|
|
45 }
|
|
46
|
|
47 IPlaceFinder placeFinder = new PlacemakerPlaceFinder(configuration.getLogger());
|
|
48
|
|
49 // if there are no results for summaries, ask place finding service.
|
|
50 if (summaryAnalysisResults.size() == 0) {
|
|
51 configuration.getLogger().logMessage(COMPONENT_NAME, "No results found for summaries, so will ask Placemaker.");
|
|
52
|
|
53 for (TextPart sum : info.getSummaries()) {
|
|
54 String sumResult = placeFinder.findPlaces(sum.getText());
|
|
55 if (sumResult != null && !sumResult.isEmpty()) {
|
|
56 summaryAnalysisResults.add(sumResult);
|
|
57
|
|
58 // if there is an analysis folder, add result to analysis file
|
|
59 if (analysisManager != null)
|
|
60 analysisManager.addSummaryPlacesResult(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 Placemaker.");
|
|
68
|
|
69 for (TextPart sum : info.getSupplInfos()) {
|
|
70 String supinfResult = placeFinder.findPlaces(sum.getText());
|
|
71 if (supinfResult != null && !supinfResult.isEmpty()) {
|
|
72 supplinfAnalysisResults.add(supinfResult);
|
|
73
|
|
74 // if there is an analysis folder, add result to analysis file
|
|
75 if (analysisManager != null)
|
|
76 analysisManager.addSupplInfPlacesResult(supinfResult);
|
|
77 }
|
|
78 }
|
|
79 }
|
|
80
|
|
81 // create objects
|
|
82 configuration.getLogger().logMessage(COMPONENT_NAME, "Creating analysis results...");
|
|
83 int idx = 0;
|
|
84 for (String summaryResult : summaryAnalysisResults) {
|
|
85 IPlaceFinderParser parser = new PlacemakerXMLParser(summaryResult);
|
|
86
|
|
87 List<PlaceInformation> places = parser.parsePlaces();
|
|
88 PlacesExtraction placeResult = new PlacesExtraction();
|
|
89 placeResult.setType(TextType.TYPE_SUMMARY);
|
|
90 placeResult.setPlaceInformation(places);
|
|
91 placeResult.setTextIdx(idx);
|
|
92
|
|
93 results.add(placeResult);
|
|
94 idx++;
|
|
95 }
|
|
96
|
|
97 idx = 0;
|
|
98 for (String suplinfResult : supplinfAnalysisResults) {
|
|
99 IPlaceFinderParser parser = new PlacemakerXMLParser(suplinfResult);
|
|
100
|
|
101 List<PlaceInformation> scientificNames = parser.parsePlaces();
|
|
102 PlacesExtraction placeResult = new PlacesExtraction();
|
|
103 placeResult.setType(TextType.TYPE_SUPLINF);
|
|
104 placeResult.setPlaceInformation(scientificNames);
|
|
105 placeResult.setTextIdx(idx);
|
|
106
|
|
107 results.add(placeResult);
|
|
108 idx++;
|
|
109 }
|
|
110
|
|
111 return results;
|
|
112 }
|
|
113 }
|