The main check method. Tokenizes the text into sentences and matches these
sentences against all currently active rules.

@param text the text to be checked
@return a List of {@link RuleMatch} objects
504358
public List<RuleMatch> check(String text) throws IOException {
    return check(text, true, ParagraphHandling.NORMAL);
  }
1358365
public TextMatchBinding setText(
                    final Collection<String> text
                    )
    {
        if (text == null  ||  text.size() == 0) {
            clearText();
            return this;
        }

        synchronized (text) {
            for (String  pattern : text) {
                if (pattern == null  ||  pattern.length() == 0) {
                    throw new IllegalArgumentException( "null element" );
                }
            }

            clearText();
            for (String  pattern : text) {
                addText( pattern );
            }
        }

        return this;
    }
326220
public static List<Term> segment(String text)
    {
        List<Term> termList = new LinkedList<Term>();
        Matcher matcher = WEB_URL.matcher(text);
        int begin = 0;
        int end;
        while (matcher.find())
        {
            end = matcher.start();
            termList.addAll(SEGMENT.seg(text.substring(begin, end)));
            termList.add(new Term(matcher.group(), Nature.xu));
            begin = matcher.end();
        }
        if (begin < text.length()) termList.addAll(SEGMENT.seg(text.substring(begin)));

        return termList;
    }
744304
public static List<String> getStringsByRegex(final String text, final String regex) {

    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(text);
    List<String> matchedStrings = new ArrayList<String>();
    while (matcher.find()) {
      matchedStrings.add(matcher.group(0));
    }
    return matchedStrings;
  }
145152
public String lookingAt(CharSequence text)
    {
        try
        {
            if (text.length() == 0)
            {
                if (acceptEmpty)
                {
                    return "";
                }
                else
                {
                    throw new SyntaxErrorException("empty string not accepted");
                }
            }
            InputReader reader = Input.getInstance(text);
            return lookingAt(reader);
        }
        catch (IOException ex)
        {
            throw new IllegalArgumentException("can't happen");
        }
    }
1221172
public List<String> tokenize(String text) {
		List<String> tokens = new ArrayList<String>();
		text = text.toLowerCase();
		char[] array = text.toCharArray();
		
		//convert all apostrophes to 0x27
		for(int i = 0; i < array.length; i++) {
			if(isApostrofe(array[i])) array[i] = 0x27;
		}
		
		int pos = 0;
		
		//term cycle
		while(pos < array.length) {
			//scan to the start of the term
			while(pos < array.length  && !Character.isLetterOrDigit(array[pos])) pos++;
			int start = pos;
			if(start == array.length) break;
			//scan to the end of the term
			while(pos < array.length  && isLetterOrDigitOrApostrofe(array[pos])) pos++;
			int newpos = pos;
			while(newpos > start && isApostrofe(array[newpos - 1])) newpos--;
			if(newpos > start) tokens.add(new String(array, start, newpos - start));
		}
		return tokens;
	}
847830
private List<Word> seg(String text){
        if(text == null){
            return Collections.emptyList();
        }
        if(segmentation == null){
            //延迟初始化
            segmentation = SegmentationFactory.getSegmentation(SegmentationAlgorithm.MaxNgramScore);
        }
        List<Word> words = segmentation.seg(text);
        if(filterStopWord) {
            //停用词过滤
            StopWord.filterStopWords(words);
        }
        return words;
    }
1183327
public List<Term> seg(char[] text)
    {
        assert text != null;
        if (HanLP.Config.Normalization)
        {
            CharTable.normalization(text);
        }
        return segSentence(text);
    }
210247
@Override
  public List<String> tokenize(final String text) {
    final List<String> l = new ArrayList<>();
    final StringTokenizer st = new StringTokenizer(text, nlTokenizingChars, true);
    while (st.hasMoreElements()) {
      String token = st.nextToken();
      String origToken = token;
      if (token.length() > 1) {
        if (startsWithQuote(token) && endsWithQuote(token) && token.length() > 2) {
          l.add(token.substring(0, 1));
          l.add(token.substring(1, token.length()-1));
          l.add(token.substring(token.length()-1, token.length()));
        } else if (endsWithQuote(token)) {
          int cnt = 0;
          while (endsWithQuote(token)) {
            token = token.substring(0, token.length() - 1);
            cnt++;
          }
          l.add(token);
          for (int i = origToken.length() - cnt; i < origToken.length(); i++) {
            l.add(origToken.substring(i, i + 1));
          }
        } else if (startsWithQuote(token)) {
          while (startsWithQuote(token)) {
            l.add(token.substring(0, 1));
            token = token.substring(1, token.length());
          }
          l.add(token);
        } else {
          l.add(token);
        }
      } else {
        l.add(token);
      }
    }
    return joinEMailsAndUrls(l);
  }
175398
public String match(String text){
		if(null == text){
			return null;
		}
		List<String> matchAll = matchAll(text, 1);
		if(CollectionUtil.isNotEmpty(matchAll)){
			return matchAll.get(0);
		}
		return null;
	}
184311
public List<RuleMatch> check(AnnotatedText annotatedText, boolean tokenizeText, ParagraphHandling paraMode, RuleMatchListener listener, Mode mode) throws IOException {
    List<String> sentences;
    if (tokenizeText) { 
      sentences = sentenceTokenize(annotatedText.getPlainText());
    } else {
      sentences = new ArrayList<>();
      sentences.add(annotatedText.getPlainText());
    }
    List<Rule> allRules = getAllRules();
    if (printStream != null) {
      printIfVerbose(allRules.size() + " rules activated for language " + language);
    }

    unknownWords = new HashSet<>();
    List<AnalyzedSentence> analyzedSentences = analyzeSentences(sentences);
    
    List<RuleMatch> ruleMatches = performCheck(analyzedSentences, sentences, allRules, paraMode, annotatedText, listener, mode);
    ruleMatches = new SameRuleGroupFilter().filter(ruleMatches);
    // no sorting: SameRuleGroupFilter sorts rule matches already
    if (cleanOverlappingMatches) {
      ruleMatches = new CleanOverlappingFilter(language).filter(ruleMatches);
    }
    return ruleMatches;
  }
1100280
private ArrayList<ArrayList<String>> parseString(String text) {

        ArrayList<ArrayList<String>> result = new ArrayList<ArrayList<String>>();
        StringTokenizer linetoken = new StringTokenizer(text, "\n");
        StringTokenizer token;
        String current;
        while (linetoken.hasMoreTokens()) {
            current = linetoken.nextToken();
            if (current.contains(",")) {
                token = new StringTokenizer(current, ",");
            } else {
                token = new StringTokenizer(current);
            }
            ArrayList<String> line = new ArrayList<String>();
            while (token.hasMoreTokens()) {
                line.add(token.nextToken());
            }
            result.add(line);
        }
        return result;
    }
76488
public T lookup(String text)
	{
		if (text == null)
			return null;
		
		for (Entry<String,T> entry :lookupMap.entrySet())
		{
			if (Text.matches(text, entry.getKey()))
				return lookupMap.get(entry.getKey());
			
		}

		return null;

	}
921465
public static boolean has(String text){
        for(char c : text.toCharArray()){
            if(is(c)){
                return true;
            }
        }
        return false;
    }
222016
public T find(String text)
    {
        T match = matcher.match(text, true);
        if (match != null)
        {
            String name = match.name();
            if (name.substring(0, Math.min(name.length(), text.length())).equalsIgnoreCase(text))
            {
                return match;
            }
        }
        return null;
    }
1069057
public List<RuleMatchApplication> applySuggestionsToOriginalText(RuleMatch match) {
    List<String> replacements = new ArrayList<>(match.getSuggestedReplacements());
    boolean hasRealReplacements = replacements.size() > 0;
    if (!hasRealReplacements) {
      // create a pseudo replacement with the error text itself
      String plainText = textMapping.getPlainText();
      replacements.add(plainText.substring(match.getFromPos(), match.getToPos()));
    }

    List<RuleMatchApplication> ruleMatchApplications = new ArrayList<>();
    Location fromPosLocation = textMapping.getOriginalTextPositionFor(match.getFromPos() + 1);  // not zero-based!
    Location toPosLocation = textMapping.getOriginalTextPositionFor(match.getToPos() + 1);

    /*System.out.println("=========");
    System.out.println(textMapping.getMapping());
    System.out.println("=========");
    System.out.println(textMapping.getPlainText());
    System.out.println("=========");
    System.out.println(originalText);
    System.out.println("=========");*/

    int fromPos = LocationHelper.absolutePositionFor(fromPosLocation, originalText);
    int toPos = LocationHelper.absolutePositionFor(toPosLocation, originalText);
    for (String replacement : replacements) {
      String errorText = textMapping.getPlainText().substring(match.getFromPos(), match.getToPos());
      // the algorithm is off a bit sometimes due to the complex syntax, so consider the next whitespace:
      int contextFrom = findNextWhitespaceToTheLeft(originalText, fromPos);
      int contextTo = findNextWhitespaceToTheRight(originalText, toPos);

      /*System.out.println(match + ":");
      System.out.println("match.getFrom/ToPos(): " + match.getFromPos() + "/" + match.getToPos());
      System.out.println("from/toPosLocation: " + fromPosLocation + "/" + toPosLocation);
      System.out.println("from/toPos: " + fromPos + "/" + toPos);
      System.out.println("contextFrom/To: " + contextFrom + "/" + contextTo);*/

      String context = originalText.substring(contextFrom, contextTo);
      String text = originalText.substring(0, contextFrom)
              + errorMarker.getStartMarker()
              + context
              + errorMarker.getEndMarker()
              + originalText.substring(contextTo);
      String newContext;
      if (StringUtils.countMatches(context, errorText) == 1) {
        newContext = context.replace(errorText, replacement);
      } else {
        // This may happen especially for very short strings. As this is an
        // error, we don't claim to have real replacements:
        newContext = context;
        hasRealReplacements = false;
      }
      String newText = originalText.substring(0, contextFrom)
              // we do a simple string replacement as that works even if our mapping is off a bit:
              + errorMarker.getStartMarker()
              + newContext
              + errorMarker.getEndMarker()
              + originalText.substring(contextTo);
      RuleMatchApplication application;
      if (hasRealReplacements) {
        application = RuleMatchApplication.forMatchWithReplacement(match, text, newText, errorMarker);
      } else {
        application = RuleMatchApplication.forMatchWithoutReplacement(match, text, newText, errorMarker);
      }
      ruleMatchApplications.add(application);
    }
    return ruleMatchApplications;
  }
719263
@Override
  public final RuleMatch[] match(AnalyzedSentence sentence) {
    List<RuleMatch> ruleMatches = new ArrayList<>();
    AnalyzedTokenReadings[] tokens = sentence.getTokensWithoutWhitespace();
    boolean repetition = false;
    Set<String> inflectedWords = new TreeSet<>();
    String prevLemma;
    int curToken = 0;
    // start from real token, 0 = SENT_START
    for (int i = 1; i < tokens.length; i++) {
      String token = tokens[i].getToken();
      // avoid "..." etc. to be matched:
      boolean isWord = true;
      boolean hasLemma = true;

      if (token.length() < 2) {
        isWord = false;
      }

      for (AnalyzedToken analyzedToken : tokens[i]) {
        String posTag = analyzedToken.getPOSTag();
        if (posTag != null) {
          if (StringTools.isEmpty(posTag)) {
            isWord = false;
            break;
          }
          String lemma = analyzedToken.getLemma();
          if (lemma == null) {
            hasLemma = false;
            break;
          }

          if (getExcludedWordsPattern().contains(lemma)) {
            isWord = false;
            break;
          }

          Matcher m2 = getExcludedPos().matcher(posTag);
          if (m2.matches()) {
            isWord = false;
            break;
          }
        } else {
          hasLemma = false;
        }

      }

      Matcher m1 = getExcludedNonWordsPattern().matcher(tokens[i].getToken());
      if (isWord && m1.matches()) {
        isWord = false;
      }

      prevLemma = "";
      if (isWord) {
        boolean notSentEnd = false;
        for (AnalyzedToken analyzedToken : tokens[i]) {
          String pos = analyzedToken.getPOSTag();
          if (pos != null) {
            notSentEnd |= JLanguageTool.SENTENCE_END_TAGNAME.equals(pos);
          }
          if (hasLemma) {
            String curLemma = analyzedToken.getLemma();
            if (!prevLemma.equals(curLemma) && !notSentEnd) {
              if (inflectedWords.contains(curLemma) && curToken != i) {
                repetition = true;
              } else {
                inflectedWords.add(analyzedToken.getLemma());
                curToken = i;
              }
            }
            prevLemma = curLemma;
          } else {
            if (inflectedWords.contains(tokens[i].getToken()) && !notSentEnd) {
              repetition = true;
            } else {
              inflectedWords.add(tokens[i].getToken());
            }
          }
        }
      }

      if (repetition) {
        int pos = tokens[i].getStartPos();
        RuleMatch ruleMatch = new RuleMatch(this, sentence, pos, pos
            + token.length(), getMessage(), getShortMessage());
        ruleMatches.add(ruleMatch);
        repetition = false;
      }

    }
    return toRuleMatchArray(ruleMatches);
  }