Search in sources :

Example 11 with PropertyIdValue

use of org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue in project OpenRefine by OpenRefine.

the class QuickStatementsExporterTest method testNoValue.

@Test
public void testNoValue() throws IOException {
    PropertyIdValue pid = Datamodel.makeWikidataPropertyIdValue("P123");
    Claim claim = Datamodel.makeClaim(qid1, Datamodel.makeNoValueSnak(pid), Collections.emptyList());
    Statement statement = Datamodel.makeStatement(claim, Collections.emptyList(), StatementRank.NORMAL, "");
    StatementEdit statementUpdate = new StatementEdit(statement, StatementMerger.FORMER_DEFAULT_STRATEGY, StatementEditingMode.ADD_OR_MERGE);
    TermedStatementEntityEdit update = new TermedStatementEntityEditBuilder(qid1).addStatement(statementUpdate).build();
    assertEquals("Q1377\tP123\tnovalue\n", export(update));
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) TermedStatementEntityEditBuilder(org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) TermedStatementEntityEdit(org.openrefine.wikidata.updates.TermedStatementEntityEdit) Claim(org.wikidata.wdtk.datamodel.interfaces.Claim) StatementEdit(org.openrefine.wikidata.updates.StatementEdit) Test(org.testng.annotations.Test) WikidataRefineTest(org.openrefine.wikidata.testing.WikidataRefineTest)

Example 12 with PropertyIdValue

use of org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue in project OpenRefine by OpenRefine.

the class QuickStatementsExporterTest method testSomeValue.

@Test
public void testSomeValue() throws IOException {
    PropertyIdValue pid = Datamodel.makeWikidataPropertyIdValue("P123");
    Claim claim = Datamodel.makeClaim(qid1, Datamodel.makeSomeValueSnak(pid), Collections.emptyList());
    Statement statement = Datamodel.makeStatement(claim, Collections.emptyList(), StatementRank.NORMAL, "");
    StatementEdit statementUpdate = new StatementEdit(statement, StatementMerger.FORMER_DEFAULT_STRATEGY, StatementEditingMode.ADD_OR_MERGE);
    TermedStatementEntityEdit update = new TermedStatementEntityEditBuilder(qid1).addStatement(statementUpdate).build();
    assertEquals("Q1377\tP123\tsomevalue\n", export(update));
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) TermedStatementEntityEditBuilder(org.openrefine.wikidata.updates.TermedStatementEntityEditBuilder) Statement(org.wikidata.wdtk.datamodel.interfaces.Statement) TermedStatementEntityEdit(org.openrefine.wikidata.updates.TermedStatementEntityEdit) Claim(org.wikidata.wdtk.datamodel.interfaces.Claim) StatementEdit(org.openrefine.wikidata.updates.StatementEdit) Test(org.testng.annotations.Test) WikidataRefineTest(org.openrefine.wikidata.testing.WikidataRefineTest)

Example 13 with PropertyIdValue

use of org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue in project OpenRefine by OpenRefine.

the class ConstraintTest method setUp.

@BeforeMethod
public void setUp() {
    Snak qualifierSnak1 = Datamodel.makeValueSnak(constraintException, exceptionValue);
    List<Snak> qualifierSnakList1 = Collections.singletonList(qualifierSnak1);
    Snak qualifierSnak2 = Datamodel.makeValueSnak(constraintStatus, statusValue);
    List<Snak> qualifierSnakList2 = Collections.singletonList(qualifierSnak2);
    SnakGroup qualifier1 = Datamodel.makeSnakGroup(qualifierSnakList1);
    SnakGroup qualifier2 = Datamodel.makeSnakGroup(qualifierSnakList2);
    List<SnakGroup> snakGroupList = Arrays.asList(qualifier1, qualifier2);
    PropertyIdValue propertyIdValue = Datamodel.makeWikidataPropertyIdValue("P2302");
    Snak mainSnak = Datamodel.makeValueSnak(propertyIdValue, itemIdValue);
    Claim claim = Datamodel.makeClaim(itemIdValue, mainSnak, snakGroupList);
    Reference reference = Datamodel.makeReference(snakGroupList);
    List<Reference> referenceList = Collections.singletonList(reference);
    statement = Datamodel.makeStatement(claim, referenceList, StatementRank.NORMAL, "P2302$77BD7FE4-C051-4776-855C-543F0CE697D0");
    constraint = new Constraint(statement);
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) Snak(org.wikidata.wdtk.datamodel.interfaces.Snak) Reference(org.wikidata.wdtk.datamodel.interfaces.Reference) SnakGroup(org.wikidata.wdtk.datamodel.interfaces.SnakGroup) Claim(org.wikidata.wdtk.datamodel.interfaces.Claim) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 14 with PropertyIdValue

use of org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue in project OpenRefine by OpenRefine.

the class SchemaPropertyExtractorTest method testNoProperties.

@Test
public void testNoProperties() {
    schema = new WikibaseSchema();
    SchemaPropertyExtractor extractor = new SchemaPropertyExtractor();
    Set<PropertyIdValue> propertyIdValues = extractor.getAllProperties(schema);
    Assert.assertEquals(propertyIdValues, new HashSet<>());
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) WikibaseSchema(org.openrefine.wikidata.schema.WikibaseSchema) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test) CommandTest(org.openrefine.wikidata.commands.CommandTest)

Example 15 with PropertyIdValue

use of org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue in project OpenRefine by OpenRefine.

the class EntityCacheTests method testGet.

@Test
public void testGet() throws MediaWikiApiErrorException, IOException {
    WikibaseDataFetcher fetcher = mock(WikibaseDataFetcher.class);
    PropertyIdValue id = Datamodel.makeWikidataPropertyIdValue("P42");
    PropertyDocument doc = Datamodel.makePropertyDocument(id, Datamodel.makeDatatypeIdValue(DatatypeIdValue.DT_GEO_SHAPE));
    when(fetcher.getEntityDocument(id.getId())).thenReturn(doc);
    EntityCache SUT = new EntityCache(fetcher);
    Assert.assertEquals(SUT.get(id), doc);
    // try another time, it is now cached
    Assert.assertEquals(SUT.get(id), doc);
    // the fetcher was only called once thanks to caching
    verify(fetcher, times(1)).getEntityDocument(id.getId());
}
Also used : PropertyIdValue(org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue) PropertyDocument(org.wikidata.wdtk.datamodel.interfaces.PropertyDocument) WikibaseDataFetcher(org.wikidata.wdtk.wikibaseapi.WikibaseDataFetcher) Test(org.testng.annotations.Test)

Aggregations

PropertyIdValue (org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue)36 Statement (org.wikidata.wdtk.datamodel.interfaces.Statement)17 QAWarning (org.openrefine.wikidata.qa.QAWarning)16 Snak (org.wikidata.wdtk.datamodel.interfaces.Snak)12 EntityIdValue (org.wikidata.wdtk.datamodel.interfaces.EntityIdValue)11 Value (org.wikidata.wdtk.datamodel.interfaces.Value)11 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 SnakGroup (org.wikidata.wdtk.datamodel.interfaces.SnakGroup)9 ValueSnak (org.wikidata.wdtk.datamodel.interfaces.ValueSnak)9 List (java.util.List)8 Set (java.util.Set)6 Claim (org.wikidata.wdtk.datamodel.interfaces.Claim)6 Reference (org.wikidata.wdtk.datamodel.interfaces.Reference)6 Collectors (java.util.stream.Collectors)5 StatementEdit (org.openrefine.wikidata.updates.StatementEdit)5 Test (org.testng.annotations.Test)5 SkipSchemaExpressionException (org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException)4 TermedStatementEntityEdit (org.openrefine.wikidata.updates.TermedStatementEntityEdit)4