/** Checks if a {@link Resource} is a given type. **/ public static boolean isType(Resource resource, String type) { return resource.listProperties(RDF.type) .toList() .stream() .anyMatch(s -> s.getResource().getURI().equalsIgnoreCase(type)); }
protected static Statement getUniqueStatement( Resource root, Property property ) { List<Statement> statements = root.listProperties( property ).toList(); if (statements.size() == 0) return null; if (statements.size() == 1) return statements.get(0); throw new NotUniqueException( root, property ); }
protected static Statement getUniqueStatement( Resource root, Property property ) { List<Statement> statements = root.listProperties( property ).toList(); if (statements.size() == 0) return null; if (statements.size() == 1) return statements.get(0); throw new NotUniqueException( root, property ); }
public void testListStatements() { final Set<Statement> statements = fill(model); final List<Statement> L = model.listStatements().toList(); Assert.assertEquals(statements.size(), L.size()); Assert.assertEquals(statements, new HashSet<>(L)); }
@Test public final void thereAre2LitsWoLang() { final StmtIterator it = TestListStatements.m.listStatements( TestListStatements.s, TestListStatements.p, null, ""); Assert.assertTrue(it.toList().size() == 2); }
@Test public final void thereAre4Literals() { final StmtIterator it = TestListStatements.m.listStatements( TestListStatements.s, TestListStatements.p, null, null); Assert.assertTrue(it.toList().size() == 4); }
@Test public final void theresAreTwoText() { final StmtIterator it = TestListStatements.m.listStatements( TestListStatements.s, TestListStatements.p, "text", null); final List<Statement> lis = it.toList(); Assert.assertTrue(lis.size() == 2); }
@Test public final void theresOneTextWoLang() { final StmtIterator it = TestListStatements.m.listStatements( TestListStatements.s, TestListStatements.p, "text", ""); final List<Statement> lis = it.toList(); Assert.assertTrue(lis.size() == 1); }
@Test public final void theresAreTwoText() { final StmtIterator it = TestListStatements.m.listStatements( TestListStatements.s, TestListStatements.p, "text", null); final List<Statement> lis = it.toList(); Assert.assertTrue(lis.size() == 2); }
@Test public final void thereIsOneFrench() { final StmtIterator it = TestListStatements.m.listStatements( TestListStatements.s, TestListStatements.p, null, "fr"); final List<Statement> lis = it.toList(); Assert.assertTrue(lis.size() == 1); Assert.assertTrue(lis.get(0).getObject().toString().equals("texte@fr")); }
@Test public final void theresOneTextEN() { final StmtIterator it = TestListStatements.m.listStatements( TestListStatements.s, TestListStatements.p, "text", "en"); final List<Statement> lis = it.toList(); Assert.assertTrue(lis.size() == 1); Assert.assertTrue(lis.get(0).getObject().toString().equals("text@en")); }
private void testCardinality( OntModelSpec owlSpec ) { Model m = model( "V owl:equivalentClass _R; _R rdf:type owl:Restriction; _R owl:onProperty P; _R owl:cardinality 1; X rdf:type V" ); OntModel ont = ModelFactory.createOntologyModel( owlSpec, m ); assertEquals( 1, ont.listStatements( resource( "X" ), property( "P" ), ANY ).toList().size() ); }
public void testLong() { final List<Statement> got = model.listLiteralStatements(null, null, TestSimpleListStatements.longValue).toList(); Assert.assertEquals(1, got.size()); final Statement it = got.get(0); Assert.assertEquals(ModelHelper.resource("http://example.org/long"), it.getSubject()); Assert.assertEquals( model.createTypedLiteral(TestSimpleListStatements.longValue), it.getObject()); }
public void testBoolean() { final List<Statement> got = model.listLiteralStatements(null, null, TestSimpleListStatements.booleanValue).toList(); Assert.assertEquals(1, got.size()); final Statement it = got.get(0); Assert.assertEquals(ModelHelper.resource("http://example.org/boolean"), it.getSubject()); Assert.assertEquals( model.createTypedLiteral(TestSimpleListStatements.booleanValue), it.getObject()); }
public void testChar() { final List<Statement> got = model.listLiteralStatements(null, null, TestSimpleListStatements.charValue).toList(); Assert.assertEquals(1, got.size()); final Statement it = got.get(0); Assert.assertEquals(ModelHelper.resource("http://example.org/char"), it.getSubject()); Assert.assertEquals( model.createTypedLiteral(TestSimpleListStatements.charValue), it.getObject()); }
public void testDouble() { final List<Statement> got = model.listLiteralStatements(null, null, TestSimpleListStatements.doubleValue).toList(); Assert.assertEquals(1, got.size()); final Statement it = got.get(0); Assert.assertEquals(ModelHelper.resource("http://example.org/double"), it.getSubject()); Assert.assertEquals( model.createTypedLiteral(TestSimpleListStatements.doubleValue), it.getObject()); }
public void testFloat() { final List<Statement> got = model.listLiteralStatements(null, null, TestSimpleListStatements.floatValue).toList(); Assert.assertEquals(1, got.size()); final Statement it = got.get(0); Assert.assertEquals(ModelHelper.resource("http://example.org/float"), it.getSubject()); Assert.assertEquals( model.createTypedLiteral(TestSimpleListStatements.floatValue), it.getObject()); }
public void testBoolean() { final List<Statement> got = model.listLiteralStatements(null, null, TestSimpleListStatements.booleanValue).toList(); Assert.assertEquals(1, got.size()); final Statement it = got.get(0); Assert.assertEquals(ModelHelper.resource("http://example.org/boolean"), it.getSubject()); Assert.assertEquals( model.createTypedLiteral(TestSimpleListStatements.booleanValue), it.getObject()); }
@Test public void insert_where_01() { Model m = ModelFactory.createDefaultModel(); Resource anon = m.createResource(); anon.addProperty(RDF.type, OWL.Thing); assertEquals(1, m.size()); UpdateRequest req = UpdateFactory.create("INSERT { ?s ?p ?o } WHERE { ?o ?p ?s }"); UpdateAction.execute(req, m); assertEquals(2, m.size()); assertEquals(1, m.listStatements(anon, null, (RDFNode)null).toList().size()); assertEquals(1, m.listStatements(null, null, anon).toList().size()); }
@Test public final void theresOneWithABNodeObject() { Model m = ModelFactory.createDefaultModel(); Resource anon = m.createResource(); m.createResource("http://example").addProperty(RDF.type, anon); StmtIterator it = m.listStatements(null, null, anon); final List<Statement> lis = it.toList(); Assert.assertTrue(lis.size() == 1); } }