Java Code Examples for com.bigdata.rdf.model.BigdataValueFactory#createBNode()
The following examples show how to use
com.bigdata.rdf.model.BigdataValueFactory#createBNode() .
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: 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 2
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 3
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 4
Source File: BlazeGraph.java From tinkerpop3 with GNU General Public License v2.0 | 4 votes |
/** * Helper for {@link BlazeVertex#property(Cardinality, String, Object, Object...)}. * * @param vertex the BlazeVertex * @param cardinality the property cardinality * @param key the property key * @param val the property value * @param kvs the properties to attach to the BlazeVertexProperty * @return a BlazeVertexProperty */ <V> BlazeVertexProperty<V> vertexProperty(final BlazeVertex vertex, final Cardinality cardinality, final String key, final V val, final Object... kvs) { final BigdataValueFactory rdfvf = rdfValueFactory(); final URI s = vertex.rdfId(); final URI p = rdfvf.asValue(vf.propertyURI(key)); final Literal lit = rdfvf.asValue(vf.toLiteral(val)); final BigdataStatement stmt; if (cardinality == Cardinality.list) { final Literal timestamp = rdfvf.createLiteral( String.valueOf(vpIdFactory.getAndIncrement()), LI_DATATYPE); stmt = rdfvf.createStatement(s, p, timestamp); } else { stmt = rdfvf.createStatement(s, p, lit); } final BigdataBNode sid = rdfvf.createBNode(stmt); final String vpId = vertexPropertyId(stmt); final RepositoryConnection cxn = cxn(); Code.wrapThrow(() -> { if (cardinality == Cardinality.list) { // <s> <key> timestamp . cxn.add(stmt); // <<<s> <key> timestamp>> rdf:value "val" . cxn.add(sid, VALUE, lit); } else { if (cardinality == Cardinality.single && !bulkLoad) { final String queryStr = sparql.cleanVertexProps(s, p, lit); update(queryStr); } // << stmt >> <key> "val" . cxn.add(stmt); } }); final BlazeProperty<V> prop = new BlazeProperty<>(this, vertex, p, lit); final BlazeVertexProperty<V> bvp = new BlazeVertexProperty<>(prop, vpId, sid); ElementHelper.attachProperties(bvp, kvs); return bvp; }
Example 5
Source File: TestReificationDoneRightEval.java From database with GNU General Public License v2.0 | 4 votes |
/** * Bootstrap test. The data are explicitly entered into the KB by hand. This * makes it possible to test evaluation without having to fix the RDF data * loader. The query is based on <code>rdf-02</code>. */ public void test_reificationDoneRight_00() throws Exception { final BigdataValueFactory vf = store.getValueFactory(); final BigdataURI SAP = vf.createURI("http://example.com/SAP"); final BigdataURI bought = vf.createURI("http://example.com/bought"); final BigdataURI sybase = vf.createURI("http://example.com/sybase"); final BigdataURI dcSource = vf.createURI(DCTermsVocabularyDecl.NAMESPACE+"source"); final BigdataURI dcCreated = vf.createURI(DCTermsVocabularyDecl.NAMESPACE+"created"); final BigdataURI newsSybase = vf.createURI("http://example.com/news/us-sybase"); final BigdataLiteral createdDate = vf.createLiteral("2011-04-05T12:00:00Z",XSD.DATETIME); final BigdataURI g1 = vf.createURI("http://example.com/g1"); // Add/resolve the terms against the lexicon. final BigdataValue[] terms = new BigdataValue[] { SAP, bought, sybase, dcSource, dcCreated, newsSybase, createdDate, g1 }; final BigdataURI context = store.isQuads() ? g1 : null; store.addTerms(terms); // ground statement. final BigdataStatement s0 = vf.createStatement(SAP, bought, sybase, context, StatementEnum.Explicit); // Setup blank node with SidIV for that Statement. final BigdataBNode s1 = vf.createBNode("s1"); s1.setStatementIdentifier(true); final ISPO spo = new SPO(s0);//SAP.getIV(), bought.getIV(), sybase.getIV(), // null/* NO CONTEXT */, StatementEnum.Explicit); s1.setIV(new SidIV<BigdataBNode>(spo)); // metadata statements. final BigdataStatement mds1 = vf.createStatement(s1, dcSource, newsSybase, context, StatementEnum.Explicit); final BigdataStatement mds2 = vf.createStatement(s1, dcCreated, createdDate, context, StatementEnum.Explicit); final ISPO[] stmts = new ISPO[] { new SPO(s0), new SPO(mds1), new SPO(mds2) }; store.addStatements(stmts, stmts.length); /* * Now that we have populated the database, we can go ahead and compile * the query. (If we compile the query first then it will not find any * matching lexical items.) */ final TestHelper h = new TestHelper(TEST_RESOURCE_PREFIX + "rdr-00", // testURI, TEST_RESOURCE_PREFIX + "rdr-02.rq",// queryFileURL TEST_RESOURCE_PREFIX + "empty.ttl",// dataFileURL TEST_RESOURCE_PREFIX + "rdr-02.srx"// resultFileURL ); h.runTest(); }
Example 6
Source File: TestReificationDoneRightEval.java From database with GNU General Public License v2.0 | 4 votes |
/** * Bootstrap test. The data are explicitly entered into the KB by hand. This * makes it possible to test evaluation without having to fix the RDF data * loader. The query is based on <code>rdf-02a</code>. */ public void test_reificationDoneRight_00a() throws Exception { final BigdataValueFactory vf = store.getValueFactory(); final BigdataURI SAP = vf.createURI("http://example.com/SAP"); final BigdataURI bought = vf.createURI("http://example.com/bought"); final BigdataURI sybase = vf.createURI("http://example.com/sybase"); final BigdataURI dcSource = vf.createURI(DCTermsVocabularyDecl.NAMESPACE+"source"); final BigdataURI dcCreated = vf.createURI(DCTermsVocabularyDecl.NAMESPACE+"created"); final BigdataURI newsSybase = vf.createURI("http://example.com/news/us-sybase"); final BigdataLiteral createdDate = vf.createLiteral("2011-04-05T12:00:00Z",XSD.DATETIME); final BigdataURI g1 = vf.createURI("http://example.com/g1"); // Add/resolve the terms against the lexicon. final BigdataValue[] terms = new BigdataValue[] { SAP, bought, sybase, dcSource, dcCreated, newsSybase, createdDate, g1 }; final BigdataURI context = store.isQuads() ? g1 : null; store.addTerms(terms); // ground statement. final BigdataStatement s0 = vf.createStatement(SAP, bought, sybase, context, StatementEnum.Explicit); // Setup blank node with SidIV for that Statement. final BigdataBNode s1 = vf.createBNode("s1"); s1.setStatementIdentifier(true); final ISPO spo = new SPO(SAP.getIV(), bought.getIV(), sybase.getIV(), null/* NO CONTEXT */, StatementEnum.Explicit); s1.setIV(new SidIV<BigdataBNode>(spo)); // metadata statements. final BigdataStatement mds1 = vf.createStatement(s1, dcSource, newsSybase, context, StatementEnum.Explicit); final BigdataStatement mds2 = vf.createStatement(s1, dcCreated, createdDate, context, StatementEnum.Explicit); final ISPO[] stmts = new ISPO[] { new SPO(s0), new SPO(mds1), new SPO(mds2) }; store.addStatements(stmts, stmts.length); /* * Now that we have populated the database, we can go ahead and compile * the query. (If we compile the query first then it will not find any * matching lexical items.) */ new TestHelper(TEST_RESOURCE_PREFIX + "rdr-00a", // testURI, TEST_RESOURCE_PREFIX + "rdr-02a.rq",// queryFileURL TEST_RESOURCE_PREFIX + "empty.ttl",// dataFileURL TEST_RESOURCE_PREFIX + "rdr-02a.srx"// resultFileURL ).runTest(); }
Example 7
Source File: TestIVCache.java From database with GNU General Public License v2.0 | 4 votes |
/** * Unit test for {@link IV#getValue()} and friends. */ public void test_getValue() { final AbstractTripleStore store = getStore(getProperties()); try { final LexiconRelation lex = store.getLexiconRelation(); final BigdataValueFactory f = lex.getValueFactory(); final BigdataURI uri = f.createURI("http://www.bigdata.com"); final BigdataBNode bnd = f.createBNode();//"12"); final BigdataLiteral lit = f.createLiteral("bigdata"); final BigdataValue[] a = new BigdataValue[] { uri, bnd, lit }; // insert some terms. lex.addTerms(a, a.length, false/*readOnly*/); doTest(lex,uri.getIV(), uri); doTest(lex,bnd.getIV(), bnd); doTest(lex,lit.getIV(), lit); doTest(lex, new XSDBooleanIV<BigdataLiteral>(true)); doTest(lex, new XSDNumericIV<BigdataLiteral>((byte)1)); doTest(lex, new XSDNumericIV<BigdataLiteral>((short)1)); doTest(lex, new XSDNumericIV<BigdataLiteral>(1)); doTest(lex, new XSDNumericIV<BigdataLiteral>(1L)); doTest(lex, new XSDNumericIV<BigdataLiteral>(1f)); doTest(lex, new XSDNumericIV<BigdataLiteral>(1d)); doTest(lex, new XSDIntegerIV<BigdataLiteral>(BigInteger.valueOf(1L))); doTest(lex, new XSDDecimalIV<BigdataLiteral>(BigDecimal.valueOf(1d))); doTest(lex, new UUIDBNodeIV<BigdataBNode>(UUID.randomUUID())); doTest(lex, new NumericBNodeIV<BigdataBNode>(1)); doTest(lex, new UUIDLiteralIV<BigdataLiteral>(UUID.randomUUID())); } finally { store.__tearDownUnitTest(); } }
Example 8
Source File: TestStatementBuffer.java From database with GNU General Public License v2.0 | 4 votes |
/** * A unit test in which the translation of reified statements into inline * statements disabled. This test uses the same data as the test below. */ public void test_reificationDoneRight_disabled() { if (QueryHints.DEFAULT_REIFICATION_DONE_RIGHT) return; final int capacity = 20; final Properties properties = new Properties(getProperties()); // turn off entailments. properties.setProperty(AbstractTripleStore.Options.AXIOMS_CLASS, NoAxioms.class.getName()); final AbstractTripleStore store = getStore(properties); try { // * @prefix : <http://example.com/> . // * @prefix news: <http://example.com/news/> . // * @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . // * @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . // * @prefix dc: <http://purl.org/dc/terms/> . // * @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . // * // * :SAP :bought :sybase . // * _:s1 rdf:subject :SAP . // * _:s1 rdf:predicate :bought . // * _:s1 rdf:object :sybase . // * _:s1 rdf:type rdf:Statement . // * _:s1 dc:source news:us-sybase . // * _:s1 dc:created "2011-04-05T12:00:00Z"^^xsd:dateTime . final BigdataValueFactory vf = store.getValueFactory(); final BigdataURI SAP = vf.createURI("http://example.com/SAP"); final BigdataURI bought = vf.createURI("http://example.com/bought"); final BigdataURI sybase = vf.createURI("http://example.com/sybase"); final BigdataURI dcSource = vf.createURI("http://purl.org/dc/terms/source"); final BigdataURI dcCreated = vf.createURI("http://purl.org/dc/terms/created"); final BigdataURI newsSybase = vf.createURI("http://example.com/news/us-sybase"); final BigdataLiteral createdDate = vf.createLiteral("2011-04-05T12:00:00Z",XSD.DATETIME); final BigdataBNode s1 = vf.createBNode("s1"); // store is empty. assertEquals(0, store.getStatementCount()); final StatementBuffer<Statement> buffer = new StatementBuffer<Statement>( store, capacity); // ground statement. buffer.add(vf.createStatement(SAP, bought, sybase, null/* context */, StatementEnum.Explicit)); // model of that statement (RDF reification). buffer.add(vf.createStatement(s1, RDF.SUBJECT, SAP, null/* context */, StatementEnum.Explicit)); buffer.add(vf.createStatement(s1, RDF.PREDICATE, bought, null/* context */, StatementEnum.Explicit)); buffer.add(vf.createStatement(s1, RDF.OBJECT, sybase, null/* context */, StatementEnum.Explicit)); buffer.add(vf.createStatement(s1, RDF.TYPE, RDF.STATEMENT, null/* context */, StatementEnum.Explicit)); // metadata statements. buffer.add(vf.createStatement(s1, dcSource, newsSybase, null/* context */, StatementEnum.Explicit)); buffer.add(vf.createStatement(s1, dcCreated, createdDate, null/* context */, StatementEnum.Explicit)); // flush the buffer. buffer.flush(); // the statements are now in the store. assertEquals(7, store.getStatementCount()); assertTrue(store.hasStatement(SAP, bought, sybase)); assertTrue(store.hasStatement(s1, RDF.SUBJECT, SAP)); assertTrue(store.hasStatement(s1, RDF.PREDICATE, bought)); assertTrue(store.hasStatement(s1, RDF.OBJECT, sybase)); assertTrue(store.hasStatement(s1, RDF.TYPE, RDF.STATEMENT)); assertTrue(store.hasStatement(s1, dcSource, newsSybase)); assertTrue(store.hasStatement(s1, dcCreated, createdDate)); } finally { store.__tearDownUnitTest(); } }
Example 9
Source File: TestTripleStore.java From database with GNU General Public License v2.0 | 4 votes |
/** * Unit test presents an array of {@link BigdataValue}s that contains * duplicates and verifies that the assigned term identifiers are * consistent. */ public void test_addTermsFiltersDuplicates() { final AbstractTripleStore store = getStore(); try { final BigdataValueFactory valueFactory = store.getValueFactory(); final BigdataURI x = valueFactory.createURI("http://www.foo.org/x"); final BigdataURI y = valueFactory.createURI("http://www.foo.org/y"); final BigdataLiteral z = valueFactory.createLiteral("z"); final BigdataBNode b = valueFactory.createBNode(); final BigdataBNode c = valueFactory.createBNode("_c"); // add terms - lots of duplicates here. store.addTerms(new BigdataValue[] { x, y, b, c, x, b, z, z, c, y, x, }); // none are NULL. assertNotSame(x.getIV(),NULL); assertNotSame(y.getIV(),NULL); assertNotSame(z.getIV(),NULL); assertNotSame(b.getIV(),NULL); assertNotSame(c.getIV(),NULL); // all distinct. assertNotSame(x.getIV(), y.getIV()); assertNotSame(x.getIV(), z.getIV()); assertNotSame(x.getIV(), b.getIV()); assertNotSame(x.getIV(), c.getIV()); assertNotSame(y.getIV(), z.getIV()); assertNotSame(y.getIV(), b.getIV()); assertNotSame(y.getIV(), c.getIV()); assertNotSame(z.getIV(), b.getIV()); assertNotSame(z.getIV(), c.getIV()); assertNotSame(b.getIV(), c.getIV()); // correct type of term identifier was assigned. assertTrue(x.getIV().isURI()); assertTrue(y.getIV().isURI()); assertTrue(z.getIV().isLiteral()); assertTrue(b.getIV().isBNode()); assertTrue(c.getIV().isBNode()); // reverse lookup is consistent with the assigned term identifiers. assertEquals(x,store.getTerm(x.getIV())); assertEquals(y,store.getTerm(y.getIV())); assertEquals(z,store.getTerm(z.getIV())); assertTrue(store.getTerm(b.getIV()) instanceof BNode); assertTrue(store.getTerm(c.getIV()) instanceof BNode); } finally { store.__tearDownUnitTest(); } }
Example 10
Source File: TestStatementIdentifiers.java From database with GNU General Public License v2.0 | 4 votes |
/** * Tests the correct rejection of cycles within statements about statements. */ public void test_correctRejection_cycles02() { AbstractTripleStore store = getStore(); try { if (!store.isStatementIdentifiers()) { log.warn("Statement identifiers are not enabled"); return; } final BigdataValueFactory valueFactory = store.getValueFactory(); final BigdataURI B = valueFactory.createURI("http://www.foo.org/B"); final BigdataURI rdfType = valueFactory.createURI(RDF.TYPE.stringValue()); final BigdataBNode sid1 = valueFactory.createBNode("_S1"); final BigdataBNode sid2 = valueFactory.createBNode("_S2"); /* * Note: Do NOT add the SIDs in advance to the lexicon. The will be * assigned blank node term identifiers rather than statement term * identifiers (SIDs). These differ in their bit pattern on the * lower two bits. */ // store.addTerms(new BigdataValue[] { B, rdfType, sid1, sid2 }); { StatementBuffer buf = new StatementBuffer(store, 100/* capacity */); /* * Flush to the database, resolving statement identifiers as * necessary. */ try { // a cycle with a period of one. buf.add(sid2, RDF.TYPE, B); buf.add(sid1, RDF.SUBJECT, sid2); buf.add(sid1, RDF.PREDICATE, RDF.TYPE); buf.add(sid1, RDF.OBJECT, B); buf.add(sid1, RDF.TYPE, B); buf.add(sid2, RDF.SUBJECT, sid1); buf.add(sid2, RDF.PREDICATE, RDF.TYPE); buf.add(sid2, RDF.OBJECT, B); buf.flush(); fail("Expecting: "+UnificationException.class); } catch(UnificationException ex) { System.err.println("Ignoring expected exception: "+ex); } } } finally { store.__tearDownUnitTest(); } }
Example 11
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 12
Source File: TestTicket1893.java From database with GNU General Public License v2.0 | 4 votes |
/** * case 20: * INLINE_TEXT_LITERALS is false * INLINE_XSD_DATATYPE_LITERALS is false * data entered via SPARQL UPDATE */ public void test_20() throws Exception { final String namespace = "test" + UUID.randomUUID(); final BigdataSailRepositoryConnection cxn = prepareTest(namespace, false /*inlineTextLiterals*/ , false /*inlineXSDDatatypeLiterals*/); insertSparql(cxn); BigdataValueFactory vf = cxn.getValueFactory(); BigdataValue[] values = new BigdataValue[]{ vf.createURI("http://s"), vf.createLiteral("1", XMLSchema.INTEGER), vf.createLiteral(2), vf.createLiteral("3.0", XMLSchema.DECIMAL), vf.createLiteral(4.0), vf.createLiteral(true), vf.createLiteral(false), vf.createLiteral("plain string"), vf.createLiteral("datatyped string", XMLSchema.STRING), vf.createLiteral("english string", "en"), vf.createBNode("_:s1"), vf.createBNode("_:s2"), }; cxn.getTripleStore().getLexiconRelation().addTerms(values, values.length, true /* readOnly */); assertFalse(values[0].getIV().isInline()); // http://s assertFalse(values[1].getIV().isInline()); // 1 assertFalse(values[2].getIV().isInline()); // "2"^^xsd:int assertFalse(values[3].getIV().isInline()); // 3.0 assertFalse(values[4].getIV().isInline()); // "4.0"^^xsd:double assertFalse(values[5].getIV().isInline()); // true assertFalse(values[6].getIV().isInline()); // "false"^^xsd:boolean assertFalse(values[7].getIV().isInline()); // "plain string" assertFalse(values[8].getIV().isInline()); // "datatyped string"^^xsd:string assertFalse(values[9].getIV().isInline()); // "english string"@en endTest(cxn); }
Example 13
Source File: BigdataSPARQLResultsJSONParser.java From database with GNU General Public License v2.0 | 4 votes |
protected Value parseValue(final String bindingStr, final JsonParser jp) throws QueryResultParseException, JsonParseException, IOException { String lang = null; String type = null; String datatype = null; String value = null; // added for Sids support final Map<String, Value> sid = new LinkedHashMap<String, Value>(); while (jp.nextToken() != JsonToken.END_OBJECT) { if (jp.getCurrentToken() != JsonToken.FIELD_NAME) { throw new QueryResultParseException("Did not find value attribute under " + bindingStr + " field", jp.getCurrentLocation().getLineNr(), jp.getCurrentLocation().getColumnNr()); } String fieldName = jp.getCurrentName(); // move to the value token jp.nextToken(); // set the appropriate state variable if (TYPE.equals(fieldName)) { type = jp.getText(); } else if (XMLLANG.equals(fieldName)) { lang = jp.getText(); } else if (DATATYPE.equals(fieldName)) { datatype = jp.getText(); } else if (VALUE.equals(fieldName)) { value = jp.getText(); } // added for Sids support else if (jp.getCurrentToken() == JsonToken.START_OBJECT) { sid.put(fieldName, parseValue(bindingStr, jp)); } else { throw new QueryResultParseException("Unexpected field name: " + fieldName, jp.getCurrentLocation().getLineNr(), jp.getCurrentLocation().getColumnNr()); } } // added for Sids support if (type.equals(SID)) { final Resource s = (Resource) sid.get(SUBJECT); final URI p = (URI) sid.get(PREDICATE); final Value o = (Value) sid.get(OBJECT); final Resource c = (Resource) sid.get(CONTEXT); if (s == null) { throw new QueryResultParseException("Missing subject for statement: " + bindingStr, jp.getCurrentLocation().getLineNr(), jp.getCurrentLocation().getColumnNr()); } if (p == null) { throw new QueryResultParseException("Missing predicate for statement: " + bindingStr, jp.getCurrentLocation().getLineNr(), jp.getCurrentLocation().getColumnNr()); } if (o == null) { throw new QueryResultParseException("Missing object for statement: " + bindingStr, jp.getCurrentLocation().getLineNr(), jp.getCurrentLocation().getColumnNr()); } final BigdataValueFactory valueFactory = (BigdataValueFactory) super.valueFactory; final BigdataStatement stmt = valueFactory.createStatement(s, p, o, c); return valueFactory.createBNode(stmt); } return parseValue(type, value, lang, datatype); }
Example 14
Source File: TestTripleStore.java From database with GNU General Public License v2.0 | 2 votes |
/** * Simple test of batch insertion of terms into the lexicon. */ public void test_insertTerms() { final AbstractTripleStore store = getStore(); try { final BigdataValueFactory valueFactory = store.getValueFactory(); final BigdataValue[] terms = new BigdataValue[] {// valueFactory.createURI("http://www.bigdata.com"),// valueFactory.createURI(RDF.TYPE.stringValue()),// valueFactory.createURI(RDFS.SUBCLASSOF.stringValue()),// valueFactory.createURI(XMLSchema.DECIMAL.stringValue()),// valueFactory.createLiteral("abc"),// valueFactory.createLiteral("abc", XMLSchema.STRING),// valueFactory.createLiteral("abc", "en"),// valueFactory.createBNode(UUID.randomUUID().toString()),// valueFactory.createBNode("a12") // }; store.addTerms(terms); final boolean storeBlankNodes = store.getLexiconRelation().isStoreBlankNodes(); for (int i = 0; i < terms.length; i++) { // verify set by side-effect on batch insert. assertNotSame(NULL, terms[i].getIV()); // save & clear final IV termId = terms[i].getIV(); terms[i].clearInternalValue(); if (storeBlankNodes || !(terms[i] instanceof BNode)) { // check the forward mapping (term -> id) assertEquals("forward mapping", termId, store .getIV(terms[i])); // verify set by side effect. assertEquals(termId, terms[i].getIV()); } // check the reverse mapping (id -> term) if (terms[i] instanceof BNode) { // the bnode ID is not preserved. assertTrue(store.getTerm(termId) instanceof BNode); } else { assertEquals("reverse mapping", terms[i], store .getTerm(termId)); } } if(log.isInfoEnabled()) { log.info(DumpLexicon .dump(store.getLexiconRelation())); } /* * verify that we can detect literals by examining the term * identifier. */ assertTrue(store.getIV(new LiteralImpl("abc")).isLiteral()); assertTrue(store.getIV(new LiteralImpl("abc",XMLSchema.STRING)).isLiteral()); assertTrue(store.getIV(new LiteralImpl("abc", "en")).isLiteral()); assertFalse(store.getIV(new URIImpl("http://www.bigdata.com")).isLiteral()); assertFalse(store.getIV(RDF.TYPE).isLiteral()); // assertFalse(VTE.isLiteral(store.getIV(new BNodeImpl(UUID.randomUUID().toString())).getTermId())); // assertFalse(VTE.isLiteral(store.getIV(new BNodeImpl("a12")).getTermId())); } finally { store.__tearDownUnitTest(); } }
Example 15
Source File: TestStatementIdentifiers.java From database with GNU General Public License v2.0 | 2 votes |
/** * Tests the correct rejection of a statement about itself. */ public void test_correctRejection_cycles01() { AbstractTripleStore store = getStore(); try { if (!store.isStatementIdentifiers()) { log.warn("Statement identifiers are not enabled"); return; } final BigdataValueFactory valueFactory = store.getValueFactory(); final BigdataURI A = valueFactory.createURI("http://www.foo.org/A"); final BigdataURI rdfType = valueFactory.createURI(RDF.TYPE.stringValue()); final BigdataBNode sid1 = valueFactory.createBNode("_S1"); /* * Note: Do NOT add the SIDs in advance to the lexicon. The will be * assigned blank node term identifiers rather than statement term * identifiers (SIDs). These differ in their bit pattern on the * lower two bits. */ // store.addTerms(new BigdataValue[] { A, rdfType, sid1 }); { StatementBuffer buf = new StatementBuffer(store, 100/* capacity */); // statement about itself is a cycle. buf.add(sid1, RDF.TYPE, A); buf.add(sid1, RDF.SUBJECT, sid1); buf.add(sid1, RDF.PREDICATE, RDF.TYPE); buf.add(sid1, RDF.OBJECT, A); /* * Flush to the database, resolving statement identifiers as * necessary. */ try { buf.flush(); fail("Expecting: " + UnificationException.class); } catch (UnificationException ex) { System.err.println("Ignoring expected exception: " + ex); } } } finally { store.__tearDownUnitTest(); } }
Example 16
Source File: TestStatementIdentifiers.java From database with GNU General Public License v2.0 | 2 votes |
/** * Tests the correct rejection when the same blank node is used in the * context position of more than one statement. */ public void test_correctRejection_unificationError() { AbstractTripleStore store = getStore(); try { if (!store.isStatementIdentifiers()) { log.warn("Statement identifiers are not enabled"); return; } final BigdataValueFactory f = store.getValueFactory(); final BigdataURI A = f.createURI("http://www.foo.org/A"); final BigdataURI B = f.createURI("http://www.foo.org/B"); final BigdataURI C = f.createURI("http://www.foo.org/C"); final BigdataURI rdfType = f.asValue(RDF.TYPE); final BigdataBNode sid1 = f.createBNode("_S1"); StatementBuffer buf = new StatementBuffer(store, 100/* capacity */); /* * Flush to the database, resolving statement identifiers as * necessary. */ try { // same blank node in both two distinct statement is an error. buf.add(A, RDF.TYPE, C); buf.add(sid1, RDF.SUBJECT, A); buf.add(sid1, RDF.PREDICATE, RDF.TYPE); buf.add(sid1, RDF.OBJECT, C); buf.add(B, RDF.TYPE, C); buf.add(sid1, RDF.SUBJECT, B); buf.add(sid1, RDF.PREDICATE, RDF.TYPE); buf.add(sid1, RDF.OBJECT, C); buf.flush(); fail("Expecting: "+UnificationException.class); } catch(UnificationException ex) { System.err.println("Ignoring expected exception: "+ex); } } finally { store.__tearDownUnitTest(); } }