当前位置: 首页>>代码示例>>Java>>正文


Java RegExp.toAutomaton方法代码示例

本文整理汇总了Java中dk.brics.automaton.RegExp.toAutomaton方法的典型用法代码示例。如果您正苦于以下问题:Java RegExp.toAutomaton方法的具体用法?Java RegExp.toAutomaton怎么用?Java RegExp.toAutomaton使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dk.brics.automaton.RegExp的用法示例。


在下文中一共展示了RegExp.toAutomaton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compareRexpAutomaton

import dk.brics.automaton.RegExp; //导入方法依赖的package包/类
private boolean compareRexpAutomaton(Automaton a0) {
    LOGGER.debug("old Automaton:" + a0.toDot());
    LOGGER.debug("is det" + a0.isDeterministic());
    String s0 = Autorex.getRegexFromAutomaton(a0);
    LOGGER.debug("Regexp 1 " + s0);
    RegExp r0new = new RegExp(s0);
    Automaton a0new = r0new.toAutomaton();
    LOGGER.debug("new Automaton:" + a0new.toDot());
    return a0new.equals(a0);
}
 
开发者ID:julianthome,项目名称:autorex,代码行数:11,代码来源:TestStateElimination.java

示例2: testTransformation

import dk.brics.automaton.RegExp; //导入方法依赖的package包/类
@Test
public void testTransformation() {
    Automaton a = new RegExp("(abc)+[0-9]{1,3}[dg]*").toAutomaton();
    Automaton b = new RegExp("12345678").toAutomaton();
    Automaton c = new RegExp(".{0,5}").toAutomaton();

    Automaton d = a.union(b).intersection(c);

    String s0 = Autorex.getRegexFromAutomaton(d);
    LOGGER.debug("Regex String: {}", s0);
    RegExp r0new = new RegExp(s0);
    Automaton a0new = r0new.toAutomaton();
    Assert.assertTrue(a0new.equals(d));
}
 
开发者ID:julianthome,项目名称:autorex,代码行数:15,代码来源:TestStateElimination.java

示例3: matchesBrics

import dk.brics.automaton.RegExp; //导入方法依赖的package包/类
@NotNull
public StringPattern matchesBrics(@NonNls @NotNull final String s) {
  final String escaped = StringUtil.escapeToRegexp(s);
  if (escaped.equals(s)) {
    return equalTo(s);
  }

  StringBuilder sb = new StringBuilder(s.length()*5);
  for (int i = 0; i < s.length(); i++) {
    final char c = s.charAt(i);
    if(c == ' ') {
      sb.append("<whitespacechar>");
    }
    else
    //This is really stupid and inconvenient builder - it breaks any normal pattern with uppercase
    if(Character.isUpperCase(c)) {
      sb.append('[').append(Character.toUpperCase(c)).append(Character.toLowerCase(c)).append(']');
    }
    else
    {
      sb.append(c);
    }
  }
  final RegExp regExp = new RegExp(sb.toString());
  final Automaton automaton = regExp.toAutomaton(new DatatypesAutomatonProvider());
  final RunAutomaton runAutomaton = new RunAutomaton(automaton, true);

  return with(new ValuePatternCondition<String>("matchesBrics") {
    @Override
    public boolean accepts(@NotNull String str, final ProcessingContext context) {
      if (!str.isEmpty() && (str.charAt(0) == '"' || str.charAt(0) == '\'')) str = str.substring(1);
      return runAutomaton.run(str);
    }

    @Override
    public Collection<String> getValues() {
      return Collections.singleton(s);
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:41,代码来源:StringPattern.java

示例4: internalCompile

import dk.brics.automaton.RegExp; //导入方法依赖的package包/类
private Automaton internalCompile() {
    Automaton am = m_automaton;
    if (am == null) {
        RegExp re = new RegExp(getRegexp());
        am = re.toAutomaton(true);
        am.minimize();
        m_automaton = am;
    }
    return am;
}
 
开发者ID:clidev,项目名称:spike.x,代码行数:11,代码来源:Pattern.java

示例5: main

import dk.brics.automaton.RegExp; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {
	RegExp regExp = new RegExp(PATTERN);
	Pattern pattern = Pattern.compile(PATTERN);
	Automaton automaton = regExp.toAutomaton();
	RunAutomaton runAutomaton = new RunAutomaton(automaton);

	long start = System.currentTimeMillis();
	for (int i = 0; i < NUMBER_LOOPS; i++) {
		runAutomaton.run(string);
	}
	System.out.println("Run automaton : " + (System.currentTimeMillis() - start));

	start = System.currentTimeMillis();
	for (int i = 0; i < NUMBER_LOOPS; i++) {
		Matcher matcher = pattern.matcher(string);
		matcher.matches();
	}
	System.out.println("Pattern : " + (System.currentTimeMillis() - start));
}
 
开发者ID:ModelWriter,项目名称:Source,代码行数:23,代码来源:Main.java

示例6: create

import dk.brics.automaton.RegExp; //导入方法依赖的package包/类
@Override
public Regex create(String pattern) {
    RegExp regexpr = new RegExp(pattern);
    Automaton auto = regexpr.toAutomaton();
    RunAutomaton runauto = new RunAutomaton(auto, true);

    return new Regex() {
        @Override
        public boolean containsMatch(String string) {
            return runauto.run(string);
        }
    };
}
 
开发者ID:gpanther,项目名称:regex-libraries-benchmarks,代码行数:14,代码来源:DkBricsAutomatonRegexFactory.java

示例7: main

import dk.brics.automaton.RegExp; //导入方法依赖的package包/类
public static void main(String[] args) {
    RegExp r = new RegExp("\"hello\" \"world\"", RegExp.ALL);
    Automaton a = r.toAutomaton();
    a.minimize();
    a.prefixClose();
    System.out.println(a.toDot());
}
 
开发者ID:zhihan,项目名称:janala2-gradle,代码行数:8,代码来源:MyRegexp.java

示例8: getRegexpFormulaString

import dk.brics.automaton.RegExp; //导入方法依赖的package包/类
public static Constraint getRegexpFormulaString(String regexp, String prefix, int length) {
  RegExp r = new RegExp(regexp);
  Automaton a = r.toAutomaton();
  length--;
  if (length == -1) {
    if (a.getInitialState().isAccept()) {
      return SymbolicTrueConstraint.instance;
    } else {
      return SymbolicFalseConstraint.instance;
    }
  } else {
    return createFormula(a, prefix, length);
  }
}
 
开发者ID:zhihan,项目名称:janala2-gradle,代码行数:15,代码来源:RegexpEncoder.java

示例9: getLengthFormulaString

import dk.brics.automaton.RegExp; //导入方法依赖的package包/类
public static Constraint getLengthFormulaString(
    String regexp, String prefix, int sym, boolean accept) {
  RegExp r = new RegExp(regexp);
  Automaton a = r.toAutomaton();
  String example = a.getShortestExample(accept);
  if (example != null)
    return intCompare(
        prefix, sym, example.length(), COMPARISON_OPS.GE);
  else return intCompare(prefix, sym, 0, COMPARISON_OPS.GE);
}
 
开发者ID:zhihan,项目名称:janala2-gradle,代码行数:11,代码来源:RegexpEncoder.java

示例10: matchesBrics

import dk.brics.automaton.RegExp; //导入方法依赖的package包/类
@NotNull
public StringPattern matchesBrics(@NonNls @NotNull final String s) {
  final String escaped = StringUtil.escapeToRegexp(s);
  if (escaped.equals(s)) {
    return equalTo(s);
  }

  StringBuilder sb = new StringBuilder(s.length()*5);
  for (int i = 0; i < s.length(); i++) {
    final char c = s.charAt(i);
    if(c == ' ') {
      sb.append("<whitespace>");
    }
    else
    //This is really stupid and inconvenient builder - it breaks any normal pattern with uppercase
    if(Character.isUpperCase(c)) {
      sb.append('[').append(Character.toUpperCase(c)).append(Character.toLowerCase(c)).append(']');
    }
    else
    {
      sb.append(c);
    }
  }
  final RegExp regExp = new RegExp(sb.toString());
  final Automaton automaton = regExp.toAutomaton(new DatatypesAutomatonProvider());
  final RunAutomaton runAutomaton = new RunAutomaton(automaton, true);

  return with(new ValuePatternCondition<String>("matchesBrics") {
    @Override
    public boolean accepts(@NotNull String str, final ProcessingContext context) {
      if (!str.isEmpty() && (str.charAt(0) == '"' || str.charAt(0) == '\'')) str = str.substring(1);
      return runAutomaton.run(str);
    }

    @Override
    public Collection<String> getValues() {
      return Collections.singleton(s);
    }
  });
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:41,代码来源:StringPattern.java

示例11: testAutomatonWithUnicode

import dk.brics.automaton.RegExp; //导入方法依赖的package包/类
@Test
public void testAutomatonWithUnicode() {
    final RegExp regexp = new RegExp("([0-9]{2,4}年)?[0-9]{1,2}月[0-9]{1,2}日");
    final Automaton forwardAutomaton = regexp.toAutomaton();
    {
        final RunAutomaton runAutomaton = new RunAutomaton(forwardAutomaton);
        Assert.assertTrue(runAutomaton.run("1982年9月17日"));
        Assert.assertFalse(runAutomaton.run("1982年9月127日"));
    }
}
 
开发者ID:fulmicoton,项目名称:multiregexp,代码行数:11,代码来源:UnicodeTest.java

示例12: matchesBrics

import dk.brics.automaton.RegExp; //导入方法依赖的package包/类
@Nonnull
public StringPattern matchesBrics(@NonNls @Nonnull final String s) {
  final String escaped = StringUtil.escapeToRegexp(s);
  if (escaped.equals(s)) {
    return equalTo(s);
  }

  StringBuilder sb = new StringBuilder(s.length()*5);
  for (int i = 0; i < s.length(); i++) {
    final char c = s.charAt(i);
    if(c == ' ') {
      sb.append("<whitespace>");
    }
    else
    //This is really stupid and inconvenient builder - it breaks any normal pattern with uppercase
    if(Character.isUpperCase(c)) {
      sb.append('[').append(Character.toUpperCase(c)).append(Character.toLowerCase(c)).append(']');
    }
    else
    {
      sb.append(c);
    }
  }
  final RegExp regExp = new RegExp(sb.toString());
  final Automaton automaton = regExp.toAutomaton(new DatatypesAutomatonProvider());
  final RunAutomaton runAutomaton = new RunAutomaton(automaton, true);

  return with(new ValuePatternCondition<String>("matchesBrics") {
    @Override
    public boolean accepts(@Nonnull String str, final ProcessingContext context) {
      if (!str.isEmpty() && (str.charAt(0) == '"' || str.charAt(0) == '\'')) str = str.substring(1);
      return runAutomaton.run(str);
    }

    @Override
    public Collection<String> getValues() {
      return Collections.singleton(s);
    }
  });
}
 
开发者ID:consulo,项目名称:consulo,代码行数:41,代码来源:StringPattern.java

示例13: generate

import dk.brics.automaton.RegExp; //导入方法依赖的package包/类
@Override
protected RunAutomaton generate(String i) {
    RegExp r = new RegExp(i);
    return new RunAutomaton(r.toAutomaton());
}
 
开发者ID:fbacchella,项目名称:RegexPerf,代码行数:6,代码来源:State_dk_brics_automaton.java

示例14: setRegEx

import dk.brics.automaton.RegExp; //导入方法依赖的package包/类
public void setRegEx(String regex)
{
	_regex = regex;
	RegExp re = new RegExp(regex);
	_ra = new RunAutomaton(re.toAutomaton());
}
 
开发者ID:yajsw,项目名称:yajsw,代码行数:7,代码来源:MyPattern.java

示例15: compareRexp

import dk.brics.automaton.RegExp; //导入方法依赖的package包/类
private boolean compareRexp(String rexp) {
    LOGGER.debug("TEST " + rexp);
    RegExp r0 = new RegExp(rexp);
    Automaton a0 = r0.toAutomaton();
    return compareRexpAutomaton(a0);
}
 
开发者ID:julianthome,项目名称:autorex,代码行数:7,代码来源:TestStateElimination.java


注:本文中的dk.brics.automaton.RegExp.toAutomaton方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。