예제 #1
0
function getWords($words)
{
    $wordArray = str_word_count($words, 1);
    global $flag_q;
    //flag for quotes
    //to add to the query string synonyms
    $synonyms = get_synonyms($words);
    foreach ($synonyms as $synonym) {
        $wordArray[] = $synonym;
    }
    if (!$flag_q) {
        //to handle expression with operator and stop word
        $wordArray = array_diff($wordArray, array('and', 'or', 'not', 'And', 'Or', 'Not', 'OR', 'AND', 'NOT'));
    }
    $wordsToSend = "";
    //aggregate all of the word searched for the query string to bold later
    foreach ($wordArray as $word) {
        $wordsToSend .= "words[]=" . $word . "&";
    }
    $wordsToSend = substr($wordsToSend, 0, -1);
    return $wordsToSend;
}
     }
     while (!$result->EOF) {
         $occurrence = new stdclass();
         $occurrence->occurrenceID = $result->fields['occurrenceID'];
         $occurrence->datasetID = $result->fields['datasetID'];
         $occurrence->institutionCode = $result->fields['institutionCode'];
         $occurrence->collectionCode = $result->fields['collectionCode'];
         $occurrence->catalogueNumber = $result->fields['catalogueNumber'];
         $occurrence->taxonID = $result->fields['taxonID'];
         $occurrence->scientificName = $result->fields['scientificName'];
         $occurrence->kingdom = $result->fields['kingdom'];
         $occurrence->class = $result->fields['class'];
         $occurrence->family = $result->fields['family'];
         $occurrence->lineage = array($result->fields['kingdom'], $result->fields['class'], $result->fields['family']);
         // GBIF synonyms...
         get_synonyms($occurrence);
         // Other identifiers
         get_other_identifiers($occurrence);
         $obj->occurrences[$occurrence->occurrenceID] = $occurrence;
         $result->MoveNext();
     }
 } else {
     $url = 'http://data.gbif.org/ws/rest/occurrence/list?institutioncode=' . $institutioncode . '&catalognumber=' . $catalognumber;
     $xml = get($url);
     //echo $xml;
     $dom = new DOMDocument();
     $dom->loadXML($xml);
     $xpath = new DOMXPath($dom);
     $xpath->registerNamespace('gbif', 'http://portal.gbif.org/ws/response/gbif');
     $xpath->registerNamespace('to', 'http://rs.tdwg.org/ontology/voc/TaxonOccurrence#');
     $xpath->registerNamespace('tc', 'http://rs.tdwg.org/ontology/voc/TaxonConcept#');
예제 #3
0
function search_words($q, $index)
{
    global $total_docs;
    global $stopwords;
    global $operators_dictionary;
    global $has_quotes;
    $total_docs = get_docs_id();
    $query_vars = explode(" ", $q);
    //for every search word the user types change to lowercase
    //check if surrounded with quotes
    //if true remove them and update flag
    //if false check they are in the stop words array
    foreach ($query_vars as $key => $value) {
        $token = strtolower($value);
        if (mb_substr($token, 0, 1) != '"' && mb_substr($token, -1) != '"') {
            $has_quotes = false;
            if (in_array($token, $stopwords)) {
                //in case of an operator command with a stop word
                $query_vars = array_diff($query_vars, array('and', 'or', 'not', 'And', 'Or', 'Not', 'OR', 'AND', 'NOT'));
                unset($query_vars[$key]);
                continue;
            }
        } else {
            $token = substr($token, 1, -1);
            $has_quotes = true;
        }
        $query_vars[$key] = $token;
    }
    //transform in the correct order for a regular expression and validity of parentheses
    $query_vars = convert_to_npr($query_vars);
    if (empty($query_vars)) {
        return array();
    }
    $added_docs = array();
    //this is the docs of the synonyms
    //foreach word in the search look up for the word and its synonyms
    foreach ($query_vars as $token) {
        if (!in_array($token, $operators_dictionary) || $has_quotes) {
            $synonyms = get_synonyms($token);
            //get all the synonyms word from a given term
            if ($synonyms != NULL) {
                //adds the synonyms words doc id from the current word
                foreach ($synonyms as $synonym) {
                    $added_docs[] = get_docs_from_index($synonym, $index);
                }
            }
            //adds to temp index the id of the docs which the word given appear in
            $temp_index[] = array("term" => $token, "docs" => get_docs_from_index($token, $index));
        } else {
            $temp_index[] = array("term" => $token, "docs" => null);
        }
    }
    //create the expression tree in which every intersection represent a boolean operator
    //and every leaf represents a word
    $root = create_tree(new ArrayIterator($temp_index));
    $result = $root->evaluate();
    //adds the synonyms docs for final search
    foreach ($added_docs as $doc) {
        foreach ($doc as $d) {
            $result[] = $d;
        }
    }
    $docs = array();
    foreach ($result as $id) {
        $docs[$id] = get_doc_details($id);
    }
    return $docs;
}
예제 #4
0
				</div>
<?php 
}
?>
			</nav>
		</div>  <!-- /Barre de navigation locale à la page -->

		<div class="row page-head"> <!-- Barre de titre locale à la page -->
			<div class="detail-font-title" align="center">
				<span style="font-size:200%;"><strong><?php 
echo $bille['NOM'];
?>
</strong></span>
<?php 
$i = 1;
$synonyms = get_synonyms($sql_get_synonyms, $bille['ID_BILLES']);
$max = count($synonyms);
if ($max != 0) {
    ?>
				<span class="pull-right">
					<span><?php 
    echo $lib_detail_220;
    ?>
</span>
<?php 
    foreach ($synonyms as $synonym) {
        ?>
					<a href="detail.php?id=<?php 
        echo $synonym['NUM'];
        ?>
" rel="tooltip" data-original-title="<?php