org.eclipse.rdf4j.model.Statement Java Examples
The following examples show how to use
org.eclipse.rdf4j.model.Statement.
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: HalyardSummary.java From Halyard with Apache License 2.0 | 6 votes |
private void copyDescription(Resource subject) throws IOException { Statement dedup = null; try (CloseableIteration<? extends Statement, SailException> it = sail.getStatements(subject, null, null, true)) { while (it.hasNext()) { Statement st = it.next(); if (!st.getPredicate().stringValue().startsWith(FILTER_NAMESPACE_PREFIX)) { st = SVF.createStatement(st.getSubject(), st.getPredicate(), st.getObject(), namedGraph); if (!st.equals(dedup)) { writer.handleStatement(st); } dedup = st; } } } if (splitOutput && fsOut.getPos() > outputLimit) { setupOutput(); } }
Example #2
Source File: DatatypeBenchmarkLinear.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Benchmark public void shacl() throws Exception { SailRepository repository = new SailRepository(Utils.getInitializedShaclSail("shaclDatatype.ttl")); try (SailRepositoryConnection connection = repository.getConnection()) { connection.begin(IsolationLevels.SNAPSHOT); connection.commit(); } try (SailRepositoryConnection connection = repository.getConnection()) { for (List<Statement> statements : allStatements) { connection.begin(IsolationLevels.SNAPSHOT); connection.add(statements); connection.commit(); } } repository.shutDown(); }
Example #3
Source File: MinCountPrefilledVsEmptyBenchmark.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Benchmark public void shaclPrefilled() { try (SailRepositoryConnection connection = shaclRepo.getConnection()) { connection.begin(); connection.commit(); } try (SailRepositoryConnection connection = shaclRepo.getConnection()) { for (List<Statement> statements : allStatements) { connection.begin(); connection.add(statements); connection.commit(); } } }
Example #4
Source File: WriteTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testReadOnlyFederation() throws Exception { prepareTest(Arrays.asList("/tests/basic/data_emptyStore.ttl", "/tests/basic/data_emptyStore.ttl")); Assertions.assertEquals(false, fedxRule.getRepository().isWritable()); Assertions.assertThrows(UnsupportedOperationException.class, () -> { Statement st = simpleStatement(); try (RepositoryConnection conn = fedxRule.getRepository().getConnection()) { try { conn.add(st); } catch (RuntimeException e) { // rollback to avoid a stack trace in the output conn.rollback(); throw e; } } }); }
Example #5
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected void loadTestData(String dataFile, Resource... contexts) throws RDFParseException, IOException, SailException { logger.debug("loading dataset {}", dataFile); InputStream dataset = this.getClass().getResourceAsStream(dataFile); SailConnection con = store.getConnection(); try { con.begin(); for (Statement nextStatement : Rio.parse(dataset, "", RDFFormat.TURTLE, contexts)) { con.addStatement(nextStatement.getSubject(), nextStatement.getPredicate(), nextStatement.getObject(), nextStatement.getContext()); } } finally { con.commit(); con.close(); dataset.close(); } logger.debug("dataset loaded."); }
Example #6
Source File: AbstractNQuadsWriterTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testBlankNodeContextAddXSDString() throws RDFHandlerException { Statement s1 = vf.createStatement(vf.createIRI("http://test.example.org/test/subject/1"), vf.createIRI("http://other.example.com/test/predicate/1"), vf.createLiteral("test literal"), vf.createBNode()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); writer = rdfWriterFactory.getWriter(baos); writer.getWriterConfig().set(BasicWriterSettings.XSD_STRING_TO_PLAIN_LITERAL, false); writer.startRDF(); writer.handleStatement(s1); writer.endRDF(); String content = baos.toString(); String[] lines = content.split("\n"); Assert.assertEquals("Unexpected number of lines.", 1, lines.length); Assert.assertTrue(lines[0].startsWith( "<http://test.example.org/test/subject/1> <http://other.example.com/test/predicate/1> \"test literal\"^^<http://www.w3.org/2001/XMLSchema#string> _:")); }
Example #7
Source File: RyaAccumuloSailFactoryTest.java From rya with Apache License 2.0 | 6 votes |
@Ignore @Test public void testAddStatement() throws Exception { SailRepositoryFactory f = new SailRepositoryFactory(); Repository r = f.getRepository(getConfig()); r.initialize(); RepositoryConnection rc = r.getConnection(); ValueFactory vf = rc.getValueFactory(); Statement s = vf.createStatement(vf.createIRI("u:a"), vf.createIRI("u:b"), vf.createIRI("u:c")); assertFalse(rc.hasStatement(s, false)); rc.add(s); Assert.assertTrue(rc.hasStatement(s, false)); rc.close(); }
Example #8
Source File: MinCountBenchmarkEmpty.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Benchmark public void noShacl() { SailRepository repository = new SailRepository(new MemoryStore()); repository.init(); try (SailRepositoryConnection connection = repository.getConnection()) { connection.begin(); connection.commit(); } try (SailRepositoryConnection connection = repository.getConnection()) { for (List<Statement> statements : allStatements) { connection.begin(); connection.add(statements); connection.commit(); } } repository.shutDown(); }
Example #9
Source File: AddRemoveBenchmarkEmpty.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Benchmark public void shacl() throws Exception { SailRepository repository = new SailRepository(Utils.getInitializedShaclSail("shaclDatatype.ttl")); // ((ShaclSail) repository.getSail()).setIgnoreNoShapesLoadedException(true); // ((ShaclSail) repository.getSail()).disableValidation(); try (SailRepositoryConnection connection = repository.getConnection()) { for (List<Statement> statements : allStatements) { connection.begin(IsolationLevels.SNAPSHOT); connection.remove((Resource) null, null, null); connection.add(statements); connection.commit(); } } repository.shutDown(); }
Example #10
Source File: AccumuloTemporalIndexer.java From rya with Apache License 2.0 | 6 votes |
/** * get statements where the date object is after the given queryInstant. */ @Override public CloseableIteration<Statement, QueryEvaluationException> queryInstantAfterInstant( final TemporalInstant queryInstant, final StatementConstraints constraints) throws QueryEvaluationException { final Query query = new Query() { @Override public Range getRange(final KeyParts keyParts) { final Text start = Range.followingPrefix(keyParts.getQueryKey()); // <-- specific logic Text endAt = null; // no constraints // <-- specific logic if (keyParts.constraintPrefix != null ) { endAt = Range.followingPrefix(keyParts.constraintPrefix); } //System.out.println("Scanning queryInstantAfterInstant from after:" + KeyParts.toHumanString(start) + " up to:" + KeyParts.toHumanString(endAt)); return new Range(start, true, endAt, false); } }; final ScannerBase scanner = query.doQuery(queryInstant, constraints); return getContextIteratorWrapper(scanner, constraints.getContext()); }
Example #11
Source File: KafkaExportIT.java From rya with Apache License 2.0 | 6 votes |
@Test public void sum() throws Exception { // A query that sums the counts of all of the items that are in the inventory. final String sparql = "SELECT (sum(?count) as ?itemSum) { " + "?item <urn:count> ?count . " + "}"; // Create the Statements that will be loaded into Rya. final ValueFactory vf = SimpleValueFactory.getInstance(); final Collection<Statement> statements = Sets.newHashSet( vf.createStatement(vf.createIRI("urn:apple"), vf.createIRI("urn:count"), vf.createLiteral(5)), vf.createStatement(vf.createIRI("urn:gum"), vf.createIRI("urn:count"), vf.createLiteral(7)), vf.createStatement(vf.createIRI("urn:sandwich"), vf.createIRI("urn:count"), vf.createLiteral(2))); // Create the PCJ in Fluo and load the statements into Rya. final String pcjId = loadDataAndCreateQuery(sparql, statements); // Create the expected results of the SPARQL query once the PCJ has been computed. final MapBindingSet expectedResult = new MapBindingSet(); expectedResult.addBinding("itemSum", vf.createLiteral("14", XMLSchema.INTEGER)); // Ensure the last result matches the expected result. final VisibilityBindingSet result = readLastResult(pcjId); assertEquals(expectedResult, result); }
Example #12
Source File: FedXBaseTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Read the expected tuple query result from the specified resource * * @param queryResource * @return * @throws RepositoryException * @throws IOException */ protected TupleQueryResult readExpectedTupleQueryResult(String resultFile) throws Exception { QueryResultFormat tqrFormat = QueryResultIO.getParserFormatForFileName(resultFile).get(); if (tqrFormat != null) { InputStream in = SPARQLBaseTest.class.getResourceAsStream(resultFile); if (in == null) { throw new IOException("File could not be opened: " + resultFile); } try { TupleQueryResultParser parser = QueryResultIO.createTupleParser(tqrFormat); TupleQueryResultBuilder qrBuilder = new TupleQueryResultBuilder(); parser.setQueryResultHandler(qrBuilder); parser.parseQueryResult(in); return qrBuilder.getQueryResult(); } finally { in.close(); } } else { Set<Statement> resultGraph = readExpectedGraphQueryResult(resultFile); return DAWGTestResultSetUtil.toTupleQueryResult(resultGraph); } }
Example #13
Source File: SailRepositoryConnection.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void exportStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, RDFHandler handler, Resource... contexts) throws RepositoryException, RDFHandlerException { handler.startRDF(); try ( // Export namespace information CloseableIteration<? extends Namespace, RepositoryException> nsIter = getNamespaces()) { while (nsIter.hasNext()) { Namespace ns = nsIter.next(); handler.handleNamespace(ns.getPrefix(), ns.getName()); } } // Export statements try (CloseableIteration<? extends Statement, RepositoryException> stIter = getStatements(subj, pred, obj, includeInferred, contexts)) { while (stIter.hasNext()) { handler.handleStatement(stIter.next()); } } handler.endRDF(); }
Example #14
Source File: NotClassBenchmarkEmpty.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Benchmark public void noShacl() { SailRepository repository = new SailRepository(new MemoryStore()); repository.init(); try (SailRepositoryConnection connection = repository.getConnection()) { connection.begin(); connection.commit(); } try (SailRepositoryConnection connection = repository.getConnection()) { for (List<Statement> statements : allStatements) { connection.begin(); connection.add(statements); connection.commit(); } } repository.shutDown(); }
Example #15
Source File: KafkaExportITBase.java From rya with Apache License 2.0 | 6 votes |
protected String loadDataAndCreateQuery(final String sparql, final Collection<Statement> statements) throws Exception { requireNonNull(sparql); requireNonNull(statements); // Register the PCJ with Rya. final Instance accInstance = super.getAccumuloConnector().getInstance(); final Connector accumuloConn = super.getAccumuloConnector(); final RyaClient ryaClient = AccumuloRyaClientFactory.build(new AccumuloConnectionDetails(ACCUMULO_USER, ACCUMULO_PASSWORD.toCharArray(), accInstance.getInstanceName(), accInstance.getZooKeepers()), accumuloConn); final String pcjId = ryaClient.getCreatePCJ().createPCJ(RYA_INSTANCE_NAME, sparql, Sets.newHashSet(ExportStrategy.KAFKA)); loadData(statements); // The PCJ Id is the topic name the results will be written to. return pcjId; }
Example #16
Source File: KafkaExportIT.java From rya with Apache License 2.0 | 6 votes |
@Test public void min() throws Exception { // A query that finds the minimum price for an item within the inventory. final String sparql = "SELECT (min(?price) as ?minPrice) { " + "?item <urn:price> ?price . " + "}"; // Create the Statements that will be loaded into Rya. final ValueFactory vf = SimpleValueFactory.getInstance(); final Collection<Statement> statements = Sets.newHashSet( vf.createStatement(vf.createIRI("urn:apple"), vf.createIRI("urn:price"), vf.createLiteral(2.50)), vf.createStatement(vf.createIRI("urn:gum"), vf.createIRI("urn:price"), vf.createLiteral(0.99)), vf.createStatement(vf.createIRI("urn:sandwich"), vf.createIRI("urn:price"), vf.createLiteral(4.99))); // Create the PCJ in Fluo and load the statements into Rya. final String pcjId = loadDataAndCreateQuery(sparql, statements); // Create the expected results of the SPARQL query once the PCJ has been computed. final MapBindingSet expectedResult = new MapBindingSet(); expectedResult.addBinding("minPrice", vf.createLiteral(0.99)); // Ensure the last result matches the expected result. final VisibilityBindingSet result = readLastResult(pcjId); assertEquals(expectedResult, result); }
Example #17
Source File: GeoMesaGeoIndexer.java From rya with Apache License 2.0 | 6 votes |
private CloseableIteration<Statement, QueryEvaluationException> performQuery(final String type, final Geometry geometry, final StatementConstraints contraints) { final List<String> filterParms = new ArrayList<String>(); filterParms.add(type + "(" + GEOMETRY_ATTRIBUTE + ", " + geometry + " )"); if (contraints.hasSubject()) { filterParms.add("( " + SUBJECT_ATTRIBUTE + "= '" + contraints.getSubject() + "') "); } if (contraints.hasContext()) { filterParms.add("( " + CONTEXT_ATTRIBUTE + "= '" + contraints.getContext() + "') "); } if (contraints.hasPredicates()) { final List<String> predicates = new ArrayList<String>(); for (final IRI iri : contraints.getPredicates()) { predicates.add("( " + PREDICATE_ATTRIBUTE + "= '" + iri.stringValue() + "') "); } filterParms.add("(" + StringUtils.join(predicates, " OR ") + ")"); } final String filterString = StringUtils.join(filterParms, " AND "); logger.info("Performing geomesa query : " + LogUtils.clean(filterString)); return getIteratorWrapper(filterString); }
Example #18
Source File: SolrIndexTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @param statement112 * @param document */ private void assertStatement(Statement statement, SearchDocument document) { List<String> fields = document.getProperty(SearchFields.getPropertyField(statement.getPredicate())); assertNotNull("field " + statement.getPredicate() + " not found in document " + document, fields); for (String f : fields) { if (((Literal) statement.getObject()).getLabel().equals(f)) { return; } } fail("Statement not found in document " + statement); }
Example #19
Source File: RyaOutputFormatTest.java From rya with Apache License 2.0 | 5 votes |
@Test public void testEntityIndexing() throws Exception { final EntityCentricIndex entity = new EntityCentricIndex(); entity.setConf(conf); final RyaStatement input = RyaStatement.builder() .setSubject(new RyaIRI(GRAPH + ":s")) .setPredicate(new RyaIRI(GRAPH + ":p")) .setObject(new RyaIRI(GRAPH + ":o")) .build(); RyaOutputFormat.setCoreTablesEnabled(job, false); RyaOutputFormat.setFreeTextEnabled(job, false); RyaOutputFormat.setTemporalEnabled(job, false); RyaOutputFormat.setEntityEnabled(job, true); write(input); entity.close(); final Set<Statement> expected = new HashSet<>(); final Set<Statement> inserted = new HashSet<>(); expected.add(RyaToRdfConversions.convertStatement(input)); final String table = EntityCentricIndex.getTableName(conf); final Scanner scanner = connector.createScanner(table, new Authorizations(CV)); for (final Map.Entry<Key, Value> row : scanner) { System.out.println(row); inserted.add(RyaToRdfConversions.convertStatement( EntityCentricIndex.deserializeStatement(row.getKey(), row.getValue()))); } Assert.assertEquals(expected, inserted); }
Example #20
Source File: AbstractShaclTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void printCurrentState(SailRepository shaclRepository) { if (!fullLogging) { return; } try (SailRepositoryConnection connection = shaclRepository.getConnection()) { if (connection.isEmpty()) { System.out.println("### CURRENT REPOSITORY STATE ###"); System.out.println(" EMPTY!"); System.out.println("################################################\n"); } else { try (Stream<Statement> stream = connection.getStatements(null, null, null, false).stream()) { LinkedHashModel model = stream.collect(Collectors.toCollection(LinkedHashModel::new)); model.setNamespace("ex", "http://example.com/ns#"); model.setNamespace(FOAF.PREFIX, FOAF.NAMESPACE); model.setNamespace(XMLSchema.PREFIX, XMLSchema.NAMESPACE); model.setNamespace(RDF.PREFIX, RDF.NAMESPACE); model.setNamespace(RDFS.PREFIX, RDFS.NAMESPACE); WriterConfig writerConfig = new WriterConfig(); writerConfig.set(BasicWriterSettings.PRETTY_PRINT, true); writerConfig.set(BasicWriterSettings.INLINE_BLANK_NODES, true); System.out.println("### CURRENT REPOSITORY STATE ###"); Rio.write(model, System.out, RDFFormat.TURTLE, writerConfig); System.out.println("################################################\n"); } } } }
Example #21
Source File: AccumuloTemporalIndexer.java From rya with Apache License 2.0 | 5 votes |
/** * Remove an interval instant * * @param writer * @param cv * @param instant * @throws MutationsRejectedException */ public void removeInstant(final BatchWriter writer, final TemporalInstant instant, final Statement statement) throws MutationsRejectedException { final KeyParts keyParts = new KeyParts(statement, instant); for (final KeyParts k: keyParts) { final Mutation m = new Mutation(k.getStoreKey()); m.putDelete(k.cf, k.cq); writer.addMutation(m); } }
Example #22
Source File: LuceneSailBuffer.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Remove this statement to the buffer * * @param s the statement */ public synchronized void remove(Statement s) { // check if the last operation was adding/Removing triples Operation o = (operations.isEmpty()) ? null : operations.get(operations.size() - 1); if ((o == null) || !(o instanceof AddRemoveOperation)) { o = new AddRemoveOperation(); operations.add(o); } AddRemoveOperation aro = (AddRemoveOperation) o; aro.remove(new ContextAwareStatementImpl(s)); }
Example #23
Source File: AccumuloTemporalIndexer.java From rya with Apache License 2.0 | 5 votes |
/** * Get instances matching the beginning of a given interval. */ @Override public CloseableIteration<Statement, QueryEvaluationException> queryInstantHasBeginningInterval( final TemporalInterval queryInterval, final StatementConstraints contraints) throws QueryEvaluationException { return queryInstantEqualsInstant(queryInterval.getHasBeginning(), contraints); }
Example #24
Source File: RdfsSubClassOfReasoner.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Stream<Statement> forwardChain(Statement statement) { if (forwardChainCache.isEmpty()) { return Stream.of(statement); } SimpleValueFactory vf = SimpleValueFactory.getInstance(); if (statement.getPredicate().equals(RDF.TYPE) && forwardChainCache.containsKey(((Resource) statement.getObject()))) { return forwardChainCache.get(statement.getObject()) .stream() .map(r -> vf.createStatement(statement.getSubject(), RDF.TYPE, r, statement.getContext())); } return Stream.of(statement); }
Example #25
Source File: WikiDataReification.java From inception with Apache License 2.0 | 5 votes |
@Override public void upsertStatement(RepositoryConnection aConnection, KnowledgeBase aKB, KBStatement aStatement) { if (!aStatement.getProperty().getIdentifier().startsWith(PREFIX_PROP)) { throw new IllegalArgumentException( "With WikiDataReification, properties must start " + "with [" + PREFIX_PROP + "] but found [" + aStatement.getProperty().getIdentifier() + "]"); } ValueFactory vf = aConnection.getValueFactory(); // According to the Wikidata reification scheme, the predicate of the secondary triple // corresponds to the predicate of the primary triple with the prefix replaced, e.g. // p:P186 -> ps:P186 String propStatementIri = aStatement.getProperty().getIdentifier().replace(PREFIX_PROP, PREFIX_PROP_STATEMENT); IRI subject = vf.createIRI(aStatement.getInstance().getIdentifier()); IRI pred1 = vf.createIRI(aStatement.getProperty().getIdentifier()); Resource stmt = aStatement.getStatementId() != null ? vf.createIRI(aStatement.getStatementId()) : vf.createIRI(generateStatementIdentifier(aConnection, aKB)); //: vf.createBNode(); IRI pred2 = vf.createIRI(propStatementIri); Value value = valueMapper.mapStatementValue(aStatement, vf); // Generate all the triples that are to be stored by this statement // Add primary and secondary triple Set<Statement> statements = new HashSet<>(); statements.add(vf.createStatement(subject, pred1, stmt)); statements.add(vf.createStatement(stmt, pred2, value)); // Delete all original triples except the ones which we would re-create anyway upsert(aConnection, aStatement.getOriginalTriples(), statements); // Update the original triples and the statement ID in the statement aStatement.setStatementId(stmt.stringValue()); aStatement.setOriginalTriples(statements); }
Example #26
Source File: TimeAwareHBaseSailTest.java From Halyard with Apache License 2.0 | 5 votes |
@Test public void timestampLongTest() throws Exception { CloseableIteration<? extends Statement, SailException> iter; HBaseSail sail = new TimeAwareHBaseSail(HBaseServerTestInstance.getInstanceConfig(), "timestamptable", true, 0, true, 0, null, null); SailRepository rep = new SailRepository(sail); rep.initialize(); SailRepositoryConnection con = rep.getConnection(); assertTrue(testUpdate(con, "insert {<http://whatever> <http://whatever> <http://whatever>} where {bind(2 as ?HALYARD_TIMESTAMP_SPECIAL_VARIABLE)}")); assertTrue(testUpdate(con, "delete {<http://whatever> <http://whatever> <http://whatever>} where {bind(1 as ?HALYARD_TIMESTAMP_SPECIAL_VARIABLE)}")); assertFalse(testUpdate(con, "delete {<http://whatever> <http://whatever> <http://whatever>} where {bind(4 as ?HALYARD_TIMESTAMP_SPECIAL_VARIABLE)}")); assertFalse(testUpdate(con, "insert {<http://whatever> <http://whatever> <http://whatever>} where {bind(3 as ?HALYARD_TIMESTAMP_SPECIAL_VARIABLE)}")); assertTrue(testUpdate(con, "insert {<http://whatever> <http://whatever> <http://whatever>} where {bind(4 as ?HALYARD_TIMESTAMP_SPECIAL_VARIABLE)}")); rep.shutDown(); }
Example #27
Source File: MemTripleSourceTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test method for * {@link org.eclipse.rdf4j.sail.memory.MemTripleSource#getStatements(org.eclipse.rdf4j.model.Resource, org.eclipse.rdf4j.model.IRI, org.eclipse.rdf4j.model.Value, org.eclipse.rdf4j.model.Resource[])} * . */ @Test public final void testGetStatementsOneContextOnePredicateOneContext() throws Exception { loadTestData("/alp-testdata.ttl", this.alice); TripleSource source = getTripleSourceCommitted(); try (CloseableIteration<? extends Statement, QueryEvaluationException> statements = source.getStatements(null, RDFS.SUBCLASSOF, null, this.alice)) { List<Statement> list = Iterations.asList(statements); assertEquals(4, list.size()); } }
Example #28
Source File: PowsyblWriter.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Override public void handleStatement(Statement st) { if (!writingStarted) { throw new RDFHandlerException("Document writing has not yet been started"); } Resource subj = st.getSubject(); IRI pred = st.getPredicate(); Value obj = st.getObject(); // Verify that an XML namespace-qualified name can be created for the predicate String predString = pred.toString(); int predSplitIdx = XMLUtil.findURISplitIndex(predString); if (predSplitIdx == -1) { throw new RDFHandlerException("Unable to create XML namespace-qualified name for predicate: " + predString); } String predNamespace = predString.substring(0, predSplitIdx); String predLocalName = predString.substring(predSplitIdx); try { if (!headerWritten) { writeHeader(); } // SUBJECT if (!subj.equals(lastWrittenSubject)) { writeNewSubject(subj, obj, st.getContext().stringValue()); } else { writeLastSubject(obj, predNamespace, predLocalName); } // Don't write </rdf:Description> yet, maybe the next statement // has the same subject. } catch (IOException e) { throw new RDFHandlerException(e); } }
Example #29
Source File: ConsoleRDFWriter.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void consumeStatement(Statement st) throws RDFHandlerException { consoleIO.write(Util.getPrefixedValue(st.getSubject(), namespaces)); consoleIO.write(" "); consoleIO.write(Util.getPrefixedValue(st.getPredicate(), namespaces)); consoleIO.write(" "); consoleIO.write(Util.getPrefixedValue(st.getObject(), namespaces)); consoleIO.writeln(); }
Example #30
Source File: TripleStoreRDF4J.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
private static int statementsCount(RepositoryConnection conn, Resource ctx) { RepositoryResult<Statement> statements = conn.getStatements(null, null, null, ctx); int counter = 0; while (statements.hasNext()) { counter++; statements.next(); } return counter; }