Package dk.brics.automaton

Examples of dk.brics.automaton.Automaton


            Set<State> tmp = queue;
            queue = queue2;
            queue2 = tmp;
        }
       
        Automaton result = new Automaton();
        State initial = result.getInitialState();
        State accept = new State();
        accept.setAccept(true);
       
        Set<State> live = a.getLiveStates();
        for (State state : queue) {
            for (Transition t : state.getTransitions()) {
                if (live.contains(t.getDest())) {
                    initial.addTransition(new Transition(t.getMin(), t.getMax(), accept));
                }
            }
        }
       
        // boilerplate stuff
        result.restoreInvariant();
        result.reduce();
        result.determinize();
        result.minimize();
       
        return result;
    }
View Full Code Here


     * @param a input automaton
     * @return resulting automaton
     */
    @Override
    public Automaton op(Automaton a) {
        Automaton b = a.clone();
        State pad = new State();
        pad.setAccept(true);
        pad.addTransition(new Transition('\u0000', pad));
        Set<StatePair> epsilons = new HashSet<StatePair>();
        for (State s : b.getStates()) {
            if (s.isAccept()) {
                epsilons.add(new StatePair(s, pad));
            } else {
                s.setAccept(true);
            }
        }
        b.setDeterministic(false);
        b.addEpsilons(epsilons);
        b.minimize();
        return b;
    }
View Full Code Here

    @Override
    public Automaton op(Automaton a) {
      if (searchFor.length() == 0)
        return emptyStringOp(a);
     
      Automaton result = a.clone();
     
      assert result.isDeterministic();
     
      List<ConstrainedEpsilon> epsilons = new LinkedList<ConstrainedEpsilon>();
      List<StateTransitionPair> killedTransitions = new LinkedList<StateTransitionPair>();
      List<StateTransitionPair> newTransitions = new LinkedList<StateTransitionPair>();
      String ghostString = searchFor.substring(0, searchFor.length() - 1);
     
      for (State origin : result.getStates()) {
        LinkedList<State> path = getPath(origin, searchFor);
       
        if (path == null)
          continue;
       
        // create a path to read the replacement string
        LinkedList<State> replacement = makeString(replaceBy);
       
        // create a path to read part of the search string, in case
        // only a prefix of the search string occurred
        LinkedList<State> ghost = makeString(ghostString);
       
        // connect to replacement string (head and tail)
        epsilons.add(new ConstrainedEpsilon(origin, replacement.getFirst()));
        epsilons.add(new ConstrainedEpsilon(replacement.getLast(), path.getLast()));
       
        // set accept states of first and last
        if (origin.isAccept()) {
          replacement.getFirst().setAccept(true);
          ghost.getFirst().setAccept(true);
        }
        if (path.getLast().isAccept()) {
          replacement.getLast().setAccept(true);
        }
       
        // connect to ghost string (head)
        epsilons.add(new ConstrainedEpsilon(origin, ghost.getFirst()));
       
        // connect to successive states in the ghost state,
        // and set accept states in the ghost
        Iterator<State> pathIt = path.iterator();
        Iterator<State> ghostIt = ghost.iterator();
        ghostIt.next(); // skip the initial state in the ghost path
        int index = 1;
        while (ghostIt.hasNext()) {
          assert pathIt.hasNext();
          State pathState = pathIt.next();
          State ghostState = ghostIt.next();
         
          // add an epsilon transition, but disallow reading the next
          // character from the search string if it is followed
          epsilons.add(new ConstrainedEpsilon(ghostState, pathState, searchFor.charAt(index)));
         
          // set accept state
          if (pathState.isAccept()) {
            ghostState.setAccept(true);
          }
         
          // next char in search string
          index++;
        }
       
        // remove the transition with the first character of
        // the search string from the origin state
        char first = searchFor.charAt(0);
        for (Transition tr : origin.getTransitions()) {
          if (tr.getMin() <= first && tr.getMax() >= first) {
            killedTransitions.add(new StateTransitionPair(origin, tr));
           
            // add back the remaining characters from the interval
            if (tr.getMin() < first) {
              newTransitions.add(new StateTransitionPair(origin, new Transition(tr.getMin(), (char)(first-1), tr.getDest())));
            }
            if (tr.getMax() > first) {
              newTransitions.add(new StateTransitionPair(origin, new Transition((char)(first+1), tr.getMax(), tr.getDest())));
            }
          }
        }
      }
     
      // apply the first character removal first
      for (StateTransitionPair pair : killedTransitions) {
        pair.state.getTransitions().remove(pair.transition);
      }
      for (StateTransitionPair pair : newTransitions) {
        pair.state.addTransition(pair.transition);
      }
     
      // apply epsilons
      addConstrainedEpsilons(result, epsilons);
      result.reduce();
      result.minimize();
     
      return result;
    }
View Full Code Here

     * as suffix)
     * @param a input automaton. Will not be modified.
     * @return new automaton
     */
    private Automaton emptyStringOp(Automaton a) {
      Automaton result = a.clone();
     
      for (State state : result.getStates()) {
        LinkedList<State> insert = makeString(replaceBy);
        insert.getLast().getTransitions().addAll(state.getTransitions());
        state.getTransitions().clear();
        state.getTransitions().addAll(insert.getFirst().getTransitions());
       
View Full Code Here

        return s;
    }
   
    @Override
    public Automaton op(Automaton a) {
        Automaton result = Automaton.makeEmpty();
        if (a.run("" + FALSE))
            result = result.union(Automaton.makeString("false"));
        if (a.run("" + TRUE))
            result = result.union(Automaton.makeString("true"));
        return result;
    }
View Full Code Here

     * @param a input automaton
     * @return resulting automaton
     */
    @Override
    public Automaton op(Automaton a) {
        Automaton a1 = a.clone();
        Map<State, State> map = new HashMap<State, State>();
        Set<State> a1s = a1.getStates();
        for (State s : a1s) {
            State p = new State();
            map.put(s, p);
            if (s.isAccept()) {
                p.setAccept(true);
                s.setAccept(false);
            }
        }
        for (State s : a1s) {
            State p = map.get(s);
            for (Transition t : s.getTransitions()) {
                p.addTransition(new Transition(t.getMin(), t.getMax(), map.get(t.getDest())));
            }
        }
        a1.setDeterministic(false);
        Set<StatePair> epsilons = new HashSet<StatePair>();
        for (State s : a1s) {
            Set<State> reachable = Basic.findReachableStates(map.get(s));
            for (State p : reachable) {
                epsilons.add(new StatePair(s, p));
            }
        }
        a1.addEpsilons(epsilons);
        a1.minimize();
        return a1;
    }
View Full Code Here

     * @param a input automaton
     * @return resulting automaton
     */
    @Override
    public Automaton op(Automaton a) {
        Automaton b = a.clone();
        for (State s : b.getStates()) {
            Set<Transition> transitions = s.getTransitions();
            for (Transition t : new ArrayList<Transition>(transitions)) {
                State dest = t.getDest();
                transitions.add(new Transition(d, dest));
            }
        }
        b.setDeterministic(false);
        b.reduce();
        b.minimize();
        return b;
    }
View Full Code Here

     * @param a input automaton
     * @return resulting automaton
     */
    @Override
    public Automaton op(Automaton a) {
        Automaton a1 = a.clone();
        Map<State, State> map = new HashMap<State, State>();
        Set<State> a1s = a1.getStates();
        for (State s : a1s) {
            State p = new State();
            map.put(s, p);
            if (s.isAccept()) {
                p.setAccept(true);
                s.setAccept(false);
            }
        }
        for (State s : a1s) {
            State p = map.get(s);
            for (Transition t : s.getTransitions()) {
                p.addTransition(new Transition(t.getMin(), t.getMax(), map.get(t.getDest())));
            }
        }
        a1.setDeterministic(false);
        Set<StatePair> epsilons = new HashSet<StatePair>();
        for (State s : a1s) {
            for (Transition t : map.get(s).getTransitions()) {
                epsilons.add(new StatePair(s, t.getDest()));
            }
        }
        a1.addEpsilons(epsilons);
        a1.minimize();
        return a1;
    }
View Full Code Here

     * @param a input automaton
     * @return resulting automaton
     */
    @Override
    public Automaton op(Automaton a) {
        Automaton b = a.clone();
        for (State s : b.getStates()) {
            Set<Transition> transitions = s.getTransitions();
            for (Transition t : new ArrayList<Transition>(transitions)) {
                char min = t.getMin();
                char max = t.getMax();
                State dest = t.getDest();
                if (min != Character.MIN_VALUE || max != Character.MAX_VALUE) {
                    transitions.remove(t);
                    for (int c = min; c <= max; c++) {
                        transitions.add(new Transition(Character.toLowerCase((char) c), dest));
                    }
                }
            }
        }
        b.setDeterministic(false);
        b.reduce();
        b.minimize();
        return b;
    }
View Full Code Here

        return a1;
    }
   
    @Override
    public Automaton op(Automaton a1, Automaton a2) {
        Automaton x = Automaton.makeAnyString().concatenate(a2).concatenate(Automaton.makeAnyString());
        return a1.intersection(x);
    }
View Full Code Here

TOP

Related Classes of dk.brics.automaton.Automaton

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.