Skip to content

Getting Started

Aohan Dang edited this page Feb 24, 2022 · 11 revisions

The easiest way to see for yourself what iKnow does with text is by giving it a try! Thanks to our Python interface, that only takes two simple steps:

  1. Use pip to install the iknowpy module as follows:

    pip install iknowpy
    
  2. From your Python prompt, instantiate the engine and start indexing:

    import iknowpy
    
    engine = iknowpy.iKnowEngine()
    
    # show supported languages
    print(engine.get_languages_set())
    
    # index some text
    text = 'This is a test of the Python interface to the iKnow engine.'
    engine.index(text, 'en')
    
    # print the raw results
    print(engine.m_index)
    
    # or make it a little nicer
    for s in engine.m_index['sentences']:
      for e in s['entities']:
        print('<'+e['type']+'>'+e['index']+'</'+e['type']+'>', end=' ')
      print('\n')

If you are looking for another programming language or interface, check out the other APIs. For more on the Python interface, read on!

Demos

The repository contains a handful of code samples and demos that are also a convenient starting point for those who want to get going with the iKnow engine. See the corresponding folder's README.md file for more details.

The Python Interface

The iknowpy wrapper module provides a Python interface to the iKnow engine. It defines the class iKnowEngine and its main method, iKnowEngine.index().

After indexing, all data is stored in the m_index property, represented as nested dictionaries and lists.

  • m_index['sentences'] : a list of sentences in the text source after indexing.
  • m_index['sentences'][i] : the ith sentence in the text source after indexing.
  • m_index['sentences'][i]['entities'] : a list of text entities in the ith sentence after indexing.
  • m_index['sentences'][i]['path'] : a list representing the path in the ith sentence.
  • m_index['sentences'][i]['path_attributes'] : a list of spans in the ith sentence's path after attribute expansion.
  • m_index['sentences'][i]['sent_attributes'] : a list of attribute sentence markers for the ith sentence.
  • m_index['proximity'] : the proximity pairs in the text source after indexing.

See <repo_root>/modules/iknowpy/tests/test.py for a basic example of how to use the module.

Debug output

To enable full, verbose debug output, use the trace flag when calling the index() function and review the trace output in the m_traces property:

engine.index(text, 'en', True)
print(engine.m_traces)

Availability

To install a pre-built release of iknowpy, execute pip install iknowpy (pip3 install iknowpy on some platforms). Installation via pip is supported for CPython 3.6 through CPython 3.10 on the following platforms.

  • Windows for x86_64
  • Mac OS X 10.9 or higher for x86_64
  • Linux for x86_64 (pip ≥19.3 is required)
  • Linux for ppc64le (pip ≥19.3 is required)
  • Linux for aarch64 (pip ≥19.3 is required)

The Linux releases are compatible with the vast majority of modern distributions that are no older than CentOS 7.

Building from source

For more on building the iknowpy module and the underlying libraries, see this section.