<commit_before><?php
/*
 * Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, version 2.0 (the "License");
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

/**
 * Extractor for QueryAnalyzer What processor
 * 
 * @param array $params
 */
class WhatExtractor {

    /*
     * Reference to QueryManager
     */
    private $queryManager;
    
    /**
     * Constructor
     * 
     * @param QueryManager $queryManager
     */
    public function __construct($queryManager) {
        $this->queryManager = $queryManager;
    }
    
    /**
     * Extract quantity
     * 
     * @param integer $startPosition
     * @param array $endPosition
     */
    public function extractQuantity($startPosition, $endPosition) {
        
        if ($startPosition > $endPosition) {
            return null;
        }
        
        /*
         * Process words within $startPosition and $endPosition
         */
        $word = '';
        for ($i = $startPosition; $i <= $endPosition; $i++) {

            /*
             * Reconstruct word from words without stop words
             */
            if ($this->queryManager->isValidPosition($i) && !$this->queryManager->isStopWordPosition($i)) {
                $word = trim($word . ' ' . $this->queryManager->words[$i]['word']);
            }
            
            $quantity = $this->getQuantity($word);
            if (isset($quantity)) {
                return array_merge($quantity, array(
                    'startPosition' => $startPosition,
                    'endPosition' => $i
                ));
            }
            
        }
        return null;
    }
    
    /**
     * Extract keyword
     * 
     * @param integer $startPosition
     */
    public function extractKeyword($startPosition) {
     
        $endPosition = $this->queryManager->getEndPosition($startPosition);
        
        /*
         * Process words within $startPosition and $endPosition
         */
        $word = '';
        for ($i = $startPosition; $i <= $endPosition; $i++) {

            /*
             * Reconstruct word from words without stop words
             */
            if (!$this->queryManager->isStopWordPosition($i)) {
                $word = trim($word . ' ' . $this->queryManager->words[$i]['word']);
            }
            
            $keyword = $this->queryManager->getNonLocationKeyword($word);
            if (isset($keyword)) {
                return array(
                    'startPosition' => $startPosition,
                    'endPosition' => $i,
                    'keyword' => $keyword['keyword'],
                    'type' => $keyword['type']
                );
            }
        }
        
        return null;
    }
    
    /**
     * Extract (of) "numeric" "unit"
     * 
     * @param integer $startPosition
     * @param integer $endPosition
     */
    public function extractValueAndUnit($startPosition, $endPosition) {
        
        for ($i = $startPosition; $i < $endPosition; $i++) {
            
            /*
             * Skip stop words and processed words
             */
            if ($this->queryManager->isStopWordPosition($i) || !$this->queryManager->isValidPosition($i)) {
                continue;
            }
           <commit_msg>Close issue #6<commit_after><?php
/*
 * Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, version 2.0 (the "License");
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

/**
 * Extractor for QueryAnalyzer What processor
 * 
 * @param array $params
 */
class WhatExtractor {

    /*
     * Reference to QueryManager
     */
    private $queryManager;
    
    /**
     * Constructor
     * 
     * @param QueryManager $queryManager
     */
    public function __construct($queryManager) {
        $this->queryManager = $queryManager;
    }
    
    /**
     * Extract quantity
     * 
     * @param integer $startPosition
     * @param array $endPosition
     */
    public function extractQuantity($startPosition, $endPosition) {
        
        if ($startPosition > $endPosition) {
            return null;
        }
        
        /*
         * Process words within $startPosition and $endPosition
         */
        $word = '';
        for ($i = $startPosition; $i <= $endPosition; $i++) {

            /*
             * Reconstruct word from words without stop words
             */
            if ($this->queryManager->isValidPosition($i) && !$this->queryManager->isStopWordPosition($i)) {
                $word = trim($word . ' ' . $this->queryManager->words[$i]['word']);
            }
            
            $quantity = $this->getQuantity($word);
            if (isset($quantity)) {
                return array_merge($quantity, array(
                    'startPosition' => $startPosition,
                    'endPosition' => $i
                ));
            }
            
        }
        return null;
    }
    
    /**
     * Extract keyword
     * 
     * @param integer $startPosition
     */
    public function extractKeyword($startPosition) {
     
        /*
         * Process words within $startPosition and $endPosition
         */
        for ($i = $startPosition; $i < $this->queryManager->length; $i++) {
            
            /*
             * Skip first word if stop words
             */
            if ($i === $startPosition && $this->queryManager->isStopWordPosition($i)) {
                continue;
            }
            
            /*
             * Search for valid keyword
             */
            $word = (isset($word) ? $word . '-' : '') . $this->queryManager->words[$i]['word'];
            $keyword = $this->queryManager->getNonLocationKeyword($word);
            if (isset($keyword)) {
                return array(
                    'startPosition' => $startPosition,
                    'endPosition' => $i,
                    'keyword' => $keyword['keyword'],
                    'type' => $keyword['type']
                );
            }
        }
        
        return null;
    }
    
    /**
     * Extract (of) "numeric" "unit"
     * 
     * @param integer $startPosition
     * @param integer $endPosition
     */
    public function extractValueAndUnit($startPosition, $endPosition) {
        
        for ($i = $startPosition; $i < $endPosition; $i++) {
            
            /*
             * Skip stop words and processed words
             */
            if ($this->queryManager->isStopWordPosition($i) || !$this->queryManager->isValidPosition($i)) {
                continue;
            }
           
{'fraction_non_alphanumeric': 0.12039774254232734, 'fraction_numerical': 0.0022843321687718355, 'mean_word_length': 1.618009145269082, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4038884', 'n_tokens_mistral': 1921, 'n_tokens_neox': 1868, 'n_words': 492}