本文整理汇总了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);
}
示例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));
}
示例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);
}
});
}
示例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;
}
示例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));
}
示例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);
}
};
}
示例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());
}
示例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);
}
}
示例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);
}
示例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);
}
});
}
示例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日"));
}
}
示例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);
}
});
}
示例13: generate
import dk.brics.automaton.RegExp; //导入方法依赖的package包/类
@Override
protected RunAutomaton generate(String i) {
RegExp r = new RegExp(i);
return new RunAutomaton(r.toAutomaton());
}
示例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());
}
示例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);
}