Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
Training
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Contact


Privacy Policy



FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

 

 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

AllWordCombinations (theWords)

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 4.2  (33 votes)
  Discuss this Custom Function

Michael E. Kupietz, Michael E. Kupietz, FileMaker Consultant
https://www.kupietz.com

List all possible subsets from a string of words

Sample Input:
AllWordCombinations("boy girl cat dog")
Sample Output:
boy
boy girl
boy girl cat
boy girl dog
boy girl cat dog
boy cat
boy dog
boy cat dog
girl
girl cat
girl dog
girl cat dog
cat
dog
cat dog


 Then copy & paste into FileMaker Advanced's Edit Custom Function window.

Description:

Given a string of words separated by spaces, this function returns a list of every unique combination of one or more of those words. For instance, AllWordCombinations("boy girl cat dog") will return:

"boy
boy girl
boy girl cat
boy girl dog
boy girl cat dog
boy cat
boy dog
boy cat dog
girl
girl cat
girl dog
girl cat dog
cat
dog
cat dog"

Please note: this returns all combination, not all permutations. "Boy cat" and "Cat boy" are two different permutations, but the same combination. A fruit salad made of apples and grapes is the same as a fruit salad made of grapes and apples.

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

Discuss:

5 most recent comments | Show all 12 comments

Oops, there shouldn't have been a space in "XYZABCSLASHXYZABC", above.

Michael E. Kupietz, FileMaker Consultant, San Francisco, CA
April 09, 2017 10:21pm

Is there a way to exclude specific words (ie: "and", "the" ) ?

Ronnie Higgins, Anaheim
March 07, 2018 10:03am

Can it be made to restrict the outcome to only consecutive word combinations?

Ronnie Higgins, Anaheim
March 07, 2018 10:05am

You can easily exclude specific words by putting a substitute() in the beginning of the function to replace theWords with substitute(theWords,["the",""],["and","& quot;],...).

To make this simpler, I'd probably run the whole thing through lower() too... substitute(lower(theWords),["the",""],["and", ""],...) since "the" will not match "The" in a substitute function().

Michael E. Kupietz, FileMaker Consultant, San Francisco, CA
March 07, 2018 5:18pm

As for your second question, if I'm understanding you correctly, you only want it to return combinations that appear in order... so AllConsecutiveWordCombinations("boy girl cat dog") would return:

"boy
boy girl
boy girl cat
boy girl cat dog
girl
girl cat
girl cat dog
cat
dog
cat dog"

This is possible in the abstract, but complicated because of the way the function works. If I wanted to do this in a real-life situation, where I wanted to get it done quickly rather than having fun with the challenge, I might just write a second recursive function that compares every value in a list to a given string, then omits values that don't appear in that string (using, say PatternCount to determine this.)

Something like:

omitNonconsecutive(firstCFresults,compareString) =

if (
patterncount ( compareString ; getvalue ( firstCFresults ; 1 ) ) > 0 ;
getvalue ( firstCFresults ; 1 ) & "¶" ;
""
) &
if (
valuecount ( valueList ) > 0 ;
omitNonconsecutive (
rightvalues ( firstCFresults ; valuecount ( firstCFresults ) - 1 ) ;
compareString
) ;
""
)

Then you could just do omitNonconsecutive(AllWordCombinations("boy girl cat dog"),"boy girl cat dog") to get only the consecutive combinations.

I haven't tested the above, though. It's just the general idea.

Alternatively you could also adapt an "explode text" function (found elsewhere on this site) to do it with one function.

Michael E. Kupietz, FileMaker Consultant, San Francisco, CA
March 07, 2018 5:22pm

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Your Name:
City/Location:
Comment:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 0 + 1 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. ChiSquare3x2 ( param ; param ; param ; param )
  (Tue, Aug 14, 6:33am)
2. ReverseByteOrder ( bytes )
  (Thu, Aug 09, 12:06pm)
3. BytesToDec ( hex )
  (Thu, Aug 09, 11:47am)
4. GetAsHexBytes ( number ; bytes )
  (Thu, Aug 09, 10:50am)
5. ValCorrelationCoeff ( XValueList; YValueList; Xmean; Ymean; XStdDev; YStdDev )
  (Wed, Aug 08, 4:17pm)
6. ValLeastSquaresSlope ( XValueList; YValueList; Xmean; Ymean )
  (Wed, Aug 08, 4:10pm)
7. ValueMath ( List1 ; List2 ; operation )
  (Wed, Aug 08, 4:05pm)
8. GetExtension ( File )
  (Tue, Aug 07, 10:22am)

RSS Feed of Custom Functions