Not in Java, but this one's in Python
#non-alphanumeric character should be ignored
text = re.sub('[^a-zA-Z\s]', '', text)
#Any other block of contiguous whitespace should be treated as a single space
#white space should be retained
text = re.sub(' +',' ',text)
#Leading and trailing whitespace should be ignored
text = text.strip(' \t\n\r')
# You probably want this too
text = text.lower()
#If they are also the same length, the earlier one in the input sequence should be kept.
# Using arrays (can use OrderedDict too, probably easier and nice, although below is clearer for you.
original_parts = text.split('|')
clean_parts = [clean_input(x) for x in original_parts]
original_parts_to_check = 
ignore_idx = 
for idx, ele in enumerate(original_parts):
if idx in ignore_idx:
#The case of alphabetic characters should be ignored
if len(ele) < 2:
#Duplicates must also be filtered -if two passages are considered equal with respect to the comparison rules listed above, only the shortest should be retained.
if clean_parts[idx] in clean_parts[:idx]+clean_parts[idx+1:]:
indices = [i for i, x in enumerate(clean_parts) if x == clean_parts[idx]]
use = indices
for i in indices[1:]:
if len(original_parts[i]) < len(original_parts[use]):
use = i
if idx == use:
ignore_idx += indices
ignore_idx += [x for x in indices if x != use]
# Doing the text in text matching here. Depending on size and type of dataset,
# Which you should test as it would affect this, you may want this as part
# of the function above, or before, etc. If you're only doing 100 bits of
# data, then it doesn't matter. Optimize accordingly.
text_to_return = 
clean_to_check = [clean_parts[x] for x in original_parts_to_check]
for idx in original_parts_to_check:
# This bit can be done better, but I have no more time to work on this.
if any([(clean_parts[idx] in clean_text) for clean_text in [x for x in clean_to_check if x != clean_parts[idx]]]):
#The retained passages should be output in their original form (identical to the input passage), and in the same order.
assert(process('IBM cognitive computing|IBM "cognitive" computing is a revolution| ibm cognitive computing|\'IBM Cognitive Computing\' is a revolution?') ==
'IBM "cognitive" computing is a revolution')
print(process('IBM cognitive computing|IBM "cognitive" computing is a revolution| ibm cognitive computing|\'IBM Cognitive Computing\' is a revolution?'))
assert(process('IBM cognitive computing|IBM "cognitive" computing is a revolution|the cognitive computing is a revolution') ==
'IBM "cognitive" computing is a revolution|the cognitive computing is a revolution')
print(process('IBM cognitive computing|IBM "cognitive" computing is a revolution|the cognitive computing is a revolution'))
Thanks ashish for your code. But the output of your code is: James
Instead it should be: James is a boy eating sausages.
Thank you NoOne for your comment. Is there any online compiler available for this language that I can test your pseudo code at? That will help me to know your code more and convert it to python or java
MorrisHelen, Speech writer at Micro Design
I am a speechwriter who works directly with senior executives or leaders to determine what points, themes, positions, or messages ...
targienaron, Public relations coordinator at Total Quality
I am a public relations coordinator . Planning publicity strategies and campaigns. writing and producing presentations and press releases. I explore ...
Whyable is an agile team of Software Specialists with vast experience across multiple languages.We will help you to define ...
zhenhsiungz, Android test engineer at AppPerfect
I am a financial planner . I help individuals and corporations meet their long-term financial objectives. I enjoy spending my spare ...
Edwards IVF Surrogate is one of the best & most successful provider of surrogate services.We provide moral, emotional, ethical and ...
Love is the spice of everyone’s life. Love adds charm and excitement to the monotonous and boring life. If ...
Our mission is to provide informative and Self Improvement advice to help people live their lives better set definite goals ...
Looking for the best child development center in Charlotte? Pal A Roos provide summer camp for children Charlotte. Our experienced ...
Hvactools, maintenence engineer
HVACTOOLS.co.nz now stocking all Javac and Spectroline HVAC and Refrigeration products. Including Recovery Units, Vacuum Pumps, Leak detectors ...
TerryDBonner, Employee at Electronic Arts
Maintained accurate personal records on maintenance crews and technical records on weekly insulation production.Have years of Installation and servicing ...
Developed several new methods for licensing g.i. joes in Los Angeles, CA. Spent high school summers creating marketing channels ...
DorothySanders, Accountant at Amazon
Hello, I am an Engineering manager. I love my work. I also love to read news articles related to the ...
hcr689121, Data Engineer at Autonomy Zantaz
Harrison is an electronic data processor experience in electronic data processor and Promotion. I enjoy providing health resources and how ...
Hello NoOne,- abhinav.thegame October 17, 2016
Thank you very much for your response. Could you please post the answer either in Java or Python???