-
Notifications
You must be signed in to change notification settings - Fork 38
Fix 128bit SimHash, and add 256bit and 512bit SimHash #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nicolaichuk
wants to merge
7
commits into
tgalopin:master
Choose a base branch
from
nicolaichuk:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
34f1cfc
fix 128 bit SimHash
nicolaichuk 3c70177
small bug fix
nicolaichuk 2938ad5
* change comment
nicolaichuk 776d0d7
change protected to private
nicolaichuk 896912d
fix by code review https://github.com/tgalopin/SimHashPhp/pull/5
nicolaichuk 284477d
support php 5.3+
nicolaichuk b263fc7
fix function call
nicolaichuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,4 +26,4 @@ interface ExtractorInterface | |
| * @return array | ||
| */ | ||
| public function extract($input); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,4 +94,4 @@ protected function parseBody(\DOMDocument $document) | |
|
|
||
| return $node->nodeValue; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,4 +34,4 @@ public function extract($text) | |
|
|
||
| return explode('-', $slugifiedText); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the SimHashPhp package. | ||
| * | ||
| * (c) Titouan Galopin <http://titouangalopin.com/> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Tga\SimHash\Tokenizer; | ||
|
|
||
| /** | ||
| * Tokenizer for strings that generate 256 bit tokens. | ||
| * | ||
| * @author Titouan Galopin <http://titouangalopin.com/> | ||
| */ | ||
| class String256Tokenizer implements TokenizerInterface | ||
| { | ||
| private static $search = array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'); | ||
| private static $replace = array('0000','0001','0010','0011','0100','0101','0110','0111','1000','1001','1010','1011','1100','1101','1110','1111'); | ||
|
|
||
| /** | ||
| * @param string $element | ||
| * @return string | ||
| */ | ||
| public function tokenize($element) | ||
| { | ||
| $hash = hash('sha256', $element); | ||
| $hash = str_replace(self::$search, self::$replace, $hash); | ||
| $hash = str_pad($hash, 256, '0', STR_PAD_LEFT); | ||
| return $hash; | ||
| } | ||
|
|
||
| /** | ||
| * Does this tokenizer supports the given element | ||
| * | ||
| * @param string $element | ||
| * @return boolean | ||
| */ | ||
| public function supportsElement($element) | ||
| { | ||
| return is_string($element); | ||
| } | ||
|
|
||
| /** | ||
| * Does this tokenizer return tokens of the given size | ||
| * | ||
| * @param int $size | ||
| * @return boolean | ||
| */ | ||
| public function supportsSize($size) | ||
| { | ||
| return $size === 256; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,4 +48,4 @@ public function supportsSize($size) | |
| { | ||
| return $size === 32; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the SimHashPhp package. | ||
| * | ||
| * (c) Titouan Galopin <http://titouangalopin.com/> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Tga\SimHash\Tokenizer; | ||
|
|
||
| /** | ||
| * Tokenizer for strings that generate 512 bit tokens. | ||
| * | ||
| * @author Titouan Galopin <http://titouangalopin.com/> | ||
| */ | ||
| class String512Tokenizer implements TokenizerInterface | ||
| { | ||
| private static $search = array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'); | ||
| private static $replace = array('0000','0001','0010','0011','0100','0101','0110','0111','1000','1001','1010','1011','1100','1101','1110','1111'); | ||
|
|
||
| /** | ||
| * @param string $element | ||
| * @return string | ||
| */ | ||
| public function tokenize($element) | ||
| { | ||
| $hash = hash('sha512', $element); | ||
| $hash = str_replace(self::$search, self::$replace, $hash); | ||
| $hash = str_pad($hash, 512, '0', STR_PAD_LEFT); | ||
| return $hash; | ||
| } | ||
|
|
||
| /** | ||
| * Does this tokenizer supports the given element | ||
| * | ||
| * @param string $element | ||
| * @return boolean | ||
| */ | ||
| public function supportsElement($element) | ||
| { | ||
| return is_string($element); | ||
| } | ||
|
|
||
| /** | ||
| * Does this tokenizer return tokens of the given size | ||
| * | ||
| * @param int $size | ||
| * @return boolean | ||
| */ | ||
| public function supportsSize($size) | ||
| { | ||
| return $size === 512; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,4 +108,4 @@ private function buildTable() | |
|
|
||
| return $crc64tab; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,4 +41,4 @@ public function supportsElement($element); | |
| * @return boolean | ||
| */ | ||
| public function supportsSize($size); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,4 +61,4 @@ protected function createWeightTokens($tokens) | |
|
|
||
| return $weightTokens; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,4 +24,4 @@ interface VectorizerInterface | |
| * @return array | ||
| */ | ||
| public function vectorize(array $tokens, $size); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to split this in parts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For more comfort debugging