Java插入到倒排索引哈希表中

Java插入到倒排索引哈希表中,java,arrays,insert,indexing,hashtable,Java,Arrays,Insert,Indexing,Hashtable,你好,我有个任务,我搞不清楚。以下是我尝试做的概述: 编写一个程序,为三个文件创建反向索引。假设程序已经读取了文件“one.txt”、“two.txt”和“three.txt”,如果用户搜索查询“oats barley”,并且包含这两个单词的唯一文件是two.txt,那么它将返回two.txt 我需要为反转索引定义一个接口。 该接口将有3个实现 使用java.util.Hashtable实现反向索引 对于文件列表,应使用java.util.ArrayList或java.util.LinkedL

你好,我有个任务,我搞不清楚。以下是我尝试做的概述:

编写一个程序,为三个文件创建反向索引。假设程序已经读取了文件“one.txt”、“two.txt”和“three.txt”,如果用户搜索查询“oats barley”,并且包含这两个单词的唯一文件是two.txt,那么它将返回two.txt

我需要为反转索引定义一个接口。 该接口将有3个实现

  • 使用java.util.Hashtable实现反向索引
  • 对于文件列表,应使用java.util.ArrayList或java.util.LinkedList
  • 使用java.util.TreeMap实现反向索引
  • 在ArrayList上使用二进制搜索实现反向索引。您应该按排序顺序将项目插入数组列表
到目前为止,我真的不知道如何开始将文件中的数据输入反向索引:

/*
 * HW 2
 */

import java.util.*;

public class InvertedIndex {

    //tester
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Please enter file name #1");
        String file1 = in.next();
         try
            {
              Scanner inputStream = new Scanner(new File(file1));
              while (inputStream.hasNext())
              {
                nextWord = inputStream.next();
                nextWord.split(" ");
                //add nextWord to inverted index 

                inputStream.nextLine();
              }
              inputStream.close();
            }
            catch(FileNotFoundException e)
            {
              System.out.println("Error opening file");
              System.exit(0);
            }
            catch(IOException e)
            {
              System.out.println("Error Reading File");
            }

        System.out.println("Please enter file name #2");
        String file2 = in.next();
         try
            {
              Scanner inputStream = new Scanner(new File(file2));
              while (inputStream.hasNext())
              {
                nextWord = inputStream.next();
                nextWord.split(" ");
                //add nextWord to inverted index 

                inputStream.nextLine();
              }
              inputStream.close();
            }
            catch(FileNotFoundException e)
            {
              System.out.println("Error opening file");
              System.exit(0);
            }
            catch(IOException e)
            {
              System.out.println("Error Reading File");
            }

        System.out.println("Please enter file name #3");
        String file3 = in.next();
         try
            {
              Scanner inputStream = new Scanner(new File(file3));
              while (inputStream.hasNext())
              {
                nextWord = inputStream.next();
                nextWord.split(" ");
                //add nextWord to inverted index 

                inputStream.nextLine();
              }
              inputStream.close();
            }
            catch(FileNotFoundException e)
            {
              System.out.println("Error opening file");
              System.exit(0);
            }
            catch(IOException e)
            {
              System.out.println("Error Reading File");
            }


    }

}

任何帮助或建议都会非常好。非常感谢!!

你可能首先想知道反向索引是什么。是的,他们把我搞糊涂了。你有什么资源可以推荐你在这方面寻求帮助吗?所有这些都涉及到哪个方向。以文本文件为例;正向索引将使用文本文件的名称作为key,将文本文件中的所有单词作为值。反向索引将使用这些单词作为键,并获取文本文件的名称。我特别喜欢书的类比,前面的目录是正向索引,而后面的索引是反向索引,因为您正在查找还有,我不太明白你的“这个接口的实现”项目清单。你是说这些是你完成作业的选项吗?