Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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 task

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions