Git Product home page Git Product logo

shellinford-python's Introduction

shellinford

travis-ci.org coveralls.io pyversion latest version license

Shellinford is an implementation of a Wavelet Matrix/Tree succinct data structure for document retrieval.

It is based on shellinford C++ library.

NOTE: This module requires C++11 compiler

Installation

$ pip install shellinford

Usage

Create a new FM-index instance

>>> import shellinford
>>> fm = shellinford.FMIndex()
  • shellinford.Shellinford([use_wavelet_tree=True, filename=None])
    • When given a filename, Shellinford loads FM-index data from the file

Build FM-index

>>> fm.build(['Milky Holmes', 'Sherlock "Sheryl" Shellingford', 'Milky'], 'milky.fm')
  • build([docs, filename])
    • When given a filename, Shellinford stores FM-index data to the file

Search word from FM-index

>>> for doc in fm.search('Milky'):
>>>     print('doc_id:', doc.doc_id)
>>>     print('count:', doc.count)
>>>     print('text:', doc.text)
doc_id: 0
count: [1]
text: Milky Holmes
doc_id: 2
count: [1]
text: Milky

>>> for doc in fm.search(['Milky', 'Holmes']):
>>>     print('doc_id:', doc.doc_id)
>>>     print('count:', doc.count)
>>>     print('text:', doc.text)
doc_id: 1
count: [1]
text: Milky Holmes
  • search(query, [_or=False, ignores=[]])
    • If _or = True, then "OR" search is executed, else "AND" search
    • Given ignores, "NOT" search is also executed
    • NOTE: The search function is available after FM-index is built or loaded

Count word from FM-index

>>> fm.count('Milky'):
2

>>> fm.count(['Milky', 'Holmes']):
1
  • count(query, [_or=False])
    • If _or = True, then "OR" search is executed, else "AND" search
    • NOTE: The count function is available after FM-index is built or loaded
    • This function is slightly faster than the search function

Add a document

>>> fm.push_back('Baritsu')
  • push_back(doc)
    • NOTE: A document added by this method is not available to search until build

Read FM-index from a binary file

>>> fm.read('milky_holmes.fm')
  • read(path)

Write FM-index binary to a file

>>> fm.write('milky_holmes.fm')
  • write(path)

Check Whether FM-Index contains string

>>> 'baritsu' in fm

License

  • Wrapper code is licensed under the New BSD License.
  • Bundled shellinford C++ library (c) 2012 echizen_tm is licensed under the New BSD License.

shellinford-python's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

shellinford-python's Issues

[Wish] Add APIs for "count" and "locate" operations

As you know, FM-index allows counting of occurrences of a pattern and finding the locations of these occurrences as separate operations. Because counting is very fast (while locating and extracting contents are not), it would be more reasonable to have "count", "locate" and "extract" as separate APIs.

Sorry for not creating PR. I'm not very knowledgeable to SWIG and etc.

Can't install release 0.3.2

I see the 0.3.2 release on PyPI, but running into trouble installing:

~ > pip install shellinford==0.3.2
Collecting shellinford==0.3.2
  Could not find a version that satisfies the requirement shellinford==0.3.2 (from versions: 0.3.1)
No matching distribution found for shellinford==0.3.2
~ > pip search shellinford
shellinford (0.3.2)  - Wavelet Matrix/Tree succinct data structure for full text
                       search (using shellinford C++ library)

Problem with deserialization in Python 3

We're running into this error when reading a save FM index in Python 3 (it works well in Python 2!)

index_contains_kmer
    for _ in fm.search(kmer):
SystemError: <built-in function delete_MapIntInt> returned a result with an error set

Finding maximal substring

Dear @ikegami-yukino,

I was wondering if there was a way to find maximal substring of query string given the FM index?

For example,

If the query is "IGPIVEGAGRE", and the FM Index contains "TIVEGAGRT", then it would return "IVEGAGR" and location (1)?

I am thinking this would involve building a bwt/fm index of both query and db and comparing, but not sure how to do this?
Thank you very much!

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.