Search in sources :

Example 1 with MeaningDetectorImpl

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();
}
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 MeaningDetectorImpl

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)));
    }
}
Also used : MeaningDetectorImpl(de.geeksfactory.opacclient.searchfields.MeaningDetectorImpl) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Before(org.junit.Before)

Example 3 with MeaningDetectorImpl

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

Aggregations

MeaningDetectorImpl (de.geeksfactory.opacclient.searchfields.MeaningDetectorImpl)3 SearchField (de.geeksfactory.opacclient.searchfields.SearchField)2 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)2 Library (de.geeksfactory.opacclient.objects.Library)1 MeaningDetector (de.geeksfactory.opacclient.searchfields.MeaningDetector)1 Meaning (de.geeksfactory.opacclient.searchfields.SearchField.Meaning)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 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 Before (org.junit.Before)1