/src/php/util.php
PHP | 822 lines | 721 code | 30 blank | 71 comment | 117 complexity | 0fd36b875836c54a357f0dc87ee89932 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, BSD-3-Clause
- <?php
- /* Copyright 2012 Aditi Muralidharan. See the file "LICENSE" for the full license governing this code. */
- ini_set('memory_limit', '3221M');
- global $query_id;
- $query_id = getGetParam('query_id');
- function table_exists($table) {
- $sql = "show tables like '".$table."'";
- $res = mysql_query($sql);
- return (mysql_num_rows($res) > 0);
- }
- function indexOf($needle, $haystack) {
- for ($i=0;$i<count($haystack);$i++) {
- if ($haystack[$i] == $needle) {
- return $i;
- }
- }
- return -1;
- }
- function encode_json($a=false)
- {
- if (is_null($a)) return 'null';
- if ($a === false) return 'false';
- if ($a === true) return 'true';
- if (is_scalar($a))
- {
- if (is_float($a))
- {
- // Always use "." for floats.
- return floatval(str_replace(",", ".", strval($a)));
- }
- if (is_string($a))
- {
- static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));
- return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"';
- }
- else
- return $a;
- }
- $isList = true;
- for ($i = 0, reset($a); $i < count($a); $i++, next($a))
- {
- if (key($a) !== $i)
- {
- $isList = false;
- break;
- }
- }
- $result = array();
- if ($isList)
- {
- foreach ($a as $v) $result[] = json_encode($v);
- return '[' . join(',', $result) . ']';
- }
- else
- {
- foreach ($a as $k => $v) $result[] = json_encode($k).':'.json_encode($v);
- return '{' . join(',', $result) . '}';
- }
- }
- function replaceWeirdCharacters($input){
- $text = str_replace(
- array("\xe2\x80\x98", "\xe2\x80\x99", "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x80\xa6", "—"),
- array("'", "'", '"', '"', '-', '--', '...', "-"),
- $input);
- // Next, replace their Windows-1252 equivalents.
- $text = str_replace(
- array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)),
- array("'", "'", '"', '"', '-', '--', '...'),
- $text);
- return $text;
- }
- function getRelationsFromFormValue($value){
- return $value;
- }
- function getNameFromRelation($value){
- $return = $value;
- switch($value){
- case "none":
- $return = "search";
- break;
- case "":
- $return = "(any relation)";
- break;
- case "amod advmod":
- $return = "described as" ;
- break;
- case "agent subj nsubj csubj nsubjpass csubjpass":
- $return = "done by";
- break;
- case "obj dobj iobj pobj":
- $return = "done to";
- break;
- case "prep_because prep_because_of prep_on_account_of prep_owing_to prepc_because prepc_because_of prepc_on_account_of prepc_owing_to":
- $return = "because";
- break;
- case "conj_and":
- $return = "and";
- break;
- case "purpcl":
- $return = "in order to";
- break;
- case "prep_with prepc_with prep_by_means_of prepc_by_means_of":
- $return = "with";
- break;
- case "prep_to":
- $return = "to";
- break;
- case "prep_from":
- $return = "from";
- break;
- case "prep_of":
- $return = "of";
- break;
- case "prep_on":
- $return = "on";
- break;
- case "prep_by":
- $return = "by";
- break;
- case "prep_in":
- $return = "in";
- break;
- case "poss":
- $return = "possessed by";
- break;
- }
- return $return;
- }
- function getRelationDescription($val){
- $return = $val;
- $value = ' '.$val.' ';
- if(strpos(" none ", $value) > 0){
- $return = "";
- } else if(strpos(" ", $value) > 0){
- $return = "(any relation)";
- } else if(strpos(" amod advmod acomp ", $value) > 0){
- $return = "amod advmod acomp" ;
- } else if(strpos(" agent subj nsubj csubj nsubjpass csubjpass ", $value) > 0){
- $return = "agent subj nsubj xsubj csubj nsubjpass csubjpass";
- } else if(strpos(" obj dobj iobj pobj ", $value) > 0){
- $return = "dobj iobj pobj";
- } else if(strpos(" prep_because prep_because_of prep_on_account_of prep_owing_to prepc_because prepc_because_of prepc_on_account_of prepc_owing_to ", $value) > 0){
- $return = "prep_because prep_because_of prep_on_account_of prep_owing_to prepc_because prepc_because_of prepc_on_account_of prepc_owing_to";
- } else if(strpos(" prep_with prepc_with prep_by_means_of prepc_by_means_of ", $value) > 0){
- $return = "prep_with prepc_with prep_by_means_of prepc_by_means_of";
- }
- return $return;
- }
- function remove_spaces_before_punctuation($sentence){
- $no_space_before_punctuation = array(".", ",", "!","`", "\"", "?", "`", "'",";", ")", ":", "—");
- $no_space_after_punctuation = array("`", "'", "\"", "`", "`", "(", "—");
-
- $sent = replaceWeirdCharacters($sentence);
- foreach($no_space_before_punctuation as $mark){
- $sent = str_replace(" ".$mark, $mark, $sent);
- }
- foreach($no_space_after_punctuation as $mark){
- $sent = str_replace($mark." ", $mark, $sent);
- }
- return $sent;
- }
- function getWordsInSentence($sentenceID){
- $sql = "SELECT surface, word_id, space_after
- from sentence_xref_word
- WHERE sentence_id = ".$sentenceID."
- ORDER BY position ASC;";
- $result = mysql_query($sql);
- $word_set_memberships = getWordSetMemberships();
- $words = array();
- while($row = mysql_fetch_array($result)){
- $word = array(
- 'word'=>replaceWeirdCharacters($row['surface']),
- 'word_id'=>$row['word_id'],
- 'space_after'=>str_replace("\n", "<br>", $row['space_after']));
- if (array_key_exists($row['word_id'], $word_set_memberships)) {
- $word['word_set'] = join(" ",
- $word_set_memberships[$row['word_id']]);
- }
- array_push($words, $word);
- }
- return $words;
- }
- function getWordSetMemberships() {
- global $word_set_memberships;
- if (!$word_set_memberships) {
- $user = getGetParam('user');
- $sql = "SELECT * from working_set LEFT JOIN working_set_contents
- ON id = working_set_id
- WHERE type = 'word'
- AND username = '$user';";
- $results = mysql_query($sql) or die(
- "Error listing word sets.<br>$sql<br> at util.php l.181");
- $word_set_memberships = array();
- while ($row = mysql_fetch_assoc($results)) {
- $word_id = $row['item_id'];
- if (!array_key_exists($word_id, $word_set_memberships)) {
- $word_set_memberships[$word_id] = array();
- }
- array_push($word_set_memberships[$word_id], $row['working_set_id']);
- }
- }
- return $word_set_memberships;
- }
- function startsWith($haystack, $needle)
- {
- $length = strlen($needle);
- return (substr($haystack, 0, $length) === $needle);
- }
- function endsWith($haystack, $needle)
- {
- $length = strlen($needle);
- $start = $length * -1; //negative
- return (substr($haystack, $start) === $needle);
- }
- function spaceBetweenWords($word1, $word2){
- $prev = substr($word1, -1);
- $next = substr($word2, 0, 1);
- $alphabet = "abcdefghijklmnopqrstuvwxyz&1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- $no_space_before=".!,`)?;:%\"'";
- $no_space_after='\'"`(';
- if(strpos($alphabet, $prev)){
- if(strstr($no_space_before, $next)){
- return '';
- }else{
- return ' ';
- }
- }else if(strstr($no_space_after, $prev)){
- return '';
- }else{
- return ' ';
- }
- }
- function getGetParam($param){
- if(array_key_exists($param, $_GET)){
- return trim(mysql_escape_string($_GET[$param]));
- }else{
- return "";
- }
- }
- function decodeGetJson($param) {
- if (array_key_exists($param, $_GET)) {
- $str = str_replace('\\"', '"', $_GET[$param]);
- return json_decode($str, true);
- } else {
- return array();
- }
- }
- function getPostParam($param){
- if(array_key_exists($param, $_POST)){
- return mysql_escape_string($_POST[$param]);
- }else{
- return "";
- }
- }
- function getRelationID($relation){
- $query = "SELECT id FROM relationship WHERE relationship ='".$relation."';";
- //echo $query.'
- //';
- $result = mysql_query($query);
- if(mysql_num_rows($result)>0){
- $row = mysql_fetch_array($result);
- return $row['id'];
- }else{
- return "";
- }
- }
- /** Returns a comma-separated string of ID's
- that correspond to a given surface word. A word can have multiple id's
- if it has different parts of speech.
- */
- function getWordID($word){
- $lemmatize = getGetParam('all_word_forms') == 'on';
- if (!$lemmatize) {
- $query = "";
- if(!(strstr($word, "*"))){
- $query = "SELECT id FROM word WHERE word ='".mysql_escape_string(trim($word))."';";
- }else{
- $query = "SELECT idlemma FROM word WHERE word like '".mysql_escape_string(trim(str_replace("*", "%", $word)))."';";
- }
- $result = mysql_query($query);
- if(mysql_num_rows($result)>0){
- $ids = array();
- while($row = mysql_fetch_array($result)){
- array_push($ids, $row['id']);
- }
- return join(", ", $ids);
- }else{
- return 'null';
- }
- } else {
- $ids = getLemmaVariantIDs($word);
- return join(", ", $ids);
- }
- }
- /** Returns an array of all the ID's that correspond to a
- given surface word. A word can have multiple id's
- if it has different parts of speech.
- */
- function getWordIDs($word){
- $lemmatize = getGetParam('all_word_forms') == 'on';
- if (!$lemmatize) {
- $query = "";
- if(!(strstr($word, "*"))){
- $query = "SELECT id
- FROM word
- WHERE word ='".mysql_escape_string(trim($word))."';";
- } else {
- $query = "SELECT id
- FROM word
- WHERE word like '".mysql_escape_string(trim(str_replace("*", "%", $word)))."';";
- }
- $result = mysql_query($query);
- if(mysql_num_rows($result)>0){
- $ids = array();
- while($row = mysql_fetch_assoc($result)){
- array_push($ids, $row['id']);
- }
- return $ids;
- }else{
- return array();
- }
- } else {
- return getLemmaVariantIDs($word);
- }
- }
- function getWord($id){
- $query = "SELECT word from word where id = $id;";
- $result = mysql_query($query);
- if(mysql_num_rows($result)>0){
- $row = mysql_fetch_assoc($result);
- return $row['word'];
- } else {
- return '??';
- }
- }
- function getDependencyID($relationID, $govID, $depID){
- $query = "SELECT id FROM dependency WHERE relation_id =".$relationID." AND gov_id =".$govID." and dep_id = ".$depID.";";
- $result = mysql_query($query);
- if(mysql_num_rows($result)>0){
- $row= mysql_fetch_array($query);
- return $row['id'];
- }else{
- return "";
- }
- }
- /** Get matching dependency ID's
- @param withinSentence True if you want to search within
- a set of sentences, or "table" if you're supplying
- the name of a temporary table with an id column if you
- want to use the id's stored in that table.
- @param withinDocument True if you want to search within a
- set of documents
- @param within a comma-separated string of sentence or document id's
- if either <withinSentence> or
- <withinDocument> is marked as True.
- Otherwise, false. If $withinSentence is "table",
- it's assumed to be the name of a temporary table with
- an id field
- */
- function getDependencyIDs($gov, $dep, $relation, $withinDocument,
- $withinSentence, $within, $start, $limit) {
- global $timing;
- global $num_search_conditions;
- $table_identifier = 'filtered_sent_ids';
- $insertion_fields = '(id, document_id, num_matched, num_searches_matched)';
- $field_identifier = "DISTINCT sentence_id, document_id, 0, 1";
- $query_id_where = '';
- global $cache_results;
- global $query_id;
- global $dont_cache_search_results;
- if (($cache_results || $query_id) && !$dont_cache_search_results) {
- $table_identifier = 'cached_filtered_sent_ids';
- $insertion_fields = '(id, document_id, query_id, num_matched, num_searches_matched)';
- $field_identifier = "DISTINCT sentence_id, document_id, $query_id, 0, 1";
- $query_id_where = " AND query_id = $query_id ";
- }
- $tablenames = "dependency_xref_sentence, sentence ";
- $where = "AND sentence.id = sentence_id";
- if($withinSentence == true && strlen($within)>0){
- $where = $where." AND sentence_id in (".$within.")";
- } else if ($withinSentence == "table") {
- $tablenames = "dependency_xref_sentence, sentence, $table_identifier ";
- $where = $where. " AND $table_identifier.id = sentence_id $query_id_where ";
- }else if ($withinDocument && strlen($within)>0){
- $where = $where." AND document_id in (".$within.")";
- }
- $r = strlen($relation)>0;
- $g = strlen($gov)>0;
- $d = strlen($dep)>0;
- $rel_w = "";
- $gov_w ="";
- $dep_w = "";
- if($r){
- $rel_w = "relation_id IN (".$relation.")";
- }
- if($g){
- $gov_w = "gov_id IN (".$gov.")";
- }
- if($d){
- $dep_w = "dep_id IN (".$dep.")";
- }
- if($r || $g || $d ){
- $query = "SELECT SQL_CALC_FOUND_ROWS * FROM ".$tablenames." WHERE ";
- $main = " ";
- if($r && $g && $d){
- $main = $main.$rel_w." AND ".$gov_w." AND ".$dep_w;
- }
- else if($r && $g){
- $main = $main.$rel_w." AND ".$gov_w;
- }
- else if($r && $d){
- $main = $main.$rel_w." AND ".$dep_w;
- }
- else if($g && $d){
- $main = $main."((".$gov_w." AND ".$dep_w.") OR ";
- $main = $main." (dep_id IN (".$gov.") AND gov_id IN (".$dep."))) ";
- }
- else if ($r){
- $main = $main.$rel_w;
- }
- else if ($g){
- $main = $main." (".$gov_w;
- $main = $main." OR dep_id IN (".$gov.")) ";
- }
- else{
- $main = $main." (".$dep_w;
- $main = $main." OR gov_id IN (".$dep.")) ";
- }
- $query = $query.$main.$where;
- if ($timing != 0) {
- echo $query;
- }
- if (!$query_id || $cache_results || $dont_cache_search_results) {
- // Update the list of filtered sentence ID's to reflect this.
- $num_search_conditions += 1;
- $sql = "INSERT INTO $table_identifier $insertion_fields
- SELECT $field_identifier
- FROM dependency_xref_sentence
- WHERE ".$main."
- ON DUPLICATE KEY
- UPDATE num_searches_matched = num_searches_matched + 1";
- mysql_query($sql) or die (mysql_error()." On: <br> $sql
- <br> util.php l 454.");
- if ($dont_cache_search_results && $query_id) {
- updateTemporarySentenceFilterTable();
- } else {
- updateSentenceFilterTable();
- }
- }
- }
- else if($withinSentence){
- $query = "SELECT SQL_CALC_FOUND_ROWS * FROM ".$tablenames.$where."
- LIMIT 500";
- }
- $paging = '';
- if(strlen($start)>0 && $limit && !getGetParam("onlyMetadata")){
- $paging = ' LIMIT '.$limit.' OFFSET '.$start;
- }
- if (!$cache_results) {
- $query = $query.$paging;
- $result = mysql_query($query." ;") or die (
- 'util.php 371 <br> mysql error <br>'.mysql_error().' '.$query);
- if ($timing) {
- echo "<br>Dependency search query:
- <br>$query
- <br>";
- }
- }
- return $result;
- }
- function relationshipIDList($words){
- if(strlen($words) > 0){
- $exploded = explode(' ', trim($words));
- $ids = array();
- foreach($exploded as $word){
- $r = getRelationID($word);
- if(strlen($r) > 0){
- array_push($ids, $r);
- }
- }
- return join(", ", $ids);
- }else{
- return "";
- }
- }
- /**
- Converts a list of words to a comma-separated string of word ID's
- */
- function wordIDList($raw_words) {
- $words = str_replace("+", "", $raw_words);
- if(strlen($words) > 0){
- $exploded = explode(' ', trim($words));
- if(strpos($words, ',')){
- $exploded = explode(',',trim($words));
- }
- $all_ids = array(-2);
- foreach($exploded as $word){
- $word_ids = getWordIDs($word);
- $all_ids = array_merge($all_ids, $word_ids);
- }
- return join(", ", $all_ids);
- } else {
- return "";
- }
- }
- /** Gets the index of a given word in a sentence **/
- function getWordIndexInSentence($word, $wordtype, $sentence_id) {
- if ($wordtype == 'word-set') {
- $word_ids = getWordIDsFromWordSet($word);
- } else {
- $ids = getWordIDs($word);
- $word_ids = join(", ", $ids);
- }
- $sql = "SELECT position from sentence_xref_word
- WHERE sentence_id = $sentence_id AND word_id in ($word_ids);";
- $result = mysql_query($sql) or die ("SQL error in util.php l. 430");
- $indexes = array();
- while ($row = mysql_fetch_assoc($result)) {
- array_push($indexes, $row['position']);
- }
- return $indexes;
- }
- /** Returns a string containing all the words in the given
- word set ID **/
- function getWordsFromWordSet($wordSetID){
- $lemmatize = getGetParam('all_word_forms') == "on";
- $sql = "SELECT DISTINCT word
- FROM working_set_contents, word
- WHERE working_set_id = $wordSetID
- AND item_id = word.id
- AND item_table_name = 'word';";
- $result = mysql_query($sql);
- $words = array();
- while($row = mysql_fetch_assoc($result)){
- if ($lemmatize) {
- $variants = getLemmaVariants($row['word']);
- $words = array_merge($words, $variants);
- } else {
- array_push($words, $row['word']);
- }
- }
- $word_string = join(" ", array_unique($words));
- return $word_string;
- }
- /** Returns a string containing all the words in the given
- word set ID **/
- function getWordIDsFromWordSet($wordSetID){
- $lemmatize = getGetParam('all_word_forms') == "on";
- $sql = "SELECT DISTINCT word.id, word
- FROM working_set_contents, word
- WHERE working_set_id = $wordSetID
- AND item_id = word.id
- AND item_table_name = 'word';";
- $result = mysql_query($sql);
- $ids = array();
- while($row = mysql_fetch_assoc($result)){
- if ($lemmatize) {
- $ids = array_merge($ids, getLemmaVariantIDs($row['word']));
- } else {
- array_push($ids, $row['id']);
- }
- }
- $id_string = join(", ", array_unique($ids));
- return $id_string;
- }
- /** Returns the name of a set with the given id
- */
- function getSetName($id){
- $sql = "SELECT name
- FROM working_set
- WHERE id = $id;";
- $result = mysql_query($sql);
- $row = mysql_fetch_assoc($result);
- return $row['name'];
- }
- /**********************
- Lemmas
- ***********************/
- /** Returns an array of word id's for all the words that have the same lemma as
- this one
- */
- function getLemmaVariantIDs($word) {
- $word = trim($word);
- $ids = array();
- $sql = "SELECT lemma from word where word = '$word';";
- $result = mysql_query($sql) or die(" Error getting lemmas of word
- <br>".mysql_error()."
- <br> $sql
- <br>");
- $lemmas = array();
- while ($row = mysql_fetch_assoc($result)) {
- array_push($lemmas, "'".$row['lemma']."'");
- }
- $lemma_string = join(", ", $lemmas);
- if (strlen($lemma_string) > 0) {
- $sql = "SELECT id from word where lemma in ($lemma_string);";
- $result = mysql_query($sql) or die ("Error getting ids of words with lemma.
- <br>".mysql_error()."
- <br> $sql
- <br>");
- while ($row = mysql_fetch_assoc($result)) {
- array_push($ids, $row['id']);
- }
- }
- return $ids;
- }
- /** Returns an array of strings (words) that all have the same lemma as this
- word.
- */
- function getLemmaVariants($word) {
- $sql = "SELECT lemma from word where word = '$word';";
- $result = mysql_query($sql) or die(" Error getting lemmas of word
- <br>".mysql_error()."
- <br> $sql
- <br>");
- $lemmas = array();
- while ($row = mysql_fetch_assoc($result)) {
- array_push($lemmas, "'".$row['lemma']."'");
- }
- $lemma_string = join(", ", $lemmas);
- $sql = "SELECT distinct word from word where lemma in ($lemma_string);";
- $result = mysql_query($sql) or die ("Error getting ids of words with lemma.
- <br>".mysql_error()."
- <br> $sql
- <br>");
- $words = array();
- while ($row = mysql_fetch_assoc($result)) {
- array_push($words, $row['word']);
- }
- return $words;
- }
- /********************
- Query string
- *********************/
- /** Returns a string representing the query in a a human-friendly way.
- */
- function makeQueryString($gov, $govtype, $dep, $deptype, $relation, $collection,
- $metadata, $phrases) {
- $query_string = $gov;
- // if just a regular word search or a phrase search
- if(strlen(trim($relation)) == 0){
- //default query
- $words = "";
- if ($gov) {
- $words = $gov;
- if($govtype == 'word-set'){
- $words = explode(" ", getWordsFromWordSet($gov));
- $word_id_string = getWordIDsFromWordSet($gov);
- $q = "(".join("|", $words).")";
- $query_string = getSetName($gov);
- } else {
- $query_string = $words;
- }
- }
- // If no search query has been specified, but there are phrases
- // acting as filters, then use the first filter phrase as the
- // search query for the center of the word tree.
- else if (count($phrases) > 0) {
- $phraseIDs = getPhraseIDs($phrases[0]);
- $sql = "SELECT sequence from sequence
- WHERE id
- IN (".join(",", $phraseIDs).");";
- $result = mysql_query($sql) or die ("Error getting phrase with ID
- ".$phrases[0].";");
- while ($row = mysql_fetch_assoc($result)) {
- $q = explode(" ", $row['sequence']);
- $query_string = $q[0];
- }
- }
- // If no search query has been specified get the most frequent
- // content word (not stop word) from the set of documents matching
- // the filters (if any) or the whole collection (if there are no
- // filters), and use that as the search query for the center of
- // the word tree.
- else {
- $phrase = mysql_real_escape_string(
- getMostFrequentContentPhrase($filtered));
- $query_string = $phrase;
- }
- $q = array("gov"=>$query_string);
- return $q;
- }
- // If it's a grammatical search, extract the gov, dep, and relation from
- // the GET parameters and issue a dependency relationship search.
- else{
- $query_string = array();
- $govIDs = wordIDList($gov);
- if($govtype == "word-set"){
- $govIDs = getWordIDsFromWordSet($gov);
- $query_string['gov'] = getSetName($gov);
- } else {
- $query_string['gov'] = $gov;
- }
- $depIDs = wordIDList($dep);
- if($deptype == 'word-set'){
- $depIDs = getWordIDsFromWordSet($dep);
- $query_string['dep'] = getSetName($dep);
- } else {
- $query_string['dep'] = $dep;
- }
- $relations = relationshipIDList($relation);
- $query_string['relation'] = $relation;
- if($filtersAreActive){
- // To stave off syntax errors if its empty, put a -1 in the list.
- array_push($filtered, "-1");
- $withinSentence = true;
- $within = join(", ", $filtered);
- $sentence_where_clause = " AND id IN ($within) ";
- }
- $dependency_id_results = null;
- $dependency_id_results = getDependencyIDs($govIDs,
- $depIDs,
- $relations,
- false,
- $withinSentence,
- $within,
- false,
- false);
- $sentence_ids = array();
- while($row = mysql_fetch_array($dependency_id_results)){
- array_push($sentence_ids, $row['sentence_id']);
- }
- if(count($sentence_ids) > 0){
- $id_string = join(", ", $sentence_ids);
- $sql = "SELECT
- sentence.id, sentence.document_id, number, sentence
- FROM
- sentence
- WHERE id IN (".$id_string.");";
- $results = mysql_query($sql) or die("<b>Fatal MySQL error</b>.
- <br/> Query: " . $sql . "
- <br/> Error: (" . mysql_errno() . ") " . mysql_error());
- // pattern
- $govs = $gov;
- if($govtype == "word-set"){
- $govs = getWordsFromWordSet($gov);
- }
- $deps = $dep;
- if($deptype == 'word-set'){
- $deps = getWordsFromWordSet($dep);
- }
- if(strlen($govs) > 0){
- $query = str_replace(" ", "|", $govs);
- }else if(strlen($deps) > 0){
- $query = str_replace(" ", "|", $deps);
- }
- $pattern = "/\b(".$query.")\b/i";
- global $PUNCTUATION;
- if (strstr($PUNCTUATION, $query)) {
- $pattern = "/$query/i";
- }
- }
- return $query_string;
- }
- }
- /***********************
- Document Sub Structures
- ************************/
- /** Return a list of structures:
- {unit_id, unit_name, parent_id, parent_name, document_id}
- within a document **/
- function getSubStructures($documentID){
- $sql = "SELECT * from document_structure WHERE document_id = $documentID;";
- $result = mysql_query($sql) or die(mysql_error()." on query:
- $sql
- made on
- on util.php line 471.");
- $structures = array();
- while($row = mysql_fetch_assoc($result)){
- array_push($structures, $row);
- }
- return $structures;
- }
- $STOPWORDS = explode(" ", "'ve does o t went was is had be were did are have do has being am 's been go 'm the and so are for be but this what 's did had they doth a to is that was as are at an of with . , ; ? ' \" : `");
- $PUNCTUATION = "!@#$%^&*()_+-=~`,./;;\"'{}[]|\\";
- ?>