Sentence jumble with all possible combinations - node.js

I was wondering if it was possible to create a sentence jumble that would output all possible variations using all words from a given sentence using node.js
ie.
"The brown fox" would output to:
"Fox the brown"
"Brown fox the"
"The fox brown"
"Brown the fox"
"Fox brown the"
Thank you in advance.

Related

Using double quotes for exact matching - how to handle edge cases? (Ex. Odd number of quotes.)

Summary
It's been requested that we add exact matching to the search form on our site.
Below are examples of how we expect the search to operate.
Example 1
No exact match has been indicated by the user
Input: quick brown fox lazy dog
Output: matches for quick, brown, fox, lazy, and dog
Example 2
"brown" is the exact match indicated by the user
Input: quick "brown" fox lazy dog
Output: matches for quick, brown, fox, lazy, and dog (Same as example 1.)
Example 3
"brown fox" is the exact match indicated by the user
Input: quick "brown fox" lazy dog
Output: matches for quick, brown fox, lazy and dog
Example 4
"quick brown" and "lazy dog" are the exact matches indicated by the user
Input: "quick brown" fox "lazy dog"
Output: matches for quick brown, fox, and lazy dog
Question
Now we're trying to determine how edge cases should be handled. Specifically, how should we handle an odd number of quotes (see example 5) and how should we handle double quotes that occur in the middle of words (see example 6 and 7)?
Example 5
Odd number of double-quotes
Input: "quick brown" fox "lazy dog
Possible Output:
Matches for quick brown, fox, "lazy, and dog (Use spaces to delimit the search)
Matches for quick brown, fox, lazy, and dog (Ignore the odd double-quote)
Matches for quick brown, fox, and lazy dog (Add a closing double-quote after the last term)
Example 6
Even number of quotes, some of which interrupt a word
Input: qu"ick brown" fox lazy dog
Possible Output:
Matches for qu, ick brown, fox, lazy, and dog ?
(I couldn't think of another way to handle it, but I'm open to ideas.)
Example 7
Odd number of quotes, final quote interrupts a word
Input: "quick brown" fox la"zy dog
Possible Output:
Matches for quick brown, fox, la"zy, and dog (Use spaces to delimit the search)
Matches for quick brown, fox, lazy, and dog (Ignore the odd double-quote)
Matches for quick brown, fox, la, and zy dog (Add a closing double-quote after the last term)
Resources
I tried to search for resources that suggest best practices or common practices for these edge cases, but I wasn't able to find anything.
If you know of any resources on this, please let me know.

vim: Line wrapping after erasing parts of line

Suppose I have the text:
The quick brown
fox jumps over
the lazy dog.
Where I have used a maximum linewidth of 15 characters.
Then, I want to replace "fox jumps over" with "and", i.e., I get:
The quick brown
and
the lazy dog.
How I can fixed again my line-wrapping, i.e.,
The quick brown
and the lazy
dog.
Is there a "fast" way for doing this ?

How to insert text assigned to variable into a file before a string

I have:
A file called 'fooBar'.
A variable called 'myVar', which has the string 'the lazy' assigned to it.
I want to insert $myVar into the file fooBar before the text '</dog>'
fooBar Before:
The quick brown fox jumps over </dog>
fooBarAfter:
The quick brown fox jumps over the lazy </dog>
What is the best way to achieve this please?
You can use sed like this:
cat fooBar
The quick brown fox jumps over </dog>
myVar='the lazy'
sed -i.bak "s~</dog>~$myVar &~" fooBar
cat fooBar
The quick brown fox jumps over the lazy </dog>

using bash command to remove nextline,space

Is sed command capable of removing space,nextline?
I want to have the following output(see output below)
TESTING The quick brown fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog
TESTING02 The quick brown fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog
TESTING03 The quick brown fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog
The output should be the following
TESTING The quick brown fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog
TESTING02 The quick brown fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog
TESTING03 The quick brown fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog
If you like to try awk you can do:
awk '/TESTING/ && NR>1 {print ""} NF' file
TESTING The quick brown fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog
TESTING02 The quick brown fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog
TESTING03 The quick brown fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog
NF prevents it from printing blank line.
/TESTING/ && NR>1 {print ""} adds one blank line before TESTING line except for first line
for your structure
sed '/^[[:space:]]*$/d
1!{
/^TESTING/ s//\
&/
}' YourFile
remove "space line" and ad a new line before TESTING entry (but not for 1st line)
This might work for you (GNU sed):
sed '/\S/!d;1b;/TESTING/i\\' file
Delete any empty lines and insert one before a line containing TESTING unless it's the first.

Solr: Phrase search when indexed phrase is shorter than the query

Is it possible to find a document if the indexed field is a part of the queried phrase?
It it easy to find "Quick brown fox jumps over the lazy dog" when searching for "brown fox" or "lazy dog". But what if I need to do it vice versa?
Here's my situation: I have a short field in a document like "brown fox" or "lazy dog" and I want this document to be found by searching for longer phrases like "Quick brown fox" or "jump over lazy dog".
Note: it should be a phrase match, so making all the terms optional in the query wouldn't work. The query like "brown dog" SHOULD NOT match.
How would you do it in Solr? Is it possible to achieve this goal by only tweaking Solr, without necessity to parse and modify the requested phrase on the client side?
look at ShingleFilterFactory. If you apply that to the query side only, you could achieve what you are looking for.

Resources