com.bigdata.rdf.model.BigdataStatement Java Examples
The following examples show how to use
com.bigdata.rdf.model.BigdataStatement.
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: BlazeGraph.java From tinkerpop3 with GNU General Public License v2.0 | 6 votes |
/** * Helper for {@link BlazeEdge#property(String, Object)} and * {@link BlazeVertexProperty#property(String, Object)}. * * @param element the BlazeEdge or BlazeVertexProperty * @param key the property key * @param val the property value * @return a BlazeProperty */ <V> BlazeProperty<V> property(final BlazeReifiedElement element, final String key, final V val) { final BigdataValueFactory rdfvf = rdfValueFactory(); final BigdataBNode s = element.rdfId(); final URI p = rdfvf.asValue(vf.propertyURI(key)); final Literal lit = rdfvf.asValue(vf.toLiteral(val)); final RepositoryConnection cxn = cxn(); Code.wrapThrow(() -> { final BigdataStatement stmt = rdfvf.createStatement(s, p, lit); if (!bulkLoad) { // remove (<<stmt>> <key> ?) cxn.remove(s, p, null); } // add (<<stmt>> <key> "val") cxn.add(stmt); }); final BlazeProperty<V> prop = new BlazeProperty<V>(this, element, p, lit); return prop; }
Example #2
Source File: BlazeGraph.java From tinkerpop3 with GNU General Public License v2.0 | 6 votes |
/** * Binding set to vertex property (for Vertex elements). */ private final <V> Function<BindingSet, VertexProperty<V>> vertexProperty(final BlazeVertex v) { return bs -> { log.debug(() -> bs); final Literal val = (Literal) bs.getValue("val"); final BigdataBNode sid = (BigdataBNode) bs.getValue("vp"); final BigdataStatement stmt = sid.getStatement(); final URI key = stmt.getPredicate(); final String vpId = vertexPropertyId(stmt); final BlazeProperty<V> prop = new BlazeProperty<>(BlazeGraph.this, v, key, val); final BlazeVertexProperty<V> bvp = new BlazeVertexProperty<>(prop, vpId, sid); return bvp; }; }
Example #3
Source File: StatementBuffer.java From database with GNU General Public License v2.0 | 6 votes |
/** * Constructor used when merging multiple batches. */ private Batch( final AbstractTripleStore database, // final AbstractTripleStore statementStore, // final boolean readOnly, // final IChangeLog changeLog, // final IWrittenSPOArray didWriteCallback, // final int numValues, // final BigdataValue[] values, // final int numStmts, // final BigdataStatement[] stmts// ) { this.database = database; this.statementStore = statementStore; this.readOnly = readOnly; this.changeLog = changeLog; this.didWriteCallback = didWriteCallback; this.numValues = numValues; this.values = values; this.numStmts = numStmts; this.stmts = stmts; }
Example #4
Source File: SparqlGenerator.java From tinkerpop3 with GNU General Public License v2.0 | 6 votes |
/** * @see {@link Templates#PROPERTIES} */ String properties(final BlazeReifiedElement element, final List<URI> uris) { final StringBuilder vc = new StringBuilder(); if (!uris.isEmpty()) { buildValuesClause(vc, "?key", uris); } final StringBuilder s = new StringBuilder(); final BigdataBNode sid = element.rdfId(); final BigdataStatement stmt = sid.getStatement(); s.append("<<") .append(sparql(stmt.getSubject())).append(' ') .append(sparql(stmt.getPredicate())).append(' ') .append(sparql(stmt.getObject())) .append(">>"); final String queryStr = PROPERTIES.replace("?s", s.toString()) .replace(Templates.VALUES, vc.toString()); return queryStr; }
Example #5
Source File: BigdataTurtleWriter.java From database with GNU General Public License v2.0 | 6 votes |
protected void writeSid(final BigdataBNode sid) throws IOException { final BigdataStatement stmt = sid.getStatement(); writer.write("<< "); writeValue(stmt.getSubject()); writer.write(", "); writeValue(stmt.getPredicate()); writer.write(", "); writeValue(stmt.getObject()); if (stmt.getContext() != null) { writer.write(", "); writeValue(stmt.getContext()); } writer.write(" >>"); }
Example #6
Source File: AsynchronousStatementBufferFactory.java From database with GNU General Public License v2.0 | 6 votes |
/** * Form the BigdataStatement object using the valueFactory now that we * bindings which were (a) allocated by the valueFactory and (b) are * canonical for the scope of this document. */ @SuppressWarnings("unchecked") private void _handleStatement(final Resource s, final URI p, final Value o, final Resource c, final StatementEnum type) { final BigdataStatement stmt = valueFactory.createStatement( (BigdataResource) s, (BigdataURI) p, (BigdataValue) o, (BigdataResource) c, type); if (statements == null) { statements = new UnsynchronizedUnboundedChunkBuffer<S>( producerChunkSize, (Class<? extends S>) BigdataStatement.class); } statements.add((S) stmt); // total #of statements accepted. statementCount++; if (log.isTraceEnabled()) log.trace("n=" + statementCount + ", added: " + stmt); }
Example #7
Source File: ASTConstructIterator.java From database with GNU General Public License v2.0 | 5 votes |
/** * Return a statement if a valid statement could be constructed for that * statement pattern and this solution. * * @param pat * A statement pattern from the construct template. * @param solution * A solution from the query. * @param bnodes * A map used to scope blank nodes to the solution. * * @return A statement if a valid statement could be constructed for that * statement pattern and this solution. */ private BigdataStatement makeStatement(final StatementPatternNode pat, final BindingSet solution, final Map<String, BigdataBNode> bnodes) { // resolve values from template and/or solution. final BigdataValue s = getValue(pat.s(), solution, bnodes); final BigdataValue p = getValue(pat.p(), solution, bnodes); final BigdataValue o = getValue(pat.o(), solution, bnodes); final BigdataValue c = pat.c() == null ? null : getValue(pat.c(), solution, bnodes); // filter out unbound values. if (s == null || p == null || o == null) return null; // filter out bindings which do not produce legal statements. if (!(s instanceof Resource)) return null; if (!(p instanceof URI)) return null; if (!(o instanceof Value)) return null; if (c != null && !(c instanceof Resource)) return null; // return the statement return f.createStatement((Resource) s, (URI) p, (Value) o, (Resource) c); }
Example #8
Source File: BigdataStatementIteratorImpl.java From database with GNU General Public License v2.0 | 5 votes |
/** * * @param db * Used to resolve term identifiers to {@link Value} objects. * @param bnodes * An optional map of known blank node term identifiers and the * corresponding {@link BigdataBNodeImpl} objects. This map may * be used to resolve blank node term identifiers to blank node * objects across a "connection" context. * @param src * The source iterator (will be closed when this iterator is * closed). */ public BigdataStatementIteratorImpl(final AbstractTripleStore db, final Map<IV, BigdataBNode> bnodes, final IChunkedOrderedIterator<ISPO> src) { super(db, src, new BlockingBuffer<BigdataStatement[]>( db.getChunkOfChunksCapacity(), db.getChunkCapacity(), db.getChunkTimeout(), TimeUnit.MILLISECONDS)); this.bnodes = bnodes; }
Example #9
Source File: AbstractStatementBuffer.java From database with GNU General Public License v2.0 | 5 votes |
/** * Invoked each time the {@link #statementBuffer} buffer would overflow. * This method is responsible for bulk resolving / adding the buffered * {@link BigdataValue}s against the {@link #db} and adding the fully * resolved {@link BigdataStatement}s to the queue on which the * iterator is reading. */ @SuppressWarnings("unchecked") final protected void overflow() { if (INFO) log.info("nvalues=" + nvalues + ", nstmts=" + nstmts); if (nstmts == 0) return; // resolve/add term identifiers for the buffered values. processBufferedValues(); /* * Note: clone the chunk since this class reuses the same array * reference for each chunk. Cloning gives us a shallow copy of the * caller's array. */ // an array with exactly the right #of elements. final G[] a = (G[]) new BigdataStatement[nstmts]; // copy references. for (int i = 0; i < nstmts; i++) { a[i] = statementBuffer[i]; } // update the counter. counter += handleProcessedStatements(a); // clear the buffered values and statements. clear(); }
Example #10
Source File: BlazeGraphEmbedded.java From tinkerpop3 with GNU General Public License v2.0 | 5 votes |
/** * Materialize a batch of change records. You MUST close this stream * when done. * * @param n * number of valid elements in the array * @param a * array of {@link IChangeRecord}s * @return * Same records with materialized values */ protected Stream<IChangeRecord> materialize(final int n, final IChangeRecord[] a) { final AbstractTripleStore db = cxn().getTripleStore(); /* * Collect up unmaterialized ISPOs out of the change records * (only the removes are unmaterialized). */ int nRemoves = 0; final ISPO[] spos = new ISPO[n]; for (int i = 0; i < n; i++) { if (a[i].getChangeAction() == ChangeAction.REMOVED) spos[nRemoves++] = a[i].getStatement(); } /* * Use the database to resolve them into BigdataStatements */ final BigdataStatementIterator it = db .asStatementIterator(new ChunkedArrayIterator<ISPO>(nRemoves, spos, null/* keyOrder */)); /* * Stream the records, replacing removes with materialized versions * of same. We can do this because the iterator above is order- * preserving. */ return Arrays.stream(a, 0, n).onClose(() -> it.close()) .map(r -> { if (r.getChangeAction() == ChangeAction.REMOVED) { final BigdataStatement stmt = it.next(); return new ChangeRecord(stmt, ChangeAction.REMOVED); } else { return r; } }); }
Example #11
Source File: BlazeEdge.java From tinkerpop3 with GNU General Public License v2.0 | 5 votes |
/** * Construct an instance without vertices. Used by * {@link BlazeGraph#bulkLoad(Graph)} */ BlazeEdge(final BlazeGraph graph, final BigdataStatement stmt, final BigdataURI label) { super(graph, stmt.getPredicate(), label); final BigdataValueFactory rdfvf = graph.rdfValueFactory(); this.sid = rdfvf.createBNode(stmt); this.vertices = null; }
Example #12
Source File: BlazeEdge.java From tinkerpop3 with GNU General Public License v2.0 | 5 votes |
/** * Construct an instance. */ BlazeEdge(final BlazeGraph graph, final BigdataStatement stmt, final BigdataURI label, final BlazeVertex from, final BlazeVertex to) { super(graph, stmt.getPredicate(), label); final BigdataValueFactory rdfvf = graph.rdfValueFactory(); this.sid = rdfvf.createBNode(stmt); this.vertices = new Vertices(from, to); }
Example #13
Source File: AsynchronousStatementBufferFactory.java From database with GNU General Public License v2.0 | 5 votes |
public void add(final S e) { add(e.getSubject(), e.getPredicate(), e.getObject(), e.getContext(), (e instanceof BigdataStatement ? ((BigdataStatement) e) .getStatementType() : null)); }
Example #14
Source File: LoadPdb.java From database with GNU General Public License v2.0 | 5 votes |
public static void readSomeData(Repository repo) throws Exception { RepositoryConnection cxn = repo.getConnection(); int counter = 0; try { RepositoryResult<Statement> stmts = cxn.getStatements(null, null, null, true /* * include * inferred */); while (stmts.hasNext()) { Statement stmt = stmts.next(); Resource s = stmt.getSubject(); URI p = stmt.getPredicate(); Value o = stmt.getObject(); // do something with the statement LOG.info(stmt); // cast to BigdataStatement to get at additional information BigdataStatement bdStmt = (BigdataStatement) stmt; if (bdStmt.isExplicit()) { // do one thing } else if (bdStmt.isInferred()) { // do another thing } else { // bdStmt.isAxiom() // do something else } LOG.info(bdStmt.getStatementType()); counter++; } } finally { // close the repository connection cxn.close(); LOG.info("Number of Triples: " + counter); } }
Example #15
Source File: TestInlineURIs.java From database with GNU General Public License v2.0 | 5 votes |
public void testInlineIPv4s() throws Exception { /* * The bigdata store, backed by a temporary journal file. */ final AbstractTripleStore store = getStore(getProperties()); try { final BigdataValueFactory vf = store.getValueFactory(); final BigdataURI uri1 = vf.createURI("urn:ipv4:10.128.1.2"); final BigdataURI uri2 = vf.createURI("urn:ipv4:10.128.1.2/24"); final BigdataURI uri3 = vf.createURI("urn:ipv4:500.425.1.2"); final BigdataURI uri4 = vf.createURI("urn:ipv4"); final BigdataLiteral l = vf.createLiteral("10.128.1.2", XSD.IPV4); final StatementBuffer<BigdataStatement> sb = new StatementBuffer<BigdataStatement>(store, 10/* capacity */); sb.add(uri1, RDF.TYPE, XSD.IPV4); sb.add(uri2, RDF.TYPE, XSD.IPV4); sb.add(uri3, RDF.TYPE, XSD.IPV4); sb.add(uri4, RDFS.LABEL, l); sb.flush(); store.commit(); if (log.isDebugEnabled()) log.debug("\n"+store.dumpStore()); assertTrue(uri1.getIV().isInline()); assertTrue(uri2.getIV().isInline()); assertFalse(uri3.getIV().isInline()); assertFalse(uri4.getIV().isInline()); } finally { store.__tearDownUnitTest(); } }
Example #16
Source File: TestTicket1086.java From database with GNU General Public License v2.0 | 5 votes |
/** * When loading quads into a triple store, the context is striped away by * default. */ public void testQuadStripping() throws Exception { BigdataSailRepositoryConnection cxn = null; final BigdataSail sail = getSail(getTriplesNoInference()); try { sail.initialize(); final BigdataSailRepository repo = new BigdataSailRepository(sail); cxn = (BigdataSailRepositoryConnection) repo.getConnection(); final BigdataValueFactory vf = (BigdataValueFactory) sail .getValueFactory(); final URI s = vf.createURI("http://test/s"); final URI p = vf.createURI("http://test/p"); final URI o = vf.createURI("http://test/o"); final URI c = vf.createURI("http://test/c"); BigdataStatement stmt = vf.createStatement(s, p, o, c); cxn.add(stmt); RepositoryResult<Statement> stmts = cxn.getStatements(null, null, null, false); Statement res = stmts.next(); assertEquals(s, res.getSubject()); assertEquals(p, res.getPredicate()); assertEquals(o, res.getObject()); assertEquals(null, res.getContext()); } finally { if (cxn != null) cxn.close(); sail.__tearDownUnitTest(); } }
Example #17
Source File: TestTicket1086.java From database with GNU General Public License v2.0 | 5 votes |
/** * When loading quads into a triple store and the BigdataSail option * REJECT_QUADS_IN_TRIPLE_MODE is set to true, an exception will be thrown. */ public void testQuadStrippingRejected() throws Exception { BigdataSailRepositoryConnection cxn = null; final BigdataSail sail = getSail(getTriplesNoInferenceNoQuadsStripping()); boolean exceptionEncountered = false; try { sail.initialize(); final BigdataSailRepository repo = new BigdataSailRepository(sail); cxn = (BigdataSailRepositoryConnection) repo.getConnection(); final BigdataValueFactory vf = (BigdataValueFactory) sail .getValueFactory(); final URI s = vf.createURI("http://test/s"); final URI p = vf.createURI("http://test/p"); final URI o = vf.createURI("http://test/o"); final URI c = vf.createURI("http://test/c"); BigdataStatement stmt = vf.createStatement(s, p, o, c); cxn.add(stmt); } catch (RepositoryException e) { exceptionEncountered = true; // expected ! } finally { if (cxn != null) cxn.close(); sail.__tearDownUnitTest(); } assertTrue(exceptionEncountered); }
Example #18
Source File: TestUpdateExprBuilder.java From database with GNU General Public License v2.0 | 5 votes |
/** * <pre> * PREFIX dc: <http://purl.org/dc/elements/1.1/> * PREFIX ns: <http://example.org/ns#> * INSERT DATA * { GRAPH <http://example/bookStore> { <http://example/book1> ns:price 42 } } * </pre> */ // @SuppressWarnings("rawtypes") public void test_insert_data_quads() throws MalformedQueryException, TokenMgrError, ParseException { final String sparql = "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" + "PREFIX ns: <http://example.org/ns#>\n" + "INSERT DATA\n" + "{ GRAPH <http://example/bookStore> { <http://example/book1> ns:price 42 } }"; final UpdateRoot expected = new UpdateRoot(); { final InsertData op = new InsertData(); expected.addChild(op); final BigdataURI bookstore = valueFactory.createURI("http://example/bookStore"); final BigdataURI book1 = valueFactory.createURI("http://example/book1"); final BigdataURI price = valueFactory.createURI("http://example.org/ns#price"); final BigdataLiteral i42 = valueFactory.createLiteral("42",XSD.INTEGER); final BigdataStatement[] data = new BigdataStatement[] { // valueFactory.createStatement(// (BigdataResource)book1,// (BigdataURI)price, // (BigdataValue)i42, // (BigdataResource)bookstore, // StatementEnum.Explicit),// }; op.setData(data); } final UpdateRoot actual = parseUpdate(sparql, baseURI); assertSameAST(sparql, expected, actual); }
Example #19
Source File: TestUpdateExprBuilder.java From database with GNU General Public License v2.0 | 5 votes |
/** * <pre> * INSERT DATA { _:bnode a <http://example/Foo> . } * </pre> * @throws MalformedQueryException * * @see <a href="https://sourceforge.net/apps/trac/bigdata/ticket/573"> * NullPointerException when attempting to INSERT DATA containing a * blank node </a> */ public void test_insert_data_ticket573() throws MalformedQueryException { final String sparql = "INSERT DATA { _:bnode a <http://example/Foo> . }"; final UpdateRoot expected = new UpdateRoot(); { final InsertData op = new InsertData(); expected.addChild(op); final BigdataBNode bnode = valueFactory.createBNode("-anon-1"); // final BigdataBNode bnode = valueFactory.createBNode("bnode"); final BigdataURI rdfType = valueFactory.createURI(RDF.TYPE.toString()); final BigdataURI foo = valueFactory.createURI("http://example/Foo"); final BigdataStatement[] data = new BigdataStatement[] { // valueFactory.createStatement(// bnode,// rdfType,// foo, // null,// c StatementEnum.Explicit),// }; op.setData(data); } final UpdateRoot actual = parseUpdate(sparql, baseURI); // no null pointer exception, but Sesame 2.7 Sparql parser will // not respect the bnode id, so we cannot assert same AST // assertSameAST(sparql, expected, actual); }
Example #20
Source File: TestRDRHistory.java From database with GNU General Public License v2.0 | 5 votes |
/** * Test whether the RDRHistory can handle statements that are added * and removed in the same commit. */ public void testFullyRedundantEvents() throws Exception { BigdataSailRepositoryConnection cxn = null; final BigdataSail sail = getSail(getProperties()); try { sail.initialize(); final BigdataSailRepository repo = new BigdataSailRepository(sail); cxn = (BigdataSailRepositoryConnection) repo.getConnection(); final BigdataValueFactory vf = (BigdataValueFactory) sail .getValueFactory(); final URI s = vf.createURI(":s"); final URI p = vf.createURI(":p"); final Literal o = vf.createLiteral("foo"); final BigdataStatement stmt = vf.createStatement(s, p, o); final BigdataBNode sid = vf.createBNode(stmt); cxn.add(stmt); cxn.commit(); assertEquals(1, cxn.getTripleStore().getAccessPath(sid, null, null).rangeCount(false)); cxn.remove(stmt); cxn.add(stmt); cxn.commit(); assertEquals(1, cxn.getTripleStore().getAccessPath(sid, null, null).rangeCount(false)); } finally { if (cxn != null) cxn.close(); sail.__tearDownUnitTest(); } }
Example #21
Source File: StatementBuffer.java From database with GNU General Public License v2.0 | 5 votes |
@Override public void add(final Statement e) { add(e.getSubject(), e.getPredicate(), e.getObject(), e.getContext(), (e instanceof BigdataStatement ? ((BigdataStatement) e) .getStatementType() : null)); }
Example #22
Source File: StatementBuffer.java From database with GNU General Public License v2.0 | 5 votes |
/** * Add a statement to the buffer (core impl, flushes on overflow). * * @param s * @param p * @param o * @param type */ @Override public void add(final Resource s, final URI p, final Value o, final Resource c, final StatementEnum type) { if (nearCapacity()) { // bulk insert the buffered data into the store. if (true) { // THIS IS THE CORRECT ACTION! incrementalWrite(); } else { /* * This will flush all blank nodes. It may be necessary on very * large files. It also resets the blank node and deferred * statement maps afterwards (since they are set to null by * reset()). */ flush(); bnodes = new HashMap<String, BigdataBNode>(bufferCapacity); deferredStmts = new HashSet<BigdataStatement>(stmts.length); } } // add to the buffer. handleStatement(s, p, o, c, type); }
Example #23
Source File: SPO.java From database with GNU General Public License v2.0 | 5 votes |
/** * Construct a triple/quad from a {@link BigdataStatement}. The term * identifiers and statement type information available on the * {@link BigdataStatement} will be used to initialize the {@link SPO}. * * @param stmt * The statement. */ public SPO(final BigdataStatement stmt) { this( stmt.s(),// stmt.p(),// stmt.o(),// stmt.c(),// stmt.getStatementType()// ); }
Example #24
Source File: ASTConstructIterator.java From database with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("serial") private IFilterTest createHashDistinctQuadsFilter(final ConstructNode construct) { return new DistinctFilter.DistinctFilterImpl(construct){ @Override public boolean isValid(Object o){ return super.isValid(new BigdataQuadWrapper((BigdataStatement)o)); } }; }
Example #25
Source File: SparqlGenerator.java From tinkerpop3 with GNU General Public License v2.0 | 5 votes |
/** * @see {@link Templates#REMOVE_REIFIED_ELEMENT} */ String removeReifiedElement(final BlazeReifiedElement e) { final BigdataBNode sid = e.rdfId(); final BigdataStatement stmt = sid.getStatement(); final Resource s = stmt.getSubject(); final URI p = stmt.getPredicate(); final Value o = stmt.getObject(); final StringBuilder vc = buildValuesClause(new StringBuilder(), new String[] { "?s", "?p", "?o" }, new Value[] { s, p, o }); final String queryStr = REMOVE_REIFIED_ELEMENT.replace(Templates.VALUES, vc.toString()); return queryStr; }
Example #26
Source File: OwlAxioms.java From database with GNU General Public License v2.0 | 4 votes |
protected void addAxioms(final Collection<BigdataStatement> axioms) { super.addAxioms(axioms); final BigdataValueFactory valueFactory = getValueFactory(); // axioms for owl:equivalentClass axioms.add( valueFactory.createStatement( OWL.EQUIVALENTCLASS, RDFS.SUBPROPERTYOF, RDFS.SUBCLASSOF, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.EQUIVALENTCLASS, RDFS.SUBPROPERTYOF, OWL.EQUIVALENTCLASS, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.EQUIVALENTCLASS, RDF.TYPE, RDF.PROPERTY, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.EQUIVALENTCLASS, RDF.TYPE, RDFS.RESOURCE, null, StatementEnum.Axiom)); // axioms for owl:equivalentProperty axioms.add( valueFactory.createStatement( OWL.EQUIVALENTPROPERTY, RDFS.SUBPROPERTYOF, RDFS.SUBPROPERTYOF, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.EQUIVALENTPROPERTY, RDFS.SUBPROPERTYOF, OWL.EQUIVALENTPROPERTY, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.EQUIVALENTPROPERTY, RDF.TYPE, RDF.PROPERTY, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.EQUIVALENTPROPERTY, RDF.TYPE, RDFS.RESOURCE, null, StatementEnum.Axiom)); // axioms for owl:sameAs axioms.add( valueFactory.createStatement( OWL.SAMEAS, RDF.TYPE, RDF.PROPERTY, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.SAMEAS, RDF.TYPE, RDFS.RESOURCE, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.SAMEAS, RDFS.SUBPROPERTYOF, OWL.SAMEAS, null, StatementEnum.Axiom)); // axioms for owl:inverseOf axioms.add( valueFactory.createStatement( OWL.INVERSEOF, RDF.TYPE, RDF.PROPERTY, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.INVERSEOF, RDF.TYPE, RDFS.RESOURCE, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.INVERSEOF, RDFS.SUBPROPERTYOF, OWL.INVERSEOF, null, StatementEnum.Axiom)); // axioms for owl:onProperty axioms.add( valueFactory.createStatement( OWL.ONPROPERTY, RDF.TYPE, RDF.PROPERTY, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.ONPROPERTY, RDF.TYPE, RDFS.RESOURCE, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.ONPROPERTY, RDFS.SUBPROPERTYOF, OWL.ONPROPERTY, null, StatementEnum.Axiom)); // axioms for owl:hasValue axioms.add( valueFactory.createStatement( OWL.HASVALUE, RDF.TYPE, RDF.PROPERTY, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.HASVALUE, RDF.TYPE, RDFS.RESOURCE, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.HASVALUE, RDFS.SUBPROPERTYOF, OWL.HASVALUE, null, StatementEnum.Axiom)); // axioms for owl:Restriction axioms.add( valueFactory.createStatement( OWL.RESTRICTION, RDFS.SUBCLASSOF, RDFS.CLASS, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.RESTRICTION, RDFS.SUBCLASSOF, RDFS.RESOURCE, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.RESTRICTION, RDFS.SUBCLASSOF, OWL.RESTRICTION, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.RESTRICTION, RDF.TYPE, RDFS.CLASS, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.RESTRICTION, RDF.TYPE, RDFS.RESOURCE, null, StatementEnum.Axiom)); // axioms for owl:Class, owl:ObjectProperty, owl:TransitiveProperty, and owl:DatatypeProperty axioms.add( valueFactory.createStatement( OWL.CLASS, RDFS.SUBCLASSOF, RDFS.CLASS, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.CLASS, RDFS.SUBCLASSOF, RDFS.RESOURCE, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.CLASS, RDFS.SUBCLASSOF, OWL.CLASS, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.CLASS, RDF.TYPE, RDFS.CLASS, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.CLASS, RDF.TYPE, RDFS.RESOURCE, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.OBJECTPROPERTY, RDFS.SUBCLASSOF, RDF.PROPERTY, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.OBJECTPROPERTY, RDFS.SUBCLASSOF, RDFS.RESOURCE, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.OBJECTPROPERTY, RDFS.SUBCLASSOF, OWL.OBJECTPROPERTY, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.OBJECTPROPERTY, RDF.TYPE, RDFS.CLASS, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.OBJECTPROPERTY, RDF.TYPE, RDFS.RESOURCE, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.TRANSITIVEPROPERTY, RDFS.SUBCLASSOF, OWL.OBJECTPROPERTY, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.TRANSITIVEPROPERTY, RDFS.SUBCLASSOF, RDF.PROPERTY, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.TRANSITIVEPROPERTY, RDFS.SUBCLASSOF, RDFS.RESOURCE, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.TRANSITIVEPROPERTY, RDFS.SUBCLASSOF, OWL.TRANSITIVEPROPERTY, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.TRANSITIVEPROPERTY, RDF.TYPE, RDFS.CLASS, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.TRANSITIVEPROPERTY, RDF.TYPE, RDFS.RESOURCE, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.DATATYPEPROPERTY, RDFS.SUBCLASSOF, RDF.PROPERTY, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.DATATYPEPROPERTY, RDFS.SUBCLASSOF, RDFS.RESOURCE, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.DATATYPEPROPERTY, RDFS.SUBCLASSOF, OWL.DATATYPEPROPERTY, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.DATATYPEPROPERTY, RDF.TYPE, RDFS.CLASS, null, StatementEnum.Axiom)); axioms.add( valueFactory.createStatement( OWL.DATATYPEPROPERTY, RDF.TYPE, RDFS.RESOURCE, null, StatementEnum.Axiom)); }
Example #27
Source File: TestRDRHistory.java From database with GNU General Public License v2.0 | 4 votes |
/** * Test whether the RDRHistory can handle statements that are added * and removed in the same commit. */ public void testPartiallyRedundantEvents() throws Exception { BigdataSailRepositoryConnection cxn = null; final BigdataSail sail = getSail(getProperties()); try { sail.initialize(); final BigdataSailRepository repo = new BigdataSailRepository(sail); cxn = (BigdataSailRepositoryConnection) repo.getConnection(); final BigdataValueFactory vf = (BigdataValueFactory) sail .getValueFactory(); final URI s = vf.createURI(":s"); final URI p = vf.createURI(":p"); final Literal o = vf.createLiteral("foo"); final Literal bar = vf.createLiteral("bar"); final BigdataStatement stmt = vf.createStatement(s, p, o); final BigdataStatement stmt2 = vf.createStatement(s, p, bar); final BigdataBNode sid = vf.createBNode(stmt); final BigdataBNode sid2 = vf.createBNode(stmt2); cxn.add(stmt); cxn.commit(); assertEquals(1, cxn.getTripleStore().getAccessPath(sid, null, null).rangeCount(false)); cxn.remove(stmt); cxn.add(stmt); cxn.add(stmt2); cxn.commit(); assertEquals(1, cxn.getTripleStore().getAccessPath(sid, null, null).rangeCount(false)); assertEquals(1, cxn.getTripleStore().getAccessPath(sid2, null, null).rangeCount(false)); } finally { if (cxn != null) cxn.close(); sail.__tearDownUnitTest(); } }
Example #28
Source File: SampleCode.java From database with GNU General Public License v2.0 | 4 votes |
/** * Read some statements from a repository. * * @param repo * @param uri * @throws Exception */ public void readSomeData(Repository repo, URI uri) throws Exception { /* * With MVCC, you read from a historical state to avoid blocking and * being blocked by writers. BigdataSailRepository.getQueryConnection * gives you a view of the repository at the last commit point. */ RepositoryConnection cxn; if (repo instanceof BigdataSailRepository) { cxn = ((BigdataSailRepository) repo).getReadOnlyConnection(); } else { cxn = repo.getConnection(); } try { RepositoryResult<Statement> stmts = cxn.getStatements(uri, null, null, true /* include inferred */); while (stmts.hasNext()) { Statement stmt = stmts.next(); Resource s = stmt.getSubject(); URI p = stmt.getPredicate(); Value o = stmt.getObject(); // do something with the statement log.info(stmt); // cast to BigdataStatement to get at additional information BigdataStatement bdStmt = (BigdataStatement) stmt; if (bdStmt.isExplicit()) { // do one thing } else if (bdStmt.isInferred()) { // do another thing } else { // bdStmt.isAxiom() // do something else } log.info(bdStmt.getStatementType()); } } finally { // close the repository connection cxn.close(); } }
Example #29
Source File: SPARQLStarUpdateDataBlockParser.java From database with GNU General Public License v2.0 | 4 votes |
private Value parseStmtValue() throws IOException, RDFParseException { StringBuilder stmtBuf = new StringBuilder(100); // First 2 characters should be '<' int c = read(); verifyCharacterOrFail(c, "<"); c = read(); verifyCharacterOrFail(c, "<"); int recursiveCounter = 1; // Read up to the next ">>" characters combination while (true) { c = read(); int c2 = peek(); if (c == '<' && c2 =='<' ) { recursiveCounter++; } else if (c == '>' && c2 == '>') { if (--recursiveCounter == 0) { c = read(); break; } } else if (c == -1) { throwEOFException(); } stmtBuf.append((char)c); if (c == '\\') { // This escapes the next character, which might be a '>' c = read(); if (c == -1) { throwEOFException(); } if (c != 'u' && c != 'U') { reportFatalError("IRI includes string escapes: '\\" + c + "'"); } stmtBuf.append((char)c); } } // Use our own class in recursion. SPARQLStarUpdateDataBlockParser p = new SPARQLStarUpdateDataBlockParser(valueFactory, namespaceTable); final List<Statement> stmts = new LinkedList<Statement>(); final StatementCollector sc = new StatementCollector(stmts); p.setRDFHandler(sc); p.setParserConfig(getParserConfig()); try { p.parse(new StringReader(stmtBuf.toString()), baseURI); } catch (RDFHandlerException e) { throw new RDFParseException("Error parsing SPARQL* value", e); } if (stmts.size() != 1) { throw new RDFParseException("Error parsing SPARQL* value, invalid number of statements"); } if (valueFactory instanceof BigdataValueFactory && stmts.get(0) instanceof BigdataStatement) { return ((BigdataValueFactory)valueFactory).createBNode((BigdataStatement)stmts.get(0)); } else { throw new RDFParseException("Error parsing SPARQL* value, incompatible valueFactory"); } }
Example #30
Source File: AST2BOpUpdate.java From database with GNU General Public License v2.0 | 4 votes |
/** * Insert or remove a statement (INSERT DATA or DELETE DATA). * * @param conn * The connection on which to write the mutation. * @param spo * The statement. * @param insert * <code>true</code> iff the statement is to be inserted and * <code>false</code> iff the statement is to be removed. * @throws SailException */ private static void addOrRemoveStatementData(final BigdataSailConnection conn, final BigdataStatement stmt, final boolean insert) throws SailException { // final Resource s = (Resource) spo.s().getValue(); // // final URI p = (URI) spo.p().getValue(); // // final Value o = (Value) spo.o().getValue(); final Resource s = stmt.getSubject(); final URI p = stmt.getPredicate(); final Value o = stmt.getObject(); /* * If [c] is not bound, then using an empty Resource[] for the contexts. * * On insert, this will cause the data to be added to the null graph. * * On remove, this will cause the statements to be removed from all * contexts (on remove it is interpreted as a wildcard). */ final Resource c = (Resource) (stmt.getContext() == null ? null : stmt .getContext()); final Resource[] contexts = (Resource[]) (c == null ? NO_CONTEXTS : new Resource[] { c }); if(log.isTraceEnabled()) log.trace((insert ? "INSERT" : "DELETE") + ": <" + s + "," + p + "," + o + "," + Arrays.toString(contexts)); if (insert) { conn.addStatement(s, p, o, contexts); } else { conn.removeStatements(s, p, o, contexts); } }