Add test-cases for methods defined in WikidataConstraintFetcher (#2943)
* Add test-cases for methods defined in WikidataConstraintFetcher tests for getConstraintsByTpe & getConstraintStatements methods. * Tests updated
This commit is contained in:
parent
e67c6c9580
commit
dd17d7a2b6
@ -27,7 +27,6 @@ import org.openrefine.wikidata.utils.EntityCache;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.PropertyDocument;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.SnakGroup;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.Statement;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.StatementGroup;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.StatementRank;
|
||||
@ -48,38 +47,12 @@ public class WikidataConstraintFetcher implements ConstraintFetcher {
|
||||
|
||||
public static String WIKIDATA_CONSTRAINT_PID = "P2302";
|
||||
|
||||
// The following constraints still need to be implemented:
|
||||
|
||||
public static String TYPE_CONSTRAINT_QID = "Q21503250";
|
||||
|
||||
protected EntityCache entityCache;
|
||||
|
||||
public WikidataConstraintFetcher(EntityCache cache) {
|
||||
entityCache = cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single constraint for a particular type and a property, or null if
|
||||
* there is no such constraint
|
||||
*
|
||||
* @param pid
|
||||
* the property to retrieve the constraints for
|
||||
* @param qid
|
||||
* the type of the constraints
|
||||
* @return the list of qualifiers for the constraint, or null if it does not
|
||||
* exist
|
||||
*/
|
||||
protected List<SnakGroup> getSingleConstraint(PropertyIdValue pid, String qid) {
|
||||
List<Statement> statementList = getConstraintsByType(pid, qid);
|
||||
if (!statementList.isEmpty()) {
|
||||
Statement statement = statementList.get(0);
|
||||
if (statement != null) {
|
||||
return statement.getClaim().getQualifiers();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of constraints of a particular type for a property
|
||||
*
|
||||
|
@ -23,14 +23,40 @@
|
||||
******************************************************************************/
|
||||
package org.openrefine.wikidata.qa;
|
||||
|
||||
import org.openrefine.wikidata.qa.scrutinizers.ConflictsWithScrutinizer;
|
||||
import org.openrefine.wikidata.qa.scrutinizers.RestrictedValuesScrutinizer;
|
||||
import org.openrefine.wikidata.utils.EntityCacheStub;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class WikidataConstraintFetcherTests {
|
||||
|
||||
private ConstraintFetcher fetcher;
|
||||
public static PropertyIdValue instanceOf;
|
||||
|
||||
public WikidataConstraintFetcherTests() {
|
||||
fetcher = new WikidataConstraintFetcher(new EntityCacheStub());
|
||||
instanceOf = Datamodel.makeWikidataPropertyIdValue("P31");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConstraintsByType() {
|
||||
Assert.assertEquals(fetcher.getConstraintsByType(instanceOf, ConflictsWithScrutinizer.CONFLICTS_WITH_CONSTRAINT_QID), new ArrayList<>());
|
||||
String constraintDefinitions = "[[ID P31$43E28495-355E-451E-A881-2EE14DFBE99D] http://www.wikidata.org/entity/P31 (property): http://www.wikidata.org/entity/P2302 :: http://www.wikidata.org/entity/Q52558054 (item)\n" +
|
||||
" http://www.wikidata.org/entity/P2305 :: http://www.wikidata.org/entity/Q467 (item)\n" +
|
||||
" http://www.wikidata.org/entity/P2305 :: http://www.wikidata.org/entity/Q6581072 (item)\n" +
|
||||
" http://www.wikidata.org/entity/P2305 :: http://www.wikidata.org/entity/Q6581097 (item)\n" +
|
||||
" http://www.wikidata.org/entity/P2305 :: http://www.wikidata.org/entity/Q8441 (item)\n" +
|
||||
" http://www.wikidata.org/entity/P2305 :: http://www.wikidata.org/entity/Q171283 (item)\n" +
|
||||
" http://www.wikidata.org/entity/P2305 :: http://www.wikidata.org/entity/Q11629 (item)\n" +
|
||||
" http://www.wikidata.org/entity/P2305 :: http://www.wikidata.org/entity/Q11634 (item)\n" +
|
||||
" http://www.wikidata.org/entity/P2305 :: http://www.wikidata.org/entity/Q131123 (item)\n" +
|
||||
" http://www.wikidata.org/entity/P2316 :: http://www.wikidata.org/entity/Q21502408 (item)\n" +
|
||||
"]";
|
||||
Assert.assertEquals(fetcher.getConstraintsByType(instanceOf, RestrictedValuesScrutinizer.DISALLOWED_VALUES_CONSTRAINT_QID).toString(), constraintDefinitions);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user