2023-02-14 10:32:17 +01:00
|
|
|
|
2023-02-09 16:13:34 +01:00
|
|
|
package eu.dnetlib.dhp.common.vocabulary;
|
|
|
|
|
2023-02-14 10:32:17 +01:00
|
|
|
import static org.mockito.Mockito.lenient;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Objects;
|
|
|
|
|
2023-02-09 16:13:34 +01:00
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
|
import org.mockito.Mock;
|
|
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
|
|
2023-02-14 10:32:17 +01:00
|
|
|
import eu.dnetlib.dhp.schema.oaf.Qualifier;
|
|
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
|
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
2023-02-09 16:13:34 +01:00
|
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class)
|
|
|
|
public class VocabularyTest {
|
|
|
|
|
2023-02-14 10:32:17 +01:00
|
|
|
@Mock
|
|
|
|
protected ISLookUpService isLookUpService;
|
2023-02-09 16:13:34 +01:00
|
|
|
|
2023-02-14 10:32:17 +01:00
|
|
|
protected VocabularyGroup vocabularies;
|
2023-02-09 16:13:34 +01:00
|
|
|
|
2023-02-14 10:32:17 +01:00
|
|
|
@BeforeEach
|
|
|
|
public void setUpVocabulary() throws ISLookUpException, IOException {
|
2023-02-09 16:13:34 +01:00
|
|
|
|
2023-02-14 10:32:17 +01:00
|
|
|
lenient().when(isLookUpService.quickSearchProfile(VocabularyGroup.VOCABULARIES_XQUERY)).thenReturn(vocs());
|
2023-02-09 16:13:34 +01:00
|
|
|
|
2023-02-14 10:32:17 +01:00
|
|
|
lenient()
|
|
|
|
.when(isLookUpService.quickSearchProfile(VocabularyGroup.VOCABULARY_SYNONYMS_XQUERY))
|
|
|
|
.thenReturn(synonyms());
|
|
|
|
vocabularies = VocabularyGroup.loadVocsFromIS(isLookUpService);
|
|
|
|
}
|
2023-02-09 16:13:34 +01:00
|
|
|
|
2023-02-14 10:32:17 +01:00
|
|
|
private static List<String> vocs() throws IOException {
|
|
|
|
return IOUtils
|
|
|
|
.readLines(
|
|
|
|
Objects
|
|
|
|
.requireNonNull(
|
|
|
|
VocabularyTest.class.getResourceAsStream("/eu/dnetlib/dhp/transform/terms.txt")));
|
|
|
|
}
|
2023-02-09 16:13:34 +01:00
|
|
|
|
2023-02-14 10:32:17 +01:00
|
|
|
private static List<String> synonyms() throws IOException {
|
|
|
|
return IOUtils
|
|
|
|
.readLines(
|
|
|
|
Objects
|
|
|
|
.requireNonNull(
|
|
|
|
VocabularyTest.class.getResourceAsStream("/eu/dnetlib/dhp/transform/synonyms.txt")));
|
|
|
|
}
|
2023-02-09 16:13:34 +01:00
|
|
|
|
2023-02-14 10:32:17 +01:00
|
|
|
@Test
|
|
|
|
void testVocabularyMatch() throws Exception {
|
|
|
|
final String s = IOUtils.toString(this.getClass().getResourceAsStream("terms"));
|
2023-02-09 16:13:34 +01:00
|
|
|
|
2023-02-14 10:32:17 +01:00
|
|
|
for (String s1 : s.split("\n")) {
|
2023-02-09 16:13:34 +01:00
|
|
|
|
2023-02-14 10:32:17 +01:00
|
|
|
final Qualifier t1 = vocabularies.getSynonymAsQualifier("dnet:publication_resource", s1);
|
2023-02-09 16:13:34 +01:00
|
|
|
|
2023-02-14 10:32:17 +01:00
|
|
|
if (t1 == null) {
|
|
|
|
System.err.println(s1 + " Missing");
|
|
|
|
} else {
|
2023-02-15 16:20:24 +01:00
|
|
|
System.out.println("syn=" + s1 + " term = " + t1.getClassid() + " " + t1.getClassname());
|
2023-02-09 16:13:34 +01:00
|
|
|
|
2023-02-14 10:32:17 +01:00
|
|
|
System.out
|
|
|
|
.println(
|
|
|
|
vocabularies.getSynonymAsQualifier("dnet:result_typologies", t1.getClassid()).getClassname());
|
|
|
|
}
|
|
|
|
}
|
2023-02-09 16:13:34 +01:00
|
|
|
|
2023-02-14 10:32:17 +01:00
|
|
|
}
|
2023-02-09 16:13:34 +01:00
|
|
|
}
|