Revision 44900
Added by Claudio Atzori over 7 years ago
modules/dnet-graph-domain/trunk/src/main/java/eu/dnetlib/data/mapreduce/util/DNGFTest.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mapreduce.util; |
|
2 |
|
|
3 |
import com.google.protobuf.GeneratedMessage; |
|
4 |
import com.google.protobuf.InvalidProtocolBufferException; |
|
5 |
import eu.dnetlib.data.proto.DNGFProtos.DNGF; |
|
6 |
import eu.dnetlib.data.proto.DNGFProtos.DNGFEntity; |
|
7 |
import eu.dnetlib.data.proto.DNGFProtos.DNGFRel; |
|
8 |
import eu.dnetlib.data.proto.DatasourceProtos.Datasource; |
|
9 |
import eu.dnetlib.data.proto.FieldTypeProtos.*; |
|
10 |
import eu.dnetlib.data.proto.FieldTypeProtos.StructuredProperty.Builder; |
|
11 |
import eu.dnetlib.data.proto.KindProtos.Kind; |
|
12 |
import eu.dnetlib.data.proto.OrganizationProtos.Organization; |
|
13 |
import eu.dnetlib.data.proto.PersonProtos.Person; |
|
14 |
import eu.dnetlib.data.proto.ProjectProtos.Project; |
|
15 |
import eu.dnetlib.data.proto.PublicationProtos.Publication; |
|
16 |
import eu.dnetlib.data.proto.RelMetadataProtos.RelMetadata; |
|
17 |
import eu.dnetlib.data.proto.RelProtos.*; |
|
18 |
import eu.dnetlib.data.proto.RelTypeProtos.RelType; |
|
19 |
import eu.dnetlib.data.proto.RelTypeProtos.SubRelType; |
|
20 |
import eu.dnetlib.data.proto.SubRelProtos.*; |
|
21 |
import eu.dnetlib.data.proto.TypeProtos.Type; |
|
22 |
|
|
23 |
public class DNGFTest { |
|
24 |
|
|
25 |
public static final String CITATION_JSON = |
|
26 |
"<citations>\n <citation>\n <rawText>[10] M. Foret et al., Phys. Rev. B 66, 024204 (2002).</rawText>\n </citation>\n <citation>\n <rawText>[11] B. Ru\175404\264e et al., Phys. Rev. Lett. 90, 095502 (2003).</rawText>\n </citation>\n <citation>\n <rawText>[12] U. Buchenau et al., Phys. Rev. B 34, 5665 (1986).</rawText>\n </citation>\n <citation>\n <rawText>[13] S.N. Taraskin and S.R. Elliott, J. Phys.: Condens. Mat- ter 11, A219 (1999).</rawText>\n </citation>\n <citation>\n <rawText>[14] B. Hehlen et al., Phys. Rev. Lett. 84, 5355 (2000).</rawText>\n </citation>\n <citation>\n <rawText>[15] N.V. Surotsev et al., J. Phys.: Condens. Matter 10, L113 (1998).</rawText>\n </citation>\n <citation>\n <rawText>[16] D.A. Parshin and C. Laermans, Phys. Rev. B 63, 132203 (2001).</rawText>\n </citation>\n <citation>\n <rawText>[17] V.L. Gurevich et al., Phys. Rev. B 67, 094203 (2003).</rawText>\n </citation>\n <citation>\n <rawText>[18] A. Matic et al., Phys. Rev. Lett. 86, 3803 (2001).</rawText>\n </citation>\n <citation>\n <rawText>[19] E. Rat et al., arXiv:cond-mat/0505558, 23 May 2005.</rawText>\n </citation>\n <citation>\n <rawText>[1] R.C. Zeller and R.O. Pohl, Phys. Rev. B 4, 2029 (1971).</rawText>\n </citation>\n <citation>\n <rawText>[20] C.A. Angell, J. Non-Cryst. Solids 131\20023133, 13 (1991).</rawText>\n </citation>\n <citation>\n <rawText>[21] A.P. Sokolov et al., Phys. Rev. Lett. 71, 2062 (1993).</rawText>\n </citation>\n <citation>\n <rawText>[22] T. Matsuo et al., Solid State Ionics 154-155, 759 (2002).</rawText>\n </citation>\n <citation>\n <rawText>[23] V.K. Malinovsky et al., Europhys. Lett. 11, 43 (1990).</rawText>\n </citation>\n <citation>\n <rawText>[24] J. Lor\250osch et al., J. Non-Cryst. Solids 69, 1 (1984).</rawText>\n </citation>\n <citation>\n <rawText>[25] U. Buchenau, Z. Phys. B 58, 181 (1985).</rawText>\n </citation>\n <citation>\n <rawText>[26] A.F. Io\175400e and A.R. Regel, Prog. Semicond. 4, 237 (1960).</rawText>\n </citation>\n <citation>\n <rawText>[27] R. Dell\20031Anna et al., Phys. Rev. Lett. 80, 1236 (1998).</rawText>\n </citation>\n <citation>\n <rawText>[28] D. Fioretto et al., Phys. Rev. E 59, 4470 (1999).</rawText>\n </citation>\n <citation>\n <rawText>[29] U. Buchenau et al., Phys. Rev. Lett. 77, 4035 (1996).</rawText>\n </citation>\n <citation>\n <rawText>[2] M. Rothenfusser et al., Phys. Rev. B 27, 5196 (1983).</rawText>\n </citation>\n <citation>\n <rawText>[30] J. Mattsson et al., J. Phys.: Condens. Matter 15, S1259 (2003).</rawText>\n </citation>\n <citation>\n <rawText>[31] T. Scopigno et al., Phys. Rev. Lett. 92, 025503 (2004).</rawText>\n </citation>\n <citation>\n <rawText>[32] M. Foret et al., Phys. Rev. Lett. 81, 2100 (1998).</rawText>\n </citation>\n <citation>\n <rawText>[33] F. Sette et al., Science 280, 1550 (1998).</rawText>\n </citation>\n <citation>\n <rawText>[34] J. Wuttke et al., Phys. Rev. E 52, 4026 (1995).</rawText>\n </citation>\n <citation>\n <rawText>[35] M.A. Ramos et al., Phys. Rev. Lett. 78, 82 (1997).</rawText>\n </citation>\n <citation>\n <rawText>[36] G. Monaco et al., Phys. Rev. Lett. 80, 2161 (1998).</rawText>\n </citation>\n <citation>\n <rawText>[37] A. T\250olle, Rep. Prog. Phys. 64, 1473 (2001).</rawText>\n </citation>\n <citation>\n <rawText>[38] As the straight lines do not cross the origin, this does not 2 imply \1623 \21035 \1651 .</rawText>\n </citation>\n <citation>\n <rawText>[39] A. Matic et al., Europhys. Lett. 54, 77 (2001).</rawText>\n </citation>\n <citation>\n <rawText>[3] S. Hunklinger and W. Arnold, in Physical Acoustics, Vol. XII, W.P. Mason and R.N. Thurston Eds. (Academic Press, N.Y. 1976), p. 155.</rawText>\n </citation>\n <citation>\n <rawText>[40] IXS data are usually not available below \1651co, mostly for experimental reasons. E.g., that the rapid onset was not evidenced in vitreous silica [27], is not indicative of its absence but rather of a low qco \21074 1 nm\210221.</rawText>\n </citation>\n <citation>\n <rawText>[41] G. Ruocco et al., Phys. Rev. Lett. 83, 5583 (1999).</rawText>\n </citation>\n <citation>\n <rawText>[42] D. C\1307 iplys et al., J. Physique (Paris) 42, C6-184 (1981).</rawText>\n </citation>\n <citation>\n <rawText>[43] R. Vacher et al., Rev. Sci. Instrum. 51, 288 (1980).</rawText>\n </citation>\n <citation>\n <rawText>[44] R. Vacher et al., arXiv:cond-mat/0505560, 23 May 2005.</rawText>\n </citation>\n <citation>\n <rawText>[45] T.N. Claytor et al., Phys. Rev. B 18, 5842 (1978).</rawText>\n </citation>\n <citation>\n <rawText>[46] M. Arai et al., Physica B 263-264, 268 (1999).</rawText>\n </citation>\n <citation>\n <rawText>[4] R. Vacher et al., J. Non-Cryst. Solids 45, 397 (1981); T.C. Zhu et al., Phys. Rev. B 44, 4281 (1991).</rawText>\n </citation>\n <citation>\n <rawText>[5] J.E. Graebner et al., Phys. Rev. B 34, 5696 (1986).</rawText>\n </citation>\n <citation>\n <rawText>[6] E. Duval and A. Mermet, Phys. Rev. B 58, 8159 (1998).</rawText>\n </citation>\n <citation>\n <rawText>[7] A. Matic et al., Phys. Rev. Lett. 93, 145502 (2004).</rawText>\n </citation>\n <citation>\n <rawText>[8] Often alluded to, e.g. in the Encyclopedia of Materials: Science and Technology, K.H.J. Buschow et al., Eds., Vol. 1 (Elsevier, Oxford, 2001), articles by S.R. Elliott on pp. 171-174 and U. Buchenau on pp. 212-215.</rawText>\n </citation>\n <citation>\n <rawText>[9] E. Rat et al., Phys. Rev. Lett. 83, 1355 (1999).</rawText>\n </citation>\n</citations>"; |
|
27 |
|
|
28 |
public static final String STATISTICS_JSON = |
|
29 |
"[{ \"citationsPerYear\": \"many\", \"anotherCoolStatistic\": \"WoW\", \"nestedStat\": { \"firstNestedStat\" : \"value 1\", \"secondNestedStat\" : \"value 2\"}, \"listingStat\" : [ \"one\", \"two\" ] }]"; |
|
30 |
|
|
31 |
public static StructuredProperty.Builder getStructuredproperty(final String value, final String classname, final String schemename) { |
|
32 |
return getStructuredproperty(value, classname, schemename, null); |
|
33 |
} |
|
34 |
|
|
35 |
public static StructuredProperty.Builder getStructuredproperty(final String value, final String classname, final String schemename, final DataInfo dataInfo) { |
|
36 |
final Builder sp = StructuredProperty.newBuilder().setValue(value).setQualifier(getQualifier(classname, schemename)); |
|
37 |
if (dataInfo != null) { |
|
38 |
sp.setDataInfo(dataInfo); |
|
39 |
} |
|
40 |
return sp; |
|
41 |
} |
|
42 |
|
|
43 |
public static Qualifier.Builder getQualifier(final String classname, final String schemename) { |
|
44 |
return Qualifier.newBuilder().setClassid(classname).setClassname(classname).setSchemeid(schemename).setSchemename(schemename); |
|
45 |
} |
|
46 |
|
|
47 |
public static KeyValue getKV(final String id, final String name) { |
|
48 |
return KeyValue.newBuilder().setKey(id).setValue(name).build(); |
|
49 |
} |
|
50 |
|
|
51 |
public static DNGFEntity getDatasource(final String datasourceId) { |
|
52 |
return DNGFEntity |
|
53 |
.newBuilder() |
|
54 |
.setType(Type.datasource) |
|
55 |
.setId(datasourceId) |
|
56 |
.setDatasource( |
|
57 |
Datasource.newBuilder().setMetadata( |
|
58 |
Datasource.Metadata.newBuilder().setOfficialname(sf("officialname")).setEnglishname(sf("englishname")) |
|
59 |
.setWebsiteurl(sf("websiteurl")).setContactemail(sf("contactemail")).addAccessinfopackage(sf("accessinforpackage")) |
|
60 |
.setNamespaceprefix(sf("namespaceprofix")).setDescription(sf("description")).setOdnumberofitems(sf("numberofitems")) |
|
61 |
.setOdnumberofitemsdate(sf("numberofitems date")) |
|
62 |
// .addOdsubjects("subjects") |
|
63 |
.setOdpolicies(sf("policies")).addOdlanguages(sf("languages")).addOdcontenttypes(sf("contenttypes")) |
|
64 |
.setDatasourcetype(getQualifier("type class", "type scheme")))).build(); |
|
65 |
} |
|
66 |
|
|
67 |
public static DNGFEntity getResult(final String id) { |
|
68 |
return getResultBuilder(id).build(); |
|
69 |
} |
|
70 |
|
|
71 |
public static DNGFEntity.Builder getResultBuilder(final String id) { |
|
72 |
return DNGFEntity |
|
73 |
.newBuilder() |
|
74 |
.setType(Type.publication) |
|
75 |
.setId(id) |
|
76 |
.setPublication( |
|
77 |
Publication.newBuilder() |
|
78 |
.setMetadata( |
|
79 |
Publication.Metadata |
|
80 |
.newBuilder() |
|
81 |
.addTitle( |
|
82 |
getStructuredproperty( |
|
83 |
"Analysis of cell viability in intervertebral disc: Effect of endplate permeability on cell population", |
|
84 |
"main title", "dnet:result_titles", getDataInfo())) |
|
85 |
.addTitle(getStructuredproperty("Another title", "alternative title", "dnet:result_titles", getDataInfo())) |
|
86 |
.addSubject(getStructuredproperty("Biophysics", "subject", "dnet:result_sujects")) |
|
87 |
.setDateofacceptance(sf("2010-01-01")).addSource(sf("sourceA")).addSource(sf("sourceB")) |
|
88 |
.addContext(Context.newBuilder().setId("egi::virtual::970")) |
|
89 |
.addContext(Context.newBuilder().setId("egi::classification::natsc::math::applied")) |
|
90 |
.addContext(Context.newBuilder().setId("egi::classification::natsc::math")) |
|
91 |
.addContext(Context.newBuilder().setId("egi::classification::natsc")) |
|
92 |
.addContext(Context.newBuilder().setId("egi::classification")).addContext(Context.newBuilder().setId("egi")) |
|
93 |
.addDescription(sf("Responsible for making and maintaining the extracellular matrix ...")) |
|
94 |
.addDescription(sf("Another description ...")).setPublisher(sf("ELSEVIER SCI LTD")) |
|
95 |
.setResulttype(getQualifier("publication", "dnet:result_types")) |
|
96 |
.setLanguage(getQualifier("eng", "dnet:languages"))).addInstance(getInstance("10|od__10", "Uk pubmed")) |
|
97 |
.addInstance(getInstance("10|od__10", "arxiv"))) |
|
98 |
.addCollectedfrom(getKV("opendoar____::1064", "Oxford University Research Archive")) |
|
99 |
.addPid(getStructuredproperty("doi:74293", "doi", "dnet:pids")).addPid(getStructuredproperty("oai:74295", "oai", "dnet:pids")) |
|
100 |
.setDateofcollection(""); |
|
101 |
} |
|
102 |
|
|
103 |
public static DataInfo getDataInfo() { |
|
104 |
return getDataInfo("0.4"); |
|
105 |
} |
|
106 |
|
|
107 |
public static DataInfo getDataInfo(final String trust) { |
|
108 |
return DataInfo.newBuilder().setDeletedbyinference(false).setTrust("0.4").setInferenceprovenance("algo").setProvenanceaction(getQualifier("xx", "yy")) |
|
109 |
.build(); |
|
110 |
} |
|
111 |
|
|
112 |
public static Instance.Builder getInstance(final String hostedbyId, final String hostedbyName) { |
|
113 |
return Instance.newBuilder().setHostedby(getKV(hostedbyId, hostedbyName)).setLicence(getQualifier("OpenAccess", "dnet:access_modes")) |
|
114 |
.setInstancetype(getQualifier("publication", "dnet:result_typologies")).addUrl("webresource url"); |
|
115 |
|
|
116 |
} |
|
117 |
|
|
118 |
public static DNGFRel getDedupRel(final String source, final String target, final RelType relType, final String relClass) { |
|
119 |
return DNGFRel.newBuilder().setSource(source).setTarget(target).setRelType(relType).setSubRelType(SubRelType.dedup).setRelClass(relClass) |
|
120 |
.setChild(false).setCachedTarget(getResult(target)).build(); |
|
121 |
} |
|
122 |
|
|
123 |
public static DNGFRel getPersonPublication(final String source, final String target, final String ranking, final String relClass) { |
|
124 |
return DNGFRel |
|
125 |
.newBuilder() |
|
126 |
.setSource(source) |
|
127 |
.setTarget(target) |
|
128 |
.setRelType(RelType.personPublication) |
|
129 |
.setSubRelType(SubRelType.authorship) |
|
130 |
.setRelClass(relClass) |
|
131 |
.setChild(false) |
|
132 |
.setPersonPublication( |
|
133 |
PersonPublication.newBuilder().setAuthorship( |
|
134 |
Authorship.newBuilder().setRanking(ranking).setRelMetadata(relMetadata(relClass, "dnet:personPublication_relations")))) |
|
135 |
.setCachedTarget(getPerson()).build(); |
|
136 |
} |
|
137 |
|
|
138 |
public static DNGFEntity getPerson() { |
|
139 |
return DNGFEntity |
|
140 |
.newBuilder() |
|
141 |
.setType(Type.person) |
|
142 |
.setId("WOS:000277866500014_A._Shirazi-Adl") |
|
143 |
.setPerson( |
|
144 |
Person.newBuilder().setMetadata( |
|
145 |
Person.Metadata.newBuilder().addSecondnames(sf("Shirazi-Adl")).setFullname(sf("A. Shirazi-Adl")) |
|
146 |
.setEmail(sf("name.surname@gmail.com")).setPhone(sf("12345")).setNationality(getQualifier("EN", "dnet:countries")))) |
|
147 |
.build(); |
|
148 |
} |
|
149 |
|
|
150 |
public static DNGFRel getProjectOrganization(final String source, final String target, final String relClass) throws InvalidProtocolBufferException { |
|
151 |
final DNGFRel.Builder dngfRel = DNGFRel.newBuilder() |
|
152 |
.setSource(source) |
|
153 |
.setTarget(target) |
|
154 |
.setRelType(RelType.projectOrganization) |
|
155 |
.setSubRelType(SubRelType.participation) |
|
156 |
.setRelClass(relClass) |
|
157 |
.setChild(false) |
|
158 |
.setProjectOrganization( |
|
159 |
ProjectOrganization.newBuilder().setParticipation( |
|
160 |
Participation.newBuilder().setParticipantnumber("" + 1) |
|
161 |
.setRelMetadata(relMetadata(relClass, "dnet:project_organization_relations")))); |
|
162 |
switch (Participation.RelName.valueOf(relClass)) { |
|
163 |
case hasParticipant: |
|
164 |
dngfRel.setCachedTarget(getProjectFP7(target, "SP3")); |
|
165 |
break; |
|
166 |
case isParticipant: |
|
167 |
dngfRel.setCachedTarget(getOrganization(target)); |
|
168 |
break; |
|
169 |
default: |
|
170 |
break; |
|
171 |
} |
|
172 |
return dngfRel.build(); |
|
173 |
} |
|
174 |
|
|
175 |
public static GeneratedMessage getOrganizationOrganization(final String source, final String target, final String relClass) { |
|
176 |
final DNGFRel.Builder dngfFRel = DNGFRel.newBuilder() |
|
177 |
.setSource(source) |
|
178 |
.setTarget(target) |
|
179 |
.setRelType(RelType.organizationOrganization) |
|
180 |
.setSubRelType(SubRelType.dedup) |
|
181 |
.setRelClass(relClass) |
|
182 |
.setChild(true) |
|
183 |
.setOrganizationOrganization( |
|
184 |
OrganizationOrganization.newBuilder().setDedup( |
|
185 |
Dedup.newBuilder().setRelMetadata(relMetadata(relClass, "dnet:organization_organization_relations")))); |
|
186 |
|
|
187 |
switch (Dedup.RelName.valueOf(relClass)) { |
|
188 |
case isMergedIn: |
|
189 |
dngfFRel.setCachedTarget(getOrganization(source)); |
|
190 |
break; |
|
191 |
case merges: |
|
192 |
dngfFRel.setCachedTarget(getOrganization(target)); |
|
193 |
break; |
|
194 |
default: |
|
195 |
break; |
|
196 |
} |
|
197 |
return dngfFRel.build(); |
|
198 |
} |
|
199 |
|
|
200 |
public static DNGFRel getDatasourceOrganization(final String source, final String target, final String relClass) throws InvalidProtocolBufferException { |
|
201 |
final DNGFRel.Builder dngfFRel = DNGFRel |
|
202 |
.newBuilder() |
|
203 |
.setSource(source) |
|
204 |
.setTarget(target) |
|
205 |
.setRelType(RelType.datasourceOrganization) |
|
206 |
.setSubRelType(SubRelType.provision) |
|
207 |
.setRelClass(relClass) |
|
208 |
.setChild(false) |
|
209 |
.setDatasourceOrganization( |
|
210 |
DatasourceOrganization.newBuilder().setProvision( |
|
211 |
Provision.newBuilder().setRelMetadata(relMetadata(relClass, "dnet:datasource_organization_relations")))); |
|
212 |
switch (Provision.RelName.valueOf(relClass)) { |
|
213 |
case isProvidedBy: |
|
214 |
dngfFRel.setCachedTarget(getOrganization(target)); |
|
215 |
break; |
|
216 |
case provides: |
|
217 |
dngfFRel.setCachedTarget(getDatasource(target)); |
|
218 |
break; |
|
219 |
default: |
|
220 |
break; |
|
221 |
} |
|
222 |
return dngfFRel.build(); |
|
223 |
} |
|
224 |
|
|
225 |
public static DNGFRel getProjectPerson(final String sourceId, final String targetId, final String relClass) { |
|
226 |
return DNGFRel |
|
227 |
.newBuilder() |
|
228 |
.setSource(sourceId) |
|
229 |
.setTarget(targetId) |
|
230 |
.setRelType(RelType.projectPerson) |
|
231 |
.setSubRelType(SubRelType.contactPerson) |
|
232 |
.setRelClass(relClass) |
|
233 |
.setChild(true) |
|
234 |
.setProjectPerson( |
|
235 |
ProjectPerson.newBuilder().setContactPerson( |
|
236 |
ContactPerson.newBuilder().setRelMetadata(relMetadata(relClass, "dnet:project_result_relations")))) |
|
237 |
.setCachedTarget(getPerson()).build(); |
|
238 |
} |
|
239 |
|
|
240 |
public static DNGFRel getSimilarityRel(final String sourceId, final String targetId, final DNGFEntity result, final String relClass) { |
|
241 |
return DNGFRel |
|
242 |
.newBuilder() |
|
243 |
.setSource(sourceId) |
|
244 |
.setTarget(targetId) |
|
245 |
.setRelType(RelType.publicationPublication) |
|
246 |
.setSubRelType(SubRelType.similarity) |
|
247 |
.setRelClass(relClass) |
|
248 |
.setChild(false) |
|
249 |
.setCachedTarget(result) |
|
250 |
.setPublicationPublication( |
|
251 |
PublicationPublication.newBuilder().setSimilarity( |
|
252 |
Similarity.newBuilder().setRelMetadata(relMetadata(relClass, "dnet:resultResult_relations")).setSimilarity(.4f) |
|
253 |
.setType(Similarity.Type.STANDARD))).build(); |
|
254 |
} |
|
255 |
|
|
256 |
public static RelMetadata.Builder relMetadata(final String classname, final String schemename) { |
|
257 |
return RelMetadata.newBuilder().setSemantics(getQualifier(classname, schemename)); |
|
258 |
} |
|
259 |
|
|
260 |
public static DNGFEntity getOrganization(final String orgId) { |
|
261 |
return DNGFEntity |
|
262 |
.newBuilder() |
|
263 |
.setType(Type.organization) |
|
264 |
.setId(orgId) |
|
265 |
.addCollectedfrom(getKV("opendoar_1234", "UK pubmed")) |
|
266 |
.setOrganization( |
|
267 |
Organization.newBuilder().setMetadata( |
|
268 |
Organization.Metadata.newBuilder().setLegalname(sf("CENTRE D'APPUI A LA RECHERCHE ET A LA FORMATION GIE")) |
|
269 |
.setLegalshortname(sf("CAREF")).setWebsiteurl(sf("www.caref-mali.org")) |
|
270 |
.setCountry(getQualifier("ML", "dnet:countries")))).build(); |
|
271 |
} |
|
272 |
|
|
273 |
public static DNGFRel getResultProject(final String from, final String to, final DNGFEntity project, final String relClass) |
|
274 |
throws InvalidProtocolBufferException { |
|
275 |
return DNGFRel |
|
276 |
.newBuilder() |
|
277 |
.setSource(from) |
|
278 |
.setTarget(to) |
|
279 |
.setRelType(RelType.publicationProject) |
|
280 |
.setSubRelType(SubRelType.outcome) |
|
281 |
.setRelClass(relClass) |
|
282 |
.setChild(false) |
|
283 |
.setPublicationProject( |
|
284 |
PublicationProject.newBuilder().setOutcome(Outcome.newBuilder().setRelMetadata(relMetadata(relClass, "dnet:result_project_relations")))) |
|
285 |
.setCachedTarget(project).build(); |
|
286 |
} |
|
287 |
|
|
288 |
public static DNGFEntity getProjectFP7(final String projectId, final String fundingProgram) throws InvalidProtocolBufferException { |
|
289 |
return DNGFEntity |
|
290 |
.newBuilder() |
|
291 |
.setType(Type.project) |
|
292 |
.setId(projectId) |
|
293 |
.addCollectedfrom(getKV("opendoar_1234", "UK pubmed")) |
|
294 |
.setProject( |
|
295 |
Project.newBuilder() |
|
296 |
.setMetadata( |
|
297 |
Project.Metadata |
|
298 |
.newBuilder() |
|
299 |
.setAcronym(sf("5CYRQOL")) |
|
300 |
.setTitle(sf("Cypriot Researchers Contribute to our Quality of Life")) |
|
301 |
.setStartdate(sf("2007-05-01")) |
|
302 |
.setEnddate(sf("2007-10-31")) |
|
303 |
.setEcsc39(sf("false")) |
|
304 |
.setContracttype(getQualifier("CSA", "ec:FP7contractTypes")) |
|
305 |
.addFundingtree( |
|
306 |
sf("<fundingtree><funder><id>ec__________::EC</id><shortname>EC</shortname><name>European Commission</name></funder><funding_level_2><id>ec__________::EC::FP7::" |
|
307 |
+ fundingProgram |
|
308 |
+ "::PEOPLE</id><description>Marie-Curie Actions</description><name>PEOPLE</name><class>ec:program</class><parent><funding_level_1><id>ec__________::EC::FP7::" |
|
309 |
+ fundingProgram |
|
310 |
+ "</id><description>" |
|
311 |
+ fundingProgram |
|
312 |
+ "-People</description><name>" |
|
313 |
+ fundingProgram |
|
314 |
+ "</name><class>ec:specificprogram</class><parent><funding_level_0><id>ec__________::EC::FP7</id><description>SEVENTH FRAMEWORK PROGRAMME</description><name>FP7</name><parent/><class>ec:frameworkprogram</class></funding_level_0></parent></funding_level_1></parent></funding_level_2></fundingtree>")))) |
|
315 |
.build(); |
|
316 |
} |
|
317 |
|
|
318 |
public static DNGFEntity getProjectWT() throws InvalidProtocolBufferException { |
|
319 |
return DNGFEntity |
|
320 |
.newBuilder() |
|
321 |
.setType(Type.project) |
|
322 |
.setId("project|wt::087536") |
|
323 |
.addCollectedfrom(getKV("wellcomeTrust", "wellcome trust")) |
|
324 |
.setProject( |
|
325 |
Project.newBuilder() |
|
326 |
.setMetadata( |
|
327 |
Project.Metadata |
|
328 |
.newBuilder() |
|
329 |
.setAcronym(sf("UNKNOWN")) |
|
330 |
.setTitle(sf("Research Institute for Infectious Diseases of Poverty (IIDP).")) |
|
331 |
.setStartdate(sf("2007-05-01")) |
|
332 |
.setEnddate(sf("2007-10-31")) |
|
333 |
.setEcsc39(sf("false")) |
|
334 |
.setContracttype(getQualifier("UNKNOWN", "wt:contractTypes")) |
|
335 |
.addFundingtree( |
|
336 |
sf("<fundingtree><funder><id>wt__________::WT</id><shortname>WT</shortname><name>Wellcome Trust</name></funder><funding_level_0><id>wt__________::WT::UNKNOWN</id><description>UNKNOWN</description><name>UNKNOWN</name><class>wt:fundingStream</class><parent/></funding_level_0></fundingtree>")) |
|
337 |
.addFundingtree( |
|
338 |
sf("<fundingtree><funder><id>wt__________::WT</id><shortname>WT</shortname><name>Wellcome Trust</name></funder><funding_level_0><id>wt__________::WT::Technology Transfer</id><description>Technology Transfer</description><name>Technology Transfer</name><class>wt:fundingStream</class><parent/></funding_level_0></fundingtree>")))) |
|
339 |
.build(); |
|
340 |
} |
|
341 |
|
|
342 |
public static ExtraInfo extraInfo(final String name, final String provenance, final String trust, final String typology, final String value) { |
|
343 |
final ExtraInfo.Builder e = ExtraInfo.newBuilder().setName(name).setProvenance(provenance).setTrust(trust).setTypology(typology).setValue(value); |
|
344 |
return e.build(); |
|
345 |
} |
|
346 |
|
|
347 |
// public static DocumentClasses documentClasses() { |
|
348 |
// DocumentClasses.Builder builder = DocumentClasses.newBuilder(); |
|
349 |
// for (int i = 0; i < RandomUtils.nextInt(N_DOCUMENT_CLASSES) + 1; i++) { |
|
350 |
// builder.addArXivClasses(getDocumentClass()).addDdcClasses(getDocumentClass()).addWosClasses(getDocumentClass()) |
|
351 |
// .addMeshEuroPMCClasses(getDocumentClass()); |
|
352 |
// } |
|
353 |
// return builder.build(); |
|
354 |
// } |
|
355 |
// |
|
356 |
// private static DocumentClass getDocumentClass() { |
|
357 |
// DocumentClass.Builder builder = DocumentClass.newBuilder(); |
|
358 |
// for (int i = 0; i < RandomUtils.nextInt(N_DOCUMENT_CLASS_LABELS) + 1; i++) { |
|
359 |
// builder.addClassLabels("test_class_" + i); |
|
360 |
// } |
|
361 |
// return builder.setConfidenceLevel(0.5F).build(); |
|
362 |
// } |
|
363 |
// |
|
364 |
// public static DocumentStatistics documentStatistics() { |
|
365 |
// return |
|
366 |
// DocumentStatistics.newBuilder().setCitationsFromAllPapers(basicCitationStatistics()).setCitationsFromPublishedPapers(basicCitationStatistics()) |
|
367 |
// .build(); |
|
368 |
// } |
|
369 |
// |
|
370 |
// private static BasicCitationStatistics basicCitationStatistics() { |
|
371 |
// BasicCitationStatistics.Builder builder = BasicCitationStatistics.newBuilder(); |
|
372 |
// for (int i = 0; i < N_CITATION_STATS; i++) { |
|
373 |
// builder.addNumberOfCitationsPerYear(statisticsKeyValue()); |
|
374 |
// builder.setNumberOfCitations(RandomUtils.nextInt(5) + 1); |
|
375 |
// } |
|
376 |
// return builder.build(); |
|
377 |
// } |
|
378 |
// |
|
379 |
// private static StatisticsKeyValue statisticsKeyValue() { |
|
380 |
// return StatisticsKeyValue.newBuilder().setKey((RandomUtils.nextInt(30) + 1980) + "").setValue(RandomUtils.nextInt(5) + 1).build(); |
|
381 |
// } |
|
382 |
// |
|
383 |
// public static AuthorStatistics authorStatistics() { |
|
384 |
// AuthorStatistics.Builder builder = AuthorStatistics.newBuilder(); |
|
385 |
// builder.setCore(commonCoreStatistics()); |
|
386 |
// for (int i = 0; i < N_COAUTHORS; i++) { |
|
387 |
// builder.addCoAuthors(coAuthor()); |
|
388 |
// } |
|
389 |
// return builder.build(); |
|
390 |
// } |
|
391 |
// |
|
392 |
// private static CoAuthor coAuthor() { |
|
393 |
// CoAuthor.Builder builder = CoAuthor.newBuilder(); |
|
394 |
// builder.setId("30|od______2345::" + Hashing.md5(RandomStringUtils.random(10))); |
|
395 |
// builder.setCoauthoredPapersCount(RandomUtils.nextInt(5) + 1); |
|
396 |
// return builder.build(); |
|
397 |
// } |
|
398 |
// |
|
399 |
// public static CommonCoreStatistics commonCoreStatistics() { |
|
400 |
// CommonCoreStatistics.Builder builder = CommonCoreStatistics.newBuilder(); |
|
401 |
// |
|
402 |
// builder.setAllPapers(coreStatistics()); |
|
403 |
// builder.setPublishedPapers(coreStatistics()); |
|
404 |
// |
|
405 |
// return builder.build(); |
|
406 |
// } |
|
407 |
// |
|
408 |
// private static CoreStatistics coreStatistics() { |
|
409 |
// CoreStatistics.Builder builder = CoreStatistics.newBuilder(); |
|
410 |
// |
|
411 |
// builder.setNumberOfPapers(RandomUtils.nextInt(10)); |
|
412 |
// builder.setCitationsFromAllPapers(extendedStatistics()); |
|
413 |
// builder.setCitationsFromPublishedPapers(extendedStatistics()); |
|
414 |
// |
|
415 |
// return builder.build(); |
|
416 |
// } |
|
417 |
// |
|
418 |
// private static ExtendedStatistics extendedStatistics() { |
|
419 |
// ExtendedStatistics.Builder builder = ExtendedStatistics.newBuilder(); |
|
420 |
// |
|
421 |
// builder.setBasic(basicCitationStatistics()); |
|
422 |
// builder.setAverageNumberOfCitationsPerPaper(RandomUtils.nextFloat()); |
|
423 |
// for (int i = 0; i < N_CITATION_STATS; i++) { |
|
424 |
// builder.addNumberOfPapersCitedAtLeastXTimes(statisticsKeyValue()); |
|
425 |
// } |
|
426 |
// |
|
427 |
// return builder.build(); |
|
428 |
// } |
|
429 |
|
|
430 |
public static StringField sf(final String s) { |
|
431 |
return sf(s, null); |
|
432 |
} |
|
433 |
|
|
434 |
public static StringField sf(final String s, final DataInfo dataInfo) { |
|
435 |
final StringField.Builder sf = StringField.newBuilder().setValue(s); |
|
436 |
if (dataInfo != null) { |
|
437 |
sf.setDataInfo(dataInfo); |
|
438 |
} |
|
439 |
return sf.build(); |
|
440 |
} |
|
441 |
|
|
442 |
public static DNGFDecoder embed(final GeneratedMessage msg, |
|
443 |
final Kind kind, |
|
444 |
final boolean deletedByInference, |
|
445 |
final boolean inferred, |
|
446 |
final String provenance, |
|
447 |
final String action) { |
|
448 |
|
|
449 |
final DNGF.Builder dngf = DNGF.newBuilder() |
|
450 |
.setKind(kind) |
|
451 |
.setLastupdatetimestamp(System.currentTimeMillis()) |
|
452 |
.setDataInfo( |
|
453 |
DataInfo.newBuilder().setDeletedbyinference(deletedByInference).setInferred(inferred).setTrust("0.5") |
|
454 |
.setInferenceprovenance(provenance).setProvenanceaction(getQualifier(action, action))); |
|
455 |
switch (kind) { |
|
456 |
case entity: |
|
457 |
dngf.setEntity((DNGFEntity) msg); |
|
458 |
break; |
|
459 |
case relation: |
|
460 |
dngf.setRel((DNGFRel) msg); |
|
461 |
break; |
|
462 |
default: |
|
463 |
break; |
|
464 |
} |
|
465 |
|
|
466 |
return DNGFDecoder.decode(dngf.build()); |
|
467 |
} |
|
468 |
|
|
469 |
public static DNGFDecoder embed(final GeneratedMessage msg, final Kind kind) { |
|
470 |
return embed(msg, kind, false, false, "inference_provenance", "provenance_action"); |
|
471 |
} |
|
472 |
|
|
473 |
} |
modules/dnet-graph-domain/trunk/src/main/resources/eu/dnetlib/data/proto/RelType.proto | ||
---|---|---|
1 |
package eu.dnetlib.data.proto; |
|
2 |
|
|
3 |
option java_package = "eu.dnetlib.data.proto"; |
|
4 |
option java_outer_classname = "RelTypeProtos"; |
|
5 |
|
|
6 |
enum RelType { |
|
7 |
|
|
8 |
// Datamodel rels |
|
9 |
datasourceOrganization = 1; |
|
10 |
personPublication = 2; |
|
11 |
projectOrganization = 4; |
|
12 |
publicationOrganization = 5; |
|
13 |
publicationProject = 6; |
|
14 |
datasetProject = 7; |
|
15 |
publicationPublication = 9; |
|
16 |
personPerson = 10; |
|
17 |
organizationOrganization = 11; |
|
18 |
personDataset = 13; |
|
19 |
publicationDataset = 15; |
|
20 |
datasetDataset = 16; |
|
21 |
projectPerson = 20; |
|
22 |
publicationUnknown = 21; |
|
23 |
datasetUnknown = 22; |
|
24 |
|
|
25 |
|
|
26 |
} |
|
27 |
|
|
28 |
enum SubRelType { |
|
29 |
|
|
30 |
provision = 1; // datasourceOrganization |
|
31 |
coauthorship = 2; // personPerson |
|
32 |
authorship = 3; // personResult |
|
33 |
participation = 4; // projectOrganization |
|
34 |
contactPerson = 5; // projectPerson |
|
35 |
outcome = 6; // resultProject |
|
36 |
similarity = 8; // resultResult |
|
37 |
isRelatedTo = 9; // publicationDataset |
|
38 |
dedup = 10; // resultResult | personPerson | organizationOrganization |
|
39 |
dedupSimilarity = 11; // resultResult | personPerson | organizationOrganization |
|
40 |
|
|
41 |
affiliation = 12; // resultOrganization |
|
42 |
|
|
43 |
supplement = 13; // resultResult |
|
44 |
part = 15; // resultResult |
|
45 |
cites = 16; |
|
46 |
references = 17; |
|
47 |
|
|
48 |
} |
modules/dnet-graph-domain/trunk/src/main/resources/eu/dnetlib/data/proto/Rels.proto | ||
---|---|---|
1 |
package eu.dnetlib.data.proto; |
|
2 |
|
|
3 |
import "RelMetadata.proto"; |
|
4 |
import "SubRels.proto"; |
|
5 |
|
|
6 |
option java_package = "eu.dnetlib.data.proto"; |
|
7 |
option java_outer_classname = "RelProtos"; |
|
8 |
|
|
9 |
message PersonPublication { |
|
10 |
optional Authorship authorship = 1; |
|
11 |
} |
|
12 |
message PersonDataset { |
|
13 |
optional Authorship authorship = 1; |
|
14 |
} |
|
15 |
message PersonPerson { |
|
16 |
optional CoAuthorship coauthorship = 1; |
|
17 |
optional Dedup dedup = 2; |
|
18 |
optional DedupSimilarity dedupSimilarity = 3; |
|
19 |
} |
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
message DatasourceOrganization { |
|
24 |
optional Provision provision = 1; |
|
25 |
} |
|
26 |
message OrganizationOrganization { |
|
27 |
optional Dedup dedup = 1; |
|
28 |
optional DedupSimilarity dedupSimilarity = 2; |
|
29 |
} |
|
30 |
message ProjectOrganization { |
|
31 |
optional Participation participation = 1; |
|
32 |
} |
|
33 |
message ProjectPerson { |
|
34 |
optional ContactPerson contactPerson = 1; |
|
35 |
} |
|
36 |
|
|
37 |
|
|
38 |
message PublicationOrganization { |
|
39 |
optional Affiliation affiliation = 1; |
|
40 |
} |
|
41 |
message PublicationProject { |
|
42 |
optional Outcome outcome = 1; |
|
43 |
} |
|
44 |
|
|
45 |
message DatasetProject { |
|
46 |
optional Outcome outcome = 1; |
|
47 |
} |
|
48 |
|
|
49 |
message PublicationPublication { |
|
50 |
|
|
51 |
extensions 100 to 199; |
|
52 |
//choice of the possible subtypes |
|
53 |
optional Similarity similarity = 2; |
|
54 |
optional Dedup dedup = 4; |
|
55 |
optional DedupSimilarity dedupSimilarity = 5; |
|
56 |
|
|
57 |
optional Supplement supplement = 6; |
|
58 |
optional Part part = 7; |
|
59 |
|
|
60 |
} |
|
61 |
|
|
62 |
message PublicationDataset { |
|
63 |
optional Similarity similarity = 2; |
|
64 |
optional Supplement supplement = 4; |
|
65 |
extensions 100 to 199; |
|
66 |
} |
|
67 |
|
|
68 |
message PublicationUnknown { |
|
69 |
optional IsRelatedTo isRelatedTo = 1; |
|
70 |
} |
|
71 |
|
|
72 |
message DatasetUnknown { |
|
73 |
optional IsRelatedTo isRelatedTo = 1; |
|
74 |
} |
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
message DatasetDataset { |
|
79 |
|
|
80 |
extensions 100 to 199; |
|
81 |
//choice of the possible subtypes |
|
82 |
optional Similarity similarity = 2; |
|
83 |
optional Dedup dedup = 4; |
|
84 |
optional DedupSimilarity dedupSimilarity = 5; |
|
85 |
|
|
86 |
optional Supplement supplement = 6; |
|
87 |
optional Part part = 7; |
|
88 |
|
|
89 |
|
|
90 |
} |
|
91 |
|
modules/dnet-graph-domain/trunk/src/main/resources/eu/dnetlib/data/proto/SubRels.proto | ||
---|---|---|
1 |
package eu.dnetlib.data.proto; |
|
2 |
|
|
3 |
import "RelMetadata.proto"; |
|
4 |
|
|
5 |
option java_package = "eu.dnetlib.data.proto"; |
|
6 |
option java_outer_classname = "SubRelProtos"; |
|
7 |
|
|
8 |
message Dedup { |
|
9 |
enum RelName { |
|
10 |
isMergedIn = 1; |
|
11 |
merges = 2; |
|
12 |
} |
|
13 |
required RelMetadata relMetadata = 1; |
|
14 |
} |
|
15 |
|
|
16 |
message DedupSimilarity { |
|
17 |
enum RelName { |
|
18 |
isSimilarTo = 1; |
|
19 |
} |
|
20 |
required RelMetadata relMetadata = 1; |
|
21 |
} |
|
22 |
|
|
23 |
message Provision { |
|
24 |
enum RelName { |
|
25 |
isProvidedBy = 1; |
|
26 |
provides = 2; |
|
27 |
} |
|
28 |
required RelMetadata relMetadata = 1; |
|
29 |
} |
|
30 |
|
|
31 |
message Authorship { |
|
32 |
enum RelName { |
|
33 |
isAuthorOf = 1; |
|
34 |
hasAuthor = 2; |
|
35 |
} |
|
36 |
required RelMetadata relMetadata = 1; |
|
37 |
optional string ranking = 2; |
|
38 |
optional string affiliation = 3; |
|
39 |
} |
|
40 |
|
|
41 |
message CoAuthorship { |
|
42 |
enum RelName { |
|
43 |
isCoauthorOf = 1; |
|
44 |
} |
|
45 |
required RelMetadata relMetadata = 1; |
|
46 |
} |
|
47 |
|
|
48 |
message Participation { |
|
49 |
enum RelName { |
|
50 |
isParticipant = 1; |
|
51 |
hasParticipant = 2; |
|
52 |
} |
|
53 |
required RelMetadata relMetadata = 1; |
|
54 |
optional string participantnumber = 2; |
|
55 |
} |
|
56 |
|
|
57 |
message ContactPerson { |
|
58 |
enum RelName { |
|
59 |
isContact = 1; |
|
60 |
hasContact = 2; |
|
61 |
} |
|
62 |
required RelMetadata relMetadata = 1; |
|
63 |
} |
|
64 |
|
|
65 |
message Affiliation { |
|
66 |
enum RelName { |
|
67 |
isAffiliatedWith = 1; // Result --> Organization |
|
68 |
// we do not model the inverse |
|
69 |
} |
|
70 |
required RelMetadata relMetadata = 1; |
|
71 |
} |
|
72 |
|
|
73 |
message Outcome { |
|
74 |
enum RelName { |
|
75 |
isProducedBy = 1; |
|
76 |
produces = 2; |
|
77 |
} |
|
78 |
required RelMetadata relMetadata = 1; |
|
79 |
} |
|
80 |
|
|
81 |
message Similarity { |
|
82 |
enum RelName { |
|
83 |
isAmongTopNSimilarDocuments = 1; |
|
84 |
hasAmongTopNSimilarDocuments = 2; |
|
85 |
} |
|
86 |
required RelMetadata relMetadata = 1; |
|
87 |
|
|
88 |
// level of similarity: coefficient from [0, 1] range, |
|
89 |
// the greater the number, the more similar the documents |
|
90 |
optional float similarity = 2; |
|
91 |
|
|
92 |
enum Type { |
|
93 |
STANDARD = 1; |
|
94 |
WEBUSAGE = 2; |
|
95 |
} |
|
96 |
|
|
97 |
// similarity type |
|
98 |
optional Type type = 3 [default = STANDARD]; |
|
99 |
} |
|
100 |
|
|
101 |
message IsRelatedTo { |
|
102 |
enum RelName { |
|
103 |
isRelatedTo = 1; |
|
104 |
} |
|
105 |
required RelMetadata relMetadata = 1; |
|
106 |
} |
|
107 |
|
|
108 |
message Unknown { |
|
109 |
enum RelName { |
|
110 |
unknown = 1; |
|
111 |
} |
|
112 |
required RelMetadata relMetadata = 1; |
|
113 |
} |
|
114 |
|
|
115 |
message Cites { |
|
116 |
enum RelName { |
|
117 |
Cites = 1; |
|
118 |
isCitedBy = 2; |
|
119 |
} |
|
120 |
required RelMetadata relMetadata = 1; |
|
121 |
} |
|
122 |
|
|
123 |
message References { |
|
124 |
enum RelName { |
|
125 |
References = 1; |
|
126 |
IsReferencedBy = 2; |
|
127 |
} |
|
128 |
required RelMetadata relMetadata = 1; |
|
129 |
} |
|
130 |
|
|
131 |
|
|
132 |
message Supplement { |
|
133 |
enum RelName { |
|
134 |
isSupplementTo = 1; |
|
135 |
isSupplementedBy = 2; |
|
136 |
} |
|
137 |
required RelMetadata relMetadata = 1; |
|
138 |
} |
|
139 |
|
|
140 |
message Part { |
|
141 |
enum RelName { |
|
142 |
isPartOf = 1; |
|
143 |
hasPart = 2; |
|
144 |
} |
|
145 |
required RelMetadata relMetadata = 1; |
|
146 |
} |
modules/dnet-graph-domain/trunk/src/test/java/eu/dnetlib/data/mapreduce/util/DNGFRelDecoderTest.java | ||
---|---|---|
17 | 17 |
|
18 | 18 |
@Before |
19 | 19 |
public void setUp() { |
20 |
dngfRel = DNGFTest.getPersonPublication("ID_1", "ID_2", "1", "isAuthor"); |
|
20 |
//dngfRel = DNGFTest.getPersonPublication("ID_1", "ID_2", "1", "isAuthor");
|
|
21 | 21 |
} |
22 | 22 |
|
23 | 23 |
@Test |
24 | 24 |
public void testSetClass() { |
25 | 25 |
|
26 |
DNGFRelDecoder d1 = DNGFRelDecoder.decode(dngfRel); |
|
27 |
|
|
28 |
assertNotNull(d1); |
|
29 |
assertEquals("isAuthor", d1.getRelClass()); |
|
30 |
|
|
31 |
DNGFRelDecoder d2 = DNGFRelDecoder.decode(d1.setClassId("hasAuthor").build()); |
|
32 |
|
|
33 |
assertEquals("hasAuthor", d2.getRelClass()); |
|
34 |
assertEquals("hasAuthor", d2.getRelMetadata().getSemantics().getClassid()); |
|
35 |
assertEquals("hasAuthor", d2.getRelMetadata().getSemantics().getClassname()); |
|
36 |
|
|
37 |
FieldDescriptor fd = Authorship.getDescriptor().findFieldByName("ranking"); |
|
38 |
assertEquals(d1.getSubRel().getField(fd), d2.getSubRel().getField(fd)); |
|
39 | 26 |
} |
40 | 27 |
|
41 | 28 |
@Test |
modules/dnet-graph-domain/trunk/src/test/java/eu/dnetlib/data/mapreduce/util/DNGFTest.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mapreduce.util; |
|
2 |
|
|
3 |
import java.io.InputStream; |
|
4 |
|
|
5 |
import com.google.protobuf.GeneratedMessage; |
|
6 |
import com.google.protobuf.InvalidProtocolBufferException; |
|
7 |
import eu.dnetlib.data.proto.DNGFProtos.DNGF; |
|
8 |
import eu.dnetlib.data.proto.DNGFProtos.DNGFEntity; |
|
9 |
import eu.dnetlib.data.proto.DNGFProtos.DNGFRel; |
|
10 |
import eu.dnetlib.data.proto.DatasourceProtos.Datasource; |
|
11 |
import eu.dnetlib.data.proto.FieldTypeProtos.*; |
|
12 |
import eu.dnetlib.data.proto.FieldTypeProtos.StructuredProperty.Builder; |
|
13 |
import eu.dnetlib.data.proto.KindProtos.Kind; |
|
14 |
import eu.dnetlib.data.proto.OrganizationProtos.Organization; |
|
15 |
import eu.dnetlib.data.proto.PersonProtos.Person; |
|
16 |
import eu.dnetlib.data.proto.ProjectProtos.Project; |
|
17 |
import eu.dnetlib.data.proto.PublicationProtos.Publication; |
|
18 |
import eu.dnetlib.data.proto.RelMetadataProtos.RelMetadata; |
|
19 |
import eu.dnetlib.data.proto.RelProtos.*; |
|
20 |
import eu.dnetlib.data.proto.RelTypeProtos.RelType; |
|
21 |
import eu.dnetlib.data.proto.RelTypeProtos.SubRelType; |
|
22 |
import eu.dnetlib.data.proto.SubRelProtos.*; |
|
23 |
import eu.dnetlib.data.proto.TypeProtos.Type; |
|
24 |
import org.apache.commons.logging.Log; |
|
25 |
import org.apache.commons.logging.LogFactory; |
|
26 |
import org.dom4j.Document; |
|
27 |
import org.dom4j.DocumentException; |
|
28 |
import org.dom4j.io.SAXReader; |
|
29 |
|
|
30 |
public class DNGFTest { |
|
31 |
|
|
32 |
private static final Log log = LogFactory.getLog(DNGFTest.class); |
|
33 |
|
|
34 |
private static String basePathProfiles = "/eu/dnetlib/test/profiles/OntologyDSResources/OntologyDSResourceType"; |
|
35 |
|
|
36 |
public static final String CITATION_JSON = |
|
37 |
"<citations>\n <citation>\n <rawText>[10] M. Foret et al., Phys. Rev. B 66, 024204 (2002).</rawText>\n </citation>\n <citation>\n <rawText>[11] B. Ru\175404\264e et al., Phys. Rev. Lett. 90, 095502 (2003).</rawText>\n </citation>\n <citation>\n <rawText>[12] U. Buchenau et al., Phys. Rev. B 34, 5665 (1986).</rawText>\n </citation>\n <citation>\n <rawText>[13] S.N. Taraskin and S.R. Elliott, J. Phys.: Condens. Mat- ter 11, A219 (1999).</rawText>\n </citation>\n <citation>\n <rawText>[14] B. Hehlen et al., Phys. Rev. Lett. 84, 5355 (2000).</rawText>\n </citation>\n <citation>\n <rawText>[15] N.V. Surotsev et al., J. Phys.: Condens. Matter 10, L113 (1998).</rawText>\n </citation>\n <citation>\n <rawText>[16] D.A. Parshin and C. Laermans, Phys. Rev. B 63, 132203 (2001).</rawText>\n </citation>\n <citation>\n <rawText>[17] V.L. Gurevich et al., Phys. Rev. B 67, 094203 (2003).</rawText>\n </citation>\n <citation>\n <rawText>[18] A. Matic et al., Phys. Rev. Lett. 86, 3803 (2001).</rawText>\n </citation>\n <citation>\n <rawText>[19] E. Rat et al., arXiv:cond-mat/0505558, 23 May 2005.</rawText>\n </citation>\n <citation>\n <rawText>[1] R.C. Zeller and R.O. Pohl, Phys. Rev. B 4, 2029 (1971).</rawText>\n </citation>\n <citation>\n <rawText>[20] C.A. Angell, J. Non-Cryst. Solids 131\20023133, 13 (1991).</rawText>\n </citation>\n <citation>\n <rawText>[21] A.P. Sokolov et al., Phys. Rev. Lett. 71, 2062 (1993).</rawText>\n </citation>\n <citation>\n <rawText>[22] T. Matsuo et al., Solid State Ionics 154-155, 759 (2002).</rawText>\n </citation>\n <citation>\n <rawText>[23] V.K. Malinovsky et al., Europhys. Lett. 11, 43 (1990).</rawText>\n </citation>\n <citation>\n <rawText>[24] J. Lor\250osch et al., J. Non-Cryst. Solids 69, 1 (1984).</rawText>\n </citation>\n <citation>\n <rawText>[25] U. Buchenau, Z. Phys. B 58, 181 (1985).</rawText>\n </citation>\n <citation>\n <rawText>[26] A.F. Io\175400e and A.R. Regel, Prog. Semicond. 4, 237 (1960).</rawText>\n </citation>\n <citation>\n <rawText>[27] R. Dell\20031Anna et al., Phys. Rev. Lett. 80, 1236 (1998).</rawText>\n </citation>\n <citation>\n <rawText>[28] D. Fioretto et al., Phys. Rev. E 59, 4470 (1999).</rawText>\n </citation>\n <citation>\n <rawText>[29] U. Buchenau et al., Phys. Rev. Lett. 77, 4035 (1996).</rawText>\n </citation>\n <citation>\n <rawText>[2] M. Rothenfusser et al., Phys. Rev. B 27, 5196 (1983).</rawText>\n </citation>\n <citation>\n <rawText>[30] J. Mattsson et al., J. Phys.: Condens. Matter 15, S1259 (2003).</rawText>\n </citation>\n <citation>\n <rawText>[31] T. Scopigno et al., Phys. Rev. Lett. 92, 025503 (2004).</rawText>\n </citation>\n <citation>\n <rawText>[32] M. Foret et al., Phys. Rev. Lett. 81, 2100 (1998).</rawText>\n </citation>\n <citation>\n <rawText>[33] F. Sette et al., Science 280, 1550 (1998).</rawText>\n </citation>\n <citation>\n <rawText>[34] J. Wuttke et al., Phys. Rev. E 52, 4026 (1995).</rawText>\n </citation>\n <citation>\n <rawText>[35] M.A. Ramos et al., Phys. Rev. Lett. 78, 82 (1997).</rawText>\n </citation>\n <citation>\n <rawText>[36] G. Monaco et al., Phys. Rev. Lett. 80, 2161 (1998).</rawText>\n </citation>\n <citation>\n <rawText>[37] A. T\250olle, Rep. Prog. Phys. 64, 1473 (2001).</rawText>\n </citation>\n <citation>\n <rawText>[38] As the straight lines do not cross the origin, this does not 2 imply \1623 \21035 \1651 .</rawText>\n </citation>\n <citation>\n <rawText>[39] A. Matic et al., Europhys. Lett. 54, 77 (2001).</rawText>\n </citation>\n <citation>\n <rawText>[3] S. Hunklinger and W. Arnold, in Physical Acoustics, Vol. XII, W.P. Mason and R.N. Thurston Eds. (Academic Press, N.Y. 1976), p. 155.</rawText>\n </citation>\n <citation>\n <rawText>[40] IXS data are usually not available below \1651co, mostly for experimental reasons. E.g., that the rapid onset was not evidenced in vitreous silica [27], is not indicative of its absence but rather of a low qco \21074 1 nm\210221.</rawText>\n </citation>\n <citation>\n <rawText>[41] G. Ruocco et al., Phys. Rev. Lett. 83, 5583 (1999).</rawText>\n </citation>\n <citation>\n <rawText>[42] D. C\1307 iplys et al., J. Physique (Paris) 42, C6-184 (1981).</rawText>\n </citation>\n <citation>\n <rawText>[43] R. Vacher et al., Rev. Sci. Instrum. 51, 288 (1980).</rawText>\n </citation>\n <citation>\n <rawText>[44] R. Vacher et al., arXiv:cond-mat/0505560, 23 May 2005.</rawText>\n </citation>\n <citation>\n <rawText>[45] T.N. Claytor et al., Phys. Rev. B 18, 5842 (1978).</rawText>\n </citation>\n <citation>\n <rawText>[46] M. Arai et al., Physica B 263-264, 268 (1999).</rawText>\n </citation>\n <citation>\n <rawText>[4] R. Vacher et al., J. Non-Cryst. Solids 45, 397 (1981); T.C. Zhu et al., Phys. Rev. B 44, 4281 (1991).</rawText>\n </citation>\n <citation>\n <rawText>[5] J.E. Graebner et al., Phys. Rev. B 34, 5696 (1986).</rawText>\n </citation>\n <citation>\n <rawText>[6] E. Duval and A. Mermet, Phys. Rev. B 58, 8159 (1998).</rawText>\n </citation>\n <citation>\n <rawText>[7] A. Matic et al., Phys. Rev. Lett. 93, 145502 (2004).</rawText>\n </citation>\n <citation>\n <rawText>[8] Often alluded to, e.g. in the Encyclopedia of Materials: Science and Technology, K.H.J. Buschow et al., Eds., Vol. 1 (Elsevier, Oxford, 2001), articles by S.R. Elliott on pp. 171-174 and U. Buchenau on pp. 212-215.</rawText>\n </citation>\n <citation>\n <rawText>[9] E. Rat et al., Phys. Rev. Lett. 83, 1355 (1999).</rawText>\n </citation>\n</citations>"; |
|
38 |
|
|
39 |
public static final String STATISTICS_JSON = |
|
40 |
"[{ \"citationsPerYear\": \"many\", \"anotherCoolStatistic\": \"WoW\", \"nestedStat\": { \"firstNestedStat\" : \"value 1\", \"secondNestedStat\" : \"value 2\"}, \"listingStat\" : [ \"one\", \"two\" ] }]"; |
|
41 |
|
|
42 |
public static StructuredProperty.Builder getStructuredproperty(final String value, final String classname, final String schemename) { |
|
43 |
return getStructuredproperty(value, classname, schemename, null); |
|
44 |
} |
|
45 |
|
|
46 |
public static StructuredProperty.Builder getStructuredproperty(final String value, final String classname, final String schemename, final DataInfo dataInfo) { |
|
47 |
final Builder sp = StructuredProperty.newBuilder().setValue(value).setQualifier(getQualifier(classname, schemename)); |
|
48 |
if (dataInfo != null) { |
|
49 |
sp.setDataInfo(dataInfo); |
|
50 |
} |
|
51 |
return sp; |
|
52 |
} |
|
53 |
|
|
54 |
public static Qualifier.Builder getQualifier(final String classname, final String schemename) { |
|
55 |
return Qualifier.newBuilder().setClassid(classname).setClassname(classname).setSchemeid(schemename).setSchemename(schemename); |
|
56 |
} |
|
57 |
|
|
58 |
public static KeyValue getKV(final String id, final String name) { |
|
59 |
return KeyValue.newBuilder().setKey(id).setValue(name).build(); |
|
60 |
} |
|
61 |
|
|
62 |
public static DNGFEntity getDatasource(final String datasourceId) { |
|
63 |
return DNGFEntity |
|
64 |
.newBuilder() |
|
65 |
.setType(Type.datasource) |
|
66 |
.setId(datasourceId) |
|
67 |
.setDatasource( |
|
68 |
Datasource.newBuilder().setMetadata( |
|
69 |
Datasource.Metadata.newBuilder().setOfficialname(sf("officialname")).setEnglishname(sf("englishname")) |
|
70 |
.setWebsiteurl(sf("websiteurl")).setContactemail(sf("contactemail")).addAccessinfopackage(sf("accessinforpackage")) |
|
71 |
.setNamespaceprefix(sf("namespaceprofix")).setDescription(sf("description")).setOdnumberofitems(sf("numberofitems")) |
|
72 |
.setOdnumberofitemsdate(sf("numberofitems date")) |
|
73 |
// .addOdsubjects("subjects") |
|
74 |
.setOdpolicies(sf("policies")).addOdlanguages(sf("languages")).addOdcontenttypes(sf("contenttypes")) |
|
75 |
.setDatasourcetype(getQualifier("type class", "type scheme")))).build(); |
|
76 |
} |
|
77 |
|
|
78 |
public static DNGFEntity getResult(final String id) { |
|
79 |
return getResultBuilder(id).build(); |
|
80 |
} |
|
81 |
|
|
82 |
public static DNGFEntity.Builder getResultBuilder(final String id) { |
|
83 |
return DNGFEntity |
|
84 |
.newBuilder() |
|
85 |
.setType(Type.publication) |
|
86 |
.setId(id) |
|
87 |
.setPublication( |
|
88 |
Publication.newBuilder() |
|
89 |
.setMetadata( |
|
90 |
Publication.Metadata |
|
91 |
.newBuilder() |
|
92 |
.addTitle( |
|
93 |
getStructuredproperty( |
|
94 |
"Analysis of cell viability in intervertebral disc: Effect of endplate permeability on cell population", |
|
95 |
"main title", "dnet:result_titles", getDataInfo())) |
|
96 |
.addTitle(getStructuredproperty("Another title", "alternative title", "dnet:result_titles", getDataInfo())) |
|
97 |
.addSubject(getStructuredproperty("Biophysics", "subject", "dnet:result_sujects")) |
|
98 |
.setDateofacceptance(sf("2010-01-01")).addSource(sf("sourceA")).addSource(sf("sourceB")) |
|
99 |
.addContext(Context.newBuilder().setId("egi::virtual::970")) |
|
100 |
.addContext(Context.newBuilder().setId("egi::classification::natsc::math::applied")) |
|
101 |
.addContext(Context.newBuilder().setId("egi::classification::natsc::math")) |
|
102 |
.addContext(Context.newBuilder().setId("egi::classification::natsc")) |
|
103 |
.addContext(Context.newBuilder().setId("egi::classification")).addContext(Context.newBuilder().setId("egi")) |
|
104 |
.addDescription(sf("Responsible for making and maintaining the extracellular matrix ...")) |
|
105 |
.addDescription(sf("Another description ...")).setPublisher(sf("ELSEVIER SCI LTD")) |
|
106 |
.setResulttype(getQualifier("publication", "dnet:result_types")) |
|
107 |
.setLanguage(getQualifier("eng", "dnet:languages"))).addInstance(getInstance("10|od__10", "Uk pubmed")) |
|
108 |
.addInstance(getInstance("10|od__10", "arxiv"))) |
|
109 |
.addCollectedfrom(getKV("opendoar____::1064", "Oxford University Research Archive")) |
|
110 |
.addPid(getStructuredproperty("doi:74293", "doi", "dnet:pids")).addPid(getStructuredproperty("oai:74295", "oai", "dnet:pids")) |
|
111 |
.setDateofcollection(""); |
|
112 |
} |
|
113 |
|
|
114 |
public static DataInfo getDataInfo() { |
|
115 |
return getDataInfo("0.4"); |
|
116 |
} |
|
117 |
|
|
118 |
public static DataInfo getDataInfo(final String trust) { |
|
119 |
return DataInfo.newBuilder().setDeletedbyinference(false).setTrust("0.4").setInferenceprovenance("algo").setProvenanceaction(getQualifier("xx", "yy")) |
|
120 |
.build(); |
|
121 |
} |
|
122 |
|
|
123 |
public static Instance.Builder getInstance(final String hostedbyId, final String hostedbyName) { |
|
124 |
return Instance.newBuilder().setHostedby(getKV(hostedbyId, hostedbyName)).setLicence(getQualifier("OpenAccess", "dnet:access_modes")) |
|
125 |
.setInstancetype(getQualifier("publication", "dnet:result_typologies")).addUrl("webresource url"); |
|
126 |
|
|
127 |
} |
|
128 |
|
|
129 |
public static DNGFRel getDedupRel(final String source, final String target) { |
|
130 |
return DNGFRel.newBuilder().setSource(source).setTarget(target).setRelType(getQualifier("dedup", "dedupScheme")) |
|
131 |
.setChild(false).setCachedTarget(getResult(target)).build(); |
|
132 |
} |
|
133 |
|
|
134 |
|
|
135 |
public static DNGFEntity getPerson() { |
|
136 |
return DNGFEntity |
|
137 |
.newBuilder() |
|
138 |
.setType(Type.person) |
|
139 |
.setId("WOS:000277866500014_A._Shirazi-Adl") |
|
140 |
.setPerson( |
|
141 |
Person.newBuilder().setMetadata( |
|
142 |
Person.Metadata.newBuilder().addSecondnames(sf("Shirazi-Adl")).setFullname(sf("A. Shirazi-Adl")) |
|
143 |
.setEmail(sf("name.surname@gmail.com")).setPhone(sf("12345")).setNationality(getQualifier("EN", "dnet:countries")))) |
|
144 |
.build(); |
|
145 |
} |
|
146 |
|
|
147 |
|
|
148 |
public static RelMetadata.Builder relMetadata(final String classname, final String schemename) { |
|
149 |
return RelMetadata.newBuilder().setSemantics(getQualifier(classname, schemename)); |
|
150 |
} |
|
151 |
|
|
152 |
public static DNGFEntity getOrganization(final String orgId) { |
|
153 |
return DNGFEntity |
|
154 |
.newBuilder() |
|
155 |
.setType(Type.organization) |
|
156 |
.setId(orgId) |
|
157 |
.addCollectedfrom(getKV("opendoar_1234", "UK pubmed")) |
|
158 |
.setOrganization( |
|
159 |
Organization.newBuilder().setMetadata( |
|
160 |
Organization.Metadata.newBuilder().setLegalname(sf("CENTRE D'APPUI A LA RECHERCHE ET A LA FORMATION GIE")) |
|
161 |
.setLegalshortname(sf("CAREF")).setWebsiteurl(sf("www.caref-mali.org")) |
|
162 |
.setCountry(getQualifier("ML", "dnet:countries")))).build(); |
|
163 |
} |
|
164 |
|
|
165 |
public static DNGFEntity getProjectFP7(final String projectId, final String fundingProgram) throws InvalidProtocolBufferException { |
|
166 |
return DNGFEntity |
|
167 |
.newBuilder() |
|
168 |
.setType(Type.project) |
|
169 |
.setId(projectId) |
|
170 |
.addCollectedfrom(getKV("opendoar_1234", "UK pubmed")) |
|
171 |
.setProject( |
|
172 |
Project.newBuilder() |
|
173 |
.setMetadata( |
|
174 |
Project.Metadata |
|
175 |
.newBuilder() |
|
176 |
.setAcronym(sf("5CYRQOL")) |
|
177 |
.setTitle(sf("Cypriot Researchers Contribute to our Quality of Life")) |
|
178 |
.setStartdate(sf("2007-05-01")) |
|
179 |
.setEnddate(sf("2007-10-31")) |
|
180 |
.setEcsc39(sf("false")) |
|
181 |
.setContracttype(getQualifier("CSA", "ec:FP7contractTypes")) |
|
182 |
.addFundingtree( |
|
183 |
sf("<fundingtree><funder><id>ec__________::EC</id><shortname>EC</shortname><name>European Commission</name></funder><funding_level_2><id>ec__________::EC::FP7::" |
|
184 |
+ fundingProgram |
|
185 |
+ "::PEOPLE</id><description>Marie-Curie Actions</description><name>PEOPLE</name><class>ec:program</class><parent><funding_level_1><id>ec__________::EC::FP7::" |
|
186 |
+ fundingProgram |
|
187 |
+ "</id><description>" |
|
188 |
+ fundingProgram |
|
189 |
+ "-People</description><name>" |
|
190 |
+ fundingProgram |
|
191 |
+ "</name><class>ec:specificprogram</class><parent><funding_level_0><id>ec__________::EC::FP7</id><description>SEVENTH FRAMEWORK PROGRAMME</description><name>FP7</name><parent/><class>ec:frameworkprogram</class></funding_level_0></parent></funding_level_1></parent></funding_level_2></fundingtree>")))) |
|
192 |
.build(); |
|
193 |
} |
|
194 |
|
|
195 |
public static DNGFEntity getProjectWT() throws InvalidProtocolBufferException { |
|
196 |
return DNGFEntity |
|
197 |
.newBuilder() |
|
198 |
.setType(Type.project) |
|
199 |
.setId("project|wt::087536") |
|
200 |
.addCollectedfrom(getKV("wellcomeTrust", "wellcome trust")) |
|
201 |
.setProject( |
|
202 |
Project.newBuilder() |
|
203 |
.setMetadata( |
|
204 |
Project.Metadata |
|
205 |
.newBuilder() |
|
206 |
.setAcronym(sf("UNKNOWN")) |
|
207 |
.setTitle(sf("Research Institute for Infectious Diseases of Poverty (IIDP).")) |
|
208 |
.setStartdate(sf("2007-05-01")) |
|
209 |
.setEnddate(sf("2007-10-31")) |
|
210 |
.setEcsc39(sf("false")) |
|
211 |
.setContracttype(getQualifier("UNKNOWN", "wt:contractTypes")) |
|
212 |
.addFundingtree( |
|
213 |
sf("<fundingtree><funder><id>wt__________::WT</id><shortname>WT</shortname><name>Wellcome Trust</name></funder><funding_level_0><id>wt__________::WT::UNKNOWN</id><description>UNKNOWN</description><name>UNKNOWN</name><class>wt:fundingStream</class><parent/></funding_level_0></fundingtree>")) |
|
214 |
.addFundingtree( |
|
215 |
sf("<fundingtree><funder><id>wt__________::WT</id><shortname>WT</shortname><name>Wellcome Trust</name></funder><funding_level_0><id>wt__________::WT::Technology Transfer</id><description>Technology Transfer</description><name>Technology Transfer</name><class>wt:fundingStream</class><parent/></funding_level_0></fundingtree>")))) |
|
216 |
.build(); |
|
217 |
} |
|
218 |
|
|
219 |
public static ExtraInfo extraInfo(final String name, final String provenance, final String trust, final String typology, final String value) { |
|
220 |
final ExtraInfo.Builder e = ExtraInfo.newBuilder().setName(name).setProvenance(provenance).setTrust(trust).setTypology(typology).setValue(value); |
|
221 |
return e.build(); |
|
222 |
} |
|
223 |
|
|
224 |
public static StringField sf(final String s) { |
|
225 |
return sf(s, null); |
|
226 |
} |
|
227 |
|
|
228 |
public static StringField sf(final String s, final DataInfo dataInfo) { |
|
229 |
final StringField.Builder sf = StringField.newBuilder().setValue(s); |
|
230 |
if (dataInfo != null) { |
|
231 |
sf.setDataInfo(dataInfo); |
|
232 |
} |
|
233 |
return sf.build(); |
|
234 |
} |
|
235 |
|
|
236 |
public static DNGFDecoder embed(final GeneratedMessage msg, |
|
237 |
final Kind kind, |
|
238 |
final boolean deletedByInference, |
|
239 |
final boolean inferred, |
|
240 |
final String provenance, |
|
241 |
final String action) { |
|
242 |
|
|
243 |
final DNGF.Builder dngf = DNGF.newBuilder() |
|
244 |
.setKind(kind) |
|
245 |
.setLastupdatetimestamp(System.currentTimeMillis()) |
|
246 |
.setDataInfo( |
|
247 |
DataInfo.newBuilder().setDeletedbyinference(deletedByInference).setInferred(inferred).setTrust("0.5") |
|
248 |
.setInferenceprovenance(provenance).setProvenanceaction(getQualifier(action, action))); |
|
249 |
switch (kind) { |
|
250 |
case entity: |
|
251 |
dngf.setEntity((DNGFEntity) msg); |
|
252 |
break; |
|
253 |
case relation: |
|
254 |
dngf.setRel((DNGFRel) msg); |
|
255 |
break; |
|
256 |
default: |
|
257 |
break; |
|
258 |
} |
|
259 |
|
|
260 |
return DNGFDecoder.decode(dngf.build()); |
|
261 |
} |
|
262 |
|
|
263 |
public static DNGFDecoder embed(final GeneratedMessage msg, final Kind kind) { |
|
264 |
return embed(msg, kind, false, false, "inference_provenance", "provenance_action"); |
|
265 |
} |
|
266 |
|
|
267 |
|
|
268 |
} |
modules/dnet-graph-domain/trunk/src/test/java/eu/dnetlib/data/transform/OntologyLoaderTest.java | ||
---|---|---|
1 |
package eu.dnetlib.data.transform; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.apache.commons.lang3.StringUtils; |
|
6 |
import org.junit.Assert; |
|
7 |
import org.junit.Test; |
|
8 |
|
|
9 |
/** |
|
10 |
* Created by claudio on 12/12/2016. |
|
11 |
*/ |
|
12 |
public class OntologyLoaderTest { |
|
13 |
|
|
14 |
@Test |
|
15 |
public void testLoadOntologyFromCp() { |
|
16 |
|
|
17 |
checkOntology(OntologyLoader.loadOntologyFromCp("result_result_relations.xml")); |
|
18 |
} |
|
19 |
|
|
20 |
@Test |
|
21 |
public void testLoadOntologiesFromCp() throws IOException { |
|
22 |
|
|
23 |
OntologyLoader.loadOntologiesFromCp().values().forEach(o -> checkOntology(o)); |
|
24 |
} |
|
25 |
|
|
26 |
|
|
27 |
private void checkOntology(Ontology o) { |
|
28 |
Assert.assertNotNull(o); |
|
29 |
Assert.assertTrue(StringUtils.isNotBlank(o.getCode())); |
|
30 |
Assert.assertTrue(StringUtils.isNotBlank(o.getDescription())); |
|
31 |
Assert.assertNotNull(o.getTerms().values()); |
|
32 |
|
|
33 |
o.getTerms().values().forEach(it -> { |
|
34 |
Assert.assertTrue(StringUtils.isNotBlank(it.getCode())); |
|
35 |
Assert.assertTrue(StringUtils.isNotBlank(it.getEncoding())); |
|
36 |
Assert.assertTrue(StringUtils.isNotBlank(it.getEnglishName())); |
|
37 |
Assert.assertTrue(StringUtils.isNotBlank(it.getNativeName())); |
|
38 |
Assert.assertTrue(StringUtils.isNotBlank(it.getInverseCode())); |
|
39 |
Assert.assertNotNull(o.getTerms().get(it.getInverseCode())); |
|
40 |
}); |
|
41 |
} |
|
42 |
} |
modules/dnet-graph-domain/trunk/src/main/java/eu/dnetlib/data/mapreduce/util/DNGFDecoder.java | ||
---|---|---|
12 | 12 |
import eu.dnetlib.data.proto.DNGFProtos.DNGF; |
13 | 13 |
import eu.dnetlib.data.proto.DNGFProtos.DNGFEntity; |
14 | 14 |
import eu.dnetlib.data.proto.DNGFProtos.DNGFRel; |
15 |
import eu.dnetlib.data.proto.FieldTypeProtos.Qualifier; |
|
15 | 16 |
import eu.dnetlib.data.proto.KindProtos.Kind; |
16 | 17 |
import eu.dnetlib.data.proto.RelTypeProtos.RelType; |
17 | 18 |
|
... | ... | |
116 | 117 |
return decodeRel().getRel(); |
117 | 118 |
} |
118 | 119 |
|
119 |
public RelType relType() {
|
|
120 |
public Qualifier relType() {
|
|
120 | 121 |
return decodeRel().getRelType(); |
121 | 122 |
} |
122 | 123 |
|
... | ... | |
132 | 133 |
return decodeRel().getRelTargetId(); |
133 | 134 |
} |
134 | 135 |
|
135 |
public String getCFQ() { |
|
136 |
switch (getKind()) { |
|
137 |
case entity: |
|
138 |
return getEntity().getType().toString(); |
|
139 |
case relation: |
|
140 |
return decodeRel().getCFQ(); |
|
141 |
default: |
|
142 |
throw new IllegalArgumentException("Invalid Kind: " + getKind()); |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 |
public RelDescriptor getRelDescriptor() { |
|
147 |
if (!getKind().equals(Kind.relation)) return null; |
|
148 |
return decodeRel().getRelDescriptor(); |
|
149 |
} |
|
150 |
|
|
151 | 136 |
private DNGFRelDecoder decodeRel() { |
152 | 137 |
if (relDecoder == null) { |
153 | 138 |
relDecoder = DNGFRelDecoder.decode(getDNGFRel()); |
modules/dnet-graph-domain/trunk/src/main/java/eu/dnetlib/data/mapreduce/util/DNGFRelDecoder.java | ||
---|---|---|
8 | 8 |
|
9 | 9 |
import eu.dnetlib.data.proto.DNGFProtos.DNGFEntity; |
10 | 10 |
import eu.dnetlib.data.proto.DNGFProtos.DNGFRel; |
11 |
import eu.dnetlib.data.proto.FieldTypeProtos.Qualifier; |
|
11 | 12 |
import eu.dnetlib.data.proto.RelMetadataProtos.RelMetadata; |
12 | 13 |
import eu.dnetlib.data.proto.RelTypeProtos.RelType; |
13 | 14 |
import eu.dnetlib.data.proto.RelTypeProtos.SubRelType; |
... | ... | |
15 | 16 |
|
16 | 17 |
public class DNGFRelDecoder { |
17 | 18 |
|
18 |
private static final String _ = "_";
|
|
19 |
private static final String SEPARATOR = "_";
|
|
19 | 20 |
|
20 | 21 |
private final DNGFRel dgnfRel; |
21 | 22 |
|
... | ... | |
27 | 28 |
this.dgnfRel = DNGFRel; |
28 | 29 |
} |
29 | 30 |
|
30 |
public RelType getRelType() {
|
|
31 |
public Qualifier getRelType() {
|
|
31 | 32 |
return dgnfRel.getRelType(); |
32 | 33 |
} |
33 | 34 |
|
... | ... | |
35 | 36 |
return getRelType().toString(); |
36 | 37 |
} |
37 | 38 |
|
38 |
public SubRelType getSubRelType() { |
|
39 |
return dgnfRel.getSubRelType(); |
|
40 |
} |
|
41 |
|
|
42 |
public String relSubTypeName() { |
|
43 |
return getSubRelType().toString(); |
|
44 |
} |
|
45 |
|
|
46 |
public String getCF() { |
|
47 |
return DNGFRelDecoder.getCF(getRelType(), getSubRelType()); |
|
48 |
} |
|
49 |
|
|
50 |
public String getCFQ() { |
|
51 |
return DNGFRelDecoder.getCFQ(getRelType(), getSubRelType(), getRelClass()); |
|
52 |
} |
|
53 |
|
|
54 | 39 |
public static String getCFQ(final RelType relType, final SubRelType subRelType, final ProtocolMessageEnum relClass) { |
55 | 40 |
return DNGFRelDecoder.getCFQ(relType, subRelType, relClass.getValueDescriptor().getName()); |
56 | 41 |
} |
57 | 42 |
|
58 | 43 |
public static String getCFQ(final RelType relType, final SubRelType subRelType, final String relClass) { |
59 |
return DNGFRelDecoder.getCF(relType, subRelType) + _ + relClass;
|
|
44 |
return DNGFRelDecoder.getCF(relType, subRelType) + SEPARATOR + relClass;
|
|
60 | 45 |
} |
61 | 46 |
|
62 | 47 |
public static String getCF(final RelType relType, final SubRelType subRelType) { |
63 |
return relType + _ + subRelType;
|
|
48 |
return relType + SEPARATOR + subRelType;
|
|
64 | 49 |
} |
65 | 50 |
|
66 | 51 |
public String getRelClass() { |
67 |
return dgnfRel.getRelClass();
|
|
52 |
return dgnfRel.getRelType().getClassid();
|
|
68 | 53 |
} |
69 | 54 |
|
70 |
public RelDescriptor getRelDescriptor() { |
|
71 |
return new RelDescriptor(getCFQ()); |
|
72 |
} |
|
73 |
|
|
74 | 55 |
public GeneratedMessage getRel() { |
75 | 56 |
|
76 | 57 |
FieldDescriptor fd = dgnfRel.getDescriptorForType().findFieldByName(relTypeName()); |
77 | 58 |
return (GeneratedMessage) dgnfRel.getField(fd); |
78 | 59 |
} |
79 | 60 |
|
80 |
public GeneratedMessage getSubRel() {
|
|
81 |
GeneratedMessage rel = getRel();
|
|
82 |
FieldDescriptor fd = rel.getDescriptorForType().findFieldByName(relSubTypeName());
|
|
83 |
return (GeneratedMessage) rel.getField(fd);
|
|
61 |
public DNGFRel.Builder setClassId(final String classid) {
|
|
62 |
final DNGFRel.Builder relBuilder = DNGFRel.newBuilder(dgnfRel);
|
|
63 |
relBuilder.getRelTypeBuilder().setClassid(classid);
|
|
64 |
return relBuilder;
|
|
84 | 65 |
} |
85 | 66 |
|
86 |
public RelMetadata getRelMetadata() { |
|
87 |
GeneratedMessage rel = getSubRel(); |
|
88 |
FieldDescriptor fd = rel.getDescriptorForType().findFieldByName("relMetadata"); |
|
89 |
return fd != null ? (RelMetadata) rel.getField(fd) : null; |
|
67 |
public Type getTargetType() { |
|
68 |
return dgnfRel.getTargetType(); |
|
90 | 69 |
} |
91 | 70 |
|
92 |
public DNGFRel.Builder setClassId(final String classid) { |
|
93 |
RelMetadata.Builder relMetadataBuilder = RelMetadata.newBuilder(getRelMetadata()); |
|
94 |
relMetadataBuilder.getSemanticsBuilder().setClassid(classid).setClassname(classid); |
|
95 |
|
|
96 |
DNGFRel.Builder builder = dgnfRel.newBuilder(dgnfRel); |
|
97 |
|
|
98 |
FieldDescriptor fdRel = fd(dgnfRel, relTypeName()); |
|
99 |
Builder relBuilder = builder.newBuilderForField(fdRel); |
|
100 |
|
|
101 |
FieldDescriptor fdSubRel = fd(relBuilder, relSubTypeName()); |
|
102 |
Builder subRelBuilder = relBuilder.newBuilderForField(fdSubRel).mergeFrom(getSubRel()); |
|
103 |
|
|
104 |
subRelBuilder.setField(fd(getSubRel(), "relMetadata"), relMetadataBuilder.build()); |
|
105 |
|
|
106 |
relBuilder.setField(fdSubRel, subRelBuilder.build()); |
|
107 |
builder.setField(fdRel, relBuilder.build()); |
|
108 |
|
|
109 |
return builder.setRelClass(classid); |
|
71 |
public Type getSourceType() { |
|
72 |
return dgnfRel.getSourceType(); |
|
110 | 73 |
} |
111 | 74 |
|
112 |
public Type getTargetType(final Type sourceType) { |
|
113 |
switch (getRelType()) { |
|
114 |
case datasourceOrganization: |
|
115 |
return sourceType.equals(Type.datasource) ? Type.organization : Type.datasource; |
|
116 |
case organizationOrganization: |
|
117 |
return Type.organization; |
|
118 |
case personPerson: |
|
119 |
return Type.person; |
|
120 |
case personPublication: |
|
121 |
return sourceType.equals(Type.person) ? Type.publication : Type.person; |
|
122 |
case personDataset: |
|
123 |
return sourceType.equals(Type.person) ? Type.dataset : Type.person; |
|
124 |
case projectOrganization: |
|
125 |
return sourceType.equals(Type.project) ? Type.organization : Type.project; |
|
126 |
case projectPerson: |
|
127 |
return sourceType.equals(Type.project) ? Type.person : Type.project; |
|
128 |
case publicationOrganization: |
|
129 |
return sourceType.equals(Type.publication) ? Type.organization : Type.publication; |
|
130 |
case publicationProject: |
|
131 |
return sourceType.equals(Type.publication) ? Type.project : Type.publication; |
|
132 |
case datasetProject: |
|
133 |
return sourceType.equals(Type.publication) ? Type.project : Type.publication; |
|
134 |
case publicationPublication: |
|
135 |
return Type.publication; |
|
136 |
case datasetDataset: |
|
137 |
return Type.dataset; |
|
138 |
case publicationDataset: |
|
139 |
return sourceType.equals(Type.publication) ? Type.dataset : Type.publication; |
|
140 |
|
|
141 |
default: |
|
142 |
throw new IllegalArgumentException("Unknown relationship type: " + relTypeName()); |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 | 75 |
protected FieldDescriptor fd(final MessageOrBuilder mb, final int fieldNumber) { |
147 | 76 |
return mb.getDescriptorForType().findFieldByNumber(fieldNumber); |
148 | 77 |
} |
modules/dnet-graph-domain/trunk/src/main/java/eu/dnetlib/data/transform/xml/AbstractDNetXsltFunctions.java | ||
---|---|---|
999 | 999 |
} |
1000 | 1000 |
|
1001 | 1001 |
protected static DNGFRel.Builder getRelBuilder(final RelType rType, final SubRelType subRelType, DNGFRel.Builder rel, final Builder subRel) { |
1002 |
|
|
1002 |
/* |
|
1003 | 1003 |
switch(rType) { |
1004 | 1004 |
|
1005 | 1005 |
case datasourceOrganization: |
... | ... | |
1088 | 1088 |
} |
1089 | 1089 |
} |
1090 | 1090 |
throw new IllegalArgumentException("invalid relation type " + rType.toString()); |
1091 |
*/ |
|
1092 |
return null; |
|
1091 | 1093 |
} |
1092 | 1094 |
|
1093 | 1095 |
protected static Builder getSubRelBuilder(final RelMetadata.Builder metadata, final SubRelType subRelType, final Map<String, String> params) { |
... | ... | |
1183 | 1185 |
return KeyValue.newBuilder().setKey(id).setValue(name).build(); |
1184 | 1186 |
} |
1185 | 1187 |
|
1186 |
protected static DNGFRel.Builder getRel(final String sourceId, |
|
1188 |
protected static DNGFRel.Builder getRel( |
|
1189 |
final String sourceId, |
|
1190 |
final Type sourceType, |
|
1187 | 1191 |
final String targetId, |
1188 |
final RelType relType, |
|
1189 |
final SubRelType subRelType, |
|
1190 |
final String relClass, |
|
1192 |
final Type targetType, |
|
1193 |
final Qualifier relType, |
|
1191 | 1194 |
final boolean isChild) { |
1192 |
return DNGFRel.newBuilder().setSource(sourceId).setTarget(targetId).setRelType(relType).setSubRelType(subRelType).setRelClass(relClass)
|
|
1195 |
return DNGFRel.newBuilder().setSource(sourceId).setTarget(targetId).setRelType(relType) |
|
1193 | 1196 |
.setChild(isChild); |
1194 | 1197 |
} |
1195 | 1198 |
|
modules/dnet-graph-domain/trunk/src/main/java/eu/dnetlib/data/transform/xml/DbmfToHbaseXsltFunctions.java | ||
---|---|---|
12 | 12 |
import eu.dnetlib.data.proto.FieldTypeProtos.DataInfo; |
13 | 13 |
import eu.dnetlib.data.proto.FieldTypeProtos.Instance; |
14 | 14 |
import eu.dnetlib.data.proto.FieldTypeProtos.KeyValue; |
15 |
import eu.dnetlib.data.proto.FieldTypeProtos.Qualifier; |
|
15 | 16 |
import eu.dnetlib.data.proto.OrganizationProtos.Organization; |
16 | 17 |
import eu.dnetlib.data.proto.PersonProtos.Person; |
17 | 18 |
import eu.dnetlib.data.proto.ProjectProtos.Project; |
... | ... | |
64 | 65 |
|
65 | 66 |
public static String oafRel(final String relationType, |
66 | 67 |
final String source, |
68 |
final String sourceType, |
|
67 | 69 |
final String target, |
70 |
final String targetType, |
|
68 | 71 |
final NodeList nodeList, |
69 | 72 |
final String relClass, |
70 | 73 |
final String relScheme) { |
71 | 74 |
|
72 | 75 |
final String eSource = DNGFRowKeyDecoder.decode(source).getKey(); |
73 | 76 |
final String eTarget = DNGFRowKeyDecoder.decode(target).getKey(); |
74 |
final RelType relType = RelType.valueOf(relationType);
|
|
77 |
final Qualifier relType = getSimpleQualifier(relClass, relScheme).build();
|
|
75 | 78 |
|
76 |
switch (relType) { |
|
77 |
case datasourceOrganization: |
|
78 |
Provision.Builder provision = Provision.newBuilder().setRelMetadata( |
|
79 |
RelMetadata.newBuilder().setSemantics(getSimpleQualifier(Provision.RelName.valueOf(relClass).toString(), relScheme))); |
|
80 |
DatasourceOrganization.Builder dorg = DatasourceOrganization.newBuilder().setProvision(provision); |
|
81 |
|
|
82 |
return serializeOafRel(nodeList, eSource, eTarget, relType, SubRelType.provision, relClass, false, dorg, provision); |
|
83 |
case personPublication: |
|
84 |
Authorship.Builder authP = Authorship.newBuilder().setRelMetadata( |
|
85 |
RelMetadata.newBuilder().setSemantics(getSimpleQualifier(Authorship.RelName.valueOf(relClass).toString(), relScheme))); |
|
86 |
PersonPublication.Builder personPublication = PersonPublication.newBuilder().setAuthorship(authP); |
|
87 |
|
|
88 |
return serializeOafRel(nodeList, eSource, eTarget, relType, SubRelType.authorship, relClass, false, personPublication, authP); |
|
89 |
case personDataset: |
|
90 |
Authorship.Builder authD = Authorship.newBuilder().setRelMetadata( |
|
91 |
RelMetadata.newBuilder().setSemantics(getSimpleQualifier(Authorship.RelName.valueOf(relClass).toString(), relScheme))); |
|
92 |
PersonDataset.Builder personDataset = PersonDataset.newBuilder().setAuthorship(authD); |
|
93 |
|
|
94 |
return serializeOafRel(nodeList, eSource, eTarget, relType, SubRelType.authorship, relClass, false, personDataset, authD); |
|
95 |
case projectPerson: |
|
96 |
ContactPerson.Builder contact = ContactPerson.newBuilder().setRelMetadata( |
|
97 |
RelMetadata.newBuilder().setSemantics(getSimpleQualifier(ContactPerson.RelName.valueOf(relClass).toString(), relScheme))); |
|
98 |
ProjectPerson.Builder projectPerson = ProjectPerson.newBuilder().setContactPerson(contact); |
|
99 |
|
|
100 |
return serializeOafRel(nodeList, eSource, eTarget, relType, SubRelType.contactPerson, relClass, false, projectPerson, contact); |
|
101 |
case projectOrganization: |
|
102 |
Participation.Builder participant = Participation.newBuilder().setRelMetadata( |
|
103 |
RelMetadata.newBuilder().setSemantics(getSimpleQualifier(Participation.RelName.valueOf(relClass).toString(), relScheme))); |
|
104 |
ProjectOrganization.Builder projectOrganization = ProjectOrganization.newBuilder().setParticipation(participant); |
|
105 |
|
|
106 |
return serializeOafRel(nodeList, eSource, eTarget, relType, SubRelType.participation, relClass, false, projectOrganization, participant); |
|
107 |
case publicationProject: |
|
108 |
Outcome.Builder outcomeP = Outcome.newBuilder().setRelMetadata( |
|
109 |
RelMetadata.newBuilder().setSemantics(getSimpleQualifier(Outcome.RelName.valueOf(relClass).toString(), relScheme))); |
|
110 |
PublicationProject.Builder publicationProject = PublicationProject.newBuilder().setOutcome(outcomeP); |
|
111 |
|
|
112 |
return serializeOafRel(nodeList, eSource, eTarget, relType, SubRelType.outcome, relClass, false, publicationProject, outcomeP); |
|
113 |
case datasetProject: |
|
114 |
Outcome.Builder outcome = Outcome.newBuilder().setRelMetadata( |
|
115 |
RelMetadata.newBuilder().setSemantics(getSimpleQualifier(Outcome.RelName.valueOf(relClass).toString(), relScheme))); |
|
116 |
DatasetProject.Builder datasetProject = DatasetProject.newBuilder().setOutcome(outcome); |
|
117 |
|
|
118 |
return serializeOafRel(nodeList, eSource, eTarget, relType, SubRelType.outcome, relClass, false, datasetProject, outcome); |
|
119 |
default: |
|
120 |
throw new IllegalArgumentException("unhandled relType: " + relationType); |
|
121 |
} |
|
79 |
return serializeOafRel(nodeList, eSource, Type.valueOf(sourceType), eTarget, Type.valueOf(targetType), relType, false, DNGFRel.newBuilder()); |
|
122 | 80 |
} |
123 | 81 |
|
124 | 82 |
// //////////////////////////////////////////////////////// |
... | ... | |
167 | 125 |
} |
168 | 126 |
} |
169 | 127 |
|
170 |
protected static String serializeOafRel(final NodeList nodeList, |
|
128 |
protected static String serializeOafRel( |
|
129 |
final NodeList nodeList, |
|
171 | 130 |
final String sourceId, |
131 |
final Type sourceType, |
|
172 | 132 |
final String targetId, |
173 |
final RelType relType, |
|
174 |
final SubRelType subRelType, |
|
175 |
final String relClass, |
|
133 |
final Type targetType, |
|
134 |
final Qualifier relType, |
|
176 | 135 |
final boolean isChild, |
177 |
final Builder rel, |
|
178 |
final Builder subRel) { |
|
136 |
final Builder rel) { |
|
179 | 137 |
try { |
180 | 138 |
|
181 | 139 |
final DataInfo.Builder dataInfo = DataInfo.newBuilder(); |
182 | 140 |
|
183 |
parseNodelist(nodeList, rel, subRel, dataInfo);
|
|
141 |
parseNodelist(nodeList, rel, dataInfo); |
|
184 | 142 |
|
185 |
DNGFRel.Builder builder = getRel(sourceId, targetId, relType, subRelType, relClass, isChild);
|
|
143 |
DNGFRel.Builder builder = getRel(sourceId, sourceType, targetId, targetType, relType, isChild);
|
|
186 | 144 |
|
187 |
FieldDescriptor subRelDescriptor = rel.getDescriptorForType().findFieldByName(subRelType.toString()); |
|
188 |
rel.setField(subRelDescriptor, subRel.build()); |
|
189 |
|
|
190 | 145 |
FieldDescriptor relDescriptor = DNGFRel.getDescriptor().findFieldByName(relType.toString()); |
191 | 146 |
builder.setField(relDescriptor, rel.build()); |
192 | 147 |
|
modules/dnet-graph-domain/trunk/src/main/java/eu/dnetlib/data/transform/xml/CommonDNetXsltFunctions.java | ||
---|---|---|
10 | 10 |
import eu.dnetlib.data.proto.DNGFProtos.DNGF; |
11 | 11 |
import eu.dnetlib.data.proto.DNGFProtos.DNGFEntity; |
12 | 12 |
import eu.dnetlib.data.proto.DNGFProtos.DNGFRel; |
13 |
import eu.dnetlib.data.proto.FieldTypeProtos.Qualifier; |
|
13 | 14 |
import eu.dnetlib.data.proto.FieldTypeProtos.StructuredProperty; |
14 | 15 |
import eu.dnetlib.data.proto.PersonProtos.Person; |
15 | 16 |
import eu.dnetlib.data.proto.PersonProtos.Person.CoAuthor; |
... | ... | |
28 | 29 |
|
29 | 30 |
private static final int MAX_COAUTHORS = 50; |
Also available in: Unified diff
1st attempt to simplify the proto model