idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
50,000
public function delete ( $ file ) : AbstractSitemapContracts { if ( $ this -> has ( __public_path ( ) . $ file . $ this -> ext ) ) { unlink ( __public_path ( ) . $ file . $ this -> ext ) ; } return $ this ; }
Delete the sitemap .
50,001
public function verify ( $ original , $ hash ) { if ( $ this -> verifyAlgorithm && $ this -> info ( $ hash ) [ 'algoName' ] !== 'bcrypt' ) { throw new \ Exception ( 'This hash does not use bcrypt algorithm' , 500 ) ; } return parent :: verify ( $ original , $ hash ) ; }
Verify the hash value .
50,002
private function toTimezone ( $ zone ) { return isset ( $ this -> windowsTimezones [ $ zone ] ) ? $ this -> windowsTimezones [ $ zone ] : $ zone ; }
Process timezone and return correct one ...
50,003
public function getSortedEvents ( ) { if ( $ events = $ this -> getEvents ( ) ) { usort ( $ events , function ( $ a , $ b ) { return $ a [ 'DTSTART' ] > $ b [ 'DTSTART' ] ; } ) ; return $ events ; } return [ ] ; }
Return sorted event list as array
50,004
public function actionIndex ( ) { $ searchModel = Yii :: createObject ( $ this -> searchClass ) ; $ dataProvider = $ searchModel -> search ( Yii :: $ app -> request -> getQueryParams ( ) ) ; return $ this -> render ( 'index' , [ 'dataProvider' => $ dataProvider , 'searchModel' => $ searchModel , ] ) ; }
List of all rules
50,005
public function actionView ( string $ id ) { $ model = $ this -> findModel ( $ id ) ; return $ this -> render ( 'view' , [ 'model' => $ model ] ) ; }
Displays a single Rule item .
50,006
public function actionDelete ( string $ id ) { $ model = $ this -> findModel ( $ id ) ; Yii :: $ app -> authManager -> remove ( $ model -> item ) ; Yii :: $ app -> session -> setFlash ( 'success' , Yii :: t ( 'yii2mod.rbac' , 'Rule has been deleted.' ) ) ; return $ this -> redirect ( [ 'index' ] ) ; }
Deletes an existing Rule item .
50,007
protected function findModel ( string $ id ) { $ item = Yii :: $ app -> authManager -> getRule ( $ id ) ; if ( ! empty ( $ item ) ) { return new BizRuleModel ( $ item ) ; } throw new NotFoundHttpException ( Yii :: t ( 'yii2mod.rbac' , 'The requested page does not exist.' ) ) ; }
Finds the BizRuleModel based on its primary key value .
50,008
private function isErrorPage ( Action $ action ) : bool { if ( $ action -> getUniqueId ( ) === Yii :: $ app -> getErrorHandler ( ) -> errorAction ) { return true ; } return false ; }
Returns a value indicating whether a current url equals errorAction property of the ErrorHandler component
50,009
private function isLoginPage ( Action $ action ) : bool { $ loginUrl = trim ( Url :: to ( Yii :: $ app -> user -> loginUrl ) , '/' ) ; if ( Yii :: $ app -> user -> isGuest && $ action -> getUniqueId ( ) === $ loginUrl ) { return true ; } return false ; }
Returns a value indicating whether a current url equals loginUrl property of the User component
50,010
private function isAllowedAction ( Action $ action ) : bool { if ( $ this -> owner instanceof Module ) { $ ownerId = $ this -> owner -> getUniqueId ( ) ; $ id = $ action -> getUniqueId ( ) ; if ( ! empty ( $ ownerId ) && strpos ( $ id , $ ownerId . '/' ) === 0 ) { $ id = substr ( $ id , strlen ( $ ownerId ) + 1 ) ; } }...
Returns a value indicating whether a current url exists in the allowActions list .
50,011
public function validateName ( ) { $ value = $ this -> name ; if ( $ this -> manager -> getRole ( $ value ) !== null || $ this -> manager -> getPermission ( $ value ) !== null ) { $ message = Yii :: t ( 'yii' , '{attribute} "{value}" has already been taken.' ) ; $ params = [ 'attribute' => $ this -> getAttributeLabel (...
Validate item name
50,012
public function addChildren ( array $ items ) : bool { if ( $ this -> _item ) { foreach ( $ items as $ name ) { $ child = $ this -> manager -> getPermission ( $ name ) ; if ( empty ( $ child ) && $ this -> type == Item :: TYPE_ROLE ) { $ child = $ this -> manager -> getRole ( $ name ) ; } $ this -> manager -> addChild ...
Add child to Item
50,013
public function removeChildren ( array $ items ) : bool { if ( $ this -> _item !== null ) { foreach ( $ items as $ name ) { $ child = $ this -> manager -> getPermission ( $ name ) ; if ( empty ( $ child ) && $ this -> type == Item :: TYPE_ROLE ) { $ child = $ this -> manager -> getRole ( $ name ) ; } $ this -> manager ...
Remove child from an item
50,014
public function getItems ( ) : array { $ available = [ ] ; $ assigned = [ ] ; if ( $ this -> type == Item :: TYPE_ROLE ) { foreach ( array_keys ( $ this -> manager -> getRoles ( ) ) as $ name ) { $ available [ $ name ] = 'role' ; } } foreach ( array_keys ( $ this -> manager -> getPermissions ( ) ) as $ name ) { $ avail...
Get all available and assigned roles permission and routes
50,015
public function assign ( array $ items ) : bool { foreach ( $ items as $ name ) { $ item = $ this -> manager -> getRole ( $ name ) ; $ item = $ item ? : $ this -> manager -> getPermission ( $ name ) ; $ this -> manager -> assign ( $ item , $ this -> userId ) ; } return true ; }
Assign a roles and permissions to the user .
50,016
public function getItems ( ) : array { $ available = [ ] ; $ assigned = [ ] ; foreach ( array_keys ( $ this -> manager -> getRoles ( ) ) as $ name ) { $ available [ $ name ] = 'role' ; } foreach ( array_keys ( $ this -> manager -> getPermissions ( ) ) as $ name ) { if ( $ name [ 0 ] != '/' ) { $ available [ $ name ] = ...
Get all available and assigned roles and permissions
50,017
public function actionIndex ( ) { $ model = Yii :: createObject ( $ this -> modelClass ) ; return $ this -> render ( 'index' , [ 'routes' => $ model -> getAvailableAndAssignedRoutes ( ) ] ) ; }
Lists all Route models .
50,018
public function actionRefresh ( ) : array { $ model = Yii :: createObject ( $ this -> modelClass ) ; $ model -> invalidate ( ) ; return $ model -> getAvailableAndAssignedRoutes ( ) ; }
Refresh cache of routes
50,019
public function actionCreate ( ) { $ model = new AuthItemModel ( ) ; $ model -> type = $ this -> type ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> save ( ) ) { Yii :: $ app -> session -> setFlash ( 'success' , Yii :: t ( 'yii2mod.rbac' , 'Item has been saved.' ) ) ; return $ this -> redi...
Creates a new AuthItem model .
50,020
protected function findModel ( string $ id ) : AuthItemModel { $ auth = Yii :: $ app -> getAuthManager ( ) ; $ item = $ this -> type === Item :: TYPE_ROLE ? $ auth -> getRole ( $ id ) : $ auth -> getPermission ( $ id ) ; if ( empty ( $ item ) ) { throw new NotFoundHttpException ( Yii :: t ( 'yii2mod.rbac' , 'The reques...
Finds the AuthItem model based on its primary key value .
50,021
protected function removeRole ( $ name ) { $ role = $ this -> authManager -> getRole ( $ name ) ; if ( empty ( $ role ) ) { throw new InvalidParamException ( "Role '{$role}' does not exists" ) ; } echo " > removing role $role->name ..." ; $ time = microtime ( true ) ; $ this -> authManager -> remove ( $ role ) ; ech...
Remove role .
50,022
protected function removePermission ( $ name ) { $ permission = $ this -> authManager -> getPermission ( $ name ) ; if ( empty ( $ permission ) ) { throw new InvalidParamException ( "Permission '{$permission}' does not exists" ) ; } echo " > removing permission $permission->name ..." ; $ time = microtime ( true ) ; ...
Remove permission .
50,023
protected function removeRule ( $ ruleName ) { $ rule = $ this -> authManager -> getRule ( $ ruleName ) ; if ( empty ( $ rule ) ) { throw new InvalidParamException ( "Rule '{$ruleName}' does not exists" ) ; } echo " > removing rule $rule->name ..." ; $ time = microtime ( true ) ; $ this -> authManager -> remove ( $ ...
Remove rule .
50,024
public function actionIndex ( ) { $ searchModel = Yii :: createObject ( $ this -> searchClass ) ; if ( $ searchModel instanceof AssignmentSearch ) { $ dataProvider = $ searchModel -> search ( Yii :: $ app -> request -> queryParams , $ this -> userIdentityClass , $ this -> idField , $ this -> usernameField ) ; } else { ...
List of all assignments
50,025
protected function setHostAndPort ( $ host ) { if ( ! str_contains ( $ host , ':' ) ) { $ this -> host = $ host ; } else { list ( $ this -> host , $ this -> port ) = explode ( ':' , $ host ) ; $ this -> port = ( int ) $ this -> port ; } }
Set the host and port from a full host string .
50,026
public function getConnection ( ) { if ( $ this -> connection ) { return $ this -> connection ; } return $ this -> connection = new SFTP ( $ this -> host , $ this -> port , $ this -> timeout ) ; }
Get the underlying SFTP connection .
50,027
protected function hasRsaKey ( ) { $ hasKey = ( isset ( $ this -> auth [ 'key' ] ) && trim ( $ this -> auth [ 'key' ] ) != '' ) ; return $ hasKey || ( isset ( $ this -> auth [ 'keytext' ] ) && trim ( $ this -> auth [ 'keytext' ] ) != '' ) ; }
Determine if an RSA key is configured .
50,028
protected function loadRsaKey ( array $ auth ) { with ( $ key = $ this -> getKey ( $ auth ) ) -> loadKey ( $ this -> readRsaKey ( $ auth ) ) ; return $ key ; }
Load the RSA key instance .
50,029
protected function getKey ( array $ auth ) { with ( $ key = $ this -> getNewKey ( ) ) -> setPassword ( array_get ( $ auth , 'keyphrase' ) ) ; return $ key ; }
Create a new RSA key instance .
50,030
public function define ( $ task , $ commands ) { foreach ( $ this -> connections as $ connection ) { $ connection -> define ( $ task , $ commands ) ; } }
Define a set of commands as a task .
50,031
public function get ( $ remote , $ local ) { foreach ( $ this -> connections as $ connection ) { $ connection -> get ( $ remote , $ local ) ; } }
Download the contents of a remote file .
50,032
public function putString ( $ remote , $ contents ) { foreach ( $ this -> connections as $ connection ) { $ connection -> putString ( $ remote , $ contents ) ; } }
Upload a string to to the given file on the server .
50,033
public function rename ( $ remote , $ newRemote ) { foreach ( $ this -> connections as $ connection ) { $ connection -> rename ( $ remote , $ newRemote ) ; } }
Rename a remote file .
50,034
protected function tailLogFile ( $ path , $ connection ) { if ( is_null ( $ connection ) ) { $ this -> tailLocalLogs ( $ path ) ; } else { $ this -> tailRemoteLogs ( $ path , $ connection ) ; } }
Tail the given log file for the connection .
50,035
protected function tailRemoteLogs ( $ path , $ connection ) { $ out = $ this -> output ; $ lines = $ this -> option ( 'lines' ) ; $ this -> getRemote ( $ connection ) -> run ( 'cd ' . escapeshellarg ( $ path ) . ' && tail -f $(ls -t | head -n 1) -n ' . $ lines , function ( $ line ) use ( $ out ) { $ out -> write ( $ li...
Tail a remote log file at the given path and connection .
50,036
protected function findNewestLocalLogfile ( $ path ) { $ files = glob ( $ path . '/*.log' ) ; $ files = array_combine ( $ files , array_map ( 'filemtime' , $ files ) ) ; arsort ( $ files ) ; $ newestLogFile = key ( $ files ) ; return $ newestLogFile ; }
Get the path to the latest local Laravel log file .
50,037
public function getGateway ( ) { if ( ! $ this -> gateway -> connected ( ) && ! $ this -> gateway -> connect ( $ this -> username ) ) { throw new \ RuntimeException ( 'Unable to connect to remote server.' ) ; } return $ this -> gateway ; }
Get the gateway implementation .
50,038
public function display ( $ line ) { $ server = $ this -> username . '@' . $ this -> host ; $ lead = '<comment>[' . $ server . ']</comment> <info>(' . $ this -> name . ')</info>' ; $ this -> getOutput ( ) -> writeln ( $ lead . ' ' . $ line ) ; }
Display the given line using the default output .
50,039
public function binarySearch ( $ ip ) { if ( is_string ( $ ip ) ) $ ip = self :: safeIp2long ( $ ip ) ; if ( $ this -> totalBlocks == 0 ) { if ( $ this -> dbFileHandler == NULL ) { $ this -> dbFileHandler = fopen ( $ this -> dbFile , 'r' ) ; if ( $ this -> dbFileHandler == false ) { throw new Exception ( "Fail to open ...
get the data block throught the specifield ip address or long ip numeric with binary search algorithm
50,040
public static function getLong ( $ b , $ offset ) { $ val = ( ( ord ( $ b [ $ offset ++ ] ) ) | ( ord ( $ b [ $ offset ++ ] ) << 8 ) | ( ord ( $ b [ $ offset ++ ] ) << 16 ) | ( ord ( $ b [ $ offset ] ) << 24 ) ) ; if ( $ val < 0 && PHP_INT_SIZE == 4 ) { $ val = sprintf ( "%u" , $ val ) ; } return $ val ; }
read a long from a byte buffer
50,041
static public function create ( array $ tokens , $ nGramSize = self :: BIGRAM , $ separator = ' ' ) : array { $ separatorLength = strlen ( $ separator ) ; $ length = count ( $ tokens ) - $ nGramSize + 1 ; if ( $ length < 1 ) { return [ ] ; } $ ngrams = array_fill ( 0 , $ length , '' ) ; for ( $ index = 0 ; $ index < $ ...
Generate Ngrams from the tokens
50,042
static public function getFreq ( array $ ngrams , string $ sep = ' ' ) : array { $ ngramsUnique = array_count_values ( $ ngrams ) ; $ ngramsFinal = array ( ) ; $ ngramsArray = self :: ngramsAsArray ( $ sep , $ ngrams ) ; $ ngramSize = count ( $ ngramsArray [ 0 ] ) ; $ tokens_frequencies = self :: readFreq ( $ sep , $ n...
Set the frenquecies of the ngrams and their respective tokens
50,043
static public function readFreq ( string $ sep , array $ ngrams ) : array { $ ngrams = self :: ngramsAsArray ( $ sep , $ ngrams ) ; $ frequencies = array ( ) ; foreach ( $ ngrams as $ ngram ) { foreach ( $ ngram as $ pos => $ token ) { if ( isset ( $ frequencies [ $ token ] [ $ pos ] ) ) { $ frequencies [ $ token ] [ $...
Counts the frequency of each token of an ngram array
50,044
static public function readCombFreq ( string $ sep , array $ ngrams ) : array { $ ngrams = self :: ngramsAsArray ( $ sep , $ ngrams ) ; $ frequencies = array ( ) ; foreach ( $ ngrams as $ ngram ) { foreach ( $ ngram as $ posToken => $ token ) { for ( $ i = $ posToken + 1 ; $ i < count ( $ ngram ) ; $ i ++ ) { if ( isse...
Counts the frequency of combo of tokens of an ngram array
50,045
static private function ngramsAsArray ( string $ sep , array $ ngrams ) : array { $ ngramsArray = array ( ) ; foreach ( $ ngrams as $ key => $ ngram ) { $ ngramsArray [ ] = explode ( $ sep , $ ngram ) ; } return $ ngramsArray ; }
Transform the ngram array to an array of their tokens
50,046
public function getDispersion ( array $ needles ) : array { $ found = array_fill_keys ( $ needles , [ ] ) ; foreach ( array_keys ( $ needles ) as $ needle ) { $ found [ $ needle ] = $ this -> findAll ( $ needle ) ; } return $ found ; }
Return a list of positions that the needs were found in the text
50,047
public function concordancePositions ( string $ text , string $ needle , int $ contextLength = 20 , bool $ ignorecase = true , string $ position = 'contain' ) : array { $ found = [ ] ; $ needleLength = strlen ( $ needle ) ; $ textLength = strlen ( $ text ) ; $ bufferLength = $ needleLength + 2 * $ contextLength ; $ spe...
Return all positions of the needle in the text according to the position of the needle in a word .
50,048
public function percentage ( string $ needle ) : float { $ freqDist = freq_dist ( $ this -> getTokens ( ) ) ; return $ freqDist -> getKeyValuesByFrequency ( ) [ $ needle ] / $ freqDist -> getTotalTokens ( ) ; }
Get percentage of times the needle shows up in the text
50,049
public function count ( string $ needle ) : int { return substr_count ( strtolower ( $ this -> getText ( ) ) , strtolower ( $ needle ) ) ; }
Performs a case insensitive search for the needle
50,050
public function findAll ( string $ needle ) : array { $ lastPos = 0 ; $ positions = [ ] ; $ needle = strtolower ( $ needle ) ; $ text = strtolower ( $ this -> getText ( ) ) ; $ needleLength = strlen ( $ needle ) ; while ( ( $ lastPos = stripos ( $ text , $ needle , $ lastPos ) ) !== false ) { $ positions [ ] = $ lastPo...
Return all the position of the needle found in the text
50,051
public function similarity ( $ text1 , $ text2 ) { if ( $ text1 === $ text2 ) { return 1.0 ; } if ( strlen ( $ text1 ) > strlen ( $ text2 ) ) { $ tmp = $ text1 ; $ text1 = $ text2 ; $ text2 = $ tmp ; } $ strLen1 = strlen ( $ text1 ) ; $ strLen2 = strlen ( $ text2 ) ; $ maxDistance = ( int ) $ strLen2 / 2 ; $ commonCoun...
Return the similarity using the JaroWinkler algorithm
50,052
public function summarize ( array $ wordTokens , array $ sentenceTokens ) : array { $ tokenCounts = array_count_values ( $ wordTokens ) ; $ scoreKeepers = [ ] ; for ( $ index = 0 ; $ index < count ( $ sentenceTokens ) ; $ index ++ ) { $ scoreKeepers [ ] = new ScoreKeeper ( $ sentenceTokens [ $ index ] , $ index ) ; } f...
Returns each sentenced scored .
50,053
public function applyExtract ( IExtractStrategy $ extract ) { $ found = [ ] ; foreach ( $ this -> documents as $ document ) { $ found = array_merge ( $ document -> applyExtract ( $ extract ) , $ found ) ; } return $ found ; }
Apply extract to the document to pull out all the points of interest
50,054
public function distance ( $ text1 , $ text2 ) { $ distance = 0 ; $ strLength = strlen ( $ text1 ) ; for ( $ index = 0 ; $ index < $ strLength ; $ index ++ ) { if ( $ text1 [ $ index ] != $ text2 [ $ index ] ) { $ distance ++ ; } } return $ distance ; }
Return the hamming distance expects the strings to be equal length
50,055
protected function toArray ( array $ stopWords ) { $ data = [ ] ; foreach ( $ stopWords as $ key => $ value ) { $ data [ ] = [ 'token' => utf8_encode ( $ key ) , 'freq' => $ value ] ; } return $ data ; }
So you can easily serialize the data to json
50,056
protected function indexRules ( array $ rules ) { $ this -> indexedRules = array ( ) ; foreach ( $ rules as $ rule ) { if ( isset ( $ this -> indexedRules [ $ rule [ self :: LOOKUP_CHAR ] ] ) ) { $ this -> indexedRules [ $ rule [ self :: LOOKUP_CHAR ] ] [ ] = $ rule ; } else { $ this -> indexedRules [ $ rule [ self :: ...
Creates an chained hashtable using the lookup char as the key
50,057
public function stem ( $ word ) { if ( empty ( trim ( $ word ) ) ) { return null ; } $ this -> originalToken = $ word ; do { $ ruleApplied = false ; $ lookupChar = $ word [ strlen ( $ word ) - 1 ] ; if ( ! array_key_exists ( $ lookupChar , $ this -> indexedRules ) ) { return $ word ; } foreach ( $ this -> indexedRules ...
Performs a Lancaster stem on the giving word
50,058
protected function applyRule ( $ word , $ rule ) { return substr_replace ( $ word , $ rule [ self :: APPEND_STRING ] , strlen ( $ word ) - $ rule [ self :: REMOVE_TOTAL ] ) ; }
Apply the lancaster rule and return the altered string .
50,059
protected function isAcceptable ( $ word , $ removeTotal ) { $ length = strlen ( $ word ) - $ removeTotal ; if ( $ this -> vowelChecker -> isVowel ( $ word , 0 ) && $ length >= 2 ) { return true ; } elseif ( $ length >= 3 && ( $ this -> vowelChecker -> isVowel ( $ word , 1 ) || $ this -> vowelChecker -> isVowel ( $ wor...
Check if a word is acceptable
50,060
public function stem ( $ token ) { if ( array_key_exists ( $ token , $ this -> dictionary ) ) { return $ this -> dictionary [ $ token ] ; } return $ token ; }
Returns a token s stemmed root
50,061
public function tokenize ( $ string ) { if ( ! $ this -> length ) { return array ( substr ( $ string , $ this -> startPosition ) ) ; } else { return array ( substr ( $ string , $ this -> startPosition , $ this -> length ) ) ; } }
Return array with single element
50,062
public function distance ( $ text1 , $ text2 ) { return levenshtein ( $ text1 , $ text2 , $ this -> insertCost , $ this -> replaceCost , $ this -> deleteCost ) ; }
Return the levenshtein distance default costs of 1 applied
50,063
public static function calculate ( array $ ngrams , string $ measure , int $ nGramSize = 2 ) : array { $ totalNgrams = array_sum ( array_column ( $ ngrams , 0 ) ) ; return array_map ( function ( $ item ) use ( $ measure , $ totalNgrams , $ nGramSize ) { if ( $ nGramSize == 2 ) { return Statistic2D :: $ measure ( $ item...
Calculate the statistic for an ngram array
50,064
public function similarity ( $ text1 , $ text2 ) { if ( $ this -> useCache && ! isset ( $ this -> cache [ $ text2 ] ) ) { $ this -> cache [ $ text2 ] = Text :: getAllSubStrings ( $ text2 ) ; } $ intersection = array_intersect ( Text :: getAllSubStrings ( $ text1 ) , ( $ this -> useCache ) ? $ this -> cache [ $ text2 ] ...
Returns the Longest common substring
50,065
static public function tmi ( array $ ngram , int $ totalNgrams ) : float { $ var = self :: setStatVariables ( $ ngram , $ totalNgrams ) ; $ tmi3 = 0 ; if ( $ var [ 'jointFrequency' ] ) { $ tmi3 += $ var [ 'jointFrequency' ] / $ totalNgrams * self :: computePMI ( $ var [ 'jointFrequency' ] , $ var [ 'e111' ] ) / log ( 2...
Calculate the true mutual information value for trigrams
50,066
static public function ll ( array $ ngram , int $ totalNgrams ) : float { $ var = self :: setStatVariables ( $ ngram , $ totalNgrams ) ; $ logLikelihood = 0 ; if ( $ var [ 'jointFrequency' ] ) { $ logLikelihood += $ var [ 'jointFrequency' ] * self :: computePMI ( $ var [ 'jointFrequency' ] , $ var [ 'e111' ] ) ; } if (...
Calculate the Loglikelihood coefficient for trigrams
50,067
protected function execute ( $ string ) { foreach ( $ this -> patternsAndReplacements as $ patternAndReplacement ) { $ tmp = preg_replace ( "/" . $ patternAndReplacement -> pattern . "/s" , $ patternAndReplacement -> replacement , $ string ) ; if ( $ tmp === null ) { InvalidExpression :: invalidRegex ( $ patternAndRepl...
Handles the data processing
50,068
public function suggest ( $ word ) { if ( ! pspell_check ( $ this -> pSpell , $ word ) ) { return pspell_suggest ( $ this -> pSpell , $ word ) ; } else { return [ $ word ] ; } }
Use pspell to get word suggestions
50,069
public function getCollocations ( ) { $ nGramTokens = ngrams ( $ this -> tokens , $ this -> nGramSize ) ; return freq_dist ( $ nGramTokens ) -> getKeyValuesByFrequency ( ) ; }
Returns a naive implementation of collocations
50,070
public function getCollocationsByPmi ( ) { $ nGramFreqDist = freq_dist ( ngrams ( $ this -> tokens , $ this -> nGramSize ) ) ; $ unigramsFreqDist = freq_dist ( $ this -> tokens ) ; $ dataSet = [ ] ; foreach ( $ nGramFreqDist -> getKeys ( ) as $ nGramToken ) { $ tokens = explode ( " " , $ nGramToken ) ; $ tally = 1 ; fo...
Compute the Pointwise Mutual Information on the collocations
50,071
public function getPdo ( ) : PDO { if ( empty ( $ this -> pdo ) ) { $ this -> pdo = new PDO ( "sqlite:" . $ this -> getDir ( ) . $ this -> getFileNames ( ) [ 0 ] ) ; } return $ this -> pdo ; }
Return the raw pdo
50,072
protected function strTokenWrapper ( $ string ) { $ token = strtok ( $ string , $ this -> tokenExpression ) ; $ tokens = array ( ) ; while ( $ token !== false ) { if ( ! empty ( trim ( $ token ) ) ) { $ tokens [ ] = $ token ; } $ token = strtok ( $ this -> tokenExpression ) ; } return $ tokens ; }
Use the php function strtok to Tokenize simple string
50,073
public function suggest ( $ word ) { if ( ! enchant_dict_check ( $ this -> enchantBroker , $ word ) ) { return enchant_dict_suggest ( $ this -> enchantBroker , $ word ) ; } else { return [ $ word ] ; } }
Use enchant to get word suggestions
50,074
public function getExceptionsMap ( ) { if ( empty ( $ this -> exceptionsMap ) ) { $ fileExtToPos = array_flip ( $ this -> getPosFileMaps ( ) ) ; foreach ( $ this -> getExceptionFileNames ( ) as $ fileName ) { $ pos = $ fileExtToPos [ substr ( $ fileName , 0 , - 4 ) ] ; $ fh = fopen ( $ this -> getDir ( ) . $ fileName ,...
Returns the list of exception spellings
50,075
public function getSynsetByOffsetAndPos ( $ synsetOffset , $ pos ) { if ( isset ( $ this -> synsets [ $ pos . $ synsetOffset ] ) ) { return $ this -> synsets [ $ pos . $ synsetOffset ] ; } $ fileName = "data.{$this->posFileMaps[$pos]}" ; if ( ! in_array ( $ fileName , $ this -> getDataFileNames ( ) ) ) { throw new Runt...
Opens the raw data file and reads the synsets in
50,076
public function getSynsetFromString ( $ line ) { $ row = str_getcsv ( $ line , " " ) ; $ synset = new Synset ( ( int ) $ row [ 0 ] , $ row [ 2 ] ) ; $ synset -> setDefinition ( trim ( substr ( $ line , strpos ( $ line , "|" ) + 1 ) ) ) ; for ( $ index = 0 ; $ index < ( int ) $ row [ 3 ] ; $ index ++ ) { $ synset -> add...
Parse the line from the synset file and turn it into a synset object
50,077
public function getPackages ( ) { if ( empty ( $ this -> packages ) ) { $ xml = $ this -> getXmlContent ( ) ; foreach ( $ xml -> packages -> package as $ package ) { $ data = ( array ) $ package ; extract ( $ data [ '@attributes' ] ) ; if ( ! isset ( $ checksum ) ) { $ checksum = null ; } $ this -> packages [ ] = new P...
Returns an array of packages available for download from the nltk project
50,078
public function getXmlContent ( ) { if ( $ this -> getUseCache ( ) && file_exists ( get_storage_path ( 'cache' ) . $ this -> getCacheFileName ( ) ) ) { $ contents = file_get_contents ( get_storage_path ( 'cache' ) . $ this -> getCacheFileName ( ) ) ; } else { $ contents = file_get_contents ( $ this -> getUrl ( ) ) ; fi...
Uses file_get_contents to pull down the content from the url
50,079
static public function tmi ( array $ ngram , int $ totalNgrams ) : float { $ var = self :: setStatVariables ( $ ngram , $ totalNgrams ) ; $ tmi = 0 ; if ( $ var [ 'jointFrequency' ] ) { $ tmi += $ var [ 'jointFrequency' ] / $ totalNgrams * self :: computePMI ( $ var [ 'jointFrequency' ] , $ var [ 'm11' ] ) / log ( 2 ) ...
Calculate the true mutual information value
50,080
static public function ll ( array $ ngram , int $ totalNgrams ) : float { $ var = self :: setStatVariables ( $ ngram , $ totalNgrams ) ; $ logLikelihood = 0 ; if ( $ var [ 'jointFrequency' ] ) { $ logLikelihood += $ var [ 'jointFrequency' ] * self :: computePMI ( $ var [ 'jointFrequency' ] , $ var [ 'm11' ] ) ; } if ( ...
Calculate the Loglikelihood coefficient
50,081
static public function pmi ( array $ ngram , int $ totalNgrams ) : float { $ var = self :: setStatVariables ( $ ngram , $ totalNgrams ) ; $ temp = ( ( $ var [ 'jointFrequency' ] / $ var [ 'leftFrequency' ] ) / $ var [ 'rightFrequency' ] ) * $ totalNgrams ; return ( log ( $ temp ) / log ( 2 ) ) ; }
Calculate the Mutual Information coefficient
50,082
static public function x2 ( array $ ngram , int $ totalNgrams ) : float { $ var = self :: setStatVariables ( $ ngram , $ totalNgrams ) ; $ Xsquare = 0 ; $ Xsquare += ( ( $ var [ 'jointFrequency' ] - $ var [ 'm11' ] ) ** 2 ) / $ var [ 'm11' ] ; $ Xsquare += ( ( $ var [ 'LminusJ' ] - $ var [ 'm12' ] ) ** 2 ) / $ var [ 'm...
Calculate the X squared coefficient
50,083
static public function tscore ( array $ ngram , int $ totalNgrams ) : float { $ var = self :: setStatVariables ( $ ngram , $ totalNgrams ) ; $ term1 = $ var [ 'jointFrequency' ] - ( ( $ var [ 'leftFrequency' ] * $ var [ 'rightFrequency' ] ) / $ totalNgrams ) ; $ term2 = sqrt ( ( $ var [ 'jointFrequency' ] ) ) ; return ...
Calculate the T - score
50,084
static public function phi ( array $ ngram , int $ totalNgrams ) : float { $ var = self :: setStatVariables ( $ ngram , $ totalNgrams ) ; $ term1 = $ var [ 'jointFrequency' ] * $ var [ 'n22' ] - $ var [ 'RminusJ' ] * $ var [ 'LminusJ' ] ; $ term2 = $ var [ 'leftFrequency' ] * $ var [ 'rightFrequency' ] * $ var [ 'Tminu...
Calculate the Phi Coefficient
50,085
static public function odds ( array $ ngram , int $ totalNgrams ) : float { $ var = self :: setStatVariables ( $ ngram , $ totalNgrams ) ; if ( $ var [ 'RminusJ' ] == 0 ) { $ var [ 'RminusJ' ] = 1 ; } if ( $ var [ 'LminusJ' ] == 0 ) { $ var [ 'LminusJ' ] = 1 ; } $ term1 = $ var [ 'jointFrequency' ] * $ var [ 'n22' ] ; ...
Calculate the Odds Ratio
50,086
public function applyStemmer ( IStemmer $ stemmer , $ removeNulls = true ) { foreach ( $ this -> tokens as & $ token ) { $ token = $ stemmer -> stem ( $ token ) ; } if ( $ removeNulls ) { $ this -> tokens = array_values ( array_filter ( $ this -> tokens ) ) ; } return $ this ; }
Apply a stemmer
50,087
public function applyTransformation ( ITokenTransformation $ transformer , $ removeNulls = true ) { foreach ( $ this -> tokens as & $ token ) { $ token = $ transformer -> transform ( $ token ) ; } if ( $ removeNulls ) { $ this -> tokens = array_values ( array_filter ( $ this -> tokens ) ) ; } return $ this ; }
Apply the transformation
50,088
public function applyExtract ( IExtractStrategy $ extract ) { $ found = [ ] ; foreach ( $ this -> tokens as $ token ) { if ( $ extract -> filter ( $ token ) ) { $ found [ ] = $ token ; } } return $ found ; }
Apply an extract filter and return the results after filter all the documents in the collection
50,089
static public function getAllSubStrings ( $ text ) { $ splitText = str_split ( $ text ) ; $ splitCount = count ( $ splitText ) ; $ subStrings = [ ] ; for ( $ i = 0 ; $ i < $ splitCount ; $ i ++ ) { for ( $ j = $ i ; $ j < $ splitCount ; $ j ++ ) { $ subStrings [ ] = implode ( array_slice ( $ splitText , $ i , $ j - $ i...
Takes a string and produces all possible substrings
50,090
static function markString ( string $ text , int $ position , int $ length , array $ mark ) : string { $ text = substr_replace ( $ text , $ mark [ 0 ] , $ position , 0 ) ; $ text = substr_replace ( $ text , $ mark [ 1 ] , $ position + $ length + strlen ( $ mark [ 0 ] ) , 0 ) ; return $ text ; }
Mark a string
50,091
static function getExcerpt ( String $ text , int $ needlePosition , int $ needleLength , int $ contextLength ) : string { $ left = max ( $ needlePosition - $ contextLength , 0 ) ; $ bufferLength = $ needleLength + ( 2 * $ contextLength ) ; if ( $ needleLength + $ contextLength + $ needlePosition > strlen ( $ text ) ) {...
Get a excerpt from a string by a neddle postion and its length
50,092
public function normalize ( float $ score , int $ alpha = 15 ) { $ normalizedScore = $ score / sqrt ( ( $ score ^ 2 ) + $ alpha ) ; if ( $ normalizedScore < - 1.0 ) { return - 1.0 ; } elseif ( $ normalizedScore > 1.0 ) { return 1.0 ; } return $ normalizedScore ; }
Normalize the score to be between - 1 and 1 using an alpha that approximates the max expected value
50,093
public function getPolarityScores ( array $ tokens ) : array { $ sentiments = [ ] ; for ( $ index = 0 ; $ index < count ( $ tokens ) ; $ index ++ ) { $ valence = 0.0 ; $ lcToken = strtolower ( $ tokens [ $ index ] ) ; if ( $ lcToken === "kind" && strtolower ( $ tokens [ $ index + 1 ] ) === 'of' || isset ( self :: $ thi...
Return a float for sentiment strength based on the input text . Positive values are positive valence negative value are negative valence .
50,094
public function leastCheck ( float $ valence , array $ tokens , int $ index ) : float { if ( $ index === 0 ) { return $ valence ; } $ inLexicon = isset ( $ this -> getLexicon ( ) [ strtolower ( $ tokens [ $ index - 1 ] ) ] ) ; if ( $ inLexicon ) { return $ valence ; } $ leastIndex = array_searchi ( 'least' , $ tokens )...
check for negation case using least
50,095
public function butCheck ( array $ tokens , array $ sentiments ) { $ index = array_searchi ( 'but' , $ tokens ) ; if ( $ index === false ) { return $ sentiments ; } for ( $ i = 0 ; $ i < count ( $ sentiments ) ; $ i ++ ) { if ( $ index < $ i ) { $ sentiments [ $ i ] *= 0.5 ; } elseif ( $ index > $ i ) { $ sentiments [ ...
check for modification in sentiment due to contrastive conjunction but
50,096
public function getLexicon ( ) : array { if ( ! file_exists ( $ this -> getTxtFilePath ( ) ) ) { throw new \ RuntimeException ( 'Package vader_lexicon must be installed, php textconsole pta:install:package vader_lexicon' ) ; } if ( empty ( $ this -> lexicon ) ) { $ fh = fopen ( $ this -> getTxtFilePath ( ) , "r" ) ; wh...
Loads the flat file data set
50,097
protected function normalize ( string $ text ) : string { $ search = [ 'jan.' , 'feb.' , 'mar.' , 'apr.' , 'may.' , 'jun.' , 'jul.' , 'aug.' , 'sep.' , 'oct.' , 'nov.' , 'dec.' ] ; $ replace = [ "january" , "february" , "march" , "april" , "may" , "june" , "july" , "august" , "september" , "october" , "november" , "dec...
Remove any periods from abbreviated month names ie Mar . to March
50,098
public function similarity ( $ text1 , $ text2 ) { $ similarity = 0 ; $ hash1 = $ this -> hashString ( $ text1 ) ; $ hash2 = $ this -> hashString ( $ text2 ) ; $ keys = array_keys ( array_intersect_key ( $ hash1 , $ hash2 ) ) ; foreach ( $ keys as $ key ) { if ( $ hash1 [ $ key ] === $ hash2 [ $ key ] && $ hash1 [ $ ke...
Returns the most frequently used letter with the same frequency
50,099
public function hashString ( $ text ) { $ charList = str_split ( $ text ) ; $ chars = array_fill_keys ( $ charList , 0 ) ; foreach ( $ charList as $ char ) { $ chars [ $ char ] ++ ; } return $ chars ; }
Returns a sorted hashed array with the frequency counts per character