25 public static function isLocationsEqual($location1, $location2)
27 foreach($location1 as $type => $name)
29 if(empty($location2[$type]))
32 if($location1[$type] <>
'' && $location2[$type] <>
'')
35 $comparator = self::getConcreteComparatorClassaName($type);
37 if(!$comparator::isEntityEqual($location1[$type], $location2[$type]))
47 if(self::$replacement ===
null)
48 self::setReplacement();
50 return self::$replacement;
63 return self::getReplacement()->isCountryRussia($countryName);
71 private static function getConcreteComparatorClassaName($type)
73 if($type === self::LOCALITY || $type ===
'LOCALITY' || $type ==
'CITY')
74 $result =
'ComparatorLocality';
75 elseif($type === self::DISTRICT || $type ===
'SUBREGION')
77 elseif($type === self::REGION || $type === 'REGION')
79 elseif($type === self::COUNTRY || $type === 'COUNTRY')
87 public static function isEntityEqual($entity1, $entity2, $type = '')
92 $comparator = self::getConcreteComparatorClassaName($type);
93 return $comparator::isEntityEqual($entity1, $entity2);
96 if(is_array($entity1) && !empty($entity1[
'NAME']))
98 $entity1N = array(
'NAME' => $entity1[
'NAME']);
99 $entity1N[
'TYPE'] = !empty($entity1[
'TYPE']) ? $entity1[
'TYPE'] :
'';
103 $entity1N = static::normalize($entity1);
106 if(is_array($entity2) && !empty($entity2[
'NAME']))
108 $entity2N = array(
'NAME' => $entity2[
'NAME']);
109 $entity2N[
'TYPE'] = !empty($entity2[
'TYPE']) ? $entity2[
'TYPE'] :
'';
113 $entity2N = static::normalize($entity2);
116 if($entity1N[
'NAME'] <>
'' && $entity2N[
'NAME'] <>
'')
117 if($entity1N[
'NAME'] != $entity2N[
'NAME'])
120 if($entity1N[
'TYPE'] <>
'' && $entity2N[
'TYPE'] <>
'')
121 if($entity1N[
'TYPE'] != $entity2N[
'TYPE'])
134 if(static::$variants ===
null)
136 static::setVariantsValues(array());
139 return static::$variants;
147 public static function setVariants(array $variants = array())
149 foreach($variants as $type => $v)
152 $comparator = self::getConcreteComparatorClassaName($type);
153 $comparator::setVariantsValues(
154 self::normalizeVariants($v)
161 $result = preg_replace(
'/\s*(\(.*\))/i'.BX_UTF_PCRE_MODIFIER,
' ', $value);
162 $result = preg_replace(
'/[~\'\"\`\!\@\#\$\%\^\&\*\+\=\\\.\,\?\:\;\{\}\[\]\-]/i'.BX_UTF_PCRE_MODIFIER,
' ', $result);
163 $result = preg_replace(
'/\s{2,}/i'.BX_UTF_PCRE_MODIFIER,
' ', $result);
164 $result = ToUpper($result);
165 $result = self::getReplacement()->changeYoE($result);
166 $result = trim($result);
175 foreach($variants as $k => $v)
176 $result[self::flatten($k)] = self::flatten($v);
181 public static function normalizeEntity($name, $type)
184 $comparator = self::getConcreteComparatorClassaName($type);
185 return $comparator::normalize($name);
191 $name = self::flatten($name);
194 return array(
'NAME' =>
'',
'TYPE' =>
'');
197 $types = static::getTypes();
203 if($name == self::flatten($wrong))
210 foreach($types as $type => $search)
212 if(!is_array($search))
217 foreach($search as $s)
220 $s = self::flatten($s);
222 if(mb_strpos($name, $s.
' ') !==
false)
223 $regexp =
'/^'.$s.
'\s+(.*)$/i'.BX_UTF_PCRE_MODIFIER;
224 elseif(mb_strpos($name,
' '.$s) !==
false)
225 $regexp =
'/^(.*)\s+'.$s.
'$/i'.BX_UTF_PCRE_MODIFIER;
227 if($regexp <>
'' && preg_match($regexp, $name, $matches))
238 'TYPE' => $resultType
248 $types = self::getReplacement()->getLocalityTypes();
252 $result[] = ToUpper($type.
' '.$name);
253 $result[] = ToUpper($name.
' '.$type);
255 if(is_array($types[$type]) && !empty($types[$type]))
257 foreach($types[$type] as $t)
259 $result[] = ToUpper($t.
' '.$name);
260 $result[] = ToUpper($name.
' '.$t);
266 foreach($types as $k => $v)
268 $result[] = ToUpper($k.
' '.$name);
269 $result[] = ToUpper($name.
' '.$k);
271 if(is_array($v) && !empty($v))
275 $result[] = ToUpper($vv.
' '.$name);
276 $result[] = ToUpper($name.
' '.$vv);