Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In java Write a program that builds an index from a large piece of text, then does fast searches to find the position of query
In java
Write a program that builds an index from a large piece of text, then does fast searches to find the position of "query" strings within the text. Your program should take two filenames as command-line arguments: the text file (which we refer to as the corpus) and a file containing the queries. Assume that both files contain only lower-case letters, blanks, and newline characters, with queries in the query file delimited by newline characters. This is not much of a restriction, since you can convert any file to this format by using tr filters (useman tr to find out about this process, if you are interested). Your program should read the corpus, store it as a (potentially huge) string, and possibly build an index for it, as discussed below. Then it should read queries one by one, assuming one query per line in the second named file on the command line, and print out the position in the corpus where each query first appears. For example, for the corpus /u/cs126/data/corpuse: it was the best of times it was the worst of times it was the age of wisdom it was the age of foolishness it was the epoch of belief it was the epoch of incredulity it was the season of light it was the season of darkness it was the spring of hope it was the winter of despair and the query file / u/cs126/data/querye, the result of a.out corpuse query should be 69 wisdom 176 season 87 age of foolishness - age of fools 19 times indicating that wisdom appears at character position 69 , age of fools does not appear, the first occurrence of times is at character position 19 , and so forth. There are numerous different ways to solve this problem, all with different characteristics in terms of ease of implementation, space requirements, and time requirements. Part of your task for this assignment is to assimilate this information to help you decide which method to use and how to apply it to this specific taskStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started