示例#1
0
 /**
  * Generate alternate titles for the film using RhymeBrain.
  * @param int $name_count, the number of names to generate
  **/
 public function generate_names($names_per_word = 5, $rhymes_per_word = 10)
 {
     if (!$this->name) {
         return false;
     }
     $names = nRhyme::process_title($this->name, $names_per_word, $rhymes_per_word);
     $db = nSQL::connect();
     if ($names) {
         foreach ($names as $data) {
             if (nGlibName::load_one(array('name' => $data['title'], 'movie_id' => $this->get_id()))) {
                 # glib title already exists
                 continue;
             }
             $glib = new nGlibName(array('name' => $data['title'], 'movie_id' => $this->get_id()));
             if ($glib->save()) {
                 $word = nWord::load_one(array('word' => $data['rhyme']));
                 if (!$word) {
                     $word = new nWord(array('word' => $data['rhyme']));
                     $word->save();
                 }
                 if ($word_id = $word->get_id()) {
                     $db->query(sprintf("INSERT INTO glib_name_word (glib_name_id, word_id) VALUES (%d, %d)", $glib->get_id(), $word_id));
                 }
             }
         }
     }
 }
示例#2
0
#!/usr/bin/php
<?php 
require_once realpath(dirname(__FILE__) . "/../settings.php");
require_once realpath(dirname(__FILE__) . "/../include/nRhyme.php");
$result = nRhyme::process_title("beasts of the southern wild");
var_dump($result);
示例#3
0
<?php

date_default_timezone_set('America/New_York');
define('SITE_ROOT', realpath(dirname(__FILE__) . "/.."));
set_include_path(get_include_path() . PATH_SEPARATOR . SITE_ROOT . "/include");
require_once SITE_ROOT . "/settings.php";
# Load up all Model objects
$model_dir = opendir(SITE_ROOT . "/model");
while (FALSE !== ($file = readdir($model_dir))) {
    if ('n' == substr($file, 0, 1) && '.php' == substr($file, -4)) {
        require_once SITE_ROOT . "/model/{$file}";
    }
}
closedir($model_dir);
require_once 'nRhyme.php';
$title = !empty($_GET['title']) ? $_GET['title'] : "Lord of the Rings";
$names_per_word = !empty($_GET['names']) ? intval($_GET['names']) : 10;
$rhymes_per_word = !empty($_GET['rhymes']) ? intval($_GET['rhymes']) : 10;
if ($title && ($result = nRhyme::process_title($title, $names_per_word, $rhymes_per_word))) {
    foreach ($result as $data) {
        echo "{$data['title']}<br />";
    }
} else {
    echo "<b>no results</b>";
}