/**
  * Given a valid servive URI and a valid string of JSON,
  * this method communcates with the SiCDS and returns a
  * list of all unique ID's
  *
  * @param string $uri
  * @param string $json
  * @return string
  */
 public function InterafceWithSiCDS($uri, $json)
 {
     include_once Setup::Modules_Directory() . "/SiSW/ServiceWrapper.php";
     $service = new \Swiftriver\Core\Modules\SiSW\ServiceWrapper($uri);
     $jsonFromService = $service->MakePOSTRequest(array("data" => $json), 5);
     return $jsonFromService;
 }
Exemplo n.º 2
0
 /**
  * Given a valid servive URI and a valid string of JSON
  * this service wraps the SiCDS service
  *
  * @param string $uri
  * @param string $json
  * @param \Swiftriver\Core\Configuration\ConfigurationHandlers\CoreConfigurationHandler $configuration
  * @return string
  */
 public function InterafceWithService($uri, $json, $configuration)
 {
     include_once $configuration->ModulesDirectory . "/SiSW/ServiceWrapper.php";
     $service = new \Swiftriver\Core\Modules\SiSW\ServiceWrapper($uri);
     $jsonFromService = $service->MakeJSONPOSTRequest($json, 1000);
     return $jsonFromService;
 }
Exemplo n.º 3
0
 /**
  * Given a valid servive URI and a valid string of JSON
  * this service wraps the SiCDS service
  *
  * @param string $uri
  * @param string $json
  * @param \Swiftriver\Core\Configuration\ConfigurationHandlers\CoreConfigurationHandler $configuration
  * @return string
  */
 public function InterafceWithService($uri, $parameters, $configuration)
 {
     include_once $configuration->ModulesDirectory . "/SiSW/ServiceWrapper.php";
     $service = new \Swiftriver\Core\Modules\SiSW\ServiceWrapper($uri);
     $return = $service->MakePOSTRequest($parameters, 10);
     return $return;
 }
Exemplo n.º 4
0
 /**
  * Given a valid servive URI and a valid string of text
  * this service wraps the SiLCC service
  *
  * @param string $uri
  * @param string $json
  * @param \Swiftriver\Core\Configuration\ConfigurationHandlers\CoreConfigurationHandler $configuration
  * @return string
  */
 public function InterafceWithService($uri, $text, $configuration)
 {
     include_once $configuration->ModulesDirectory . "/SiSW/ServiceWrapper.php";
     $uri = $uri . "?text=" . $text;
     $service = new \Swiftriver\Core\Modules\SiSW\ServiceWrapper($uri);
     $jsonFromService = $service->MakeGETRequest();
     return $jsonFromService;
 }
 /**
  * Given a valid servive URI and a valid string of text
  * this service wraps the TagThe.Net taggin service
  *
  * @param string $uri
  * @param string $json
  * @return string
  */
 public function InterafceWithService($uri, $text)
 {
     $config = Setup::Configuration();
     require $config["SwiftriverModulesDirectory"] . "/SwiftriverServiceWrapper/ServiceWrapper.php";
     $uri = str_replace("?view=json", "", $uri);
     $uri = $uri . "?view=json&text=" . $text;
     $service = new \Swiftriver\Core\Modules\SiSW\ServiceWrapper($uri);
     $jsonFromService = $service->MakeGETRequest();
     return $jsonFromService;
 }
 public function YahooPlacemakerRequest($location, $appid)
 {
     $encodedLocation = \urlencode($location);
     $url = "http://wherein.yahooapis.com/v1/document";
     $postvars = array("documentContent" => $encodedLocation, "documentType" => "text/plain", "appid" => $appid);
     $serviceWrapper = new \Swiftriver\Core\Modules\SiSW\ServiceWrapper($url);
     $return = $serviceWrapper->MakePOSTRequest($postvars, 10);
     $xml = new \SimpleXMLElement($return);
     $long = (double) $xml->document->placeDetails->place->centroid->longitude;
     $latt = (double) $xml->document->placeDetails->place->centroid->latitude;
     $gis = new \Swiftriver\Core\ObjectModel\GisData($long, $latt, $location);
     return $gis;
 }
 public function Translate($text)
 {
     $logger = $this->logger;
     $logger->log("Swiftriver::GoogleLanguageServiceInterface::TranslationInterface::Translate [Method invoked]", \PEAR_LOG_DEBUG);
     try {
         $text = urlencode($text);
         $languagePair = "{$this->sourceLangCode}%7C{$this->requiredLangCode}";
         $uri = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q={$text}&langpair={$languagePair}";
         $serviceWrapper = new \Swiftriver\Core\Modules\SiSW\ServiceWrapper($uri);
         $returnData = $serviceWrapper->MakeGETRequest(array("Referer: " . $this->referer));
         $object = json_decode($returnData);
         $return = $object->responseData->translatedText;
     } catch (\Exception $e) {
         $logger->log("Swiftriver::GoogleLanguageServiceInterface::TranslationInterface::Translate [{$e}]", \PEAR_LOG_DEBUG);
         $logger->log("Swiftriver::GoogleLanguageServiceInterface::TranslationInterface::Translate [Method finished]", \PEAR_LOG_DEBUG);
         return null;
     }
     $logger->log("Swiftriver::GoogleLanguageServiceInterface::TranslationInterface::Translate [Method finished]", \PEAR_LOG_DEBUG);
     return $return;
 }
Exemplo n.º 8
0
 /**
  * Given a valid servive URI and a valid string of JSON
  * this service wraps the SiCDS service
  *
  * @param string $uri
  * @param string $json
  * @param \Swiftriver\Core\Configuration\ConfigurationHandlers\CoreConfigurationHandler $configuration
  * @return string
  */
 public function InterafceWithService($uri, $json, $configuration)
 {
     $service = new \Swiftriver\Core\Modules\SiSW\ServiceWrapper($uri);
     $jsonFromService = $service->MakeJSONPOSTRequest($json, 1000);
     return $jsonFromService;
 }
 /**
  * Given a collection of content items, this method will use the Enterprise version
  * of the Google Translation Services to both assertain the language the content
  * was writen in and where possible and nessasary, translate that content to
  * the base language. 
  * Each piece of content that comes into this method, can expect to be returned with this
  * pattern - ie: the $content->text[0] LanguageSpecificText class being in the base
  * language and (if applicable) the original LanguageSpecificText class begin at
  * $content->text[1]
  *
  * @param \Swiftriver\Core\ObjectModel\Content[] $contentItems
  * @param \Swiftriver\Core\Configuration\ConfigurationHandlers\CoreConfigurationHandler $configuration
  * @param \Log $logger
  * @return \Swiftriver\Core\ObjectModel\Content[]
  */
 public function Process($contentItems, $configuration, $logger)
 {
     $logger->log("PreProcessingSteps::GoogleEnterpriseLanguageServicePreProcessingStep::Process [Method invoked]", \PEAR_LOG_DEBUG);
     //if the content is not valid, jsut return it
     if (!isset($contentItems) || !is_array($contentItems) || count($contentItems) < 1) {
         $logger->log("PreProcessingSteps::GoogleEnterpriseLanguageServicePreProcessingStep::Process [No content supplied]", \PEAR_LOG_DEBUG);
         $logger->log("PreProcessingSteps::GoogleEnterpriseLanguageServicePreProcessingStep::Process [Method finished]", \PEAR_LOG_DEBUG);
         return $contentItems;
     }
     $config = \Swiftriver\Core\Setup::DynamicModuleConfiguration()->Configuration;
     //Check for the existance of config for this pre processing step
     if (!key_exists($this->Name(), $config)) {
         $logger->log("PreProcessingSteps::GoogleEnterpriseLanguageServicePreProcessingStep::Process [The Google Enterprise Language Service Turbine was called but no configuration exists for this module]", \PEAR_LOG_ERR);
         $logger->log("PreProcessingSteps::GoogleEnterpriseLanguageServicePreProcessingStep::Process [Method finished]", \PEAR_LOG_DEBUG);
         return $contentItems;
     }
     //Get the config
     $config = $config[$this->Name()];
     //Check that all the config entries are there
     foreach ($this->ReturnRequiredParameters() as $requiredParam) {
         if (!key_exists($requiredParam->name, $config)) {
             $logger->log("PreProcessingSteps::GoogleEnterpriseLanguageServicePreProcessingStep::Process [The Google Enterprise Language Service Turbine  was called but all the required configuration properties could not be loaded]", \PEAR_LOG_ERR);
             $logger->log("PreProcessingSteps::GoogleEnterpriseLanguageServicePreProcessingStep::Process [Method finished]", \PEAR_LOG_DEBUG);
             return $contentItems;
         }
     }
     //get the api key
     $apikey = (string) $config["Google API Key"]->value;
     //get the base language for this swift instance
     $baseLanguageCode = $configuration->BaseLanguageCode;
     //create the return array
     $translatedContent = array();
     $logger->log("PreProcessingSteps::GoogleEnterpriseLanguageServicePreProcessingStep::Process [START: Looping through content items]", \PEAR_LOG_DEBUG);
     //Loop throught the content
     foreach ($contentItems as $content) {
         $logger->log("PreProcessingSteps::GoogleEnterpriseLanguageServicePreProcessingStep::Process [START: Running Workflow for content]", \PEAR_LOG_DEBUG);
         //Get the first language specific text blok
         $lsp = \reset($content->text);
         //If the language code is set and matches the base language code then skip it
         if (isset($lsp->languageCode) && $lsp->languageCode != null && \strtolower($lsp->languageCode) == \strtolower($baseLanguageCode)) {
             $logger->log("PreProcessingSteps::GoogleEnterpriseLanguageServicePreProcessingStep::Process [Content text is already in the base language]", \PEAR_LOG_DEBUG);
             $logger->log("PreProcessingSteps::GoogleEnterpriseLanguageServicePreProcessingStep::Process [END: Running Workflow for content]", \PEAR_LOG_DEBUG);
             $translatedContent[] = $content;
             continue;
         }
         try {
             //Get the title
             $title = $lsp->title;
             //url encode the title
             $title = \urlencode($title);
             //Get the text
             $text = "";
             //Concatenate all text
             foreach ($lsp->text as $t) {
                 $text .= " {$t}";
             }
             //Urlencode text
             $text = \urlencode($text);
             //Construct the service uri
             $uri = "https://www.googleapis.com/language/translate/v2?key={$apikey}&target={$baseLanguageCode}&q={$title}&q={$text}";
             //create a service wrapper
             $serviceWrapper = new \Swiftriver\Core\Modules\SiSW\ServiceWrapper($uri);
             //Call the service and get back the json
             $json = $serviceWrapper->MakeGETRequest();
             //decode the json
             $object = \json_decode($json);
             //if not translation was required
             if (\reset($object->data->translations)->detectedSourceLanguage == \strtolower($baseLanguageCode)) {
                 $logger->log("PreProcessingSteps::GoogleEnterpriseLanguageServicePreProcessingStep::Process [Google Language service detected that content text is already in the base language]", \PEAR_LOG_DEBUG);
                 $logger->log("PreProcessingSteps::GoogleEnterpriseLanguageServicePreProcessingStep::Process [END: Running Workflow for content]", \PEAR_LOG_DEBUG);
                 //Set the language code
                 $lsp->languageCode = $baseLanguageCode;
                 //Set the text block back to the content item
                 $content->text[0] = $lsp;
             } else {
                 $languagecode = \reset($object->data->translations)->detectedSourceLanguage;
                 $title = \reset($object->data->translations)->translatedText;
                 $text = \count($object->data->translations) > 1 ? $object->data->translations[1]->translatedText : "";
                 $newLsp = new \Swiftriver\Core\ObjectModel\LanguageSpecificText($baseLanguageCode, $title, array($text));
                 $lsp->languageCode = $languagecode;
                 $content->text[0] = $newLsp;
                 $content->text[1] = $lsp;
             }
             $translatedContent[] = $content;
         } catch (\Exception $e) {
             $logger->log("PreProcessingSteps::GoogleEnterpriseLanguageServicePreProcessingStep::Process [{$e}]", \PEAR_LOG_ERR);
             $logger->log("PreProcessingSteps::GoogleEnterpriseLanguageServicePreProcessingStep::Process [An exception was throw, moving to the next content item]", \PEAR_LOG_DEBUG);
             $translatedContent[] = $content;
         }
         $logger->log("PreProcessingSteps::GoogleEnterpriseLanguageServicePreProcessingStep::Process [END: Running Workflow for content]", \PEAR_LOG_DEBUG);
     }
     $logger->log("PreProcessingSteps::GoogleEnterpriseLanguageServicePreProcessingStep::Process [END: Looping through content items]", \PEAR_LOG_DEBUG);
     $logger->log("PreProcessingSteps::GoogleEnterpriseLanguageServicePreProcessingStep::Process [Method finished]", \PEAR_LOG_DEBUG);
     //return the translated content
     return $translatedContent;
 }