use of de.geeksfactory.opacclient.searchfields.MeaningDetectorImpl in project opacclient by opacapp.
the class Main method main.
public static void main(String[] args) throws IOException, JSONException {
Security.addProvider(new BouncyCastleProvider());
Collection<String[]> libraries = libraries();
Set<String> ignored = new MeaningDetectorImpl(null).getIgnoredFields();
Scanner in = new Scanner(System.in);
final ExecutorService service = Executors.newFixedThreadPool(25);
List<TaskInfo> tasks = new ArrayList<>();
for (String[] libraryNameArray : libraries) {
String libraryName = libraryNameArray[0];
Library library;
try {
library = Library.fromJSON(libraryName, new JSONObject(readFile(BIBS_DIR + libraryName + ".json")));
Future<Map<String, List<SearchField>>> future = service.submit(new GetSearchFieldsCallable(library));
tasks.add(new TaskInfo(library, future));
} catch (JSONException | IOException e) {
// e.printStackTrace();
}
}
for (TaskInfo entry : tasks) {
Library library = entry.lib;
try {
Map<String, List<SearchField>> fields = entry.future.get();
if (fields == null)
continue;
for (String lang : fields.keySet()) {
System.out.println("Bibliothek: " + library.getIdent() + ", Sprache: " + lang);
MeaningDetectorImpl detector = new MeaningDetectorImpl(library);
for (int i = 0; i < fields.get(lang).size(); i++) {
fields.get(lang).set(i, detector.detectMeaning(fields.get(lang).get(i)));
}
for (SearchField field : fields.get(lang)) {
if (field.getMeaning() != null || ignored.contains(field.getDisplayName()) || field.getData() != null && field.getData().has("meaning") && ignored.contains(field.getData().getString("meaning")))
continue;
String name;
if (field.getData() != null && field.getData().has("meaning")) {
name = field.getData().getString("meaning");
System.out.print("Unbekanntes Feld: '" + name + "' (Anzeigename: " + field.getDisplayName() + ") ");
} else {
name = field.getDisplayName();
System.out.print("Unbekanntes Feld: '" + name + "' ");
}
Meaning meaning = null;
boolean ignoredField = false;
while (meaning == null && !ignoredField) {
String str = in.nextLine();
if (str.equals("") || str.toLowerCase().equals("ignore")) {
ignoredField = true;
addIgnoredField(name);
ignored.add(name);
} else {
try {
meaning = Meaning.valueOf(str.toUpperCase());
} catch (IllegalArgumentException e) {
meaning = null;
}
}
}
if (meaning != null) {
detector.addMeaning(name, meaning);
saveMeaning(name, meaning);
}
}
}
} catch (JSONException | IOException | ExecutionException | InterruptedException e) {
e.printStackTrace();
}
}
in.close();
service.shutdown();
}
use of de.geeksfactory.opacclient.searchfields.MeaningDetectorImpl in project opacclient by opacapp.
the class LibraryApiTestCases method setUp.
@Before
public void setUp() throws IOException, OpacErrorException, JSONException {
Security.addProvider(new BouncyCastleProvider());
api = OpacApiFactory.create(library, "OpacApp/Test");
fields = api.getSearchFields();
MeaningDetectorImpl detector = new MeaningDetectorImpl(library);
for (int i = 0; i < fields.size(); i++) {
fields.set(i, detector.detectMeaning(fields.get(i)));
}
}
use of de.geeksfactory.opacclient.searchfields.MeaningDetectorImpl in project opacclient by opacapp.
the class BaseApi method getSearchFields.
@Override
public List<SearchField> getSearchFields() throws JSONException, OpacErrorException, IOException {
List<SearchField> fields = parseSearchFields();
if (shouldUseMeaningDetector()) {
MeaningDetector md = new MeaningDetectorImpl(library);
for (int i = 0; i < fields.size(); i++) {
fields.set(i, md.detectMeaning(fields.get(i)));
}
Collections.sort(fields, new SearchField.OrderComparator());
}
return fields;
}
Aggregations