0
|
1 package de.mpiwg.anteater;
|
|
2
|
|
3 import java.io.File;
|
|
4 import java.io.FilenameFilter;
|
|
5 import java.util.ArrayList;
|
|
6 import java.util.List;
|
|
7
|
|
8 import de.mpiwg.anteater.events.EventController;
|
|
9 import de.mpiwg.anteater.persons.PersonFinderController;
|
|
10 import de.mpiwg.anteater.persons.PersonsExtraction;
|
|
11 import de.mpiwg.anteater.places.PlaceFinderController;
|
|
12 import de.mpiwg.anteater.places.PlacesExtraction;
|
|
13 import de.mpiwg.anteater.results.ResultController;
|
|
14 import de.mpiwg.anteater.results.ResultsCarrier;
|
3
|
15 import de.mpiwg.anteater.species.common.CommonNameFindController;
|
0
|
16 import de.mpiwg.anteater.species.scientific.ScientificNameFindController;
|
|
17 import de.mpiwg.anteater.species.scientific.ScientificNamesExtraction;
|
|
18 import de.mpiwg.anteater.text.TextInformation;
|
|
19 import de.mpiwg.anteater.text.TextManager;
|
|
20
|
|
21 public class AnteaterController {
|
|
22
|
|
23 public final static String COMPONENT_NAME = AnteaterController.class.getSimpleName();
|
|
24
|
|
25 public void runAnteater(AnteaterConfiguration configuration) {
|
|
26 configuration.getLogger().logMessage(COMPONENT_NAME, "Retrieving files...");
|
|
27
|
|
28 File folder = new File(configuration.getPathToTexts());
|
|
29 File[] files = folder.listFiles(new FilenameFilter() {
|
|
30
|
|
31 @Override
|
|
32 public boolean accept(File arg0, String arg1) {
|
|
33 File child = new File(arg0.getAbsolutePath() + File.separator + arg1);
|
|
34 if (child.isFile() && arg1.endsWith(".xml"))
|
|
35 return true;
|
|
36 return false;
|
|
37 }
|
|
38 });
|
|
39
|
|
40 ScientificNameFindController scienceNameFindController = new ScientificNameFindController(configuration);
|
|
41 PlaceFinderController placesController = new PlaceFinderController(configuration);
|
|
42 PersonFinderController personsController = new PersonFinderController(configuration);
|
3
|
43 CommonNameFindController commonNameFindController = new CommonNameFindController(configuration);
|
0
|
44
|
|
45 List<TextInformation> textInformations = new ArrayList<TextInformation>();
|
|
46 TextManager textManager = new TextManager(configuration);
|
|
47
|
|
48 for (File f : files) {
|
|
49 TextInformation info = textManager.createTextInformations(f);
|
|
50 textInformations.add(info);
|
|
51 }
|
|
52
|
|
53
|
|
54 for (TextInformation info : textInformations) {
|
|
55 configuration.getLogger().logMessage(COMPONENT_NAME, "Working on file: " + info.getFilepath());
|
|
56 // get scientific names
|
|
57 List<ScientificNamesExtraction> scienNameResults = scienceNameFindController.findScientificNamesInXML(info);
|
|
58 info.setScientificNamesExtractions(scienNameResults);
|
|
59
|
3
|
60 //get common names and scientiric
|
4
|
61 List<ScientificNamesExtraction> commonNamesResults = commonNameFindController.findCommonNamesInXML(info);
|
|
62 info.getScientificNamesExtractions().addAll(commonNamesResults);
|
3
|
63
|
0
|
64 // get places
|
|
65 List<PlacesExtraction> placesResults = placesController.findPlacesInXML(info);
|
|
66 info.setPlacesExtractions(placesResults);
|
|
67
|
|
68 // get persons
|
|
69 List<PersonsExtraction> personsResults = personsController.findPersonsInXML(info);
|
|
70 info.setPersonsExtractions(personsResults);
|
|
71
|
|
72 }
|
|
73
|
|
74 // retrieve and save results
|
|
75 ResultController resultController = new ResultController(configuration);
|
|
76 List<ResultsCarrier> resultCarriers = resultController.saveResults(textInformations);
|
|
77
|
|
78 EventController eventController = new EventController(configuration);
|
|
79 eventController.createEvents(resultCarriers);
|
|
80 }
|
|
81
|
|
82 }
|