Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
1.7 kB · 49 lines
Java
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950package TemplateCompiler;
import jess.JessException;import jess.Rete;
/** * Drop-in replacement for the game's TemplateCompiler.Preprocessor. * * The original turns a typed line into word facts, which a few thousand Jess * rules then reduce to (DA type char p1 p2 p3) facts; the game's FactListener * turns each DA fact into a DAWME. This version asks Jev for the DA facts and * asserts them directly, so no word facts exist and none of the word rules * fire. Everything downstream of the DA facts is untouched. * * The original class is kept, renamed to PreprocessorRules by the build, and * handles any line the sidecar cannot answer. */public class Preprocessor { public static void initializeReteEngine(Rete rete) throws JessException { PreprocessorRules.initializeReteEngine(rete); }
public static String replaceAll(String s, String find, String replacement) { return PreprocessorRules.replaceAll(s, find, replacement); }
public static void Process(String text, Rete rete) { int[][] acts = JevBridge.classify(text); if (acts == null) { PreprocessorRules.Process(text, rete); return; } try { for (int i = 0; i < acts.length; i++) { rete.executeCommand(daFact(acts[i])); } } catch (JessException failure) { JessExceptionHelper.processJessException(failure); } }
static String daFact(int[] act) { StringBuffer command = new StringBuffer("(assert (DA"); for (int i = 0; i < act.length; i++) { command.append(' ').append(act[i]); } return command.append("))").toString(); }}