Revision 56080
Added by Miriam Baglioni about 5 years ago
modules/dnet-mapreduce-jobs/trunk/src/test/java/eu/dnetlib/data/mapreduce/hbase/dataexport/linkinganalysis/publicationsoftware/PubSfwLinkTest.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mapreduce.hbase.dataexport.linkinganalysis.publicationsoftware; |
|
2 |
|
|
3 |
|
|
4 |
import eu.dnetlib.data.bulktag.Pair; |
|
5 |
import org.apache.hadoop.io.Text; |
|
6 |
import org.elasticsearch.hadoop.util.Assert; |
|
7 |
import org.junit.Test; |
|
8 |
|
|
9 |
import java.io.IOException; |
|
10 |
import java.util.ArrayList; |
|
11 |
import java.util.List; |
|
12 |
|
|
13 |
public class PubSfwLinkTest { |
|
14 |
List<Text> list; |
|
15 |
ValueList vl; |
|
16 |
|
|
17 |
|
|
18 |
@Test |
|
19 |
public void test1() throws IOException { |
|
20 |
ValueList vl = new ValueList("linking1.json"); |
|
21 |
|
|
22 |
list = vl.getValueToText();//new ArrayList<>(Arrays.asList(new Text(Value.newInstance( "p1,p2,p3","0.9", PropagationConstants.Type.fromsemrel).toJson()),new Text(Value.newInstance( "p1,p2","0.9", PropagationConstants.Type.fromresult).toJson()) )); |
|
23 |
|
|
24 |
ReturnedValues rv = new ReturnedValues(); |
|
25 |
rv.setOpenAireId("pippo"); |
|
26 |
PubSfwLinkIterator it = new PubSfwLinkIterator(list, "pippo"); |
|
27 |
|
|
28 |
Assert.isTrue(it.hasNext()); |
|
29 |
while(it.hasNext()){ |
|
30 |
Pair<Constants.Type, Object> p = it.next(); |
|
31 |
if(p.getFst()== Constants.Type.publication){ |
|
32 |
rv.addPublicationId((Identifier)p.getSnd()); |
|
33 |
}else{ |
|
34 |
rv.addLinkedSoftware((SoftwareResource)p.getSnd()); |
|
35 |
} |
|
36 |
|
|
37 |
|
|
38 |
} |
|
39 |
System.out.print(rv.toJson()); |
|
40 |
} |
|
41 |
|
|
42 |
@Test |
|
43 |
public void test2(){ |
|
44 |
Identifier id = new Identifier(); |
|
45 |
id.setPid("pid1").setPidtype("doi"); |
|
46 |
System.out.println("id.toJson() = " + id.toJson()); |
|
47 |
|
|
48 |
SoftwareResource sr = new SoftwareResource().setOpenAireId("oaSwId"); |
|
49 |
List<String> urls = new ArrayList<String>(){{add("url1");add("url2");add("url3");}}; |
|
50 |
List<Identifier> pids = new ArrayList<Identifier>(){{ |
|
51 |
add(new Identifier().setPid("doi1").setPidtype("doi")); |
|
52 |
add(new Identifier().setPid("doi2").setPidtype("doi")); |
|
53 |
}}; |
|
54 |
|
|
55 |
sr.setSoftwarePIDs(pids).setUrls(urls); |
|
56 |
System.out.println("sr.toJson() = " + sr.toJson()); |
|
57 |
} |
|
58 |
|
|
59 |
@Test |
|
60 |
public void test3(){ |
|
61 |
String json = "{\"pidtype\":\"doi\",\"pid\":\"pid1\"}"; |
|
62 |
Identifier id = Identifier.fromJson(json); |
|
63 |
System.out.println("id.getPid() = " + id.getPid()); |
|
64 |
System.out.println("id.getPidtype() = " + id.getPidtype()); |
|
65 |
} |
|
66 |
} |
modules/dnet-mapreduce-jobs/trunk/src/test/java/eu/dnetlib/data/mapreduce/hbase/dataexport/linkinganalysis/publicationsoftware/ValueList.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mapreduce.hbase.dataexport.linkinganalysis.publicationsoftware; |
|
2 |
|
|
3 |
import com.google.gson.Gson; |
|
4 |
|
|
5 |
import org.apache.commons.io.IOUtils; |
|
6 |
import org.apache.hadoop.io.Text; |
|
7 |
|
|
8 |
import java.io.IOException; |
|
9 |
import java.util.List; |
|
10 |
import java.util.stream.Collectors; |
|
11 |
|
|
12 |
public class ValueList { |
|
13 |
private String jsonFile; |
|
14 |
public ValueList(String jsonFile) { |
|
15 |
this.jsonFile=jsonFile; |
|
16 |
} |
|
17 |
|
|
18 |
public List<Value> getValueList() { |
|
19 |
return valueList; |
|
20 |
} |
|
21 |
|
|
22 |
public void setValueList(List<Value> valueList) { |
|
23 |
this.valueList = valueList; |
|
24 |
} |
|
25 |
|
|
26 |
private List<Value> valueList ; |
|
27 |
|
|
28 |
public List<Text> getValueToText() throws IOException { |
|
29 |
ValueList tmp = new Gson().fromJson(IOUtils.toString(getClass().getResourceAsStream(jsonFile)), ValueList.class); |
|
30 |
//IOUtils.toString(getClass().getResourceAsStream("community_configuration.xml")); |
|
31 |
return tmp.getValueList().stream().map(Value::toJson).map(Text::new).collect(Collectors.toList()); |
|
32 |
} |
|
33 |
} |
|
34 |
|
|
35 |
|
modules/dnet-mapreduce-jobs/trunk/src/test/resources/eu/dnetlib/data/mapreduce/hbase/dataexport/linkinganalysis/publicationsoftware/linking1.json | ||
---|---|---|
1 |
{"valueList":[ |
|
2 |
{"value":"{openAireId:oaSwId,softwarePIDs:[{pidtype:doi,pid:doi1},{pidtype:doi,pid:doi2}],urls:[url1,url2,url3]}","type":"software"}, |
|
3 |
{"value":"{pidtype:doi,pid:pid1}","type":"publication"} |
|
4 |
]} |
Also available in: Unified diff
test for exporting link between publications and softwares (related to #4593)