Java Code Examples for org.eclipse.rdf4j.model.Model#iterator()
The following examples show how to use
org.eclipse.rdf4j.model.Model#iterator() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSONLDInternalTripleCallbackTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void triplesTest() throws JsonLdError, IOException { // String inputstring = // "{\"@id\":{\"@id\":\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/machine/DVC-1_8\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceElement\":\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceelement/DET-1_8\",\"http://igreen-projekt.de/ontologies/isoxml#deviceID\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"DVC-1\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceLocalizationLabel\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"FF000000406564\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceProcessData\":[\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/13_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/6_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/14_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/11_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/8_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/4_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/5_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/10_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/2_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/21_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/15_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/16_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/19_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/17_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/3_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/12_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/7_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/18_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/9_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/22_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/20_8\"],\"http://igreen-projekt.de/ontologies/isoxml#deviceSerialNumber\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"12345\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceSoftwareVersion\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"01.009\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceStructureLabel\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"31303030303030\"},\"http://igreen-projekt.de/ontologies/isoxml#workingSetMasterNAME\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"A000860020800001\"},\"http://www.w3.org/1999/02/22-rdf-syntax-ns#type\":{\"@iri\":\"http://www.agroxml.de/rdfs#Machine\"},\"http://www.w3.org/2000/01/rdf-schema#label\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"Krone // Device\"}}"; final String inputstring = "{ \"@id\":\"http://nonexistent.com/abox#Document1823812\", \"@type\":\"http://nonexistent.com/tbox#Document\" }"; final String expectedString = "(http://nonexistent.com/abox#Document1823812, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://nonexistent.com/tbox#Document) [null]"; final Object input = JsonUtils.fromString(inputstring); final Model graph = new LinkedHashModel(); final ParseErrorCollector parseErrorListener = new ParseErrorCollector(); final ParserConfig parserConfig = new ParserConfig(); final JSONLDInternalTripleCallback callback = new JSONLDInternalTripleCallback(new StatementCollector(graph), SimpleValueFactory.getInstance(), parserConfig, parseErrorListener, nodeID -> SimpleValueFactory.getInstance().createBNode(nodeID), () -> SimpleValueFactory.getInstance().createBNode()); JsonLdProcessor.toRDF(input, callback); final Iterator<Statement> statements = graph.iterator(); // contains only one statement (type) while (statements.hasNext()) { final Statement stmt = statements.next(); System.out.println(stmt.toString()); assertEquals("Output was not as expected", stmt.toString(), expectedString); } assertEquals(0, parseErrorListener.getFatalErrors().size()); assertEquals(0, parseErrorListener.getErrors().size()); assertEquals(0, parseErrorListener.getWarnings().size()); }
Example 2
Source File: EntityModelWriterTest.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test void testCreateRfdModelStringAttribute() { List<Attribute> attributeList = singletonList(attr1); when(objectEntity.getEntityType()).thenReturn(entityType); when(objectEntity.get("attributeName1")).thenReturn("value1"); when(objectEntity.getString("attributeName1")).thenReturn("value1"); when(entityType.getAtomicAttributes()).thenReturn(attributeList); when(attr1.getName()).thenReturn("attributeName1"); when(attr1.getDataType()).thenReturn(AttributeType.STRING); LabeledResource tag1 = new LabeledResource("http://IRI1.nl", "tag1Label"); Multimap<Relation, LabeledResource> tags = ImmutableMultimap.of(Relation.isAssociatedWith, tag1); when(tagService.getTagsForAttribute(entityType, attr1)).thenReturn(tags); Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity); assertEquals(1, result.size()); Iterator results = result.iterator(); assertEquals( "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI1.nl, \"value1\"^^<http://www.w3.org/2001/XMLSchema#string>) [null]", results.next().toString()); }
Example 3
Source File: EntityModelWriterTest.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test void testCreateRfdModelIntAttribute() { List<Attribute> attributeList = singletonList(attr2); when(objectEntity.getEntityType()).thenReturn(entityType); when(objectEntity.get("attributeName2")).thenReturn(2); when(objectEntity.getInt("attributeName2")).thenReturn(2); when(entityType.getAtomicAttributes()).thenReturn(attributeList); when(attr2.getName()).thenReturn("attributeName2"); when(attr2.getDataType()).thenReturn(AttributeType.INT); LabeledResource tag2 = new LabeledResource("http://IRI2.nl", "tag2Label"); Multimap<Relation, LabeledResource> tags2 = ImmutableMultimap.of(Relation.isAssociatedWith, tag2); when(tagService.getTagsForAttribute(entityType, attr2)).thenReturn(tags2); Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity); assertEquals(1, result.size()); Iterator results = result.iterator(); assertEquals( "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI2.nl, \"2\"^^<http://www.w3.org/2001/XMLSchema#int>) [null]", results.next().toString()); }
Example 4
Source File: EntityModelWriterTest.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test void testCreateRfdModelXREF() { List<Attribute> attributeList = singletonList(attr3); List<String> refAttributeList = singletonList("refAttr"); when(objectEntity.getEntityType()).thenReturn(entityType); when(objectEntity.get("attributeName3")).thenReturn(refEntity); when(objectEntity.getEntity("attributeName3")).thenReturn(refEntity); when(refEntity.getEntityType()).thenReturn(refEntityType); when(refEntityType.getAttributeNames()).thenReturn(refAttributeList); when(refEntity.getIdValue()).thenReturn("refID"); when(entityType.getAtomicAttributes()).thenReturn(attributeList); when(attr3.getName()).thenReturn("attributeName3"); when(attr3.getDataType()).thenReturn(AttributeType.XREF); LabeledResource tag3 = new LabeledResource("http://IRI3.nl", "labelTag3"); Multimap<Relation, LabeledResource> tags3 = ImmutableMultimap.of(Relation.isAssociatedWith, tag3); when(tagService.getTagsForAttribute(entityType, attr3)).thenReturn(tags3); Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity); assertEquals(1, result.size()); Iterator results = result.iterator(); assertEquals( "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI3.nl, http://molgenis01.gcc.rug.nl/fdp/catolog/test/this/refID) [null]", results.next().toString()); }
Example 5
Source File: EntityModelWriterTest.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test void testCreateRfdModelMREF() { List<Attribute> attributeList = singletonList(attribute); when(objectEntity.getEntityType()).thenReturn(entityType); when(objectEntity.get("attributeName")).thenReturn(refEntity); when(objectEntity.getEntities("attributeName")).thenReturn(singletonList(refEntity)); when(refEntity.getIdValue()).thenReturn("refID"); when(entityType.getAtomicAttributes()).thenReturn(attributeList); when(attribute.getName()).thenReturn("attributeName"); when(attribute.getDataType()).thenReturn(AttributeType.MREF); LabeledResource tag = new LabeledResource("http://IRI.nl", "labelTag3"); Multimap<Relation, LabeledResource> tags = ImmutableMultimap.of(Relation.isAssociatedWith, tag); when(tagService.getTagsForAttribute(entityType, attribute)).thenReturn(tags); Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity); assertEquals(1, result.size()); Iterator results = result.iterator(); assertEquals( "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI.nl, http://molgenis01.gcc.rug.nl/fdp/catolog/test/this/refID) [null]", results.next().toString()); }
Example 6
Source File: EntityModelWriterTest.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test void testCreateRfdModelBOOL() { Entity objectEntity = mock(Entity.class); EntityType entityType = mock(EntityType.class); Attribute attribute = mock(Attribute.class); List<Attribute> attributeList = singletonList(attribute); when(objectEntity.getEntityType()).thenReturn(entityType); when(objectEntity.get("attributeName")).thenReturn(true); when(objectEntity.getBoolean("attributeName")).thenReturn(true); when(entityType.getAtomicAttributes()).thenReturn(attributeList); when(attribute.getName()).thenReturn("attributeName"); when(attribute.getDataType()).thenReturn(AttributeType.BOOL); LabeledResource tag = new LabeledResource("http://IRI.nl", "tag label"); Multimap<Relation, LabeledResource> tags = ImmutableMultimap.of(Relation.isAssociatedWith, tag); when(tagService.getTagsForAttribute(entityType, attribute)).thenReturn(tags); Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity); assertEquals(1, result.size()); Iterator results = result.iterator(); assertEquals( "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI.nl, \"true\"^^<http://www.w3.org/2001/XMLSchema#boolean>) [null]", results.next().toString()); }
Example 7
Source File: EntityModelWriterTest.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test void testCreateRfdModelDATE() { // Model createRdfModel(String subjectIRI, Entity objectEntity) Entity objectEntity = mock(Entity.class); EntityType entityType = mock(EntityType.class); Attribute attribute = mock(Attribute.class); List<Attribute> attributeList = singletonList(attribute); when(objectEntity.getEntityType()).thenReturn(entityType); LocalDate value = LocalDate.of(2013, Month.AUGUST, 12); when(objectEntity.get("attributeName")).thenReturn(value); when(objectEntity.getLocalDate("attributeName")).thenReturn(value); when(entityType.getAtomicAttributes()).thenReturn(attributeList); when(attribute.getName()).thenReturn("attributeName"); when(attribute.getDataType()).thenReturn(AttributeType.DATE); LabeledResource tag = new LabeledResource("http://IRI.nl", "tag label"); Multimap<Relation, LabeledResource> tags = ImmutableMultimap.of(Relation.isAssociatedWith, tag); when(tagService.getTagsForAttribute(entityType, attribute)).thenReturn(tags); Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity); assertEquals(1, result.size()); Iterator results = result.iterator(); assertEquals( "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI.nl, \"2013-08-12\"^^<http://www.w3.org/2001/XMLSchema#date>) [null]", results.next().toString()); }
Example 8
Source File: EntityModelWriterTest.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test void testCreateRfdModelDATETIME() { // Model createRdfModel(String subjectIRI, Entity objectEntity) Entity objectEntity = mock(Entity.class); EntityType entityType = mock(EntityType.class); Attribute attribute = mock(Attribute.class); List<Attribute> attributeList = singletonList(attribute); when(objectEntity.getEntityType()).thenReturn(entityType); Instant value = Instant.parse("2011-12-03T10:15:30Z"); when(objectEntity.get("attributeName")).thenReturn(value); when(objectEntity.getInstant("attributeName")).thenReturn(value); when(entityType.getAtomicAttributes()).thenReturn(attributeList); when(attribute.getName()).thenReturn("attributeName"); when(attribute.getDataType()).thenReturn(AttributeType.DATE_TIME); LabeledResource tag = new LabeledResource("http://IRI.nl", "tag label"); Multimap<Relation, LabeledResource> tags = ImmutableMultimap.of(Relation.isAssociatedWith, tag); when(tagService.getTagsForAttribute(entityType, attribute)).thenReturn(tags); Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity); assertEquals(1, result.size()); Iterator results = result.iterator(); assertEquals( "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI.nl, \"2011-12-03T10:15:30Z\"^^<http://www.w3.org/2001/XMLSchema#dateTime>) [null]", results.next().toString()); }
Example 9
Source File: EntityModelWriterTest.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test void testCreateRfdModelDECIMAL() { // Model createRdfModel(String subjectIRI, Entity objectEntity) Entity objectEntity = mock(Entity.class); EntityType entityType = mock(EntityType.class); Attribute attribute = mock(Attribute.class); List<Attribute> attributeList = singletonList(attribute); when(objectEntity.getEntityType()).thenReturn(entityType); double value = 10.0; when(objectEntity.get("attributeName")).thenReturn(value); when(objectEntity.getDouble("attributeName")).thenReturn(value); when(entityType.getAtomicAttributes()).thenReturn(attributeList); when(attribute.getName()).thenReturn("attributeName"); when(attribute.getDataType()).thenReturn(AttributeType.DECIMAL); LabeledResource tag = new LabeledResource("http://IRI.nl", "tag label"); Multimap<Relation, LabeledResource> tags = ImmutableMultimap.of(Relation.isAssociatedWith, tag); when(tagService.getTagsForAttribute(entityType, attribute)).thenReturn(tags); Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity); assertEquals(1, result.size()); Iterator results = result.iterator(); assertEquals( "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI.nl, \"10.0\"^^<http://www.w3.org/2001/XMLSchema#double>) [null]", results.next().toString()); }
Example 10
Source File: EntityModelWriterTest.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test void testCreateRfdModelLONG() { // Model createRdfModel(String subjectIRI, Entity objectEntity) Entity objectEntity = mock(Entity.class); EntityType entityType = mock(EntityType.class); Attribute attribute = mock(Attribute.class); List<Attribute> attributeList = singletonList(attribute); when(objectEntity.getEntityType()).thenReturn(entityType); long value = 987654321L; when(objectEntity.get("attributeName")).thenReturn(value); when(objectEntity.getLong("attributeName")).thenReturn(value); when(entityType.getAtomicAttributes()).thenReturn(attributeList); when(attribute.getName()).thenReturn("attributeName"); when(attribute.getDataType()).thenReturn(AttributeType.LONG); LabeledResource tag = new LabeledResource("http://IRI.nl", "tag label"); Multimap<Relation, LabeledResource> tags = ImmutableMultimap.of(Relation.isAssociatedWith, tag); when(tagService.getTagsForAttribute(entityType, attribute)).thenReturn(tags); Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity); assertEquals(1, result.size()); Iterator results = result.iterator(); assertEquals( "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI.nl, \"987654321\"^^<http://www.w3.org/2001/XMLSchema#long>) [null]", results.next().toString()); }
Example 11
Source File: EntityModelWriterTest.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test void testCreateRfdModelNullValuePlusHyperlink() { // Model createRdfModel(String subjectIRI, Entity objectEntity) Entity objectEntity = mock(Entity.class); EntityType entityType = mock(EntityType.class); Attribute attribute1 = mock(Attribute.class); Attribute attribute2 = mock(Attribute.class); List<Attribute> attributeList = Arrays.asList(attribute1, attribute2); when(objectEntity.getEntityType()).thenReturn(entityType); when(objectEntity.get("attribute1Name")).thenReturn(null); String value = "http://molgenis.org/index.html"; doReturn(value).when(objectEntity).get("attribute2Name"); when(objectEntity.getString("attribute2Name")).thenReturn(value); when(entityType.getAtomicAttributes()).thenReturn(attributeList); when(attribute1.getName()).thenReturn("attribute1Name"); when(attribute2.getName()).thenReturn("attribute2Name"); when(attribute2.getDataType()).thenReturn(AttributeType.HYPERLINK); LabeledResource tag2 = new LabeledResource("http://IRI1.nl", "tag1 label"); Multimap<Relation, LabeledResource> tags2 = ImmutableMultimap.of(Relation.isAssociatedWith, tag2); doReturn(tags2).when(tagService).getTagsForAttribute(entityType, attribute2); Model result = writer.createRdfModel("http://molgenis01.gcc.rug.nl/fdp/catolog/test/this", objectEntity); assertEquals(1, result.size()); Iterator results = result.iterator(); assertEquals( "(http://molgenis01.gcc.rug.nl/fdp/catolog/test/this, http://IRI1.nl, http://molgenis.org/index.html) [null]", results.next().toString()); }