use of de.geeksfactory.opacclient.searchfields.SearchField.Meaning 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.SearchField.Meaning in project opacclient by opacapp.
the class MeaningDetectorImpl method processMeaning.
private SearchField processMeaning(SearchField field, String meaningName) {
Meaning meaning = Meaning.valueOf(meaningName);
SearchField oldfield = field;
if (field instanceof TextSearchField && meaning == Meaning.FREE) {
((TextSearchField) field).setFreeSearch(true);
((TextSearchField) field).setHint(field.getDisplayName());
} else if (field instanceof TextSearchField && (meaning == Meaning.BARCODE || meaning == Meaning.ISBN)) {
field = new BarcodeSearchField(field.getId(), field.getDisplayName(), field.isAdvanced(), ((TextSearchField) field).isHalfWidth(), ((TextSearchField) field).getHint());
} else if (meaning == Meaning.AUDIENCE || meaning == Meaning.SYSTEM || meaning == Meaning.KEYWORD || meaning == Meaning.PUBLISHER) {
field.setAdvanced(true);
}
field.setData(oldfield.getData());
field.setMeaning(meaning);
return field;
}
Aggregations