Search in sources :

Example 6 with Language

use of com.redhat.devtools.alizer.api.Language in project jbosstools-openshift by jbosstools.

the class LanguageRecognizerTest method checkLanguageRecognizerOnEmptyFolder.

@Test
public void checkLanguageRecognizerOnEmptyFolder() throws IOException {
    LanguageRecognizer recognize = new RecognizerFactory().createLanguageRecognizer();
    List<Language> languages = recognize.analyze(folder.newFolder().getAbsolutePath());
    assertTrue(languages.isEmpty());
}
Also used : LanguageRecognizer(com.redhat.devtools.alizer.api.LanguageRecognizer) Language(com.redhat.devtools.alizer.api.Language) RecognizerFactory(com.redhat.devtools.alizer.api.RecognizerFactory) Test(org.junit.Test)

Example 7 with Language

use of com.redhat.devtools.alizer.api.Language in project intellij-tekton by redhat-developer.

the class HubItemScore method computeScore.

private int computeScore(HubItem hubItem) {
    int score = 0;
    ResourceData resourceData = hubItem.getResource();
    ResourceVersionData resourceVersionData = resourceData.getLatestVersion();
    for (int i = 0; i < languages.size(); i++) {
        Language language = languages.get(i);
        int multiplier = i >= LANGUAGES_MULTIPLIER.length ? LANGUAGES_MULTIPLIER[LANGUAGES_MULTIPLIER.length - 1] : LANGUAGES_MULTIPLIER[i];
        if (matches(resourceData.getName(), language)) {
            score += NAME_WEIGHT * multiplier;
        }
        if (resourceVersionData != null && matches(resourceVersionData.getDescription(), language)) {
            score += DESCRIPTION_WEIGHT * multiplier;
        }
        List<String> tags = resourceData.getTags().stream().map(c -> c.getName()).collect(Collectors.toList());
        if (resourceData.getTags().contains(language.getName()) || matches(tags, language)) {
            score += TAG_WEIGHT * multiplier;
        }
    }
    return score;
}
Also used : ResourceVersionData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData) Strings(com.google.common.base.Strings) Language(com.redhat.devtools.alizer.api.Language) List(java.util.List) ResourceData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData) Comparator(java.util.Comparator) Collectors(java.util.stream.Collectors) ResourceData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData) Language(com.redhat.devtools.alizer.api.Language) ResourceVersionData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData)

Example 8 with Language

use of com.redhat.devtools.alizer.api.Language in project intellij-tekton by redhat-developer.

the class HubItemScoreTest method Compare_2HubItems_VerifyCalculatedScoreWithOnlyName.

@Test
public void Compare_2HubItems_VerifyCalculatedScoreWithOnlyName() {
    Language lang = new Language("First", Collections.emptyList(), 99.0, false);
    Language lang2 = new Language("Second", Collections.emptyList(), 1.0, false);
    List<Language> languages = Arrays.asList(lang, lang2);
    HubItem hubItem1 = buildHubItem("Second", "", Collections.emptyList());
    HubItem hubItem2 = buildHubItem("First", "", Collections.emptyList());
    HubItemScore hubItemScore = new HubItemScore(languages);
    assertEquals(-20, hubItemScore.compare(hubItem1, hubItem2));
}
Also used : Language(com.redhat.devtools.alizer.api.Language) Test(org.junit.Test)

Example 9 with Language

use of com.redhat.devtools.alizer.api.Language in project intellij-tekton by redhat-developer.

the class HubItemScoreTest method Compare_1HubItemAndValue_VerifyCalculatedScoreWithAliases.

@Test
public void Compare_1HubItemAndValue_VerifyCalculatedScoreWithAliases() {
    Language lang = new Language("First", Arrays.asList("alias1", "alias2"), 99.0, false);
    Language lang2 = new Language("Second", Arrays.asList("alias3", "alias4"), 1.0, false);
    List<Language> languages = Arrays.asList(lang, lang2);
    HubItem hubItem1 = buildHubItem("alias1", "", Collections.emptyList());
    HubItemScore hubItemScore = new HubItemScore(languages);
    assertEquals(39, hubItemScore.compare(hubItem1, 1));
}
Also used : Language(com.redhat.devtools.alizer.api.Language) Test(org.junit.Test)

Example 10 with Language

use of com.redhat.devtools.alizer.api.Language in project intellij-tekton by redhat-developer.

the class HubItemScoreTest method Compare_1HubItemAndValue_VerifyCalculatedScoreWithDescription.

@Test
public void Compare_1HubItemAndValue_VerifyCalculatedScoreWithDescription() {
    Language lang = new Language("First", Arrays.asList("alias1", "alias2"), 99.0, Arrays.asList("framework1"), Collections.emptyList(), false);
    Language lang2 = new Language("Second", Arrays.asList("alias3", "alias4"), 1.0, Arrays.asList("framework2"), Collections.emptyList(), false);
    List<Language> languages = Arrays.asList(lang, lang2);
    HubItem hubItem1 = buildHubItem("name", "this is the first item for the first language", Collections.emptyList());
    HubItemScore hubItemScore = new HubItemScore(languages);
    assertEquals(11, hubItemScore.compare(hubItem1, 1));
}
Also used : Language(com.redhat.devtools.alizer.api.Language) Test(org.junit.Test)

Aggregations

Language (com.redhat.devtools.alizer.api.Language)13 Test (org.junit.Test)11 RecognizerFactory (com.redhat.devtools.alizer.api.RecognizerFactory)3 Tag (com.redhat.devtools.intellij.tektoncd.hub.model.Tag)3 LanguageRecognizer (com.redhat.devtools.alizer.api.LanguageRecognizer)2 ResourceApi (com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi)2 ResourceData (com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData)2 ResourceVersionData (com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData)2 Resources (com.redhat.devtools.intellij.tektoncd.hub.model.Resources)2 Strings (com.google.common.base.Strings)1 BaseTest (com.redhat.devtools.intellij.tektoncd.BaseTest)1 ClusterTasksNode (com.redhat.devtools.intellij.tektoncd.tree.ClusterTasksNode)1 PipelinesNode (com.redhat.devtools.intellij.tektoncd.tree.PipelinesNode)1 Watch (io.fabric8.kubernetes.client.Watch)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Before (org.junit.Before)1