1
|
package eu.dnetlib.data.mapreduce.hbase.index.config;
|
2
|
|
3
|
import eu.dnetlib.data.mapreduce.util.RelDescriptor;
|
4
|
import eu.dnetlib.data.proto.TypeProtos.Type;
|
5
|
import org.junit.Test;
|
6
|
|
7
|
import static org.junit.Assert.*;
|
8
|
|
9
|
public class IndexConfigTest {
|
10
|
|
11
|
public static final String config =
|
12
|
"index.conf { "
|
13
|
+ "result { dups = true, links = ["
|
14
|
+ "{ relType = personResult_authorship_hasAuthor, targetEntity = person, expandAs = rel, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,collectedfrom] }, "
|
15
|
+ "{ relType = resultProject_outcome_isProducedBy, targetEntity = result, expandAs = rel, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype], max = 1 }, "
|
16
|
+ "{ relType = resultResult_dedup_isMergedIn, targetEntity = result, expandAs = child, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,pid] }, "
|
17
|
+ "{ relType = resultResult_dedup_merges, targetEntity = result, expandAs = child, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,pid] }, "
|
18
|
+ "{ relType = resultResult_publicationDataset_isRelatedTo, targetEntity = result, expandAs = rel, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,pid,url,collectedfrom] },"
|
19
|
+ "{ relType = resultResult_similarity_isAmongTopNSimilarDocuments, targetEntity = result, expandAs = rel, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,similarity,type,pid] },"
|
20
|
+ "{ relType = resultResult_similarity_hasAmongTopNSimilarDocuments, targetEntity = result, expandAs = rel, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,similarity,type,pid] },"
|
21
|
+ "{ relType = resultResult_supplement_isSupplementTo, targetEntity = result, expandAs = rel, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,similarity,type,pid,url,collectedfrom] },"
|
22
|
+ "{ relType = resultResult_supplement_isSupplementedBy, targetEntity = result, expandAs = rel, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,similarity,type,pid,url,collectedfrom] },"
|
23
|
+ "{ relType = resultResult_part_isPartOf, targetEntity = result, expandAs = rel, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,similarity,type,pid,url] },"
|
24
|
+ "{ relType = resultResult_part_hasPart, targetEntity = result, expandAs = rel, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,similarity,type,pid,url] }"
|
25
|
+ "]}, "
|
26
|
+ "person { dups = false, links = ["
|
27
|
+ "{ relType = personResult_authorship_isAuthorOf, targetEntity = result, expandAs = rel, symmetric = true, fields = [fullname,ranking,pid], max = 2 }, "
|
28
|
+ "{ relType = projectPerson_contactPerson_isContact, targetEntity = project, expandAs = rel, symmetric = true, fields = [fullname,email,fax,phone] } "
|
29
|
+ "]}, "
|
30
|
+ "datasource { dups = false, links = ["
|
31
|
+ "{ relType = datasourceOrganization_provision_provides, targetEntity = organization, expandAs = rel, symmetric = true, fields = [officialname,websiteurl,datasourcetype,aggregatortype] } "
|
32
|
+ "]}, "
|
33
|
+ "organization { dups = false, links = ["
|
34
|
+ "{ relType = projectOrganization_participation_isParticipant, targetEntity = project, expandAs = rel, symmetric = true, fields = [legalname,legalshortname,websiteurl,country] }, "
|
35
|
+ "{ relType = datasourceOrganization_provision_isProvidedBy, targetEntity = datasource, expandAs = rel, symmetric = true, fields = [legalname,legalshortname,websiteurl,country] }, "
|
36
|
+ "{ relType = organizationOrganization_dedup_merges, targetEntity = organization, expandAs = child, symmetric = true, fields = [legalname,legalshortname,websiteurl,country] }, "
|
37
|
+ "{ relType = organizationOrganization_dedup_isMergedIn, targetEntity = organization, expandAs = child, symmetric = true, fields = [legalname,legalshortname,websiteurl,country] }, "
|
38
|
+ "{ relType = resultOrganization_affiliation_isAuthorInstitutionOf, targetEntity = result, expandAs = rel, symmetric = true, fields = [legalname,legalshortname,websiteurl,country] }"
|
39
|
+ "]}, "
|
40
|
+ "project { dups = false, links = ["
|
41
|
+ "{ relType = projectOrganization_participation_hasParticipant, targetEntity = organization, expandAs = rel, symmetric = true, fields = [code,acronym,title,websiteurl,contracttype,fundingtree] }, "
|
42
|
+ "{ relType = resultProject_outcome_produces, targetEntity = result, expandAs = rel, symmetric = true, fields = [code,acronym,title,websiteurl,contracttype,fundingtree] }, "
|
43
|
+ "{ relType = projectPerson_contactPerson_hasContact, targetEntity = person, expandAs = rel, symmetric = true, fields = [code,acronym,title,websiteurl,contracttype,fundingtree] } "
|
44
|
+ "], excludeFields = [jsonextrainfo,optional1,optional2]}} ";
|
45
|
|
46
|
public static final String configWithIncludesExcludes =
|
47
|
"index.conf { "
|
48
|
+ "result { dups = true, links = ["
|
49
|
+ "{ relType = resultResult_dedup_isMergedIn, targetEntity = result, expandAs = child, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,pid] }, "
|
50
|
+ "{ relType = resultResult_dedup_merges, targetEntity = result, expandAs = child, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,pid] }, "
|
51
|
+ "{ relType = resultResult_publicationDataset_isRelatedTo, targetEntity = result, expandAs = rel, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,pid,url,collectedfrom] },"
|
52
|
+ "{ relType = resultResult_similarity_isAmongTopNSimilarDocuments, targetEntity = result, expandAs = rel, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,similarity,type,pid] },"
|
53
|
+ "{ relType = resultResult_similarity_hasAmongTopNSimilarDocuments, targetEntity = result, expandAs = rel, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,similarity,type,pid] },"
|
54
|
+ "{ relType = resultResult_supplement_isSupplementTo, targetEntity = result, expandAs = rel, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,similarity,type,pid,url,collectedfrom] },"
|
55
|
+ "{ relType = resultResult_supplement_isSupplementedBy, targetEntity = result, expandAs = rel, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,similarity,type,pid,url,collectedfrom] },"
|
56
|
+ "{ relType = resultResult_part_isPartOf, targetEntity = result, expandAs = rel, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,similarity,type,pid,url] },"
|
57
|
+ "{ relType = resultResult_part_hasPart, targetEntity = result, expandAs = rel, symmetric = true, fields = [title,dateofacceptance,publisher,resulttype,similarity,type,pid,url] }"
|
58
|
+ "], excludeFields = [jsonextrainfo] }, "
|
59
|
+ "person { dups = false, links = ["
|
60
|
+ "{ relType = personResult_authorship_isAuthorOf, targetEntity = result, expandAs = rel, symmetric = true, fields = [fullname,ranking,pid], max = 2 }, "
|
61
|
+ "{ relType = projectPerson_contactPerson_isContact, targetEntity = project, expandAs = rel, symmetric = true, fields = [fullname,email,fax,phone] } "
|
62
|
+ "], includeFields=[fullname, ranking]}"
|
63
|
+ "}";
|
64
|
|
65
|
public static final String wrongConfig =
|
66
|
"index.conf { "
|
67
|
+ "person { dups = false, links = ["
|
68
|
+ "{ relType = personResult_authorship_isAuthorOf, targetEntity = result, expandAs = rel, symmetric = true, fields = [fullname,ranking,pid], max = 2 }, "
|
69
|
+ "{ relType = projectPerson_contactPerson_isContact, targetEntity = project, expandAs = rel, symmetric = true, fields = [fullname,email,fax,phone] } "
|
70
|
+ "], includeFields=[fullname, ranking], excludeFields=[email] }"
|
71
|
+ "}";
|
72
|
|
73
|
|
74
|
public static final String context = "[{id:'egi', label:'EGI', element:'context'}, "
|
75
|
+ "{id:'egi::classification', label:'EGI classification scheme', element:'category'}, "
|
76
|
+ "{id:'egi::classification::natsc', label:'Natural Sciences', element:'concept'}, "
|
77
|
+ "{id:'egi::classification::natsc::math', label:'Mathematics', element:'concept'}, "
|
78
|
+ "{id:'egi::classification::natsc::math::applied', label:'Applied Mathematics', element:'concept'}, "
|
79
|
+ "{id:'egi::classification::natsc::math::pure', label:'Pure Mathematics', element:'concept'}, "
|
80
|
+ "{id:'egi::classification::natsc::math::stats', label:'Statistics and Probability', element:'concept'}, "
|
81
|
+ "{id:'egi::classification::natsc::math::other', label:'Other', element:'concept'}, "
|
82
|
+ "{id:'egi::classification::natsc::cis', label:'Computer and Information sciences', element:'concept'}, "
|
83
|
+ "{id:'egi::classification::natsc::cis::ai', label:'Artificial Intelligence', element:'concept'}, "
|
84
|
+ "{id:'egi::classification::natsc::cis::bio', label:'Bioinformatics', element:'concept'}, "
|
85
|
+ "{id:'egi::classification::natsc::cis::cs', label:'Computer sciences', element:'concept'}, "
|
86
|
+ "{id:'egi::classification::natsc::cis::is', label:'Information science', element:'concept'}, "
|
87
|
+ "{id:'egi::classification::natsc::cis::other', label:'Other', element:'concept'}, "
|
88
|
+ "{id:'egi::classification::physc', label:'Physical Sciences', element:'concept'}, "
|
89
|
+ "{id:'egi::vo', label:'EGI Virtual Organizations', element:'category'}, " + "{id:'egi::vo::alice', label:'alice', element:'concept'}, "
|
90
|
+ "{id:'egi::vo::ams', label:'ams', element:'concept'}, " + "{id:'egi::vo::ams02', label:'ams02.cern.ch', element:'concept'}, "
|
91
|
+ "{id:'egi::projects', label:'EGI Projects', element:'category'}, " + "{id:'egi::projects::wenmr', label:'WeNMR', element:'concept'}]";
|
92
|
|
93
|
@Test
|
94
|
public void testParse() {
|
95
|
final IndexConfig conf = IndexConfig.load(config);
|
96
|
assertNotNull(conf);
|
97
|
}
|
98
|
|
99
|
@Test
|
100
|
public void testLoadEntityConfTable() {
|
101
|
final IndexConfig conf = IndexConfig.load(config);
|
102
|
|
103
|
final EntityConfigTable map = conf.getConfigMap();
|
104
|
assertNotNull(map);
|
105
|
assertTrue(map.size() > 0);
|
106
|
for (final Type t : Type.values()) {
|
107
|
assertTrue(map.keySet().contains(t));
|
108
|
assertNotNull(map.get(t).getIndexDuplicates());
|
109
|
for (final LinkDescriptor ld : map.get(t).getLinks().values()) {
|
110
|
assertNotNull(ld.getFields());
|
111
|
assertNotNull(ld.getTarget());
|
112
|
|
113
|
final RelDescriptor relDescriptor = ld.getRelDescriptor();
|
114
|
assertNotNull(relDescriptor);
|
115
|
assertNotNull(relDescriptor.getIt());
|
116
|
assertFalse(relDescriptor.getIt().isEmpty());
|
117
|
assertNotNull(relDescriptor.getRelType());
|
118
|
assertNotNull(relDescriptor.getSubRelType());
|
119
|
|
120
|
System.out.println(ld);
|
121
|
}
|
122
|
}
|
123
|
}
|
124
|
|
125
|
@Test
|
126
|
public void testLoadEntityConfTableIncludeExclude() {
|
127
|
final IndexConfig conf = IndexConfig.load(configWithIncludesExcludes);
|
128
|
final EntityConfigTable map = conf.getConfigMap();
|
129
|
assertNotNull(map);
|
130
|
assertTrue(map.size() > 0);
|
131
|
assertTrue(map.hasIncludeFields(Type.person));
|
132
|
assertTrue(map.hasExcludeFields(Type.result));
|
133
|
}
|
134
|
|
135
|
@Test(expected = RuntimeException.class)
|
136
|
public void testBothIncludeExclude() {
|
137
|
final IndexConfig conf = IndexConfig.load(wrongConfig);
|
138
|
final EntityConfigTable map = conf.getConfigMap();
|
139
|
}
|
140
|
|
141
|
|
142
|
|
143
|
|
144
|
}
|