scholexplorer_incremental_index #14

Merged
sandro.labruzzo merged 12 commits from scholexplorer_incremental_index into master 2022-03-29 11:43:02 +02:00
2 changed files with 128 additions and 34 deletions
Showing only changes of commit d899bacebb - Show all commits

View File

@ -4,7 +4,11 @@
| **Version** | **Changes** | **Readiness** |
|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| 2.10.25 | [Graph model]</br>implements enrichment on Result specializing in the method mergefrom. | beta |
| 2.10.29 | [Merge Result] </br>merge logics changed to consider invisble in dataInfo | beta |
| 2.10.28 | [Graph Model] </br> Added APC information at the level of the result | beta |
| 2.10.27 | [Graph Model] </br> change name and id of OpenAPC datasource | beta |
| 2.10.26 | [Graph Model] </br> OpenAIRE ids of the delegated authorities and enrichment providers in the identifier creation strategy | beta |
| 2.10.25 | [Graph model]</br>implemented enrichment on Result specializing in the method mergefrom. | beta |
| 2.10.24 | [Graph model]</br>added utility method and constants for checking weather is an OafEntity represents an enrichment. | beta |
| 2.9.24 | [Dump model]</br>change the names of the classes to be able to automatically create the json schema with specific descriptions | beta |
| 2.9.23 | [Graph model]<br>Added Instance.measures field, allowing to maintain the association between them and the individual result instance</br>[Dump model]</br>added json schemas | beta |

View File

@ -1,39 +1,34 @@
package eu.dnetlib.dhp.schema.sx.scholix;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
public class ScholixCompareTest {
private ScholixIdentifier generateMockScholixId(final String baseId ,boolean toUpper, int idCount) {
private ScholixIdentifier generateMockScholixId(boolean toUpper, int idCount) {
final String id = String.format("10.11646/zootaxa.5099.1.%d", idCount);
final String id = String.format("%s.%d",baseId, idCount);
final String schema = "DOI";
final String url =String.format("http://dx.dOI.org/10.11646/Zootaxa.5099.1.%d", idCount);
final String url =String.format("http://dx.dOI.org/%s.%d",baseId, idCount);
final ScholixIdentifier result = new ScholixIdentifier();
result.setIdentifier(toUpper ? id.toUpperCase(): id.toLowerCase());
result.setSchema(toUpper ? schema.toUpperCase():schema.toLowerCase());
result.setUrl(toUpper ? url.toUpperCase():url.toLowerCase());
return result;
}
private ScholixIdentifier generateMockScholixId(boolean toUpper, int idCount) {
return generateMockScholixId("10.11646/zootaxa.5099.1", toUpper, idCount);
}
private ScholixEntityId generateMockScholixEntityId(boolean toUpper, boolean invertOrder, int numberOfIds) {
private ScholixEntityId generateMockScholixEntityId(String name, boolean toUpper, boolean invertOrder, int numberOfIds) {
final String datasourceName = "Datacite";
final List<ScholixIdentifier> ids = new ArrayList<>();
@ -48,20 +43,30 @@ public class ScholixCompareTest {
}
}
return new ScholixEntityId(toUpper? datasourceName.toUpperCase(): datasourceName.toLowerCase(), ids);
return new ScholixEntityId(toUpper? name.toUpperCase(): name.toLowerCase(), ids);
}
private ScholixCollectedFrom generateMockScholixCollectedFrom(boolean toUpper, boolean invertOrder, int numberOfIds) {
private ScholixEntityId generateMockScholixEntityId(boolean toUpper, boolean invertOrder, int numberOfIds) {
return generateMockScholixEntityId("datacite", toUpper, invertOrder,numberOfIds);
}
private ScholixCollectedFrom generateMockScholixCollectedFrom(final String dsName , final boolean toUpper, final boolean invertOrder, final int numberOfIds) {
final ScholixCollectedFrom result = new ScholixCollectedFrom();
final String completionStatus = "complete";
final String provisionMode = "collected";
result.setProvider(generateMockScholixEntityId(toUpper, invertOrder, numberOfIds));
result.setProvider(generateMockScholixEntityId(dsName,toUpper, invertOrder, numberOfIds));
result.setCompletionStatus(toUpper ? completionStatus.toUpperCase(): completionStatus.toLowerCase());
result.setProvisionMode(toUpper ? provisionMode.toUpperCase(): provisionMode.toLowerCase());
return result;
}
private ScholixCollectedFrom generateMockScholixCollectedFrom(boolean toUpper, boolean invertOrder, int numberOfIds) {
return generateMockScholixCollectedFrom("datasource", toUpper, invertOrder,numberOfIds);
}
private ScholixRelationship generateMockScholixRelationships(boolean toUpper) {
final String name = "IsRelatedTo";
@ -78,26 +83,86 @@ public class ScholixCompareTest {
}
private ScholixResource generateMockScholixResource(final String sourceBase, boolean toUpper, int idCount, boolean invertOrder, int numEntityIds) {
final ScholixResource resource = new ScholixResource();
final String baseSourceId = "%s_10.1000/ID_%d/";
final String creatorBase ="Creator %d";
final String publisherBase ="Publisher %d";
final String collectedFromBase ="Datasource %d";
final String title = String.format("Resource %s Title 1", sourceBase);
final List<ScholixIdentifier> ids = IntStream.range(0,numEntityIds)
.mapToObj(i -> String.format(baseSourceId,sourceBase, i))
.map(s ->generateMockScholixId(s, toUpper, idCount))
.collect(Collectors.toList());
resource.setIdentifier(ids);
resource.setDnetIdentifier("dnetId");
resource.setObjectType("dataset");
resource.setObjectSubType("dataset");
resource.setTitle(title);
final List<ScholixEntityId> creators = IntStream.range(0,numEntityIds)
.mapToObj(i -> String.format(creatorBase, i))
.map(s ->generateMockScholixEntityId(s, toUpper,invertOrder,idCount))
.collect(Collectors.toList());
resource.setCreator(creators);
resource.setPublicationDate("22-02-2022");
final List<ScholixEntityId> publishers = IntStream.range(0,numEntityIds)
.mapToObj(i -> String.format(publisherBase, i))
.map(s ->generateMockScholixEntityId(s, toUpper,invertOrder,idCount))
.collect(Collectors.toList());
resource.setPublisher(publishers);
final List<ScholixCollectedFrom> collectedFroms = IntStream.range(0,numEntityIds)
.mapToObj(i -> String.format(collectedFromBase, i))
.map(s -> generateMockScholixCollectedFrom(s,toUpper, invertOrder, idCount))
.collect(Collectors.toList());
resource.setCollectedFrom(collectedFroms);
return resource;
}
private Scholix generateMockScholix( boolean toUpper, int idCount, boolean invertOrder, int numEntityIds) {
final Scholix result = new Scholix();
result.setPublicationDate("2022-02-22");
final String id = "dnetID";
final String publisherBase ="Publisher %d";
result.setPublisher(IntStream.range(0,numEntityIds)
.mapToObj(i -> String.format(publisherBase, i))
.map(s ->generateMockScholixEntityId(s, toUpper,invertOrder,idCount))
.collect(Collectors.toList()));
result.setLinkprovider(IntStream.range(0,numEntityIds)
.mapToObj(i -> String.format(publisherBase, i))
.map(s ->generateMockScholixEntityId(s, toUpper,invertOrder,idCount))
.collect(Collectors.toList()));
result.setRelationship(generateMockScholixRelationships(toUpper));
result.setSource(generateMockScholixResource("source", toUpper, idCount,invertOrder, numEntityIds));
result.setTarget(generateMockScholixResource("target", toUpper, idCount,invertOrder, numEntityIds));
result.setIdentifier(toUpper?id.toUpperCase():id.toLowerCase());
return result;
}
@Test
public void testScholixIdentifierComparison() {
final ScholixIdentifier left = generateMockScholixId(true, 1);
final ScholixIdentifier right = generateMockScholixId(false,1);
assertEquals(0,left.compareTo(right));
assertEquals(left, right);
assertEquals(left.hashCode(), right.hashCode());
left.setIdentifier(null);
assertEquals(-1, left.compareTo(right));
}
@ -116,8 +181,6 @@ public class ScholixCompareTest {
public void testScholixCollectedFromComparison() {
final ScholixCollectedFrom cfLeft = generateMockScholixCollectedFrom(true, true, 20);
final ScholixCollectedFrom cfRight = generateMockScholixCollectedFrom(false, false, 20);
assertEquals(cfLeft, cfRight);
@ -127,6 +190,35 @@ public class ScholixCompareTest {
cfRight.setCompletionStatus(null);
assertNotEquals(cfLeft, cfRight);
}
@Test
public void testCompareScholixResource() {
final ScholixResource left = generateMockScholixResource("source",true,5, true,5);
final ScholixResource right = generateMockScholixResource("source",false,5, false,5);
assertEquals(left,right);
assertEquals(left.hashCode(), right.hashCode());
final ScholixResource different = generateMockScholixResource("source",false,4, false,5);
assertNotEquals(different,right);
assertNotEquals(different,left);
assertNotEquals(left.hashCode(), different.hashCode());
assertNotEquals(right.hashCode(), different.hashCode());
}
@Test
public void testCompareScholix() {
final Scholix left = generateMockScholix(true,5, true,5);
final Scholix right = generateMockScholix(false,5, false,5);
assertEquals(left,right);
assertEquals(left.hashCode(), right.hashCode());
final Scholix different = generateMockScholix(true,4, false,5);
assertNotEquals(different,right);
assertNotEquals(different,left);
assertNotEquals(left.hashCode(), different.hashCode());
assertNotEquals(right.hashCode(), different.hashCode());
}
@ -134,16 +226,14 @@ public class ScholixCompareTest {
@Test
public void testCompareScholixRelation() {
final ScholixRelationship left = generateMockScholixRelationships(true);
final ScholixRelationship right = generateMockScholixRelationships(false);
assertEquals(left, right);
assertEquals(left.hashCode(), right.hashCode());
}
}
}