Search in sources :

Example 1 with Meaning

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();
}
Also used : Scanner(java.util.Scanner) MeaningDetectorImpl(de.geeksfactory.opacclient.searchfields.MeaningDetectorImpl) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) JSONException(org.json.JSONException) IOException(java.io.IOException) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) JSONObject(org.json.JSONObject) ExecutorService(java.util.concurrent.ExecutorService) Library(de.geeksfactory.opacclient.objects.Library) Map(java.util.Map) Meaning(de.geeksfactory.opacclient.searchfields.SearchField.Meaning)

Example 2 with Meaning

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;
}
Also used : Meaning(de.geeksfactory.opacclient.searchfields.SearchField.Meaning)

Aggregations

Meaning (de.geeksfactory.opacclient.searchfields.SearchField.Meaning)2 Library (de.geeksfactory.opacclient.objects.Library)1 MeaningDetectorImpl (de.geeksfactory.opacclient.searchfields.MeaningDetectorImpl)1 SearchField (de.geeksfactory.opacclient.searchfields.SearchField)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Scanner (java.util.Scanner)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1