RdfToDocument { public ItemDocument loadItemDocument( Collection<Statement> statements, String iriAsStr) { return loadItemDocument( statements, SimpleValueFactory.getInstance().createIRI(iriAsStr)); } RdfToDocument(PropertyRegister register, String siteUrl); ItemDocument loadItemDocument(
            Collection<Statement> statements,
            String iriAsStr); ItemDocument loadItemDocument(
            Collection<Statement> statements,
            Resource resource); Map<Object, MergeStrategy> getMergeStrategyForLastLoadedDocument();  }
@Test public void loadSimpleValue() throws IOException { Model model = loadModelFromResource("simple-value.ttl"); RdfToDocument rdfToDocument = new RdfToDocument(register, "https: ItemDocument document = rdfToDocument.loadItemDocument( model, "https: List<Statement> statements = asList(document.getAllStatements()); Assert.assertEquals(1, statements.size()); Statement statement = statements.get(0); Assert.assertEquals( Datamodel.makeStringValue("103064"), statement.getValue()); }
@Test public void loadTimeValueAndQualifier() throws IOException { Model model = loadModelFromResource("time-value-and-qualifier.ttl"); RdfToDocument rdfToDocument = new RdfToDocument(register, "https: ItemDocument document = rdfToDocument.loadItemDocument( model, "urn:NewItem"); List<Statement> statements = asList(document.getAllStatements()); Assert.assertEquals(1, statements.size()); Statement statement = statements.get(0); Assert.assertEquals( Datamodel.makeTimeValue( 1990, (byte) 11, (byte) 1, "http: statement.getValue()); List<Snak> qualifiers = asList(statement.getAllQualifiers()); Assert.assertEquals(1, qualifiers.size()); ValueSnak qualifier = (ValueSnak) qualifiers.get(0); Assert.assertEquals(qualifier.getPropertyId().getId(), "P11"); Assert.assertEquals( Datamodel.makeTimeValue( 2020, (byte) 1, (byte) 1, "http: qualifier.getValue()); }
@Test public void loadSomeValue() throws IOException { Model model = loadModelFromResource("some-value.ttl"); RdfToDocument rdfToDocument = new RdfToDocument(register, "https: ItemDocument document = rdfToDocument.loadItemDocument( model, "urn:NewItem"); List<Statement> statements = asList(document.getAllStatements()); Assert.assertEquals(1, statements.size()); Statement statement = statements.get(0); Assert.assertEquals( null, statement.getValue()); }
@Test public void loadQuantityValueAndQualifier() throws IOException { Model model = loadModelFromResource("quantity-value-and-qualifier.ttl"); RdfToDocument rdfToDocument = new RdfToDocument(register, "https: ItemDocument document = rdfToDocument.loadItemDocument( model, "urn:NewItem"); List<Statement> statements = asList(document.getAllStatements()); Assert.assertEquals(1, statements.size()); Statement statement = statements.get(0); Assert.assertEquals( Datamodel.makeQuantityValue( BigDecimal.valueOf(362.0), BigDecimal.valueOf(362.0), BigDecimal.valueOf(362.0), "https: statement.getValue()); List<Snak> qualifiers = asList(statement.getAllQualifiers()); Assert.assertEquals(1, qualifiers.size()); ValueSnak qualifier = (ValueSnak) qualifiers.get(0); Assert.assertEquals(qualifier.getPropertyId().getId(), "P8"); Assert.assertEquals( Datamodel.makeQuantityValue( BigDecimal.valueOf(3.62), BigDecimal.valueOf(3.62), BigDecimal.valueOf(3.62), "https: qualifier.getValue()); }
@Test public void loadNoValue() throws IOException { Model model = loadModelFromResource("no-value.ttl"); RdfToDocument rdfToDocument = new RdfToDocument(register, "https: ItemDocument document = rdfToDocument.loadItemDocument( model, "urn:NewItem"); List<Statement> statements = asList(document.getAllStatements()); Assert.assertEquals(1, statements.size()); Statement statement = statements.get(0); Assert.assertTrue(statement.getMainSnak() instanceof SomeValueSnak); }
@Test public void loadGeoValueAndQualifier() throws IOException { Model model = loadModelFromResource("geo-value-and-qualifier.ttl"); RdfToDocument rdfToDocument = new RdfToDocument(register, "https: ItemDocument document = rdfToDocument.loadItemDocument( model, "urn:NewItem"); List<Statement> statements = asList(document.getAllStatements()); Assert.assertEquals(1, statements.size()); Statement statement = statements.get(0); Assert.assertEquals( Datamodel.makeGlobeCoordinatesValue( 12.933333333333, 35.3, 0.000277778, "http: statement.getValue()); List<Snak> qualifiers = asList(statement.getAllQualifiers()); Assert.assertEquals(1, qualifiers.size()); ValueSnak qualifier = (ValueSnak) qualifiers.get(0); Assert.assertEquals(qualifier.getPropertyId().getId(), "P12"); Assert.assertEquals( Datamodel.makeGlobeCoordinatesValue( 50.675546897005, 15.538850308905, 0.000001, "http: qualifier.getValue()); }
@Test public void loadDeriveFrom() throws IOException { Model model = loadModelFromResource("derive-from.ttl"); RdfToDocument rdfToDocument = new RdfToDocument(register, "https: ItemDocument document = rdfToDocument.loadItemDocument( model, "urn:NewItem"); List<Statement> statements = asList(document.getAllStatements()); Assert.assertEquals(1, statements.size()); Statement statement = statements.get(0); Assert.assertEquals( Datamodel.makeQuantityValue( BigDecimal.valueOf(362.0), BigDecimal.valueOf(362.0), BigDecimal.valueOf(362.0), "https: statement.getValue()); List<Reference> references = statement.getReferences(); Assert.assertEquals(1, references.size()); Reference reference = references.get(0); List<Snak> refs = asList(reference.getAllSnaks()); Assert.assertEquals(1, refs.size()); Assert.assertEquals( Datamodel.makeQuantityValue( BigDecimal.valueOf(3.62), BigDecimal.valueOf(3.62), BigDecimal.valueOf(3.62), "https: ((ValueSnak) refs.get(0)).getValue()); }
@Test public void loadUpdateOfQ10768607() throws IOException { Model model = loadModelFromResource("Q10768607-update.ttl"); RdfToDocument rdfToDocument = new RdfToDocument(register, "http: ItemDocument document = rdfToDocument.loadItemDocument( model, "http: List<Statement> statements = asList(document.getAllStatements()); Assert.assertEquals(1, statements.size()); Statement statement = statements.get(0); Assert.assertEquals( Datamodel.makeItemIdValue( "Q811534", "http: statement.getValue()); Assert.assertEquals(1, statement.getReferences().size()); Snak reference = statement.getReferences().get(0).getAllSnaks().next(); Assert.assertEquals( Datamodel.makeItemIdValue( "Q26778346", "http: ((ValueSnak) reference).getValue()); Assert.assertEquals(1, statement.getQualifiers().size()); Snak qualifier = asList(statement.getAllQualifiers()).get(0); Assert.assertEquals( Datamodel.makeTimeValue( 1985, (byte) 11, (byte) 21, (byte) 0, (byte) 0, (byte) 0, (byte) 11, 0, 0, 0, "http: ((ValueSnak) qualifier).getValue()); }
@Test public void loadQ10768607() throws IOException { ObjectMapper mapper = new DatamodelMapper("http: File jsonFile = TestUtils.fileFromResource("Q10768607.json"); JsonNode node = mapper.readTree(jsonFile); EntityDocument expected = mapper.treeToValue(node, EntityDocumentImpl.class); Model model = loadModelFromResource("Q10768607.ttl"); RdfToDocument rdfToDocument = new RdfToDocument(register, "http: ItemDocument actual = rdfToDocument.loadItemDocument( model, "http: }
@Test public void roundRobinOfQ10768607() throws IOException { ObjectMapper mapper = new DatamodelMapper("http: File jsonFile = TestUtils.fileFromResource("Q10768607.json"); JsonNode node = mapper.readTree(jsonFile); EntityDocument expected = mapper.treeToValue(node, EntityDocumentImpl.class); Sites sites = new SitesImpl(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); RdfSerializer serializer = new RdfSerializer(RDFFormat.NTRIPLES, stream, sites, register); serializer.open(); serializer.processItemDocument((ItemDocument) expected); serializer.close(); Model model = Rio.parse( new ByteArrayInputStream(stream.toByteArray()), "http: RDFFormat.NTRIPLES); stream.close(); RdfToDocument rdfToDocument = new RdfToDocument(register, "http: ItemDocument actual = rdfToDocument.loadItemDocument( model, "http: }
@Test public void issues786() throws IOException { Model model = loadModelFromResource("issues-786.ttl"); RdfToDocument rdfToDocument = new RdfToDocument(register, "https: ItemDocument document = rdfToDocument.loadItemDocument( model, "urn:item"); Assert.assertEquals(1, document.getLabels().size()); List<Statement> statements = asList(document.getAllStatements()); Assert.assertEquals(1, statements.size()); Statement statement = statements.get(0); Assert.assertEquals( Datamodel.makeGlobeCoordinatesValue( 28, 20, 0.000277778, "http: statement.getValue()); List<Snak> qualifiers = asList(statement.getAllQualifiers()); Assert.assertEquals(1, qualifiers.size()); ValueSnak qualifier = (ValueSnak) qualifiers.get(0); Assert.assertEquals(qualifier.getPropertyId().getId(), "P19"); Assert.assertEquals( Datamodel.makeItemIdValue( "Q2212", "https: qualifier.getValue()); }