Exemplo n.º 1
0
 public function multicollocations()
 {
     if ($this->request->is('post')) {
         if (!empty($this->request['data']['multiWord1Value']) && !empty($this->request['data']['multiWord2Value']) && !empty($this->request['data']['multiWord3Value'])) {
             $this->set('multiWord1Value', $this->request['data']['multiWord1Value']);
             $this->set('multiWord2Value', $this->request['data']['multiWord2Value']);
             $this->set('multiWord3Value', $this->request['data']['multiWord3Value']);
             $this->set('documentFilter', array_key_exists('documentFilter', $this->request['data']) ? $this->request['data']['documentFilter'] : 0);
             $languageModel = ClassRegistry::init('Language');
             $languageModel->recursive = 1;
             $languages = $languageModel->find('all');
             $this->set('languages', $languages);
             $documentModel = ClassRegistry::init('Document');
             $documentModel->recursive = 1;
             $documents = $documentModel->find('all');
             $this->set('documents', $documents);
             if (isset($this->request['data']['documentIds'])) {
                 $documentIds = $this->request['data']['documentIds'];
             } else {
                 $documentIds = array();
             }
             $this->set('documentIds', $documentIds);
             $multiWord1Params = explode(',', $this->request['data']['multiWord1Value']);
             $multiWord2Params = explode(',', $this->request['data']['multiWord2Value']);
             $multiWord3Params = explode(',', $this->request['data']['multiWord3Value']);
             $sentenceModel = ClassRegistry::init('Sentence');
             $rawCollocations = $sentenceModel->query(QueryBuilder::multicollocations($documentIds, $multiWord1Params, $multiWord2Params, $multiWord3Params));
             $contexts = array();
             foreach ($rawCollocations as $rawCollocation) {
                 array_push($contexts, $documentModel->query("select * from documents inner join languages on languages.id = documents.language_id inner join sentences on documents.id = sentences.document_id and sentences.id = " . $rawCollocation['sentences']['id'] . " inner join words on sentences.id = words.sentence_id order by words.position;"));
             }
             if (count($rawCollocations) != count($contexts)) {
                 die("annotatedWords is of different length than contexts");
             }
             $this->set('collocations', $rawCollocations);
             $this->set('contexts', $contexts);
         } else {
             $this->Session->setFlash("Empty search query, add search criteria for all searched words.");
             return $this->redirect(array('action' => 'generator'));
         }
     }
 }