/* Word Med in Picat. This is a port of my Perl/CGI program Word Meld: http://www.hakank.org/prefix_meld/word_meld.html """ This program searches for words that has some (pre|suf|in)fix common with a specific word (given by the user). House rule: The word you type in must be at least 5 characters. E.g. Try "kjellerstrand" (my last name). One word meld is "kjellerst-ran-domize (randomize)". The word in parenthesis ("randomize"") is thus melded with "kjellerstrand". The dashes ("-") is used to separate the different parts ("kjellerst-" and "rand-omize") from each other. House rule: The word you type in must be at least 5 characters. """ Some (silly) examples: * kjellerstrand + randomize: kjellerst-ran-domize * tesla + facilitate: facilita-te-sla * circular + artificial: circul-ar-tificial * compat + athletic: comb-at-hletic * kleenex + expertise: kleen-ex-pertise * picat + catalogue: pi-cat-alogue * picat + attitude: pic-at-titude This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import v3_utils. import util. main => go. go ?=> SourceWord = "kjellerstrand", % SourceWord = "hakank", % SourceWord = "anders", % SourceWord = "program", % SourceWord = "google", % SourceWord = "tesla", % SourceWord = "intelligence", % SourceWord = "artificial", % SourceWord = "picat", % SourceWord = "prolog", % WordList = "unixdict.txt", % WordList = "words_lower.txt", % WordList = "allwords3.txt", WordList = "sv_spelling_org_utf8.txt", Words = read_file_lines(WordList), List = [], foreach(Word in Words,length(Word) >= 5,Word != SourceWord) Found = check_word(SourceWord,Word), if Found == true then List := List ++ [Word] end end, println(list=List), println(len=List.len), nl. go => true. % % Check specific words % go2 ?=> SourceWord = "kjellerstrand", Word = "random", _ = check_word(SourceWord,Word), nl. go2 => true. % % Play with a random word % go3 ?=> WordList = "unixdict.txt", % WordList = "words_lower.txt", % WordList = "allwords3.txt", % WordList = "sv_spelling_org_utf8.txt", Words = read_file_lines(WordList), _ = random2(), SourceWord := Words[1+random() mod Words.len], println(sourceWord=SourceWord), List = [], foreach(Word in Words,length(Word) >= 5,Word != SourceWord) Found = check_word(SourceWord,Word), if Found == true then List := List ++ [Word] end end, println(list=List), println(len=List.len), nl. go3 => true. % % Some different ways of combining SourceWord and Word % check_word(SourceWord,Word) = FoundIt => SourceWordLen = SourceWord.len, Len = Word.len, Found = false, if append(SourceWord,Pre,Word) then println(type1=[word=Word,SourceWord ++ Pre, SourceWord ++ "-" ++ Pre]), Found := true end, if append(Word,Post,SourceWord) then println(type2=[word=Word,Word++Post,Word ++ "-" ++ Post]), Found := true end, if append(Pre,Post1,Word), append(Pre2,Pre,SourceWord), Pre.length >= 2, Post1.length >= 2, Pre2.length >= 2, Pre.length >= 2 then println(type3=[word=Word,Pre2++Pre++Post1, Pre2 ++ "-" ++ Pre ++ "-" ++ Post1]), Found := true end, if append(Pre,Post1,SourceWord), append(Pre2,Pre,Word), Pre.length >= 2, Post1.length >= 2, Pre2.length >= 2, Pre.length >= 2 then println(type4=[word=Word,Pre2++Pre++Post1, Pre2 ++ "-" ++ Pre ++ "-" ++ Post1]), Found := true end, if append(Pre,Word,Post,SourceWord), Pre.len >= 2, Post.len >= 2 then println(type5=[word=Word, cond(Pre.length > 0,Pre ++ "-","") ++ Word ++ cond(Post.length > 0,"-" ++ Post,"")]), Found := true end, if find(SourceWord,Word,From,To), From > 1, To < SourceWordLen then println(type6=[word=Word,SourceWord[1..From-1] ++ "-" ++ Word ++ "-" ++ SourceWord[To+1..SourceWordLen]]), Found := true end, if find(Word,SourceWord,From,To), From > 1, To < Len then println(type7=[word=Word,Word[1..From-1] ++ "-" ++ SourceWord ++ "-" ++ Word[To+1..Len]]), Found := true end, FoundIt = Found.