Search in sources :

Example 1 with Struct

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

the class VoiceRouter method getSpeakableStreetName.

public Term getSpeakableStreetName(RouteSegmentResult currentSegment, RouteDirectionInfo i, boolean includeDest) {
    if (i == null || !router.getSettings().SPEAK_STREET_NAMES.get()) {
        return empty;
    }
    if (player != null && player.supportsStructuredStreetNames()) {
        Term next = empty;
        // Issue 2377: Play Dest here only if not already previously announced, to avoid repetition
        if (includeDest == true) {
            next = new Struct(new Term[] { getTermString(getSpeakablePointName(i.getRef())), getTermString(getSpeakablePointName(i.getStreetName())), getTermString(getSpeakablePointName(i.getDestinationName())) });
        } else {
            next = new Struct(new Term[] { getTermString(getSpeakablePointName(i.getRef())), getTermString(getSpeakablePointName(i.getStreetName())), empty });
        }
        Term current = empty;
        if (currentSegment != null) {
            // Issue 2377: Play Dest here only if not already previously announced, to avoid repetition
            if (includeDest == true) {
                RouteDataObject obj = currentSegment.getObject();
                current = new Struct(new Term[] { getTermString(getSpeakablePointName(obj.getRef(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), currentSegment.isForwardDirection()))), getTermString(getSpeakablePointName(obj.getName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get()))), getTermString(getSpeakablePointName(obj.getDestinationName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), currentSegment.isForwardDirection()))) });
            } else {
                RouteDataObject obj = currentSegment.getObject();
                current = new Struct(new Term[] { getTermString(getSpeakablePointName(obj.getRef(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), currentSegment.isForwardDirection()))), getTermString(getSpeakablePointName(obj.getName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get()))), empty });
            }
        }
        Struct voice = new Struct("voice", next, current);
        return voice;
    } else {
        Term rf = getTermString(getSpeakablePointName(i.getRef()));
        if (rf == empty) {
            rf = getTermString(getSpeakablePointName(i.getStreetName()));
        }
        return rf;
    }
}
Also used : RouteDataObject(net.osmand.binary.RouteDataObject) Term(alice.tuprolog.Term) Struct(alice.tuprolog.Struct)

Example 2 with Struct

use of alice.tuprolog.Struct 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)

Example 3 with Struct

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

the class AbstractPrologCommandPlayer method stateChanged.

@Override
public void stateChanged(ApplicationMode change) {
    if (prologSystem != null) {
        prologSystem.getTheoryManager().retract(new Struct("appMode", new Var()));
        prologSystem.getTheoryManager().assertA(new Struct("appMode", new Struct(ctx.getSettings().APPLICATION_MODE.get().getStringKey().toLowerCase())), true, "", true);
    }
}
Also used : Var(alice.tuprolog.Var) Struct(alice.tuprolog.Struct)

Example 4 with Struct

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

the class CommandBuilder method prepareStruct.

private Struct prepareStruct(String name, Object... args) {
    checkState();
    Term[] list = new Term[args.length];
    for (int i = 0; i < args.length; i++) {
        Object o = args[i];
        if (o instanceof Term) {
            list[i] = (Term) o;
        } else if (o instanceof java.lang.Number) {
            if (o instanceof java.lang.Double) {
                list[i] = new alice.tuprolog.Double((Double) o);
            } else if (o instanceof java.lang.Float) {
                list[i] = new alice.tuprolog.Float((Float) o);
            } else if (o instanceof java.lang.Long) {
                list[i] = new alice.tuprolog.Long((Long) o);
            } else {
                list[i] = new alice.tuprolog.Int(((java.lang.Number) o).intValue());
            }
        } else if (o instanceof String) {
            list[i] = new Struct((String) o);
        }
        if (o == null) {
            list[i] = new Struct("");
        }
    }
    Struct struct = new Struct(name, list);
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$ //$NON-NLS-2$
        log.debug("Adding command : " + name + " " + Arrays.toString(args));
    }
    return struct;
}
Also used : Term(alice.tuprolog.Term) Struct(alice.tuprolog.Struct)

Example 5 with Struct

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

the class TestVoiceActivity method street.

private Term street(CommandPlayer p, String name, String ref, String destName, String currentName) {
    // Pass all test strings through our character replacement method
    ref = VoiceRouter.getSpeakablePointName(ref);
    name = VoiceRouter.getSpeakablePointName(name);
    destName = VoiceRouter.getSpeakablePointName(destName);
    currentName = VoiceRouter.getSpeakablePointName(currentName);
    if (p.supportsStructuredStreetNames()) {
        Struct next = new Struct(new Term[] { getTermString(ref), getTermString(name), getTermString(destName) });
        Term current = new Struct("");
        if (currentName.length() > 0) {
            current = new Struct(new Term[] { getTermString(""), getTermString(currentName), getTermString("") });
        }
        Struct voice = new Struct("voice", next, current);
        return voice;
    }
    return new Struct(name);
}
Also used : Term(alice.tuprolog.Term) Struct(alice.tuprolog.Struct)

Aggregations

Struct (alice.tuprolog.Struct)9 Term (alice.tuprolog.Term)6 Var (alice.tuprolog.Var)4 NoSolutionException (alice.tuprolog.NoSolutionException)2 SolveInfo (alice.tuprolog.SolveInfo)2 Theory (alice.tuprolog.Theory)2 InvalidTheoryException (alice.tuprolog.InvalidTheoryException)1 Number (alice.tuprolog.Number)1 NumberTerm (alice.tuprolog.NumberTerm)1 Iterables (com.google.common.collect.Iterables)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 TODO (jcog.TODO)1 Util (jcog.Util)1 nars.$ (nars.$)1 Op (nars.Op)1