use of alice.tuprolog.InvalidTheoryException 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.InvalidTheoryException in project narchy by automenta.
the class ProNALTest method test1.
@Test
public void test1() throws InvalidTheoryException, Narsese.NarseseException, IOException, URISyntaxException {
// Theory t = Theory.string(
// "add(0,X,X).",
// "add(s(X),Y,s(Z)):-add(X,Y,Z).\n",
// "goal(R):-add(s(s(0)),s(s(0)),R)."
// );
Theory t = Theory.resource("../../../resources/prolog/furniture.pl");
Param.DEBUG = true;
NAR n = NARS.tmp(6);
n.questPriDefault.set(1f);
n.beliefPriDefault.set(0.5f);
// n.log();
Set<String> answers = new TreeSet();
for (nars.term.Term xx : PrologToNAL.N(t)) {
if (Op.functor(xx, (xt) -> xt.equals(PrologToNAL.QUESTION_GOAL) ? xt : null) != null) {
Term qTerm = Operator.args(xx).sub(0).normalize();
// n.question(q);
n.question(qTerm, ETERNAL, (q, a) -> {
if (answers.add(a.term().toString())) {
System.err.println(q + " " + a);
System.err.println(a.proof());
}
/*else {
System.err.println("dup");
}*/
});
} else {
n.believe(xx.normalize());
}
}
n.run(2500);
// ?- made_of(your_chair,X), colour(X,Colour).
assertTrue(answers.contains("(colour(wood,brown)&&made_of(your_chair,wood))"));
// n.concepts().forEach(c -> {
// c.print();
// });
/*
[0] *** ANSWER=goal(s(s(s(s(0)))))
TOTAL ANSWERS=1
*/
}
use of alice.tuprolog.InvalidTheoryException in project narchy by automenta.
the class PrologCoreTest method testPrologShell.
@Test
public void testPrologShell() throws MalformedGoalException {
NAR n = NARS.tmp();
PrologCore p = new PrologCore(n);
try {
p.input(new Theory(PrologCoreTest.class.getClassLoader().getResource("shell.prolog").openStream()));
} catch (InvalidTheoryException | IOException e) {
e.printStackTrace();
}
p.solve("do(help).");
}
Aggregations