init.php
Go to the documentation of this file.
00001 <?php 00002 00003 /* 00004 This script initialize all the running (and persisted) Gate application sessions. 00005 These sessions are used simultaneously to process different corpus of documents 00006 requested by different users. 00007 00008 This init.php script has to be ran each time that tomcat is restarted. 00009 */ 00010 00011 /* 00012 Get the pool of stories to process 00013 Can be a URL or a file reference. 00014 */ 00015 $config_ini = parse_ini_file("../config.ini", TRUE); 00016 00017 // Starts the GATE process/bridge 00018 require_once($config_ini["gate"]["gateBridgeURI"]); 00019 00020 // Create a Scones session where wewill save the Gate objects (started & loaded Gate application). 00021 // Second param "false" => we re-use the pre-created session without destroying the previous one 00022 // third param "0" => it nevers timeout. 00023 $SconesSession = java_session($config_ini["gate"]["sessionName"], false, 0); 00024 00025 // Make sure the scones session is not already opened 00026 if(is_null(java_values($SconesSession->get("initialized")))) 00027 { 00028 00034 $test = new java('gate.creole.ontology.OConstants$OntologyFormat'); 00035 00036 00037 // The session is not yet initialized. 00038 $SconesSession->put("initialized", FALSE); 00039 00040 // The number of sessions that have been created for this Scones instance 00041 $SconesSession->put("nbSessions", $config_ini["gate"]["nbSessions"]); 00042 00043 $Gate = java("gate.Gate"); 00044 $PersistenceManager = java("gate.util.persistence.PersistenceManager"); 00045 00046 // Initialize GATE 00047 $Gate->init(); 00048 00049 $sessions = array(); 00050 00051 // $docs = array("document #1", "document #2", "document #3"); 00052 00053 for($i = 1; $i <= $config_ini["gate"]["nbSessions"]; $i++) 00054 { 00055 // Load the corpus pipeline from the application (XGAPP) file. 00056 $corpusController = $PersistenceManager->loadObjectFromFile( 00057 new java("java.io.File", $config_ini["gate"]["applicationFile"])); 00058 00059 // Initialize and save sessions 00060 $SconesSession->put("session".$i."_used", FALSE); 00061 $SconesSession->put("session".$i."_instance", $corpusController); 00062 } 00063 00064 $SconesSession->put("sessions", $sessions); 00065 00066 $SconesSession->put("initialized", TRUE); 00067 00068 echo "Initialized..."; 00069 } 00070 else 00071 { 00072 echo "Scones threads are already created. Destroy them first before running this script (using destroy.php)..."; 00073 } 00074 00075 00076 ?>
