本文整理汇总了Java中org.fusesource.lmdbjni.Database类的典型用法代码示例。如果您正苦于以下问题:Java Database类的具体用法?Java Database怎么用?Java Database使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Database类属于org.fusesource.lmdbjni包,在下文中一共展示了Database类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: valuesOfKey
import org.fusesource.lmdbjni.Database; //导入依赖的package包/类
public Count valuesOfKey(final Key key, final long cost, final boolean isEstimateOk)
{
index.checkOpen();
if (cost == 0)
return null;
else
{
Ref<Long> counter = new Ref<Long>() {
public Long get() {
Database db = index.keyBucket(key) == 0 ? index.db : index.db2;
try (Cursor cursor = db.openCursor(index.txn().getDbTransaction()))
{
byte[] keyAsBytes = index.keyConverter.toByteArray(key);
Entry entry = cursor.get(CursorOp.SET, keyAsBytes);
if (entry != null)
return cursor.count();
else
return 0l;
}
catch (LMDBException ex)
{
throw new HGException(ex);
}
}};
return new Count(counter, false);
}
}
示例2: checkIndexExisting
import org.fusesource.lmdbjni.Database; //导入依赖的package包/类
boolean checkIndexExisting(String name)
{
if (openIndices.get(name) != null)
return true;
else
{
Database db = null;
try
{
db = env.openDatabase(txn().getDbTransaction(), DefaultIndexImpl.DB_NAME_PREFIX + name, 0);
}
catch (Exception ex)
{
}
if (db != null)
{
try
{
db.close();
}
catch (Throwable t)
{
t.printStackTrace();
}
return true;
}
else
return false;
}
}
示例3: removeIndex
import org.fusesource.lmdbjni.Database; //导入依赖的package包/类
@Override
public void removeIndex(String name)
{
indicesLock.writeLock().lock();
try
{
HGIndex<?, ?> idx = openIndices.get(name);
if (idx != null)
{
idx.close();
openIndices.remove(name);
}
try
{
Database db = env.openDatabase(DefaultIndexImpl.DB_NAME_PREFIX + name);
db.drop(true);
}
catch (Exception e)
{
throw new HGException(e);
}
}
finally
{
indicesLock.writeLock().unlock();
}
}
示例4: query
import org.fusesource.lmdbjni.Database; //导入依赖的package包/类
/**
* Optimized _linear_search_ for the best N documents by cosine similarity.
* Be warned: This will be slow.
*/
public List<Passage> query(Question question) {
// Convert the question to a vector.
float[] query_vector = DenseVectors.mean(
question.memo(Phrase.simpleTokens)
.stream().map(DenseVectors::vectorFor)
.filter(v -> v.isPresent())
.map(v -> v.get())
.collect(Collectors.toList()));
// Now look for (almost) that vector!
// This is a little ugly because we desperately avoid copying.
byte[][] winners = new byte[LEN][];
double[] sims = new double[LEN];
/*try (Transaction tx = wiki_vectors_env.createReadTransaction();
Database doc_vectors = wiki_vectors_env.openDatabase(tx, "wiki-vectors", 0);
BufferCursor cursor = doc_vectors.bufferCursor(tx)) {
cursor.first();
while (cursor.next()) {
double this_sim = sim(query_vector, cursor);
bubble(sims, winners, this_sim, cursor);
}
}*/
try (Transaction tx = wiki_vectors_env.createReadTransaction();
Database doc_vectors = wiki_vectors_env.openDatabase(tx, "wiki-vectors", 0)) {
for (Entry e : doc_vectors.iterate(tx).iterable()) {
double this_sim = DenseVectors.sim(query_vector, KV.asVector(e.getValue()));
if (Double.isFinite(this_sim))
bubble(sims, winners, this_sim, e.getKey(), K);
}
}
// Now get the passages for the top entries.
List<Passage> passages = new ArrayList<>();
for (int i=0; i<K; i++) {
if (winners[i] != null) {
String id = string(winners[i]);
passages.add(new Passage("meandv", "", "", id));
System.out.println("value is : " + id + " sim: " + sims[i]);
}
}
/*try{
Process p = Runtime.getRuntime().exec("python /home/sean/yeshvant/top100vectorSimilarDocs.py " + query );
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while((line = in.readLine())!= null)
{
String[] sim_id = line.split(" ");
passages.add(new Passage("meandv", "", "", sim_id[1]));
System.out.println("value is : "+sim_id[1]);
}
} catch(Exception e) {
e.printStackTrace();
}*/
return fillFromSources(passages);
}
示例5: LMDBMapSet
import org.fusesource.lmdbjni.Database; //导入依赖的package包/类
public LMDBMapSet(Env env, Database db)
{
this.db = db;
this.env = env;
}
示例6: LMDBMap
import org.fusesource.lmdbjni.Database; //导入依赖的package包/类
public LMDBMap(Env env, Database db)
{
this.env = env;
this.db = db;
}