How can I split multiple joined words?

The Viterbi algorithm is much faster. It computes the same scores as the recursive search in Dmitry’s answer above, but in O(n) time. (Dmitry’s search takes exponential time; Viterbi does it by dynamic programming.) import re from collections import Counter def viterbi_segment(text): probs, lasts = [1.0], [0] for i in range(1, len(text) + 1): prob_k, … Read more

How do I remove the file suffix and path portion from a path string in Bash?

Here’s how to do it with the # and % operators in Bash. $ x=”/foo/fizzbuzz.bar” $ y=${x%.bar} $ echo ${y##*/} fizzbuzz ${x%.bar} could also be ${x%.*} to remove everything after a dot or ${x%%.*} to remove everything after the first dot. Example: $ x=”/foo/fizzbuzz.bar.quux” $ y=${x%.*} $ echo $y /foo/fizzbuzz.bar $ y=${x%%.*} $ echo $y … Read more

Using on a List doesn’t update model values

The String class is immutable and doesn’t have a setter for the value. The getter is basically the Object#toString() method. You need to get/set the value directly on the List instead. You can do that by the list index which is available by <ui:repeat varStatus>. <ui:repeat value=”#{mrBean.stringList}” varStatus=”loop”> <h:inputText value=”#{mrBean.stringList[loop.index]}” /> </ui:repeat> You don’t need … Read more

Sqlite convert string to date

As SQLite doesn’t have a date type you will need to do string comparison to achieve this. For that to work you need to reverse the order – eg from dd/MM/yyyy to yyyyMMdd, using something like where substr(column,7)||substr(column,4,2)||substr(column,1,2) between ‘20101101’ and ‘20101130’

How to find numbers from a string?

Assuming you mean you want the non-numbers stripped out, you should be able to use something like: Function onlyDigits(s As String) As String ‘ Variables needed (remember to use “option explicit”). ‘ Dim retval As String ‘ This is the return string. ‘ Dim i As Integer ‘ Counter for character position. ‘ ‘ Initialise … Read more

How to extract file name from path?

The best way of working with files and directories in VBA for Office 2000/2003 is using the scripting library. Create a filesystem object and do all operations using that. Early binding: Add a reference to Microsoft Scripting Runtime (Tools > References in the IDE). Dim fso as new FileSystemObject Dim fileName As String fileName = … Read more