Fix siteIRI of new item ids (switch to SITE_LOCAL)
This commit is contained in:
parent
975c3529cb
commit
03c7674858
@ -15,7 +15,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.EntityDocument;
|
import org.wikidata.wdtk.datamodel.interfaces.EntityDocument;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.ItemDocument;
|
import org.wikidata.wdtk.datamodel.interfaces.ItemDocument;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
|
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue;
|
import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue;
|
||||||
import org.wikidata.wdtk.wikibaseapi.WikibaseDataEditor;
|
import org.wikidata.wdtk.wikibaseapi.WikibaseDataEditor;
|
||||||
import org.wikidata.wdtk.wikibaseapi.WikibaseDataFetcher;
|
import org.wikidata.wdtk.wikibaseapi.WikibaseDataFetcher;
|
||||||
@ -112,9 +111,9 @@ public class EditBatchProcessor {
|
|||||||
// New item
|
// New item
|
||||||
if (update.isNew()) {
|
if (update.isNew()) {
|
||||||
ReconEntityIdValue newCell = (ReconEntityIdValue)update.getItemId();
|
ReconEntityIdValue newCell = (ReconEntityIdValue)update.getItemId();
|
||||||
update.normalizeLabelsAndAliases();
|
update = update.normalizeLabelsAndAliases();
|
||||||
|
|
||||||
ItemDocument itemDocument = Datamodel.makeItemDocument(ItemIdValue.NULL,
|
ItemDocument itemDocument = Datamodel.makeItemDocument(update.getItemId(),
|
||||||
update.getLabels().stream().collect(Collectors.toList()),
|
update.getLabels().stream().collect(Collectors.toList()),
|
||||||
update.getDescriptions().stream().collect(Collectors.toList()),
|
update.getDescriptions().stream().collect(Collectors.toList()),
|
||||||
update.getAliases().stream().collect(Collectors.toList()),
|
update.getAliases().stream().collect(Collectors.toList()),
|
||||||
|
@ -65,7 +65,7 @@ public class ReconEntityRewriter extends DatamodelConverter {
|
|||||||
"Trying to rewrite an update where a new item was not created yet.");
|
"Trying to rewrite an update where a new item was not created yet.");
|
||||||
}
|
}
|
||||||
return Datamodel.makeItemIdValue(newId,
|
return Datamodel.makeItemIdValue(newId,
|
||||||
recon.getSiteIri());
|
recon.getRecon().identifierSpace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.copy(value);
|
return super.copy(value);
|
||||||
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.wikidata.wdtk.datamodel.helpers.Equality;
|
||||||
import org.wikidata.wdtk.datamodel.helpers.Hash;
|
import org.wikidata.wdtk.datamodel.helpers.Hash;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
|
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
|
||||||
import org.wikidata.wdtk.datamodel.interfaces.ValueVisitor;
|
import org.wikidata.wdtk.datamodel.interfaces.ValueVisitor;
|
||||||
@ -87,7 +88,7 @@ public abstract class ReconEntityIdValue implements PrefetchedEntityIdValue {
|
|||||||
* @return
|
* @return
|
||||||
* the full reconciliation metadata of the corresponding cell
|
* the full reconciliation metadata of the corresponding cell
|
||||||
*/
|
*/
|
||||||
protected Recon getRecon() {
|
public Recon getRecon() {
|
||||||
return _recon;
|
return _recon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,16 +100,20 @@ public abstract class ReconEntityIdValue implements PrefetchedEntityIdValue {
|
|||||||
if (isMatched()) {
|
if (isMatched()) {
|
||||||
return _recon.match.id;
|
return _recon.match.id;
|
||||||
} else if (ET_ITEM.equals(getEntityType())) {
|
} else if (ET_ITEM.equals(getEntityType())) {
|
||||||
return "Q0";
|
return "Q"+getReconInternalId();
|
||||||
} else if (ET_PROPERTY.equals(getEntityType())) {
|
} else if (ET_PROPERTY.equals(getEntityType())) {
|
||||||
return "P0";
|
return "P"+getReconInternalId();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSiteIri() {
|
public String getSiteIri() {
|
||||||
return _recon.identifierSpace;
|
if (isMatched()) {
|
||||||
|
return _recon.identifierSpace;
|
||||||
|
} else {
|
||||||
|
return EntityIdValue.SITE_LOCAL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -121,45 +126,15 @@ public abstract class ReconEntityIdValue implements PrefetchedEntityIdValue {
|
|||||||
return valueVisitor.visit(this);
|
return valueVisitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Equality check is important when we gather
|
|
||||||
* all ItemUpdates related to an ItemId.
|
|
||||||
*
|
|
||||||
* The label is ignored in the equality check.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (other == null ||
|
return Equality.equalsEntityIdValue(this, other);
|
||||||
!EntityIdValue.class.isInstance(other)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ReconEntityIdValue.class.isInstance(other)) {
|
|
||||||
final ReconEntityIdValue reconOther = (ReconEntityIdValue)other;
|
|
||||||
|
|
||||||
if (isNew() != reconOther.isNew()) {
|
|
||||||
return false;
|
|
||||||
} else if (isNew()) {
|
|
||||||
// This ensures compliance with OR's notion of new items
|
|
||||||
// (it is possible that two cells are reconciled to the same
|
|
||||||
// new item, in which case they share the same internal recon id).
|
|
||||||
return (getReconInternalId() == reconOther.getReconInternalId() &&
|
|
||||||
getEntityType().equals(reconOther.getEntityType()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final EntityIdValue otherNew = (EntityIdValue)other;
|
|
||||||
return getIri().equals(otherNew.getIri());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
if (isMatched()) {
|
return Hash.hashCode(this);
|
||||||
return Hash.hashCode(this);
|
|
||||||
} else {
|
|
||||||
return (int) getReconInternalId();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -238,7 +238,7 @@ public class ItemUpdate {
|
|||||||
* Is this update about a new item?
|
* Is this update about a new item?
|
||||||
*/
|
*/
|
||||||
public boolean isNew() {
|
public boolean isNew() {
|
||||||
return "Q0".equals(getItemId().getId());
|
return EntityIdValue.SITE_LOCAL.equals(getItemId().getSiteIri());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,7 +56,7 @@ public class EditBatchProcessorTest extends RefineTest {
|
|||||||
.build());
|
.build());
|
||||||
MonolingualTextValue label = Datamodel.makeMonolingualTextValue("better label", "en");
|
MonolingualTextValue label = Datamodel.makeMonolingualTextValue("better label", "en");
|
||||||
batch.add(new ItemUpdateBuilder(TestingData.newIdA)
|
batch.add(new ItemUpdateBuilder(TestingData.newIdA)
|
||||||
.addLabel(label)
|
.addAlias(label)
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
// Plan expected edits
|
// Plan expected edits
|
||||||
@ -67,7 +67,7 @@ public class EditBatchProcessorTest extends RefineTest {
|
|||||||
when(fetcher.getEntityDocuments(Collections.singletonList(TestingData.existingId.getId())))
|
when(fetcher.getEntityDocuments(Collections.singletonList(TestingData.existingId.getId())))
|
||||||
.thenReturn(Collections.singletonMap(TestingData.existingId.getId(), existingItem));
|
.thenReturn(Collections.singletonMap(TestingData.existingId.getId(), existingItem));
|
||||||
|
|
||||||
ItemDocument expectedNewItem = ItemDocumentBuilder.forItemId(ItemIdValue.NULL)
|
ItemDocument expectedNewItem = ItemDocumentBuilder.forItemId(TestingData.newIdA)
|
||||||
.withLabel(label).build();
|
.withLabel(label).build();
|
||||||
ItemDocument createdNewItem = ItemDocumentBuilder.forItemId(Datamodel.makeWikidataItemIdValue("Q1234"))
|
ItemDocument createdNewItem = ItemDocumentBuilder.forItemId(Datamodel.makeWikidataItemIdValue("Q1234"))
|
||||||
.withLabel(label).withRevisionId(37828L).build();
|
.withLabel(label).withRevisionId(37828L).build();
|
||||||
|
@ -10,6 +10,7 @@ import java.util.Collections;
|
|||||||
import org.openrefine.wikidata.testing.TestingData;
|
import org.openrefine.wikidata.testing.TestingData;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||||
|
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
|
||||||
|
|
||||||
import com.google.refine.model.Recon;
|
import com.google.refine.model.Recon;
|
||||||
|
|
||||||
@ -47,21 +48,21 @@ public class ReconEntityIdValueTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetId() {
|
public void testGetId() {
|
||||||
assertEquals("Q42", existingItem.getId());
|
assertEquals("Q42", existingItem.getId());
|
||||||
assertEquals("Q0", newItem.getId());
|
assertEquals("Q1234", newItem.getId());
|
||||||
assertEquals("P53", existingProp.getId());
|
assertEquals("P53", existingProp.getId());
|
||||||
assertEquals("P0", newProp.getId());
|
assertEquals("P1234", newProp.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetIri() {
|
public void testGetIri() {
|
||||||
assertEquals("http://www.wikidata.org/entity/Q42", existingItem.getIri());
|
assertEquals("http://www.wikidata.org/entity/Q42", existingItem.getIri());
|
||||||
assertEquals("http://www.wikidata.org/entity/Q0", newItem.getIri());
|
assertEquals(EntityIdValue.SITE_LOCAL+"Q1234", newItem.getIri());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetSiteIri() {
|
public void testGetSiteIri() {
|
||||||
assertEquals("http://www.wikidata.org/entity/", existingItem.getSiteIri());
|
assertEquals("http://www.wikidata.org/entity/", existingItem.getSiteIri());
|
||||||
assertEquals("http://www.wikidata.org/entity/", newItem.getSiteIri());
|
assertEquals(EntityIdValue.SITE_LOCAL, newItem.getSiteIri());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user