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


Java RunAutomaton类代码示例

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


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

示例1: RegexListSearcher

import dk.brics.automaton.RunAutomaton; //导入依赖的package包/类
public RegexListSearcher(String re) {
  if (re.startsWith("^")) {
    re = re.substring(1);
  }

  if (re.endsWith("$") && !re.endsWith("\\$")) {
    re = re.substring(0, re.length() - 1);
  }

  Automaton automaton = new RegExp(re).toAutomaton();
  prefixBegin = automaton.getCommonPrefix();
  prefixLen = prefixBegin.length();

  if (0 < prefixLen) {
    char max = Chars.checkedCast(prefixBegin.charAt(prefixLen - 1) + 1);
    prefixEnd = prefixBegin.substring(0, prefixLen - 1) + max;
    prefixOnly = re.equals(prefixBegin + ".*");
  } else {
    prefixEnd = "";
    prefixOnly = false;
  }

  pattern = prefixOnly ? null : new RunAutomaton(automaton);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:25,代码来源:RegexListSearcher.java

示例2: matchesBrics

import dk.brics.automaton.RunAutomaton; //导入依赖的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

示例3: doSimilaritiesToTextAnnotation

import dk.brics.automaton.RunAutomaton; //导入依赖的package包/类
/**
 * Does the annotation from given similarities to the given text.
 * 
 * @param text
 *            the text to annotate
 * @param runAutomaton
 *            the {@link RunAutomaton} computed from given similarities
 * @param similarities
 *            similarities mapping
 * @return the concept -> similarity type -> positions mapping
 */
private Map<Object, Map<Object, Set<int[]>>> doSimilaritiesToTextAnnotation(String text,
		RunAutomaton runAutomaton, Map<String, Map<Object, Set<Object>>> similarities) {
	final Map<Object, Map<Object, Set<int[]>>> res = new HashMap<Object, Map<Object, Set<int[]>>>();

	final AutomatonMatcher matcher = runAutomaton.newMatcher(text);
	while (matcher.find()) {
		if (isFullWord(text, matcher.start(), matcher.end())) {
			final String foundWord = text.substring(matcher.start(), matcher.end());
			final Map<Object, Set<Object>> similarityMap = similarities.get(foundWord);
			if (similarityMap != null) {
				for (Entry<Object, Set<Object>> entry : similarityMap.entrySet()) {
					final Object similarityType = entry.getKey();
					for (Object concept : entry.getValue()) {
						Map<Object, Set<int[]>> resMap = res.get(concept);
						if (resMap == null) {
							resMap = new LinkedHashMap<Object, Set<int[]>>();
							res.put(concept, resMap);
						}
						Set<int[]> positions = resMap.get(similarityType);
						if (positions == null) {
							positions = new LinkedHashSet<int[]>();
							resMap.put(similarityType, positions);
						}
						positions.add(new int[] {matcher.start(), matcher.end() });
					}
				}
			}
		}
	}

	return res;
}
 
开发者ID:ModelWriter,项目名称:Source,代码行数:44,代码来源:SemanticAnnotator.java

示例4: computeSimilarityAutomaton

import dk.brics.automaton.RunAutomaton; //导入依赖的package包/类
/**
 * Computes the similatiry {@link RunAutomaton} from the given similarities.
 * 
 * @param similarities
 *            the mapping of similarities
 * @return the computed {@link RunAutomaton}
 */
private RunAutomaton computeSimilarityAutomaton(Map<String, Map<Object, Set<Object>>> similarities) {
	Automaton automaton = Automaton.makeEmpty();
	for (String word : similarities.keySet()) {
		automaton = automaton.union(Automaton.makeString(word, false));
	}

	final RunAutomaton runAutomaton = new RunAutomaton(automaton);
	return runAutomaton;
}
 
开发者ID:ModelWriter,项目名称:Source,代码行数:17,代码来源:SemanticAnnotator.java

示例5: main

import dk.brics.automaton.RunAutomaton; //导入依赖的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.RunAutomaton; //导入依赖的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: RegexPredicate

import dk.brics.automaton.RunAutomaton; //导入依赖的package包/类
private RegexPredicate(String regex) throws BadRequestException {
  if (regex.startsWith("^")) {
    regex = regex.substring(1);
    if (regex.endsWith("$") && !regex.endsWith("\\$")) {
      regex = regex.substring(0, regex.length() - 1);
    }
  }
  try {
    a = new RunAutomaton(new RegExp(regex).toAutomaton());
  } catch (IllegalArgumentException e) {
    throw new BadRequestException(e.getMessage());
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:14,代码来源:RefFilter.java

示例8: RegexRefPredicate

import dk.brics.automaton.RunAutomaton; //导入依赖的package包/类
public RegexRefPredicate(String re) {
  super(ChangeField.REF, re);

  if (re.startsWith("^")) {
    re = re.substring(1);
  }

  if (re.endsWith("$") && !re.endsWith("\\$")) {
    re = re.substring(0, re.length() - 1);
  }

  this.pattern = new RunAutomaton(new RegExp(re).toAutomaton());
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:14,代码来源:RegexRefPredicate.java

示例9: RegexProjectPredicate

import dk.brics.automaton.RunAutomaton; //导入依赖的package包/类
public RegexProjectPredicate(String re) {
  super(ChangeField.PROJECT, re);

  if (re.startsWith("^")) {
    re = re.substring(1);
  }

  if (re.endsWith("$") && !re.endsWith("\\$")) {
    re = re.substring(0, re.length() - 1);
  }

  this.pattern = new RunAutomaton(new RegExp(re).toAutomaton());
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:14,代码来源:RegexProjectPredicate.java

示例10: RegexTopicPredicate

import dk.brics.automaton.RunAutomaton; //导入依赖的package包/类
public RegexTopicPredicate(String re) {
  super(EXACT_TOPIC, re);

  if (re.startsWith("^")) {
    re = re.substring(1);
  }

  if (re.endsWith("$") && !re.endsWith("\\$")) {
    re = re.substring(0, re.length() - 1);
  }

  this.pattern = new RunAutomaton(new RegExp(re).toAutomaton());
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:14,代码来源:RegexTopicPredicate.java

示例11: BricsAutomatonManager

import dk.brics.automaton.RunAutomaton; //导入依赖的package包/类
public BricsAutomatonManager(AutomatonCallback callback, String regexes[]) {
    super(callback);
    automata = new RunAutomaton[regexes.length];
    for (int i = 0; i < regexes.length; ++i) {
        automata[i] = new RunAutomaton((new RegExp(regexes[i])).toAutomaton());
    }
}
 
开发者ID:dice-group,项目名称:CoreferenceResolution,代码行数:8,代码来源:BricsAutomatonManager.java

示例12: matchesBrics

import dk.brics.automaton.RunAutomaton; //导入依赖的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

示例13: testAutomatonWithUnicode

import dk.brics.automaton.RunAutomaton; //导入依赖的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

示例14: matchesBrics

import dk.brics.automaton.RunAutomaton; //导入依赖的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

示例15: generate

import dk.brics.automaton.RunAutomaton; //导入依赖的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


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