/** * Thread-local object for constructing keys for the lexicon. */ public LexiconKeyBuilder getLexiconKeyBuilder() { /* * FIXME We should save off a reference to this to reduce heap churn * and then use that reference in this class. */ return new LexiconKeyBuilder(getKeyBuilder()); }
return uri2key(term); return languageCodeLiteral2key(languageCode, text); return datatypeLiteral2key(datatypeUri, text); return plainLiteral2key(text); return blankNode2Key(bnodeId);
/** * Return the unsigned byte[] key for an RDF {@link Value}. * * @param obj * The RDF {@link Value}. */ @Override public byte[] serializeKey(Object obj) { return getLexiconKeyBuilder().value2Key((Value)obj); }
/** * Test verifies the ordering among URIs, Literals, and BNodes. This * ordering is important when batching terms of these different types into * the term index since you want to insert the type types according to this * order for the best performance. */ public void test_termTypeOrder() { /* * one key of each type. the specific values for the types do not matter * since we are only interested in the relative order between those * types in this test. */ final byte[] k1 = fixture.uri2key("http://www.cognitiveweb.org"); final byte[] k2 = fixture.plainLiteral2key("hello world!"); final byte[] k3 = fixture.blankNode2Key("a12"); assertTrue(BytesUtil.compareBytes(k1, k2)<0); assertTrue(BytesUtil.compareBytes(k2, k3)<0); }
public void test_plain_vs_languageCode_literal() { final String en = "en"; // String de = "de"; final String lit1 = "abc"; // String lit2 = "abc"; // String lit3 = "abce"; // final Literal a = new LiteralImpl("foo"); // final Literal b = new LiteralImpl("foo", "en"); final byte[] k1 = fixture.plainLiteral2key(lit1); final byte[] k2 = fixture.languageCodeLiteral2key(en, lit1); // not encoded onto the same key. assertFalse(BytesUtil.bytesEqual(k1, k2)); // the plain literals are ordered before the language code literals. assertTrue(BytesUtil.compareBytes(k1, k2)<0); }
/** * Verify an unknown datatype URI is coded. */ public void test_datatype_unknown() { fixture.datatypeLiteral2key(new URIImpl("http://www.bigdata.com/foo"), "foo"); }
.newUnicodeInstance(properties); final LexiconKeyBuilder lexKeyBuilder = new LexiconKeyBuilder( keyBuilder); final byte[] newValKey = lexKeyBuilder.value2Key(newValue); final byte[] oldValKey = lexKeyBuilder.value2Key(oldValue);
public void test_plainLiteral() { final String lit1 = "abc"; final String lit2 = "abcd"; final String lit3 = "abcde"; final byte[] k1 = fixture.plainLiteral2key(lit1); final byte[] k2 = fixture.plainLiteral2key(lit2); final byte[] k3 = fixture.plainLiteral2key(lit3); if (log.isInfoEnabled()) { log.info("k1(" + lit1 + ") = " + BytesUtil.toString(k1)); log.info("k2(" + lit2 + ") = " + BytesUtil.toString(k2)); log.info("k3(" + lit3 + ") = " + BytesUtil.toString(k3)); } assertTrue(BytesUtil.compareBytes(k1, k2)<0); assertTrue(BytesUtil.compareBytes(k2, k3)<0); }
public void test_blankNode() { final String id1 = "_12"; final String id2 = "_abc"; final String id3 = "abc"; final byte[] k1 = fixture.blankNode2Key(id1); final byte[] k2 = fixture.blankNode2Key(id2); final byte[] k3 = fixture.blankNode2Key(id3); if (log.isInfoEnabled()) { log.info("k1(bnodeId:" + id1 + ") = " + BytesUtil.toString(k1)); log.info("k2(bnodeId:" + id2 + ") = " + BytesUtil.toString(k2)); log.info("k3(bnodeId:" + id3 + ") = " + BytesUtil.toString(k3)); } assertTrue(BytesUtil.compareBytes(k1, k2)<0); assertTrue(BytesUtil.compareBytes(k2, k3)<0); }
public void test_uri() { final String uri1 = "http://www.cognitiveweb.org"; final String uri2 = "http://www.cognitiveweb.org/a"; final String uri3 = "http://www.cognitiveweb.com/a"; final byte[] k1 = fixture.uri2key(uri1); final byte[] k2 = fixture.uri2key(uri2); final byte[] k3 = fixture.uri2key(uri3); if (log.isInfoEnabled()) { log.info("k1(" + uri1 + ") = " + BytesUtil.toString(k1)); log.info("k2(" + uri2 + ") = " + BytesUtil.toString(k2)); log.info("k3(" + uri3 + ") = " + BytesUtil.toString(k3)); } // subdirectory sorts after root directory. assertTrue(BytesUtil.compareBytes(k1, k2)<0); // .com extension sorts before .org assertTrue(BytesUtil.compareBytes(k2, k3)>0); }
public void test_languageCodeLiteral() { final String en = "en"; final String de = "de"; final String lit1 = "abc"; final String lit2 = "abc"; final String lit3 = "abce"; final byte[] k1 = fixture.languageCodeLiteral2key(en, lit1); final byte[] k2 = fixture.languageCodeLiteral2key(de, lit2); final byte[] k3 = fixture.languageCodeLiteral2key(de, lit3); if (log.isInfoEnabled()) { log.info("k1(en:" + lit1 + ") = " + BytesUtil.toString(k1)); log.info("k2(de:" + lit2 + ") = " + BytesUtil.toString(k2)); log.info("k3(de:" + lit3 + ") = " + BytesUtil.toString(k3)); } // "en" sorts after "de". assertTrue(BytesUtil.compareBytes(k1, k2)>0); // en:abc != de:abc assertTrue(BytesUtil.compareBytes(k1, k2) != 0); assertTrue(BytesUtil.compareBytes(k2, k3)<0); }
/** * Test verifies the ordering among URIs, Literals, and BNodes. This * ordering is important when batching terms of these different types into * the term index since you want to insert the type types according to this * order for the best performance. */ public void test_termTypeOrder() { /* * one key of each type. the specific values for the types do not matter * since we are only interested in the relative order between those * types in this test. */ final byte[] k1 = fixture.uri2key("http://www.cognitiveweb.org"); final byte[] k2 = fixture.plainLiteral2key("hello world!"); final byte[] k3 = fixture.blankNode2Key("a12"); assertTrue(BytesUtil.compareBytes(k1, k2)<0); assertTrue(BytesUtil.compareBytes(k2, k3)<0); }
/** * Verify an unknown datatype URI is coded. */ public void test_datatype_unknown() { fixture.datatypeLiteral2key(new URIImpl("http://www.bigdata.com/foo"), "foo"); }
public void test_plain_vs_languageCode_literal() { final String en = "en"; // String de = "de"; final String lit1 = "abc"; // String lit2 = "abc"; // String lit3 = "abce"; // final Literal a = new LiteralImpl("foo"); // final Literal b = new LiteralImpl("foo", "en"); final byte[] k1 = fixture.plainLiteral2key(lit1); final byte[] k2 = fixture.languageCodeLiteral2key(en, lit1); // not encoded onto the same key. assertFalse(BytesUtil.bytesEqual(k1, k2)); // the plain literals are ordered before the language code literals. assertTrue(BytesUtil.compareBytes(k1, k2)<0); }
.newUnicodeInstance(properties); final LexiconKeyBuilder lexKeyBuilder = new LexiconKeyBuilder( keyBuilder); final byte[] newValKey = lexKeyBuilder.value2Key(newValue); final byte[] oldValKey = lexKeyBuilder.value2Key(oldValue);
public void test_plainLiteral() { final String lit1 = "abc"; final String lit2 = "abcd"; final String lit3 = "abcde"; final byte[] k1 = fixture.plainLiteral2key(lit1); final byte[] k2 = fixture.plainLiteral2key(lit2); final byte[] k3 = fixture.plainLiteral2key(lit3); if (log.isInfoEnabled()) { log.info("k1(" + lit1 + ") = " + BytesUtil.toString(k1)); log.info("k2(" + lit2 + ") = " + BytesUtil.toString(k2)); log.info("k3(" + lit3 + ") = " + BytesUtil.toString(k3)); } assertTrue(BytesUtil.compareBytes(k1, k2)<0); assertTrue(BytesUtil.compareBytes(k2, k3)<0); }
public void test_blankNode() { final String id1 = "_12"; final String id2 = "_abc"; final String id3 = "abc"; final byte[] k1 = fixture.blankNode2Key(id1); final byte[] k2 = fixture.blankNode2Key(id2); final byte[] k3 = fixture.blankNode2Key(id3); if (log.isInfoEnabled()) { log.info("k1(bnodeId:" + id1 + ") = " + BytesUtil.toString(k1)); log.info("k2(bnodeId:" + id2 + ") = " + BytesUtil.toString(k2)); log.info("k3(bnodeId:" + id3 + ") = " + BytesUtil.toString(k3)); } assertTrue(BytesUtil.compareBytes(k1, k2)<0); assertTrue(BytesUtil.compareBytes(k2, k3)<0); }
public void test_uri() { final String uri1 = "http://www.cognitiveweb.org"; final String uri2 = "http://www.cognitiveweb.org/a"; final String uri3 = "http://www.cognitiveweb.com/a"; final byte[] k1 = fixture.uri2key(uri1); final byte[] k2 = fixture.uri2key(uri2); final byte[] k3 = fixture.uri2key(uri3); if (log.isInfoEnabled()) { log.info("k1(" + uri1 + ") = " + BytesUtil.toString(k1)); log.info("k2(" + uri2 + ") = " + BytesUtil.toString(k2)); log.info("k3(" + uri3 + ") = " + BytesUtil.toString(k3)); } // subdirectory sorts after root directory. assertTrue(BytesUtil.compareBytes(k1, k2)<0); // .com extension sorts before .org assertTrue(BytesUtil.compareBytes(k2, k3)>0); }
public void test_languageCodeLiteral() { final String en = "en"; final String de = "de"; final String lit1 = "abc"; final String lit2 = "abc"; final String lit3 = "abce"; final byte[] k1 = fixture.languageCodeLiteral2key(en, lit1); final byte[] k2 = fixture.languageCodeLiteral2key(de, lit2); final byte[] k3 = fixture.languageCodeLiteral2key(de, lit3); if (log.isInfoEnabled()) { log.info("k1(en:" + lit1 + ") = " + BytesUtil.toString(k1)); log.info("k2(de:" + lit2 + ") = " + BytesUtil.toString(k2)); log.info("k3(de:" + lit3 + ") = " + BytesUtil.toString(k3)); } // "en" sorts after "de". assertTrue(BytesUtil.compareBytes(k1, k2)>0); // en:abc != de:abc assertTrue(BytesUtil.compareBytes(k1, k2) != 0); assertTrue(BytesUtil.compareBytes(k2, k3)<0); }
return uri2key(term); return languageCodeLiteral2key(languageCode, text); return datatypeLiteral2key(datatypeUri, text); return plainLiteral2key(text); return blankNode2Key(bnodeId);