Skip to content

Commit

Permalink
implementation for TokenizedAttributedString->setTokenDictionaryAttri…
Browse files Browse the repository at this point in the history
…bute() and ->lowercaseTokens()
  • Loading branch information
apemsel committed Mar 1, 2016
1 parent 590981a commit 2c239bc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/TokenizedAttributedString.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,24 @@ public function setTokenRangeAttribute($from, $to, $attribute, $state = true) {
return $this->setRange($fromOffset, $toOffset, $attribute, $state);
}

public function setTokenDictionaryAttribute($dictionary, $attribute) {
foreach($this->tokens as $i => $token) {
if (in_array($token, $dictionary)) {
$this->setTokenAttribute($i, $attribute);
}
}
}

public function attributesAtToken($i) {
return $this->attributesAt($this->tokenOffsets[$i]);
}

public function lowercaseTokens() {
$this->tokens = array_map(function($token) {
return mb_strtolower($token, "utf-8");
}, $this->tokens);
}

protected static function tokenizeOnWhitespace($string) {
// Matches pontential whitespace in front of the token and the token itself.
// Matching the whitespace could be omitted, but that results in slower execution ;-)
Expand Down

0 comments on commit 2c239bc

Please sign in to comment.