/** * Returns a new blank node with an AG-allocated id. * <p> * See also the javadoc for allowing external blank nodes for more discussion. * * @see AGHttpRepoClient#setAllowExternalBlankNodeIds(boolean) * @see AGRepositoryConnection#prepareHttpRepoClient() */ @Override public Resource createResource() { AGValueFactory vf = getGraph().getConnection().getValueFactory(); BNode blank = vf.createBNode(); return createResource(new AnonId(blank.stringValue())); }
@Override public Set<Statement> reify(KnowledgeBase kb, KBStatement aStatement) { String statementId = aStatement.getStatementId(); KBHandle instance = aStatement.getInstance(); KBHandle property = aStatement.getProperty(); Value value = valueMapper.mapStatementValue(aStatement, vf); IRI subject = vf.createIRI(instance.getIdentifier()); IRI predicate = vf.createIRI(property.getIdentifier()); if (statementId == null) { statementId = vf.createBNode().stringValue(); } Resource id = vf.createBNode(statementId); Statement root = vf.createStatement(subject, predicate, id); IRI valuePredicate = vf.createIRI(PREDICATE_NAMESPACE, predicate.getLocalName()); Statement valueStatement = vf.createStatement(id, valuePredicate, value); Set<Statement> statements = new HashSet<>(); statements.add(root); // S P id statements.add(valueStatement); // id p_s V for (KBQualifier aQualifier : aStatement.getQualifiers()) { Set<Statement> qualifierStatement = reifyQualifier(kb, aQualifier); aQualifier.setOriginalStatements(qualifierStatement); } return statements; }
@Override public Set<Statement> reify(KnowledgeBase kb, KBStatement aStatement) { String statementId = aStatement.getStatementId(); KBHandle instance = aStatement.getInstance(); KBHandle property = aStatement.getProperty(); Value value = valueMapper.mapStatementValue(aStatement, vf); IRI subject = vf.createIRI(instance.getIdentifier()); IRI predicate = vf.createIRI(property.getIdentifier()); if (statementId == null) { statementId = vf.createBNode().stringValue(); } Resource id = vf.createBNode(statementId); Statement root = vf.createStatement(subject, predicate, id); IRI valuePredicate = vf.createIRI(PREDICATE_NAMESPACE, predicate.getLocalName()); Statement valueStatement = vf.createStatement(id, valuePredicate, value); Set<Statement> statements = new HashSet<>(); statements.add(root); // S P id statements.add(valueStatement); // id p_s V for (KBQualifier aQualifier : aStatement.getQualifiers()) { Set<Statement> qualifierStatement = reifyQualifier(kb, aQualifier); aQualifier.setOriginalStatements(qualifierStatement); } return statements; }
statementId = vf.createBNode().stringValue();
statementId = vf.createBNode().stringValue();
@Test @Category(TestSuites.Prepush.class) public void federationBNodes() throws Exception { BNode bnode = vf.createBNode(); conn.add(bnode, RDF.TYPE, vf.createIRI("http://Foo")); AGVirtualRepository fed = server.federate(repo, repo); AGRepositoryConnection conn2 = fed.getConnection(); // Should be able to create BNodes for a federation conn2.getValueFactory().createBNode(); conn2.getValueFactory().createBNode("foo"); try { conn2.add(bnode, RDF.TYPE, vf.createIRI("http://Boo")); Assert.fail("expected can't write to federation."); } catch (RepositoryException e) { //expected } AGTupleQuery q = conn2.prepareTupleQuery(QueryLanguage.SPARQL, "select ?s {?s ?p ?o}"); TupleQueryResult result = q.evaluate(); Assert.assertTrue(result.hasNext()); BindingSet bind = result.next(); Assert.assertEquals(bnode.stringValue(), bind.getValue("s").stringValue()); }