Search in sources :

Example 1 with Number

use of alice.tuprolog.Number in project Osmand by osmandapp.

the class AbstractPrologCommandPlayer method init.

private void init(String voiceProvider, OsmandSettings settings, String configFile) throws CommandPlayerException {
    prologSystem.clearTheory();
    voiceDir = null;
    if (voiceProvider != null) {
        File parent = ctx.getAppPath(IndexConstants.VOICE_INDEX_DIR);
        voiceDir = new File(parent, voiceProvider);
        if (!voiceDir.exists()) {
            voiceDir = null;
            throw new CommandPlayerException(ctx.getString(R.string.voice_data_unavailable));
        }
    }
    // voiceZipFile = null;
    if (voiceDir != null) {
        long time = System.currentTimeMillis();
        boolean wrong = false;
        try {
            InputStream config;
            // if (voiceDir.getName().endsWith(".zip")) { //$NON-NLS-1$
            // voiceZipFile = new ZipFile(voiceDir);
            // config = voiceZipFile.getInputStream(voiceZipFile.getEntry("_config.p")); //$NON-NLS-1$
            // } else {
            // $NON-NLS-1$
            config = new FileInputStream(new File(voiceDir, configFile));
            // }
            MetricsConstants mc = settings.METRIC_SYSTEM.get();
            ApplicationMode m = settings.getApplicationMode();
            if (m.getParent() != null) {
                m = m.getParent();
            }
            settings.APPLICATION_MODE.addListener(this);
            prologSystem.getTheoryManager().assertA(new Struct("appMode", new Struct(ctx.getSettings().APPLICATION_MODE.get().getStringKey().toLowerCase())), true, "", true);
            prologSystem.addTheory(new Theory("measure('" + mc.toTTSString() + "')."));
            prologSystem.addTheory(new Theory(config));
            config.close();
        } catch (InvalidTheoryException e) {
            // $NON-NLS-1$
            log.error("Loading voice config exception " + voiceProvider, e);
            wrong = true;
        } catch (IOException e) {
            // $NON-NLS-1$
            log.error("Loading voice config exception " + voiceProvider, e);
            wrong = true;
        }
        if (wrong) {
            throw new CommandPlayerException(ctx.getString(R.string.voice_data_corrupted));
        } else {
            Term val = solveSimplePredicate(P_VERSION);
            if (!(val instanceof Number) || Arrays.binarySearch(sortedVoiceVersions, ((Number) val).intValue()) < 0) {
                throw new CommandPlayerException(ctx.getString(R.string.voice_data_not_supported));
            }
            currentVersion = ((Number) val).intValue();
        }
        if (log.isInfoEnabled()) {
            // $NON-NLS-1$ //$NON-NLS-2$
            log.info("Initializing voice subsystem  " + voiceProvider + " : " + (System.currentTimeMillis() - time));
        }
    }
}
Also used : Theory(alice.tuprolog.Theory) InvalidTheoryException(alice.tuprolog.InvalidTheoryException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ApplicationMode(net.osmand.plus.ApplicationMode) IOException(java.io.IOException) Term(alice.tuprolog.Term) FileInputStream(java.io.FileInputStream) Struct(alice.tuprolog.Struct) Number(alice.tuprolog.Number) MetricsConstants(net.osmand.plus.OsmandSettings.MetricsConstants) File(java.io.File)

Aggregations

InvalidTheoryException (alice.tuprolog.InvalidTheoryException)1 Number (alice.tuprolog.Number)1 Struct (alice.tuprolog.Struct)1 Term (alice.tuprolog.Term)1 Theory (alice.tuprolog.Theory)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ApplicationMode (net.osmand.plus.ApplicationMode)1 MetricsConstants (net.osmand.plus.OsmandSettings.MetricsConstants)1