Giter Club home page Giter Club logo

kvdict2's Introduction

KVdict2

作用

用于 Python 中加载内存词典的小工具,最主要作用是

  • 节省空间,对于大量python调研工作,python 读取数据的大小是不可接受的。这个词典可以以几乎等同于原始文件大小读入内存。
  • 快速建词典及加载,可以很容易构建一份key-value 词典,快速读取到内存,方便使用。

安装及使用方式

安装

  • 修改 Makefile 中 PythonPath,对应到你的 python 库
  • 执行make
  • 测试:cd output; python benchmark.py 如果执行ok,恭喜你

将数据读入

文件是tab 分割key 和value,则使用如下命令读入。

> python kvdict2.py -f <your_text_input> -b <kvdict2_output_dict>

然后可以用这个命令测试下是否符合预期

> python kvdict2.py -i <kvdict2_output_dict>

输入key,看看输出的value 是否符合预期。

在代码中如何使用。

代码中如下:

# import package.
import kvdict2

...
# initialize.
d = kvdict2.KVDict()
d.load_bin('your_kvdict2_dict')

# seek.
r = d.find(key)
if r None:
    # not found.
else:
    # do what you want to do.

Summary

key-value dict for python.

Installation.

  • change python header path in Makefile:
  • make
  • cd output; python benchmark.py if run ok. you can see the bench mark QPS.

How to use in your python code.

Convert your text data to kvdict2 format.

you can use this command to do:

> python kvdict2.py -f <your_text_input> -b <kvdict2_output_dict>

then if you want to check the dict. you can use this command.

> python kvdict2.py -i <kvdict2_output_dict>

input query to see if output is ok.

Use dict in your python code.

you can use code as:

# import package.
import kvdict2

...
# initialize.
d = kvdict2.KVDict()
d.load_bin('your_kvdict2_dict')

# seek.
r = d.find(key)
if r None:
    # not found.
else:
    # do what you want to do.

kvdict2's People

Contributors

nickgu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.