Java Code Examples for com.bigdata.rdf.model.BigdataValueFactory#createLiteral()
The following examples show how to use
com.bigdata.rdf.model.BigdataValueFactory#createLiteral() .
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: GeoSpatialLiteralExtension.java From database with GNU General Public License v2.0 | 6 votes |
/** * Decodes an xsd:integer into an n-dimensional string of the form * <int_1>#...#<int_n>. * * Implements transformation G->A. */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public V asValue(final LiteralExtensionIV iv, final BigdataValueFactory vf) { // get the components represented by the IV (which must be of type // xsd:integer (G->C) final long[] componentsAsLongArr = asLongArray(iv); // convert long array to components array final Object[] componentArr = longArrAsComponentArr(componentsAsLongArr); // set up the component and merge them into a string (C->B) final String litStr = litSerializer.fromComponents(componentArr); // setup a literal carrying the component string (B->A) return (V) vf.createLiteral(litStr, datatype); }
Example 2
Source File: TestTicket1893.java From database with GNU General Public License v2.0 | 5 votes |
/** * case 18: * INLINE_TEXT_LITERALS is true * INLINE_XSD_DATATYPE_LITERALS is true * data entered via SPARQL UPDATE */ public void test_18() throws Exception { final String namespace = "test" + UUID.randomUUID(); final BigdataSailRepositoryConnection cxn = prepareTest(namespace, true /*inlineTextLiterals*/ , true /*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"), }; cxn.getTripleStore().getLexiconRelation().addTerms(values, values.length, true /* readOnly */); assertTrue(values[0].getIV().isInline()); // http://s assertTrue(values[1].getIV().isInline()); // 1 assertTrue(values[2].getIV().isInline()); // "2"^^xsd:int assertTrue(values[3].getIV().isInline()); // 3.0 assertTrue(values[4].getIV().isInline()); // "4.0"^^xsd:double assertTrue(values[5].getIV().isInline()); // true assertTrue(values[6].getIV().isInline()); // "false"^^xsd:boolean assertTrue(values[7].getIV().isInline()); // "plain string" assertTrue(values[8].getIV().isInline()); // "datatyped string"^^xsd:string assertTrue(values[9].getIV().isInline()); // "english string"@en endTest(cxn); }
Example 3
Source File: XsdUnsignedLongBOp.java From database with GNU General Public License v2.0 | 5 votes |
public IV get(final IBindingSet bs) { final IV iv = getAndCheckBound(0, bs); if (log.isDebugEnabled()) { log.debug(iv); } final Value val = asValue(iv); if (log.isDebugEnabled()) { log.debug(val); } // use to create my simple literals final BigdataValueFactory vf = getValueFactory(); try { if (val instanceof Literal) { final Literal lit = (Literal) val; if (lit.getDatatype() != null && lit.getDatatype().equals(XSD.UNSIGNED_LONG)) { // if xsd:unsignedLong literal return it return iv; } else { final BigInteger valAsBigInt = new BigInteger(lit.getLabel()); if (valAsBigInt.compareTo(MIN_UNSIGNED_LONG)>=0 && valAsBigInt.compareTo(MAX_UNSIGNED_LONG)<=0) { final BigdataLiteral str = vf.createLiteral(String.valueOf(valAsBigInt.toString()), XSD.UNSIGNED_LONG); return super.asIV(str, bs); } } } } catch (Exception e) { // exception handling following } throw new SparqlTypeErrorException(); // fallback }
Example 4
Source File: TestBind.java From database with GNU General Public License v2.0 | 5 votes |
/** * Unit test for Constant/2 semantics. The value of the constant needs to be * propagated onto the named variable. */ public void test_bind06() { final BigdataValueFactory f = BigdataValueFactoryImpl .getInstance(getName()); final BigdataLiteral lit = f.createLiteral(1); final IVariable<?> x = Var.var("x"); final IV iv1 = new XSDNumericIV<BigdataLiteral>(1); final IV iv2 = new XSDNumericIV<BigdataLiteral>(1); final IV iv3 = new XSDNumericIV<BigdataLiteral>(1); final IConstant<?> val1 = new Constant(iv1); final IConstant<?> val2 = new Constant(iv2); final IConstant<?> val3 = new Constant(iv3); iv2.setValue((BigdataValue) lit); iv3.setValue((BigdataValue) lit); final ListBindingSet expected = new ListBindingSet(); expected.set(x, val3); final ListBindingSet left = new ListBindingSet(); left.set(x, val1); final ListBindingSet right = new ListBindingSet(); right.set(x, val2); final IBindingSet actual = BOpContext.bind(left, right, //true/*leftIsPipeline*/, null/*constraints*/, null/*varsToKeep*/); assertEquals(expected, actual); assertEquals(iv3.getValue(), ((IV)actual.get(x).get()).getValue()); }
Example 5
Source File: TestEncodeDecodeXSDDateIVs.java From database with GNU General Public License v2.0 | 5 votes |
/** * Unit test for xsd:dateTime literal encoding. */ public void test_encodeDecodeDateTime() throws Exception { final BigdataValueFactory vf = BigdataValueFactoryImpl.getInstance("test"); final DateTimeExtension<BigdataValue> ext = getDateTimeExtensionGMT(vf); final BigdataLiteral[] dt = { vf.createLiteral("-2015-01-01T10:10:10", XSD.DATETIME), vf.createLiteral("-1000-12-31T00:00:00", XSD.DATETIME), vf.createLiteral("0001-01-01T23:59:59", XSD.DATETIME), vf.createLiteral("9999-12-31T12:12:12", XSD.DATETIME) }; final String[] expected = { "-2015-01-01T10:10:10", "-1000-12-31T00:00:00", "0001-01-01T23:59:59", "9999-12-31T12:12:12" }; // create associated IVs final IV<?, ?>[] e = new IV[dt.length]; for (int i = 0; i < dt.length; i++) { e[i] = ext.createIV(dt[i]); } for (int i = 0; i < e.length; i++) { @SuppressWarnings("rawtypes") final BigdataValue valRoundTrip = ext.asValue((LiteralExtensionIV) e[i], vf); assertEquals(valRoundTrip.toString(), "\"" + expected[i] + ".000Z\"^^<http://www.w3.org/2001/XMLSchema#dateTime>" ); } final IV<?, ?>[] a = doEncodeDecodeTest(e); doComparatorTest(e); }
Example 6
Source File: CompressedTimestampExtension.java From database with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") public V asValue(final LiteralExtensionIV iv, final BigdataValueFactory vf) { AbstractLiteralIV delegate = iv.getDelegate(); if (delegate==null || !(delegate instanceof PackedLongIV)) { throw new IllegalArgumentException(); } final PackedLongIV pIv = (PackedLongIV)delegate; return (V) vf.createLiteral( String.valueOf(pIv.getInlineValue()), CompressedTimestampExtension.COMPRESSED_TIMESTAMP); }
Example 7
Source File: TestEncodeDecodeXSDDateIVs.java From database with GNU General Public License v2.0 | 5 votes |
/** * Unit test for xsd:date literal encoding. */ public void test_encodeDecodeDateLiterals() throws Exception { final BigdataValueFactory vf = BigdataValueFactoryImpl.getInstance("test"); final DateTimeExtension<BigdataValue> ext = getDateTimeExtensionGMT(vf); final BigdataLiteral[] dt = { vf.createLiteral("-2015-01-01", XSD.DATE), vf.createLiteral("-2015-12-31", XSD.DATE), vf.createLiteral("9999-01-01", XSD.DATE), vf.createLiteral("9999-12-31", XSD.DATE) }; // create associated IVs final IV<?, ?>[] e = new IV[dt.length]; for (int i = 0; i < dt.length; i++) { e[i] = ext.createIV(dt[i]); } for (int i = 0; i < e.length; i++) { @SuppressWarnings("rawtypes") final BigdataValue valRoundTrip = ext.asValue((LiteralExtensionIV) e[i], vf); assertEquals(valRoundTrip, dt[i] /* original value */); } final IV<?, ?>[] a = doEncodeDecodeTest(e); doComparatorTest(e); }
Example 8
Source File: TestPackedLongIVs.java From database with GNU General Public License v2.0 | 4 votes |
/** * Test math operations such as +, -, *, /, MIN and MAX over the datatype. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public void testMath() { final BigdataValueFactory vf = BigdataValueFactoryImpl.getInstance(getName() + UUID.randomUUID()); final MockTermIdFactory termIdFactory = new MockTermIdFactory(); final CompressedTimestampExtension<BigdataValue> ext = new CompressedTimestampExtension<BigdataValue>( new IDatatypeURIResolver() { @Override public BigdataURI resolve(final URI uri) { final BigdataURI buri = vf.createURI(uri.stringValue()); buri.setIV(termIdFactory.newTermId(VTE.URI)); return buri; } }); final BigdataValue bvZero = vf.createLiteral("0", CompressedTimestampExtension.COMPRESSED_TIMESTAMP); final LiteralExtensionIV zero = ext.createIV(bvZero); zero.setValue(bvZero); final BigdataValue bfOne = vf.createLiteral("1", CompressedTimestampExtension.COMPRESSED_TIMESTAMP); final LiteralExtensionIV one = ext.createIV(bfOne); one.setValue(bfOne); final BigdataValue bfTen = vf.createLiteral("10", CompressedTimestampExtension.COMPRESSED_TIMESTAMP); final LiteralExtensionIV ten = ext.createIV(bfTen); ten.setValue(bfTen); final BigdataValue bfTwenty = vf.createLiteral("20", CompressedTimestampExtension.COMPRESSED_TIMESTAMP); final LiteralExtensionIV twenty = ext.createIV(bfTwenty); twenty.setValue(bfTwenty); final NumericIV<BigdataLiteral, ?> result10a_int_act = MathUtility.literalMath(zero, ten, MathOp.PLUS); final NumericIV<BigdataLiteral, ?> result10b_int_act = MathUtility.literalMath(twenty, ten, MathOp.MINUS); final NumericIV<BigdataLiteral, ?> result10c_int_act = MathUtility.literalMath(ten, one, MathOp.MULTIPLY); final NumericIV<BigdataLiteral, ?> result10d_dec_act = MathUtility.literalMath(ten, one, MathOp.DIVIDE); final NumericIV<BigdataLiteral, ?> result10e_int_act = MathUtility.literalMath(ten, twenty, MathOp.MIN); final NumericIV<BigdataLiteral, ?> result10f_int_act = MathUtility.literalMath(twenty, ten, MathOp.MIN); final NumericIV<BigdataLiteral, ?> result20a_int_act = MathUtility.literalMath(ten, ten, MathOp.PLUS); final NumericIV<BigdataLiteral, ?> result20b_int_act = MathUtility.literalMath(ten, twenty, MathOp.MAX); final NumericIV<BigdataLiteral, ?> result20c_int_act = MathUtility.literalMath(twenty, ten, MathOp.MAX); final XSDIntegerIV<?> result10_int = new XSDIntegerIV<>(new BigInteger("10")); final XSDDecimalIV<?> result10_dec = new XSDDecimalIV<>(new BigDecimal(new BigInteger("10"))); final XSDIntegerIV<?> result20_int = new XSDIntegerIV<>(new BigInteger("20")); assertEquals(result10_int, result10a_int_act); assertEquals(result10_int, result10b_int_act); assertEquals(result10_int, result10c_int_act); assertEquals(result10_dec, result10d_dec_act); assertEquals(result10_int, result10e_int_act); assertEquals(result10_int, result10f_int_act); assertEquals(result20_int, result20a_int_act); assertEquals(result20_int, result20b_int_act); assertEquals(result20_int, result20c_int_act); }
Example 9
Source File: TestTripleStore.java From database with GNU General Public License v2.0 | 4 votes |
/** * Unit test verifies that {@link BigdataValue}s whose term identifiers * have already been assigned are unchanged by * {@link LexiconRelation#addTerms(BigdataValue[], int, boolean)}. * <p> * Note: {@link BNode}s are not tested for this property since they will be * assigned a new term identifier each time. Blank nodes are ONLY made * self-consistent within a canonicalizing mapping imposed for some blank * node context, e.g., a source document that is being parsed. */ public void test_addTermsFiltersAlreadyAssigned() { 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"); // add terms - lots of duplicates here. store.addTerms(new BigdataValue[] { x, y, x, z, y, z}); final IV _x = x.getIV(); final IV _y = y.getIV(); final IV _z = z.getIV(); // none are NULL. assertNotSame(x.getIV(),NULL); assertNotSame(y.getIV(),NULL); assertNotSame(z.getIV(),NULL); // all distinct. assertNotSame(x.getIV(), y.getIV()); assertNotSame(x.getIV(), z.getIV()); assertNotSame(y.getIV(), z.getIV()); // correct type of term identifier was assigned. assertTrue(x.getIV().isURI()); assertTrue(y.getIV().isURI()); assertTrue(z.getIV().isLiteral()); // 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())); /* * re-adding the same term instances does not change their term * identifer assignments. */ // add terms - lots of duplicates here. store.addTerms(new BigdataValue[] { x, y, x, z, y, z}); assertEquals(_x, x.getIV()); assertEquals(_y, y.getIV()); assertEquals(_z, z.getIV()); /* * verify that re-adding distinct term identifier instances having * the same data assigns the same term identifiers. */ { final BigdataURI x1 = valueFactory.createURI("http://www.foo.org/x"); final BigdataURI y1 = valueFactory.createURI("http://www.foo.org/y"); final BigdataLiteral z1 = valueFactory.createLiteral("z"); // add terms - lots of duplicates here. store.addTerms(new BigdataValue[] { x1, y1, x1, z1, y1, z1}); // same term identifiers were assigned. assertEquals(_x, x1.getIV()); assertEquals(_y, y1.getIV()); assertEquals(_z, z1.getIV()); } } finally { store.__tearDownUnitTest(); } }
Example 10
Source File: TestEncodeDecodeKeys.java From database with GNU General Public License v2.0 | 4 votes |
/** * Unit test for round-trip of derived numeric values. */ public void test_encodeDecodeDerivedNumerics() throws Exception { final BigdataValueFactory vf = BigdataValueFactoryImpl.getInstance("test"); final DerivedNumericsExtension<BigdataValue> ext = new DerivedNumericsExtension<BigdataValue>(new IDatatypeURIResolver() { public BigdataURI resolve(URI uri) { final BigdataURI buri = vf.createURI(uri.stringValue()); buri.setIV(newTermId(VTE.URI)); return buri; } }); final BigdataLiteral[] dt = { vf.createLiteral("1", XSD.POSITIVE_INTEGER), vf.createLiteral("-1", XSD.NEGATIVE_INTEGER), vf.createLiteral("-1", XSD.NON_POSITIVE_INTEGER), vf.createLiteral("1", XSD.NON_NEGATIVE_INTEGER), vf.createLiteral("0", XSD.NON_POSITIVE_INTEGER), vf.createLiteral("0", XSD.NON_NEGATIVE_INTEGER), }; final IV<?, ?>[] e = new IV[dt.length]; for (int i = 0; i < dt.length; i++) { e[i] = ext.createIV(dt[i]); } final IV<?, ?>[] a = doEncodeDecodeTest(e); if (log.isInfoEnabled()) { for (int i = 0; i < e.length; i++) { log.info("original: " + dt[i]); log.info("asValue : " + ext.asValue((LiteralExtensionIV<?>) e[i], vf)); log.info("decoded : " + ext.asValue((LiteralExtensionIV<?>) a[i], vf)); log.info(""); } // log.info(svf.createLiteral( // df.newXMLGregorianCalendar("2001-10-26T21:32:52.12679"))); } doComparatorTest(e); }
Example 11
Source File: TestTermIVComparator.java From database with GNU General Public License v2.0 | 4 votes |
public void test_termIdComparator() { final TermId<?> lmin = new TermId<BigdataURI>(VTE.URI, Long.MIN_VALUE); final TermId<?> lm1 = new TermId<BigdataURI>(VTE.URI, -1L); final TermId<?> l0 = new TermId<BigdataURI>(VTE.URI, 0L); final TermId<?> lp1 = new TermId<BigdataURI>(VTE.URI, 1L); final TermId<?> lmax = new TermId<BigdataURI>(VTE.URI, Long.MAX_VALUE); final BigdataValueFactory f = BigdataValueFactoryImpl .getInstance(getName()/*namespace*/); final BigdataValue vmin = f.createLiteral("a"); vmin.setIV( lmin); final BigdataValue vm1 = f.createLiteral("b"); vm1 .setIV( lm1 ); final BigdataValue v0 = f.createLiteral("c"); v0 .setIV( l0 ); final BigdataValue vp1 = f.createLiteral("d"); vp1 .setIV( lp1 ); final BigdataValue vmax = f.createLiteral("e"); vmax.setIV( lmax); // IVs out of order. final TermId<?>[] actualIds = new TermId[] { lm1, lmax, l0, lp1, lmin }; // IVs in order. final TermId<?>[] expectedIds = new TermId[] { lmin, lm1, l0, lp1, lmax }; // values out of order. final BigdataValue[] terms = new BigdataValue[] { vmax, vm1, vmin, v0, vp1 }; /* * Test conversion of longs to unsigned byte[]s using the KeyBuilder and * verify the order on those unsigned byte[]s. */ { final byte[][] keys = new byte[actualIds.length][]; final KeyBuilder keyBuilder = new KeyBuilder(8); for (int i = 0; i < actualIds.length; i++) { keys[i] = keyBuilder.reset().append(actualIds[i].getTermId()) .getKey(); } Arrays.sort(keys, UnsignedByteArrayComparator.INSTANCE); for (int i = 0; i < actualIds.length; i++) { if (log.isInfoEnabled()) log.info(BytesUtil.toString(keys[i])); /* * Decode and verify sorted into the expected order. */ assertEquals(expectedIds[i].getTermId(), KeyBuilder.decodeLong( keys[i], 0)); } } /* * Test unsigned long integer comparator. */ if (log.isInfoEnabled()) log.info("unsorted ids : " + Arrays.toString(actualIds)); Arrays.sort(actualIds); if (log.isInfoEnabled()) { log.info("sorted ids : " + Arrays.toString(actualIds)); log.info("expected ids : " + Arrays.toString(expectedIds)); } assertEquals("ids order", expectedIds, actualIds); /* * Test the term identifier comparator. */ final Comparator<BigdataValue> c = TermIVComparator.INSTANCE; if (log.isInfoEnabled()) log.info("unsorted terms: " + Arrays.toString(terms)); Arrays.sort(terms, c); if (log.isInfoEnabled()) log.info("sorted terms : " + Arrays.toString(terms)); assertTrue("kmin<km1", c.compare(vmin, vm1) < 0); assertTrue("km1<k0", c.compare(vm1, v0) < 0); assertTrue("k0<kp1", c.compare(v0, vp1) < 0); assertTrue("kp1<kmax", c.compare(vp1, vmax) < 0); assertTrue("kmin<kmax", c.compare(vmin, vmax) < 0); }
Example 12
Source File: LangBOp.java From database with GNU General Public License v2.0 | 4 votes |
@Override public IV get(final IBindingSet bs) { final Literal literal = getAndCheckLiteralValue(0, bs); String langTag = literal.getLanguage(); if (langTag == null) { langTag = ""; } final BigdataValueFactory vf = getValueFactory(); final BigdataValue lang = vf.createLiteral(langTag); return super.asIV(lang, bs); }
Example 13
Source File: TestASTBottomUpOptimizer.java From database with GNU General Public License v2.0 | 4 votes |
/** * Slight variation on the structure of the query in the test above which * should not be recognized as a badly designed left join. * * @throws MalformedQueryException */ public void test_wellDesigned03() throws MalformedQueryException { final String queryStr = "" + // "PREFIX : <http://example/>\n" + // "SELECT * \n" + // "{ \n" + // " ?X :name \"paul\" . \n" + // " OPTIONAL {?X :name \"george\" } OPTIONAL { ?X :email ?Z } \n" + // "}"// ; /* * Add the Values used in the query to the lexicon. This makes it * possible for us to explicitly construct the expected AST and * the verify it using equals(). */ final BigdataValueFactory f = store.getValueFactory(); final BigdataURI name = f.createURI("http://example/name"); final BigdataURI email = f.createURI("http://example/email"); final BigdataLiteral paul = f.createLiteral("paul"); final BigdataLiteral george = f.createLiteral("george"); final BigdataValue[] values = new BigdataValue[] { name, email, paul, george }; store.getLexiconRelation() .addTerms(values, values.length, false/* readOnly */); final ASTContainer astContainer = new Bigdata2ASTSPARQLParser() .parseQuery2(queryStr, baseURI); final AST2BOpContext context = new AST2BOpContext(astContainer, store); QueryRoot queryRoot = astContainer.getOriginalAST(); queryRoot = (QueryRoot) new ASTWildcardProjectionOptimizer().optimize( context, new QueryNodeWithBindingSet(queryRoot, null)). getQueryNode(); final QueryRoot expected = BOpUtility.deepCopy(queryRoot); queryRoot = (QueryRoot) new ASTBottomUpOptimizer().optimize( context, new QueryNodeWithBindingSet(queryRoot, null)). getQueryNode(); // Verify NO transform. assertEquals(expected, queryRoot); }
Example 14
Source File: TestASTBottomUpOptimizer.java From database with GNU General Public License v2.0 | 4 votes |
/** * Slight variation on the structure of the query in the test above which * should not be recognized as a badly designed left join. * * @throws MalformedQueryException */ public void test_wellDesigned02() throws MalformedQueryException { final String queryStr = "" + // "PREFIX : <http://example/>\n" + // "SELECT * \n" + // "{ \n" + // " ?X :name \"paul\" . \n" + // " OPTIONAL {?X :name \"george\" . ?X :email ?Z } \n" + // "}"// ; /* * Add the Values used in the query to the lexicon. This makes it * possible for us to explicitly construct the expected AST and * the verify it using equals(). */ final BigdataValueFactory f = store.getValueFactory(); final BigdataURI name = f.createURI("http://example/name"); final BigdataURI email = f.createURI("http://example/email"); final BigdataLiteral paul = f.createLiteral("paul"); final BigdataLiteral george = f.createLiteral("george"); final BigdataValue[] values = new BigdataValue[] { name, email, paul, george }; store.getLexiconRelation() .addTerms(values, values.length, false/* readOnly */); final ASTContainer astContainer = new Bigdata2ASTSPARQLParser() .parseQuery2(queryStr, baseURI); final AST2BOpContext context = new AST2BOpContext(astContainer, store); QueryRoot queryRoot = astContainer.getOriginalAST(); queryRoot = (QueryRoot) new ASTWildcardProjectionOptimizer().optimize( context, new QueryNodeWithBindingSet(queryRoot, null)). getQueryNode(); final QueryRoot expected = BOpUtility.deepCopy(queryRoot); queryRoot = (QueryRoot) new ASTBottomUpOptimizer().optimize( context, new QueryNodeWithBindingSet(queryRoot, null)). getQueryNode(); // Verify NO transform. assertEquals(expected, queryRoot); }
Example 15
Source File: TestASTBottomUpOptimizer.java From database with GNU General Public License v2.0 | 4 votes |
/** * Variant on {@link #test_bottomUpOptimizer_join_scope_1()} where the query * is well designed due to the presence of a shared variable <code>?X</code> * in the intermediate join group. This test verifies that we DO NOT rewrite * the query. */ public void test_wellDesigned01() throws MalformedQueryException { final String queryStr = "" + // "PREFIX : <http://example/>\n" + // "SELECT * \n" + // "{ \n" + // " ?X :name \"paul\" . \n" + // " {?X :name \"george\" . OPTIONAL { ?X :email ?Z } } \n" + // "}"// ; /* * Add the Values used in the query to the lexicon. This makes it * possible for us to explicitly construct the expected AST and * the verify it using equals(). */ final BigdataValueFactory f = store.getValueFactory(); final BigdataURI name = f.createURI("http://example/name"); final BigdataURI email = f.createURI("http://example/email"); final BigdataLiteral paul = f.createLiteral("paul"); final BigdataLiteral george = f.createLiteral("george"); final BigdataValue[] values = new BigdataValue[] { name, email, paul, george }; store.getLexiconRelation() .addTerms(values, values.length, false/* readOnly */); final ASTContainer astContainer = new Bigdata2ASTSPARQLParser() .parseQuery2(queryStr, baseURI); final AST2BOpContext context = new AST2BOpContext(astContainer, store); QueryRoot queryRoot = astContainer.getOriginalAST(); queryRoot = (QueryRoot) new ASTWildcardProjectionOptimizer().optimize( context, new QueryNodeWithBindingSet(queryRoot, null)). getQueryNode(); final QueryRoot expected = BOpUtility.deepCopy(queryRoot); queryRoot = (QueryRoot) new ASTBottomUpOptimizer().optimize( context, new QueryNodeWithBindingSet(queryRoot, null)). getQueryNode(); // Verify NO transform. assertEquals(expected, queryRoot); }
Example 16
Source File: ColorsEnumExtension.java From database with GNU General Public License v2.0 | 3 votes |
/** * Attempt to convert the {@link AbstractLiteralIV#byteValue()} back into * a {@link Color}, and then use the string value of the {@link Color} to * create an RDF literal. */ public V asValue(final LiteralExtensionIV iv, final BigdataValueFactory vf) { final byte b = iv.getDelegate().byteValue(); final Color c = Color.valueOf(b); if (c == null) throw new RuntimeException("bad color got encoded somehow"); return (V) vf.createLiteral(c.toString(), color); }
Example 17
Source File: USDFloatExtension.java From database with GNU General Public License v2.0 | 3 votes |
@SuppressWarnings("unchecked") public V asValue(final LiteralExtensionIV iv, final BigdataValueFactory vf) { final String s = Float.toString(iv.getDelegate().floatValue()); return (V) vf.createLiteral(s, datatype); }
Example 18
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 19
Source File: TestCompletionScan.java From database with GNU General Public License v2.0 | 2 votes |
/** * Unit test for a completion scan. */ public void test_completionScan() { final AbstractTripleStore store = getStore(); try { /* * Populate the KB with some terms. */ { final BigdataValueFactory f = store.getValueFactory(); final BigdataValue[] terms = new BigdataValue[] { f.createLiteral("mingus"), f.createLiteral("minor"), f.createLiteral("minor league"), f.createLiteral("minor threat"), f.createLiteral("minority report"), f.createLiteral("missing report"), }; store.addTerms(terms); } /* * Do a completion scan on "minor". */ { final Set<Literal> expected = new HashSet<Literal>(); expected.add(new LiteralImpl("minor")); expected.add(new LiteralImpl("minor league")); expected.add(new LiteralImpl("minor threat")); expected.add(new LiteralImpl("minority report")); final Iterator<IV> itr = store.getLexiconRelation() .prefixScan(new LiteralImpl("minor")); while(itr.hasNext()) { if(expected.isEmpty()) { fail("Nothing else is expected"); } final IV tid = itr.next(); final Literal lit = (Literal) store.getLexiconRelation() .getTerm(tid); if (log.isInfoEnabled()) log.info("Found: " + lit); if(!expected.remove(lit)) { fail("Not expecting: "+lit); } } if(!expected.isEmpty()) { fail("Additional terms were expected: not found="+expected); } } } finally { store.__tearDownUnitTest(); } }
Example 20
Source File: TestInlining.java From database with GNU General Public License v2.0 | 2 votes |
public void test_epoch() { final Properties properties = getProperties(); // test w/o predefined vocab. properties.setProperty(Options.VOCABULARY_CLASS, MyVocabulary.class .getName()); // test w/o axioms - they imply a predefined vocab. properties.setProperty(Options.AXIOMS_CLASS, NoAxioms.class.getName()); // test w/o the full text index. properties.setProperty(Options.TEXT_INDEX, "false"); // do not inline unicode data. properties.setProperty(Options.MAX_INLINE_TEXT_LENGTH, "0"); // test with the sample extension factory properties.setProperty(Options.EXTENSION_FACTORY_CLASS, SampleExtensionFactory.class.getName()); AbstractTripleStore store = getStore(properties); try { if (!store.isStable()) { /* * We need a restart safe store to test this since otherwise a * term cache could give us a false positive. */ return; } final Collection<BigdataValue> terms = new HashSet<BigdataValue>(); // lookup/add some values. final BigdataValueFactory f = store.getValueFactory(); final BigdataLiteral l1 = f.createLiteral("1", EpochExtension.EPOCH); final BigdataLiteral l2 = f.createLiteral(String.valueOf(System.currentTimeMillis()), EpochExtension.EPOCH); // final BigdataLiteral l3 = f.createLiteral("-100", EpochExtension.EPOCH); final BigdataURI datatype = f.createURI(EpochExtension.EPOCH.stringValue()); terms.add(l1); terms.add(l2); // terms.add(l3); terms.add(datatype); final Map<IV<?,?>, BigdataValue> ids = doAddTermsTest(store, terms); assertTrue(l1.getIV().isInline()); assertTrue(l2.getIV().isInline()); // assertFalse(l3.getIV().isInline()); final LiteralExtensionIV iv1 = (LiteralExtensionIV) l1.getIV(); final LiteralExtensionIV iv2 = (LiteralExtensionIV) l2.getIV(); assertEquals(iv1.getExtensionIV(), datatype.getIV()); assertEquals(iv2.getExtensionIV(), datatype.getIV()); if (store.isStable()) { store.commit(); store = reopenStore(store); // verify same reverse mappings. final Map<IV<?,?>, BigdataValue> ids2 = store.getLexiconRelation() .getTerms(ids.keySet()); assertEquals(ids.size(),ids2.size()); for (Map.Entry<IV<?, ?>, BigdataValue> e : ids.entrySet()) { final IV<?, ?> iv = e.getKey(); if(log.isInfoEnabled()) log.info(iv); assertEquals("Id mapped to a different term? : iv=" + iv, ids.get(iv), ids2.get(iv)); } } } finally { store.__tearDownUnitTest(); } }