Multiple entries with same key error

Chào mọi người,
Mọi người xem giúp mình sửa lỗi “Multiple entries with same key”
Cám ơn mọi người nhiều !!!

public class Ex {

    private static final Log LOG = AutoLog.getLog();

    static Ex ex = new Ex();

    public static void main(String[] args) throws IOException, TException, UnknownWordException {
        System.out.println("Test Word2Vec: ");
        ex.loadModel();
    }

    public void interact(Searcher searcher) throws IOException, UnknownWordException {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            while (true) {
                System.out.print("Enter word or sentence (EXIT to break): ");
                String word = br.readLine();
                if (word.equals("EXIT")) {
                    break;
                }
                List<Match> matches = searcher.getMatches(word, 20);
                System.out.println(Strings.joinObjects("\n", matches));
            }
        }
    }

    public void loadModel() throws IOException, TException, UnknownWordException {
        Word2VecModel model;
        try (ProfilingTimer timer = ProfilingTimer.create(LOG, "Loading model")) {
            String json = Common.readFileToString(new File("D:\\DT\\aaa.model"));
            model = Word2VecModel.fromThrift(ThriftUtils.deserializeJson(new Word2VecModelThrift(), json));
        }
        ex.interact(model.forSearch());
    }

}

Run -> Lỗi
Exception in thread “main” java.lang.IllegalArgumentException: Multiple entries with same key: ??=3000 and ??=2000
at com.google.common.collect.ImmutableMap.checkNoConflict(ImmutableMap.java:136)
at com.google.common.collect.RegularImmutableMap.checkNoConflictInKeyBucket(RegularImmutableMap.java:98)
at com.google.common.collect.RegularImmutableMap.fromEntryArray(RegularImmutableMap.java:84)
at com.google.common.collect.ImmutableMap$Builder.build(ImmutableMap.java:295)
at com.medallia.word2vec.SearcherImpl.(SearcherImpl.java:27)
at com.medallia.word2vec.SearcherImpl.(SearcherImpl.java:31)
at com.medallia.word2vec.Word2VecModel.forSearch(Word2VecModel.java:62)
at com.medallia.word2vec.Ex.loadModel(Ex.java:55)
at com.medallia.word2vec.Ex.main(Ex.java:31)

Hỏi nhỏ phát, bạn post bài có bao giờ xem lại không, tự mình đánh giá xem bài post được mấy điểm về mức độ dễ nhìn

2 Likes

Mình đã sửa lại rồi, cám ơn bạn !!! còn dòng "public class Ex { " bị lỗi. mong bạn thông cảm.

Lôi ở method forSearch của class Word2VecModel do lỗi builder trong class SearcherImpl, bạn nên post 2 class ấy lên, ngoài ra xem lại json xem có 2 json object có chung key không

Mình đã timg được lỗi rồi bạn, do nó gọi đến 2 hàm khởi tạo… Cám ơn bạn nhiều :slight_smile:

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?