CS267
Chris Pollett
Mar 8, 2021
class Foo{ static $bob=1;} echo "bob: ".Foo::$bob;
class Goo{ const BLOB=1;}
Goo::BLOB
define("PI", 22/7); echo PI;
$my_copy = clone $my_obj;
class A{} class B extends A {}
interface MyInterface { function method1($a, $b); }
class C implements MyInterfaceA, MyInterfaceB {}
class A {function foo(){} } class B extends A {function foo(){} }
class A {final function foo() {} /* can't override*/ }
namespace TheNameOfMyNamespace; // code for namespace class A { //code for class A } function foo() { }This declaration with the same name can be at the top of multiple files if you would like to group the contents of these files into the same namespace.
namespace TheNameOfMyNamespace\MySubNameSpace; //code
namespace D { // code for D } namespace E { // code for E }
namespace N; function foo() { //some code } foo(); //assume N namespace.
M\foo(); /*in context of above we are in N namespace already, so M\foo() means the foo() in N\M namespace. */ \N\M\foo(); \time(); //time function in the global (default) namespace.
use A\B\C; //rather than typing A\B\C\foo(); could type foo(); use D\E\F as G; //rather than typing D\E\F\goo(); could type G\goo();
namespace seekquarry\yioop;
namespace seekquarry\yioop\models;
if (file_exists(__DIR__."/../../vendor/autoload.php")) { require_once __DIR__."/../../vendor/autoload.php"; } else { spl_autoload_register(function ($class) { // project-specific namespace prefix $prefix = 'seekquarry\\yioop\\tests'; // does the class use the namespace prefix? $len = strlen($prefix); if (strncmp($prefix, $class, $len) !== 0) { $prefix = 'seekquarry\\yioop'; $len = strlen($prefix); // no, move to the next registered autoloader if (strncmp($prefix, $class, $len) !== 0) { return; } else { $check_dirs = [WORK_DIRECTORY . "/app", BASE_DIR]; } } else { $check_dirs = [PARENT_DIR . "/tests"]; } // get the relative class name $relative_class = substr($class, $len); // use forward-slashes, add ./php $unixify_class_name = "/".str_replace('\\', '/', $relative_class) . '.php'; foreach($check_dirs as $dir) { $file = $dir . $unixify_class_name; if (file_exists($file)) { require $file; break; } } }); }
Which of the following is true?
composer some_directive_for_composer
{ "name": "your_vendor_name/your_project", "description": "put what your project is about here", "authors": [ { "name": "Your Full Name", "email": "Where@to_contact.you" } ], "config": { "secure-http": false }, "require": { "seekquarry/yioop": "dev-master" } }
namespace cpollett\test_composer; use seekquarry\yioop\configs as SYC; use seekquarry\yioop\library as SYL; use seekquarry\yioop\library\Library; use seekquarry\yioop\library\PhraseParser; require_once "vendor/autoload.php"; /* Since a normal Yioop instance needs a Profile.php file to be generated, the following is used to set up Yioop in library mode so you don't need this. To enable debugging use Library::init(true); */ Library::init(); print_r(PhraseParser::stemTerms("jumping", 'en-US')); echo SYL\crawlHash(SYC\NAME_SERVER . "1234");
composer installIf you want to update composer projects later you type:
composer update
php index.phpto execute out project. It should output:
Array ( [0] => jump ) joQWpC4Sdy4
<?php namespace cpollett\test_composer; use seekquarry\yioop\library as L; use seekquarry\yioop\library\Library; use seekquarry\yioop\library\LinearAlgebra as LA; use seekquarry\yioop\library\FetchUrl; use seekquarry\yioop\library\PhraseParser; use seekquarry\yioop\library\CrawlConstants; require_once "vendor/autoload.php"; /* Since a normal Yioop instance needs a Profile.php file to be generated, the following is used to set up Yioop in library mode so you don't need this. To enable debugging use Library::init(true); */ Library::init(); // download a collection of web pages and then pretty print $page_info = FetchUrl::getPages( [[CrawlConstants::URL => "https://www.yahoo.com/"]], // we could list more urls to download ); print_r($page_info); // stem word or phrases print_r(PhraseParser::stemTerms("image", 'en-US')); print_r(PhraseParser::stemTerms("I once knew a jumpy cat", 'en-US')); print_r(PhraseParser::stemTerms("Allons enfants de la Patrie, Le jour de gloire est arrivé!", 'fr-FR')); // segment strings into words print_r(PhraseParser::segmentSegment("从前,在一块遥远的土地上", 'zh-CN')); //detect language from text $pinocchio = <<< EOD Come andò che Maestro Ciliegia, falegname trovò un pezzo di legno che piangeva e rideva come un bambino. C'era una volta.... Un re! — diranno subito i miei piccoli lettori. No, ragazzi, avete sbagliato. C'era una volta un pezzo di legno. Non era un legno di lusso, ma un semplice pezzo da catasta, di quelli che d'inverno si mettono nelle stufe e nei caminetti per accendere il fuoco e per riscaldare le stanze. EOD; $lang = L\guessLocaleFromString($pinocchio); echo $lang . "\n"; //make term frequency vector of stemmed terms $vec = PhraseParser::extractPhrasesAndCount($pinocchio, $lang); print_r($vec); // Normalize this vector $norm = LA::normalize($vec); print_r($norm);