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;
}
}
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));
}
}
}
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);
}
}
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;
}
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);
}
Aggregations