{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"The Sørensen-Dice coefficient is calculated using the following formula:\n\nDice(A, B) = 2 * |A ∩ B| / (|A| + |B|)\n\nwhere A and B are two sets, |A| and |B| represent the number of elements in sets A and B, respectively, and |A ∩ B| denotes the number of elements common to both sets.\n\nThe coefficient ranges from 0 to 1, where 0 indicates no similarity between the two sets, and 1 indicates that the sets are identical.","metadata":{}},{"cell_type":"code","source":"def bigrams(string):\n    return set(string[i:i + 2] for i in range(len(string) - 1))\n\ndef sorensen_dice_coefficient(string1, string2):\n    bigrams1 = bigrams(string1)\n    bigrams2 = bigrams(string2)\n    intersection = bigrams1.intersection(bigrams2)\n    return 2 * len(intersection) / (len(bigrams1) + len(bigrams2))\n\n# Example usage\nstring1 = \"example\"\nstring2 = \"samples\"\ncoefficient = sorensen_dice_coefficient(string1, string2)\nprint(f\"The Sørensen-Dice coefficient for '{string1}' and '{string2}' is: {coefficient}\")\n","metadata":{"execution":{"iopub.status.busy":"2023-03-16T19:05:55.570354Z","iopub.execute_input":"2023-03-16T19:05:55.570805Z","iopub.status.idle":"2023-03-16T19:05:55.601444Z","shell.execute_reply.started":"2023-03-16T19:05:55.570766Z","shell.execute_reply":"2023-03-16T19:05:55.600026Z"},"trusted":true},"execution_count":null,"outputs":[]}]}