public void test_Screwed1a() throws ReSyntaxException, CompileDfaException, java.io.IOException {
   Nfa nfa = new Nfa("[XY](!A|M)", new Printf(true, "[%1]", 0));
   DfaRun r = new DfaRun(nfa.compile(DfaRun.UNMATCHED_DROP));
   // the buggy code will throw an Error here
   String s = r.filter("XA");
   assertEquals("[A]", s);
 }
 public void test_Challenge2a()
     throws ReSyntaxException, CompileDfaException, java.io.IOException {
   Nfa nfa = new Nfa(Nfa.NOTHING);
   nfa.or("((!([a-z]*))abc)!x", new Printf(true, "[%1]", 0));
   Dfa dfa = nfa.compile(DfaRun.UNMATCHED_DROP);
   String s;
   s = dfa.createRun().filter("#zzzabcx--");
   assertEquals("[zzzabc]", s);
 }
 // exhibit problems with early implementations which picked up too
 // much to easily
 //   public void test_Challenge1()
 //     throws ReSyntaxException, CompileDfaException, java.io.IOException {
 //     Nfa nfa = new Nfa(Nfa.NOTHING);
 //     nfa.or("([a-z]+)@1@ *([0-9]*)@2@ *([a-z]+)@3@",
 // 	   new Printf(true, "[%1] [%2] [%3]", 0));
 //     Dfa dfa = nfa.compile();
 //     String s;
 //     s = dfa.createRun(DfaRun.UNMATCHED_DROP).filter("a 99 c");
 //     assertEquals("[a] [99] [c]", s);
 //   }
 public void test_Challenge1a()
     throws ReSyntaxException, CompileDfaException, java.io.IOException {
   Nfa nfa = new Nfa(Nfa.NOTHING);
   nfa.or("(!([a-z]+)) *(!([0-9]*)) *(!([a-z]+))", new Printf(true, "[%1] [%2] [%3]", 0));
   Dfa dfa = nfa.compile(DfaRun.UNMATCHED_DROP);
   String s;
   s = dfa.createRun().filter("a 99 c");
   assertEquals("[a] [99] [c]", s);
 }
  //     Dfa dfa = nfa.compile();
  //     String s;
  //     s = dfa.createRun(DfaRun.UNMATCHED_DROP).filter("..cat=1bcat=2bWRONG..");
  //     assertEquals("cat=1b", s);
  //   }
  public void test_Or3a() throws ReSyntaxException, CompileDfaException, java.io.IOException {
    Nfa nfa = new Nfa(Nfa.NOTHING);
    nfa.or("(!(cat=1b)+)cat=2b(!WRONG)", new Printf(true, "%1", 0));

    Dfa dfa = nfa.compile(DfaRun.UNMATCHED_DROP);
    String s;
    s = dfa.createRun().filter("..cat=1bcat=2bWRONG..");
    assertEquals("cat=1b", s);
  }
Esempio n. 5
0
  public JSONWriter(final Corpus corpus) throws NejiException {
    super();
    this.corpus = corpus;
    this.sentenceCounter = 0;
    this.offset = 0;
    this.json = new ArrayList<JSONSentence>();

    try {
      Nfa nfa = new Nfa(Nfa.NOTHING);
      nfa.or(Xml.GoofedElement("s"), end_sentence);
      setNFA(nfa, DfaRun.UNMATCHED_COPY, eof);
    } catch (ReSyntaxException ex) {
      throw new NejiException(ex);
    }
  }
Esempio n. 6
0
 protected void draw(Digraph result, Nfa<STATE> nfa) {
   for (STATE s : new NfaUtil().collect(nfa)) {
     result.add(create(result, nfa, s));
     for (STATE f : nfa.getFollowers(s)) result.add(create(result, nfa, s, f));
   }
 }
Esempio n. 7
0
 protected Node create(Digraph result, Nfa<STATE> nfa, STATE state) {
   Node n = new Node(state, stateToString(nfa, state));
   if (state == nfa.getStart() || state == nfa.getStop()) n.setShape("point");
   return n;
 }