CPP API

From RL3 Wiki
Jump to: navigation, search

Installation

C++ API is a part of the official RL3 binary package. In order to install it, please consult the Installation Guide page.

Requirements

To use C++ API in your project you will need an ICU development package (headers and libraries):

$ sudo apt-get install libicu-dev

Example usage

#include <iostream>

#include <rl3.hpp>

int main(void)
{
    // create engine
    rl3::RL3Engine engine;

    // parse and compile (link) simple annotation pattern
    auto definition = engine.make_simple_annotation_def("text", "(?i:{dawg continent})", "continent");
    engine.parse(definition);
    engine.link();

    // create factsheet
    auto fs = engine.create_factsheet();

    // assert input text
    fs->assert_fact("text", "Antarctica is Earth's southernmost continent... Europe is the sixth largest continent in size.");

    // run engine - it should now annotate a continent names mentioned in our text
    engine.run(fs);

    // iterate and print all "continent" annotations
    auto i = fs->get_fact_iterator("continent");
    while (!i->is_end())
    {
        std::cout << i->get_value_str() << std::endl;
        i->next();
    }

    return 0;
}

Output:

Antarctica
Europe

General notes

  • Use -lrl3 -licuuc compiler flags to link RL3 and ICU libraries.
  • If you are using an old G++ compiler, you may need to add an -std=c++0x flag.

Interface

Core classes

Info functions

string rl3::get_copyright_str();

Get copyright.

Returns: copyright
string rl3::get_maintainer_str();

Get the maintainer's name.

Returns: the name of a maintainer