यहां मैथमैटिका में एक कोड है जिसे मैंने हाल ही में कोड गोल्फ के लिए विकसित करना शुरू किया था।
यह एक न्यूनतम मिलान, गैर लालची, रिकर्सिव एल्गोरिदम है। इसका मतलब है कि वाक्य "कलम तलवार से अधिक mighter है" (रिक्तियों के बिना) देता है :)
findAll[s_] :=
Module[{a = s, b = "", c, sy = "="},
While[
StringLength[a] != 0,
j = "";
While[(c = findFirst[a]) == {} && StringLength[a] != 0,
j = j <> StringTake[a, 1];
sy = "~";
a = StringDrop[a, 1];
];
b = b <> " " <> j ;
If[c != {},
b = b <> " " <> c[[1]];
a = StringDrop[a, StringLength[c[[1]]]];
];
];
Return[{StringTrim[StringReplace[b, " " -> " "]], sy}];
]
findFirst[s_] :=
If[s != "" && (c = DictionaryLookup[s]) == {},
findFirst[StringDrop[s, -1]], Return[c]];
नमूना इनपुट
ss = {"twodreamstop",
"onebackstop",
"butterfingers",
"dependentrelationship",
"payperiodmatchcode",
"labordistributioncodedesc",
"benefitcalcrulecodedesc",
"psaddresstype",
"ageconrolnoticeperiod",
"month05",
"as_benefits",
"fname"}
आउटपुट { "कलम तलवार से अधिक हो सकता है एर है}
twodreamstop = two dreams top
onebackstop = one backstop
butterfingers = butterfingers
dependentrelationship = dependent relationship
payperiodmatchcode = pay period match code
labordistributioncodedesc ~ labor distribution coded es c
benefitcalcrulecodedesc ~ benefit c a lc rule coded es c
psaddresstype ~ p sad dress type
ageconrolnoticeperiod ~ age con rol notice period
month05 ~ month 05
as_benefits ~ as _ benefits
fname ~ f name
HTH
स्रोत
2010-10-11 02:56:43
[जस्टैडिस्ट्रक्शन: संभवतः व्हाइटस्पेस के बिना अंग्रेजी टोकनिंग के संभावित डुप्लिकेट। मुराकामी भेड़मान] (http://stackoverflow.com/questions/3851723/justadistraction-tokenizing-english-without-whitespaces-murakami-sheepman) –
कुछ अर्थपूर्ण ज्ञान के बिना हमेशा संभव डुप्लीकेट होंगे। "उनके" = "लोहे" = "उनके" –