|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* @Name : similar-text |
|
5
|
|
|
* @Programmer : Akpé Aurelle Emmanuel Moïse Zinsou |
|
6
|
|
|
* @Date : 2019-04-01 |
|
7
|
|
|
* @Released under : https://github.com/manuwhat/similar-text/blob/master/LICENSE |
|
8
|
|
|
* @Repository : https://github.com/manuwhat/similar |
|
9
|
|
|
* |
|
10
|
|
|
**/ |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
namespace EZAMA{ |
|
14
|
|
|
|
|
15
|
|
|
class complexCommonTextSimilarities extends complexCommonTextSimilaritiesHelper |
|
16
|
|
|
{ |
|
17
|
|
|
public static function strippedUrl($a, $b) |
|
18
|
|
|
{ |
|
19
|
|
|
if (self::isUrl($a, $domain) && is_string($b)) { |
|
20
|
|
|
return $domain === trim($b); |
|
21
|
|
|
} elseif (self::isUrl($b, $domain) && is_string($a)) { |
|
22
|
|
|
return $domain === trim($a); |
|
23
|
|
|
} else { |
|
24
|
|
|
return false; |
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
public static function areStems($a, $b) |
|
28
|
|
|
{ |
|
29
|
|
|
if (!is_string($a) || !is_string($b)) { |
|
30
|
|
|
return false; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
$a = self::getParts(self::strtolower($a)); |
|
34
|
|
|
$b = self::getParts(self::strtolower($b)); |
|
35
|
|
|
foreach ((array) $a as $index=>$word) { |
|
36
|
|
|
if (!self::haveSameRoot($word, $b[$index])) { |
|
37
|
|
|
return false; |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
return true; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public static function wordsAddedOrRemoved($a, $b) |
|
44
|
|
|
{ |
|
45
|
|
|
if (!is_string($a) || !is_string($b)) { |
|
46
|
|
|
return false; |
|
47
|
|
|
} |
|
48
|
|
|
$filter = function($v) { |
|
49
|
|
|
return !(ctype_space($v)); |
|
50
|
|
|
}; |
|
51
|
|
|
self::filter($a, $b, $filter, true); |
|
52
|
|
|
return self::waorDiff($a, $b, count($a), count($b)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
public static function punctuationChangesOccured($a, $b, $insensitive = true, $considerSpace = true) |
|
57
|
|
|
{ |
|
58
|
|
|
$filter = function($v) use ($considerSpace) { |
|
59
|
|
|
return $considerSpace ? !(ctype_space($v) || ctype_punct($v)) : !ctype_punct($v); |
|
60
|
|
|
}; |
|
61
|
|
|
if (!is_string($a) || !is_string($b)) { |
|
62
|
|
|
return false; |
|
63
|
|
|
} |
|
64
|
|
|
self::filter($a, $b, $filter, $insensitive); |
|
65
|
|
|
return empty(array_diff($a, $b)); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
public static function acronymOrExpanded($a, $b) |
|
70
|
|
|
{ |
|
71
|
|
|
if (!is_string($a) || !is_string($b)) { |
|
72
|
|
|
return false; |
|
73
|
|
|
} |
|
74
|
|
|
$filter = function($v) { |
|
75
|
|
|
return !(ctype_space($v[0]) || ctype_punct($v[0])); |
|
76
|
|
|
}; |
|
77
|
|
|
|
|
78
|
|
|
self::filter($a, $b, $filter, true, true); |
|
79
|
|
|
return self::aoeStemming($a, $b); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|