Advertisement
ullallulloo

Untitled

Feb 8th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.36 KB | None | 0 0
  1. $stop_words = array("american", "and", "authority", "between", "board", "commonwealth", "comp", "construction", "corp", "court", "district", "estate", "fair", "great", "group", "health", "home", "inc", "insurance", "international", "int'l", "island", "life", "llc", "litigation", "long", "mutual", "national", "of", "over", "practices", "railroad", "rel", "road", "service", "services", "state", "states", "superior", "the", "thing", "trust", "united", "ux", "virginia");
  2. $tok_text = strtolower(preg_replace("/[[:punct:]]|amp;|lt;|gt;/", " ", $return_text));
  3. $tok_text = preg_replace("/\s\s+/", " ", $tok_text);
  4. $tok = strtok($tok_text, " \n\t");
  5. $stripped_brief = strtolower(preg_replace("/[[:punct:]]|amp;|lt;|gt;/", " ", $brief_name));
  6. $brief_parts = explode(" ", $stripped_brief);
  7. // ^^ Existed before ^^
  8. // vv Wrote tonight vv
  9. $regex_separators = '[!"\#$%&\'()*+,\-.\/:;=?@\[\]\\^_`{|}~ ]';
  10. $v_key = array_search('v', $brief_parts);
  11. $last_matched_key = false;
  12. $matched_key = false;
  13. $substance_found = false;
  14. $v = false;
  15. while ($tok !== false) {
  16.     if ($tok === 'v' && in_array('v', $brief_parts))
  17.         $v = true;
  18.     else
  19.         $v = false;
  20.     if ($matched_keys = array_keys($brief_parts, $tok)) {
  21.         if (!$last_matched_key)
  22.             $matched_key = $matched_keys[0];
  23.         elseif (in_array($last_matched_key + 1, $matched_keys))
  24.             $matched_key = $last_matched_key + 1;
  25.         elseif ($v && $v_key)
  26.             if ($last_matched_key < $v_key && max($matched_keys) > $v_key)
  27.                 $matched_key = max($matched_keys);
  28.             elseif ($last_matched_key < $v_key && min($matched_keys) < $v_key)
  29.                 $matched_key = min($matched_keys);
  30.     }
  31.     if ($matched_key !== false) {
  32.         $possible_parts[] = $tok;
  33.         $last_matched_key = $matched_key;
  34.         $matched_key = false;
  35.         if (!$substance_found && strlen($tok) >= MIN_CASE_LETTERS && !in_array($tok, $stop_words))
  36.             $substance_found = true;
  37.     }
  38.     else {
  39.         if ($substance_found) {
  40.             $return_text = preg_replace_callback(
  41.                 '/(^|(?:<(?!a |h3|sc|span))[^<>]+>[^<>]*)(?<![a-zA-Z])('.implode($regex_separators, $possible_parts).')(?!<\/a>)/i',
  42.                 function($matches) use ($brief_folder, $brief_name) {
  43.                     return $matches[1].form_brief_link($brief_folder, $brief_name, EXPAND_CASE_NAMES ? null : $matches[2]);
  44.                 },
  45.                 $return_text
  46.             );
  47.             $substance_found = false;
  48.         }
  49.         $possible_parts = array();
  50.         $last_matched_key = false;
  51.         $v = false;
  52.     }
  53.    
  54.     $tok = strtok(" \n\t");
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement