जब Christopher Johnson McCandless {1}{2} . पर मैप किया गया है :
दो समूह बनाने के लिए संभावित संयोजन है:
Christopher JohnsonऔरMcCandlessChristopherऔरJohnson McCandless
जब cinema tomorrow at night {3}{4} में मैप किया गया है
दो समूह बनाने के लिए संभावित संयोजन है:
cinemaऔरtomorrow at nightcinema tomorrowऔरat nightcinema tomorrow atऔरnight
get_possible_groups($string_of_words, $group_count) पर एक PHP फ़ंक्शन लिखें समूह संयोजनों की सरणी की सरणी देता है।
और एक SQL कथन जैसे:
SELECT count(*), 'cinema' firstWordGroup, 'tomorrow at night' secondWordGroup
FROM possibleMatchTable
WHERE possible_match IN ('cinema', 'tomorrow at night')
UNION
SELECT count(*), 'cinema tomorrow', 'at night'
FROM possibleMatchTable
WHERE possible_match IN ('cinema tomorrow', 'at night')
UNION
SELECT count(*), 'cinema tomorrow at', 'night'
FROM possibleMatchTable
WHERE possible_match IN ('cinema tomorrow at', 'night');
एक संभावित आउटपुट हो सकता है:
+----------+--------------------+-------------------+
| count(*) | firstWordGroup | secondWordGroup |
+----------+--------------------+-------------------+
| 2 | cinema | tomorrow at night |
| 0 | cinema tomorrow | at night |
| 0 | cinema tomorrow at | night |
+----------+--------------------+-------------------+
जिस किसी की गिनती 2 (दो शब्द समूह) है, वह आपका उत्तर है।
अगर MODEL टेक्स्ट एक fulltext है अनुक्रमित कॉलम तो किसी दिए गए यादृच्छिक स्ट्रिंग के लिए आप सबसे अधिक प्रासंगिक मॉडल प्राप्त कर सकते हैं जैसे:
SELECT * FROM model_strings
WHERE MATCH(model) AGAINST ('Damn you Spar, Kot will kill you.');
क्वेरी आपको कुछ इस तरह लौटा सकती है:
+----------------------------------+
| model |
+----------------------------------+
| Damn you {1}, {2} will kill you. |
+----------------------------------+
MODEL . से प्लेसहोल्डर्स का उपयोग करके रैंडम स्ट्रिंग के लिए शब्द निकालना :
<?php
$placeholder_pRegEx = '#\{\d+\}#';
$model = 'Damn you {1}, {2} will kill you. {3}{4}{5}';
$string = 'Damn you Spar, Will will kill you. I Love it man.';
$model_words = explode(' ', $model);
$string_words = explode(' ', $string);
$placeholder_words = array();
for ($idx =0, $jdx=0; $idx < count($string_words); $idx ++) {
if ($jdx < count($model_words)) {
if (strcmp($string_words[$idx], $model_words[$jdx])) {
$placeholder_words[] = $string_words[$idx];
//Move to next word in Model only if it's a placeholder
if (preg_match($placeholder_pRegEx, $model_words[$jdx]))
$jdx++;
} else
$jdx++; //they match so move to next word
} else
$placeholder_words[] = $string_words[$idx];
}
//Even status will have the count
$status = preg_match_all ($placeholder_pRegEx, $model, $placeholders);
$group_count = count($placeholders[0]);
var_dump(get_defined_vars());
?>
ऊपर दिए गए कोड से आपको इस तरह के मान मिलेंगे:
'placeholder_words' => array (size=6)
0 => string 'Spar,' (length=5)
1 => string 'Will' (length=4)
2 => string 'I' (length=1)
3 => string 'Love' (length=4)
4 => string 'it' (length=2)
5 => string 'man.' (length=4)
'placeholders' => array (size=1)
0 =>
array (size=5)
0 => string '{1}' (length=3)
1 => string '{2}' (length=3)
2 => string '{3}' (length=3)
3 => string '{4}' (length=3)
4 => string '{5}' (length=3)
'group_count' => int 5
- वहां से आप कॉल कर सकते हैं
get possible groupings - फिर SQL क्वेरी अनुमत संभावित मिलानों के विरुद्ध जाँच करने के लिए
- आवश्यक समूहों में वास्तविक शब्द।
काश, यह कुछ सवाल होता, एह!