Package dk.brics.automaton

Examples of dk.brics.automaton.Automaton


    private RunAutomaton runauto = null;
   
    public CompiledAutomaton( String rhsPattern ) {
        RegExp regexpr = new dk.brics.automaton.RegExp(rhsPattern);
        Automaton auto = regexpr.toAutomaton();
        this.runauto = new RunAutomaton(auto, true);
    }
View Full Code Here


*/
public class AutomatonOperation {


    public static Automaton makeAcceptAllOfLength(int length, int[] alphabet) {
        Automaton auto = new Automaton();
        State start = new State();
        State tmp = start;
        State last = start;

        for (int i = 0; i < length; i++) {
            last = new State();
            for (int k : alphabet) {
                tmp.addTransition(new Transition(FiniteAutomaton.getCharFromInt(k), last));
            }
            tmp = last;

        }
        last.setAccept(true);
        auto.setInitialState(start);
        return auto;
    }
View Full Code Here

        registerPatternDatatype(XSD_NS+"NCName");
        registerPatternDatatype(XSD_NS+"NMTOKEN");
        registerPatternDatatype(XSD_NS+"language");
    }
    protected static void registerPatternDatatype(String datatypeURI) {
        Automaton automaton=RDFPlainLiteralPatternValueSpaceSubset.getDatatypeAutomaton(datatypeURI);
        s_subsetsByDatatype.put(datatypeURI,new RDFPlainLiteralPatternValueSpaceSubset(automaton));
    }
View Full Code Here

        String datatypeURI=datatypeRestriction.getDatatypeURI();
        assert s_subsetsByDatatype.containsKey(datatypeURI);
        if (datatypeRestriction.getNumberOfFacetRestrictions()==0)
            return s_subsetsByDatatype.get(datatypeURI);
        else if (needsAutomatons(datatypeRestriction)) {
            Automaton automaton=getAutomatonFor(datatypeRestriction);
            if (automaton==null)
                return EMPTY_SUBSET;
            else
                return new RDFPlainLiteralPatternValueSpaceSubset(automaton);
        }
View Full Code Here

        String datatypeURI=datatypeRestriction.getDatatypeURI();
        assert s_subsetsByDatatype.containsKey(datatypeURI);
        if (valueSpaceSubset==EMPTY_SUBSET)
            return EMPTY_SUBSET;
        else if ((valueSpaceSubset instanceof RDFPlainLiteralPatternValueSpaceSubset) || needsAutomatons(datatypeRestriction)) {
            Automaton restrictionAutomaton=getAutomatonFor(datatypeRestriction);
            if (restrictionAutomaton==null)
                return EMPTY_SUBSET;
            Automaton valueSpaceSubsetAutomaton=getAutomatonFor(valueSpaceSubset);
            if (valueSpaceSubsetAutomaton==null)
                return EMPTY_SUBSET;
            Automaton intersection=valueSpaceSubsetAutomaton.intersection(restrictionAutomaton);
            if (intersection.isEmpty())
                return EMPTY_SUBSET;
            else
                return new RDFPlainLiteralPatternValueSpaceSubset(intersection);
        }
        else {
View Full Code Here

        String datatypeURI=datatypeRestriction.getDatatypeURI();
        assert s_subsetsByDatatype.containsKey(datatypeURI);
        if (valueSpaceSubset==EMPTY_SUBSET)
            return EMPTY_SUBSET;
        else if ((valueSpaceSubset instanceof RDFPlainLiteralPatternValueSpaceSubset) || needsAutomatons(datatypeRestriction)) {
            Automaton restrictionAutomaton=getAutomatonFor(datatypeRestriction);
            if (restrictionAutomaton==null)
                return valueSpaceSubset;
            Automaton valueSpaceSubsetAutomaton=getAutomatonFor(valueSpaceSubset);
            if (valueSpaceSubsetAutomaton==null)
                return EMPTY_SUBSET;
            Automaton difference=valueSpaceSubsetAutomaton.minus(restrictionAutomaton);
            if (difference.isEmpty())
                return EMPTY_SUBSET;
            else
                return new RDFPlainLiteralPatternValueSpaceSubset(difference);
        }
        else {
View Full Code Here

        else
            return RDFPlainLiteralPatternValueSpaceSubset.toAutomaton((RDFPlainLiteralLengthValueSpaceSubset)valueSpaceSubset);
    }
    protected Automaton getAutomatonFor(DatatypeRestriction datatypeRestriction) {
        String datatypeURI=datatypeRestriction.getDatatypeURI();
        Automaton automaton=RDFPlainLiteralPatternValueSpaceSubset.getDatatypeAutomaton(datatypeURI);
        int minLength=0;
        int maxLength=Integer.MAX_VALUE;
        for (int index=datatypeRestriction.getNumberOfFacetRestrictions()-1;index>=0;--index) {
            String facetURI=datatypeRestriction.getFacetURI(index);
            Object facetDataValue=datatypeRestriction.getFacetValue(index).getDataValue();
            if ((XSD_NS+"minLength").equals(facetURI))
                minLength=Math.max(minLength,(Integer)facetDataValue);
            else if ((XSD_NS+"maxLength").equals(facetURI))
                maxLength=Math.min(maxLength,(Integer)facetDataValue);
            else if ((XSD_NS+"length").equals(facetURI)) {
                minLength=Math.max(minLength,(Integer)facetDataValue);
                maxLength=Math.min(maxLength,(Integer)facetDataValue);
            }
            else if ((XSD_NS+"pattern").equals(facetURI)) {
                String pattern=(String)facetDataValue;
                Automaton facetAutomaton=RDFPlainLiteralPatternValueSpaceSubset.getPatternAutomaton(pattern);
                automaton=automaton.intersection(facetAutomaton);
            }
            else if ((RDF_NS+"langRange").equals(facetURI)) {
                String languageRange=(String)facetDataValue;
                Automaton languageRangeAutomaton=RDFPlainLiteralPatternValueSpaceSubset.getLanguageRangeAutomaton(languageRange);
                automaton=automaton.intersection(languageRangeAutomaton);
            }
            else
                throw new UnsupportedFacetException("Facet with URI '"+facetURI+"' not supported on '"+datatypeURI+"'.");
        }
View Full Code Here

        buffer.append('}');
        return buffer.toString();
    }
    public static Automaton toAutomaton(RDFPlainLiteralLengthValueSpaceSubset valueSpaceSubset) {
        List<RDFPlainLiteralLengthInterval> intervals=valueSpaceSubset.m_intervals;
        Automaton result=null;
        for (int intervalIndex=intervals.size()-1;intervalIndex>=0;--intervalIndex) {
            RDFPlainLiteralLengthInterval interval=intervals.get(intervalIndex);
            Automaton stringPart;
            if (interval.m_maxLength==Integer.MAX_VALUE) {
                if (interval.m_minLength==0)
                    stringPart=s_anyString;
                else
                    stringPart=s_anyString.intersection(BasicOperations.repeat(s_anyChar,interval.m_minLength));
            }
            else
                stringPart=s_anyString.intersection(BasicOperations.repeat(s_anyChar,interval.m_minLength,interval.m_maxLength));
            Automaton intervalAutomaton;
            if (interval.m_languageTagMode==RDFPlainLiteralLengthInterval.LanguageTagMode.ABSENT)
                intervalAutomaton=stringPart.concatenate(s_emptyLangTag);
            else
                intervalAutomaton=stringPart.concatenate(s_nonemptyLangTag);
            if (result==null)
View Full Code Here

        }
        return result;
    }
    public static Automaton toAutomaton(int minLength,int maxLength) {
        assert minLength<=maxLength;
        Automaton stringPart;
        if (maxLength==Integer.MAX_VALUE) {
            if (minLength==0)
                stringPart=s_anyString;
            else
                stringPart=s_anyString.intersection(BasicOperations.repeat(s_anyChar,minLength));
        }
        else
            stringPart=s_anyString.intersection(BasicOperations.repeat(s_anyChar,minLength,maxLength));
        return stringPart.concatenate(s_anyLangTag);
    }
View Full Code Here

        catch (IllegalArgumentException e) {
            return false;
        }
    }
    public static Automaton getPatternAutomaton(String pattern) {
        Automaton stringPart=new RegExp(pattern).toAutomaton();
        return stringPart.concatenate(s_anyLangTag);
    }
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.