Haskell file reading

Not a bad start! The only thing to remember is that pure function application should use let instead of the binding <-. import System.IO import Control.Monad main = do let list = [] handle <- openFile “test.txt” ReadMode contents <- hGetContents handle let singlewords = words contents list = f singlewords print list hClose handle … Read more

Explode a paragraph into sentences in PHP

You can use preg_split() combined with a PCRE lookahead condition to split the string after each occurance of ., ;, :, ?, !, .. while keeping the actual punctuation intact: Code: $subject=”abc sdfs. def ghi; this is [email protected]! asdasdasd? abc xyz”; // split on whitespace between sentences preceded by a punctuation mark $result = preg_split(‘/(?<=[.?!;:])\s+/’, … Read more

Android Word-Wrap EditText text

Besides finding the source of the issue, I found the solution. If android:inputType is used, then textMultiLine must be used to enable multi-line support. Also, using inputType supersedes the code android:singleLine=”false”. If using inputType, then, to reiterate, textMultiLine must be used or the EditText object will only consist of one line, without word-wrapping. Edit: Thank … Read more

How to split a string into words. Ex: “stringintowords” -> “String Into Words”?

Let’s assume that you have a function isWord(w), which checks if w is a word using a dictionary. Let’s for simplicity also assume for now that you only want to know whether for some word w such a splitting is possible. This can be easily done with dynamic programming. Let S[1..length(w)] be a table with … Read more

php sentence boundaries detection [duplicate]

An enhanced regex solution Assuming you do care about handling: Mr. and Mrs. etc. abbreviations, then the following single regex solution works pretty well: <?php // test.php Rev:20160820_1800 $split_sentences=”%(?#!php/i split_sentences Rev:20160820_1800) # Split sentences on whitespace between them. # See: http://stackoverflow.com/a/5844564/433790 (?<= # Sentence split location preceded by [.!?] # either an end of sentence … Read more

Converting a String to a List of Words?

Try this: import re mystr=”This is a string, with words!” wordList = re.sub(“[^\w]”, ” “, mystr).split() How it works: From the docs : re.sub(pattern, repl, string, count=0, flags=0) Return the string obtained by replacing the leftmost non-overlapping occurrences of pattern in string by the replacement repl. If the pattern isn’t found, string is returned unchanged. … Read more