Project

General

Profile

« Previous | Next » 

Revision 33076

#577 introducing PMCCitationCollapser unit test

View differences:

modules/icm-iis-collapsers/trunk/src/test/java/eu/dnetlib/iis/collapsers/origins/PMCCitationCollapserTest.java
1
package eu.dnetlib.iis.collapsers.origins;
2

  
3
import static org.junit.Assert.assertEquals;
4
import static org.junit.Assert.assertNotNull;
5

  
6
import java.util.Arrays;
7
import java.util.HashMap;
8
import java.util.List;
9
import java.util.Map;
10

  
11
import org.junit.Test;
12

  
13
import eu.dnetlib.iis.common.citations.schemas.Citation;
14
import eu.dnetlib.iis.common.citations.schemas.CitationEntry;
15

  
16
/**
17
 * {@link PMCCitationCollapser} test class.
18
 * @author mhorst
19
 *
20
 */
21
public class PMCCitationCollapserTest {
22

  
23
	@Test
24
	public void testCollapsingWhenPmcTargetIdSet() throws Exception {
25
		PMCCitationCollapser collapser = new PMCCitationCollapser();
26
		Map<String,List<Citation>> objects = new HashMap<String, List<Citation>>();
27
		
28
		String sourceId = "sourceId";
29
		String pmcTargetId = "pmcTargetId";
30
		String cermineTargetId = "cermineTargetId";
31
		String text = "citation text";
32
		
33
		objects.put("pmc_ingestion", Arrays.asList(new Citation[] {
34
				Citation
35
						.newBuilder()
36
						.setSourceDocumentId(sourceId)
37
						.setEntry(
38
								CitationEntry.newBuilder()
39
										.setConfidenceLevel(1f)
40
										.setDestinationDocumentId(pmcTargetId)
41
										.setExternalDestinationDocumentIds(new HashMap<CharSequence, CharSequence>())
42
										.setRawText(text).build()).build()		
43
		}));
44
		objects.put("cermine", Arrays.asList(new Citation[] {
45
				Citation
46
						.newBuilder()
47
						.setSourceDocumentId(sourceId)
48
						.setEntry(
49
								CitationEntry
50
										.newBuilder()
51
										.setConfidenceLevel(0.1f)
52
										.setDestinationDocumentId(cermineTargetId)
53
										.setExternalDestinationDocumentIds(new HashMap<CharSequence, CharSequence>())
54
										.setRawText(text).build()).build()
55
		}));
56
		
57
		List<Citation> results = collapser.collapseBetweenOrigins(objects);
58
		assertNotNull(results);
59
		assertEquals(1, results.size());
60
		assertEquals(pmcTargetId,results.get(0).getEntry().getDestinationDocumentId());
61
		assertEquals(new Float(1f),results.get(0).getEntry().getConfidenceLevel());
62
	}
63
	
64
	@Test
65
	public void testCollapsingWhenPmcTargetIdNotSet() throws Exception {
66
		PMCCitationCollapser collapser = new PMCCitationCollapser();
67
		Map<String,List<Citation>> objects = new HashMap<String, List<Citation>>();
68
		
69
		String sourceId = "sourceId";
70
		String cermineTargetId = "cermineTargetId";
71
		String text = "citation text";
72
		
73
		objects.put("pmc_ingestion", Arrays.asList(new Citation[] {
74
				Citation
75
						.newBuilder()
76
						.setSourceDocumentId(sourceId)
77
						.setEntry(
78
								CitationEntry.newBuilder()
79
										.setExternalDestinationDocumentIds(new HashMap<CharSequence, CharSequence>())
80
										.setRawText(text).build()).build()		
81
		}));
82
		objects.put("cermine", Arrays.asList(new Citation[] {
83
				Citation
84
						.newBuilder()
85
						.setSourceDocumentId(sourceId)
86
						.setEntry(
87
								CitationEntry
88
										.newBuilder()
89
										.setConfidenceLevel(0.1f)
90
										.setDestinationDocumentId(cermineTargetId)
91
										.setExternalDestinationDocumentIds(new HashMap<CharSequence, CharSequence>())
92
										.setRawText(text).build()).build()
93
		}));
94
		
95
		List<Citation> results = collapser.collapseBetweenOrigins(objects);
96
		assertNotNull(results);
97
		assertEquals(1, results.size());
98
		assertEquals(cermineTargetId,results.get(0).getEntry().getDestinationDocumentId());
99
		assertEquals(new Float(0.1f),results.get(0).getEntry().getConfidenceLevel());
100
	}
101
	
102
	@Test
103
	public void testCollapsingWithDifferentText() throws Exception {
104
		PMCCitationCollapser collapser = new PMCCitationCollapser();
105
		Map<String,List<Citation>> objects = new HashMap<String, List<Citation>>();
106
		
107
		String sourceId = "sourceId";
108
		String pmcTargetId = "pmcTargetId";
109
		String cermineTargetId = "cermineTargetId";
110
		String textPmc = "pmc citation text";
111
		String textCermine = "cermine citation text";
112
		
113
		objects.put("pmc_ingestion", Arrays.asList(new Citation[] {
114
				Citation
115
						.newBuilder()
116
						.setSourceDocumentId(sourceId)
117
						.setEntry(
118
								CitationEntry.newBuilder()
119
										.setConfidenceLevel(1f)
120
										.setDestinationDocumentId(pmcTargetId)
121
										.setExternalDestinationDocumentIds(new HashMap<CharSequence, CharSequence>())
122
										.setRawText(textPmc).build()).build()		
123
		}));
124
		objects.put("cermine", Arrays.asList(new Citation[] {
125
				Citation
126
						.newBuilder()
127
						.setSourceDocumentId(sourceId)
128
						.setEntry(
129
								CitationEntry
130
										.newBuilder()
131
										.setConfidenceLevel(0.1f)
132
										.setDestinationDocumentId(cermineTargetId)
133
										.setExternalDestinationDocumentIds(new HashMap<CharSequence, CharSequence>())
134
										.setRawText(textCermine).build()).build()
135
		}));
136
		
137
		List<Citation> results = collapser.collapseBetweenOrigins(objects);
138
		assertNotNull(results);
139
		assertEquals(2, results.size());
140
		assertEquals(pmcTargetId,results.get(0).getEntry().getDestinationDocumentId());
141
		assertEquals(new Float(1f),results.get(0).getEntry().getConfidenceLevel());
142
		assertEquals(textPmc,results.get(0).getEntry().getRawText());
143
		
144
		assertEquals(cermineTargetId,results.get(1).getEntry().getDestinationDocumentId());
145
		assertEquals(new Float(0.1f),results.get(1).getEntry().getConfidenceLevel());
146
		assertEquals(textCermine,results.get(1).getEntry().getRawText());
147
	}
148
}
0 149

  

Also available in: Unified diff