aboutsummaryrefslogtreecommitdiffstats
path: root/linguistics/src/test/java/com/yahoo/language/significance/DefaultSignificanceModelRegistryTest.java
blob: d4849571b5e99bc469724779df52f0500624fdc8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.language.significance;

import com.yahoo.language.Language;
import com.yahoo.language.significance.impl.DefaultSignificanceModelRegistry;
import org.junit.Test;

import java.nio.file.Path;
import java.util.HashMap;

import static org.junit.jupiter.api.Assertions.*;


/**
 * @author MariusArhaug
 */
public class DefaultSignificanceModelRegistryTest {

    @Test
    public void testDefaultSignificanceModelRegistry() {
        HashMap<Language, Path> models = new HashMap<>();

        models.put(Language.ENGLISH, Path.of("src/test/models/en.json"));
        models.put(Language.NORWEGIAN_BOKMAL, Path.of("src/test/models/no.json"));

        DefaultSignificanceModelRegistry defaultSignificanceModelRegistry = new DefaultSignificanceModelRegistry(models);

        var optionalEnglishModel = defaultSignificanceModelRegistry.getModel(Language.ENGLISH);
        var optionalNorwegianModel = defaultSignificanceModelRegistry.getModel(Language.NORWEGIAN_BOKMAL);

        assertTrue(optionalEnglishModel.isPresent());
        assertTrue(optionalNorwegianModel.isPresent());

        var englishModel = optionalEnglishModel.get();
        var norwegianModel = optionalNorwegianModel.get();

        assertTrue( defaultSignificanceModelRegistry.getModel(Language.FRENCH).isEmpty());

        assertNotNull(englishModel);
        assertNotNull(norwegianModel);

        assertEquals(2, englishModel.documentFrequency("test").frequency());
        assertEquals(10, englishModel.documentFrequency("test").corpusSize());

        assertEquals(3, norwegianModel.documentFrequency("nei").frequency());
        assertEquals(20, norwegianModel.documentFrequency("nei").corpusSize());

        assertEquals(1, norwegianModel.documentFrequency("non-existent-word").frequency());
        assertEquals(20, norwegianModel.documentFrequency("non-existent-word").corpusSize());

    }
}