Package dk.brics.automaton

Examples of dk.brics.automaton.Automaton


     * @param a input automaton
     * @return resulting automaton
     */
    @Override
    public Automaton op(Automaton a) {
        Automaton b = a.clone();
        State initial = new State();
        State accept = new State();
        accept.setAccept(true);
        Set<StatePair> epsilons = new HashSet<StatePair>();
        for (State s : b.getStates()) {
            epsilons.add(new StatePair(initial, s));
            epsilons.add(new StatePair(s, accept));
        }
        b.setInitialState(initial);
        b.addEpsilons(epsilons);
        b.minimize();
        return b;
    }
View Full Code Here


     * @param a input automaton
     * @return resulting automaton
     */
    @Override
    public Automaton op(Automaton a) {
        Automaton b = new Automaton();
        Map<State, State> map = new HashMap<State, State>();
        for (State s : a.getStates()) {
            State ss = new State();
            map.put(s, ss);
        }
        State initial = new State();
        b.setInitialState(initial);
        map.get(a.getInitialState()).setAccept(true);
        Set<StatePair> epsilons = new HashSet<StatePair>();
        for (State s : a.getStates()) {
            State ss = map.get(s);
            if (s.isAccept()) {
                epsilons.add(new StatePair(initial, ss));
            }
            for (Transition t : s.getTransitions()) {
                State pp = map.get(t.getDest());
                pp.addTransition(new Transition(t.getMin(), t.getMax(), ss));
            }
        }
        b.setDeterministic(false);
        b.addEpsilons(epsilons);
        b.minimize();
        return b;
    }
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.remove(t);
                transitions.add(new Transition(Character.MIN_VALUE, Character.MAX_VALUE, 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);
        for (State s : a1s) {
            for (Transition t : map.get(s).getTransitions()) {
                s.addTransition(new Transition(c, t.getDest()));
            }
        }
        a1.minimize();
        return a1;
    }
View Full Code Here

        Set<String> gapNames = getLocalPlugGapNames(st, body);
        if (gapNames.contains(null)) {
            Feedbacks.add(new NonConstantGapName(st, body.getMethod()));
            return null;
        }
        Automaton names = Automaton.makeEmpty();
        for (String string : gapNames) {
            names = names.union(Automaton.makeString(string));
        }
        return new Plugging(st, body.getMethod(), detector.getTypes(), names);
    }
View Full Code Here

        return convert(new MyPatternMatcher(pattern, true));
    }

    private Automaton convert(MyPatternMatcher matcher) {
        Pattern pattern = matcher.getParsedpattern();
        Automaton choices = Automaton.makeEmpty();
        for (ChoicePattern choice : pattern.getChoices()) {
            choices = choices.union(convert(choice));
        }
        return choices;
    }
View Full Code Here

        }
        return choices;
    }

    Automaton convert(ChoicePattern choice) {
        Automaton parts = null;
        final Iterator<PartPattern> iterator = choice.getParts().iterator();
        while (iterator.hasNext()) {
            PartPattern part = iterator.next();
            if (parts == null)
                parts = convert(part);
            else
                parts = parts.concatenate(convert(part));
            boolean hasMoreParts = iterator.hasNext();
            if (hasMoreParts)
                parts = parts.concatenate(Automaton.makeChar('/'));

        }
        if (parts == null)
            throw new IllegalArgumentException(
                    "The ChoicePattern may not be empty!");
View Full Code Here

                    "The ChoicePattern may not be empty!");
        return parts;
    }

    Automaton convert(PartPattern part) {
        Automaton automaton;
        if (part instanceof StarPattern) {
            automaton = anyStringWithoutSlash;
        } else if (part instanceof StarStarPattern) {
            automaton = anyString;
        } else if (part instanceof ConstPattern) {
View Full Code Here

    }

    public URLPatternToAutomatonConverter() {
        this.anyString = Automaton.makeAnyString();
        emptyString = Automaton.makeEmptyString();
        Automaton slash = Automaton.makeChar('/');
        Automaton anyStringWithSlash = anyString.concatenate(slash)
                .concatenate(anyString);
        this.anyStringWithoutSlash = anyStringWithSlash.complement();
    }
View Full Code Here

        String pattern;
        if (urlPattern != null)
            pattern = urlPattern.value();
        else
            pattern = method.getName();
        final Automaton converted = new URLPatternToAutomatonConverter()
                .convert(pattern);

        return converted;
    }
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.