Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $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");
- $tok_text = strtolower(preg_replace("/[[:punct:]]|amp;|lt;|gt;/", " ", $return_text));
- $tok_text = preg_replace("/\s\s+/", " ", $tok_text);
- $tok = strtok($tok_text, " \n\t");
- $stripped_brief = strtolower(preg_replace("/[[:punct:]]|amp;|lt;|gt;/", " ", $brief_name));
- $brief_parts = explode(" ", $stripped_brief);
- // ^^ Existed before ^^
- // vv Wrote tonight vv
- $regex_separators = '[!"\#$%&\'()*+,\-.\/:;=?@\[\]\\^_`{|}~ ]';
- $v_key = array_search('v', $brief_parts);
- $last_matched_key = false;
- $matched_key = false;
- $substance_found = false;
- $v = false;
- while ($tok !== false) {
- if ($tok === 'v' && in_array('v', $brief_parts))
- $v = true;
- else
- $v = false;
- if ($matched_keys = array_keys($brief_parts, $tok)) {
- if (!$last_matched_key)
- $matched_key = $matched_keys[0];
- elseif (in_array($last_matched_key + 1, $matched_keys))
- $matched_key = $last_matched_key + 1;
- elseif ($v && $v_key)
- if ($last_matched_key < $v_key && max($matched_keys) > $v_key)
- $matched_key = max($matched_keys);
- elseif ($last_matched_key < $v_key && min($matched_keys) < $v_key)
- $matched_key = min($matched_keys);
- }
- if ($matched_key !== false) {
- $possible_parts[] = $tok;
- $last_matched_key = $matched_key;
- $matched_key = false;
- if (!$substance_found && strlen($tok) >= MIN_CASE_LETTERS && !in_array($tok, $stop_words))
- $substance_found = true;
- }
- else {
- if ($substance_found) {
- $return_text = preg_replace_callback(
- '/(^|(?:<(?!a |h3|sc|span))[^<>]+>[^<>]*)(?<![a-zA-Z])('.implode($regex_separators, $possible_parts).')(?!<\/a>)/i',
- function($matches) use ($brief_folder, $brief_name) {
- return $matches[1].form_brief_link($brief_folder, $brief_name, EXPAND_CASE_NAMES ? null : $matches[2]);
- },
- $return_text
- );
- $substance_found = false;
- }
- $possible_parts = array();
- $last_matched_key = false;
- $v = false;
- }
- $tok = strtok(" \n\t");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement