Writing OTS plugins

From: Nadav Rotem (nadavrotem@mail.ru)
Date: Sun Jun 08 2003 - 07:11:08 EDT

  • Next message: Tomas Frydrych: "commit (HEAD): doc props import"

    This is a first draft for the OTS plugin Tutorial. This tutorial will
    help developers of programs such as Abiword , Gedit and others to create
    a plugin that uses OTS. The style-information section is still missing.

    Writing OTS plugins

    To create a plugin that uses OTS for your program to use two

    functions need to be written. One to parse your text and place

    it into the ots structure and the other is the exporter plugin

    to get the data from the ots data structure back into your


    create this function:

    ots_parse_myprog (myprog_struct * mytext , OtsArticle * Doc)

    This function will parse the text from your internal data structure.

    It will have to insert each word to a node of (char *) using

    each space , punctuation and other symbols will be added as a separate


    [Stuff]-[ ]-[that]-[ ]-[matters]-[.]

    To create the data structure first we need to create a new sentence

    using " newLine = ots_append_line (Doc); " This adds a line to

    the article and returns a pointer to that line. To add a word to this

    line we will call " ots_append_word (tmpLine, string); " This will add

    a new node of (char *) to the sentence.

    Remember to call " ots_add_wordstat(Doc , aWord); " for every word that

    we enter the line. This will add it to the word list for more statistics

    on the article. ots will not work without you adding each word to the

    Do not add punctuations , spaces and non words strings;

    example of such list:




    Now that we have created an OTSsentence would be a good time to attach

    original sentence to the line using " tmpLine->user_data=(some token);

    This may be a pointer to the original sentence in your program or

    token number.

    This pointer is not moderator and OTS will ignore it. we define this

    so later we can go through the ots data structure and have the original

    sentence with all the font , style etc.

    For more examples look into parser.c


    After ots has worked on the data structure your plugin will have to go

    through a list of sentences and see if ots marked them as "selected".

    If the "selected" flag is set then it means that ots found this sentence

    important for the article. Now you can access your "user_data" pointer

    either remove your original sentence or paste it to a new canvas.

    Code sample:

     GList *li;

     for (li = (GList *) Doc->lines; li != NULL; li = li->next) {

      if ((li->data->selected)) {

         /* do something with li->data->user_data */



    For more examples look into text.c or html.c

    general program flow:

     OtsArticle *Art; //ots article

     OtsWordList *dict; //Ots Dictionary file

     OtsWordList *ImpWords; //Ots list of words

     Art = ots_new_article (); //new

     ImpWords = ots_new_wordlist (); //new

     dict = ots_new_wordlist (); //new

     ots_load_dictionary (dict, dictionary_file); //load dictionary

     ots_parse_myprogram (input_stream, Art); // <---- Your parser here!

     ots_sort_list (Art->wordStat); //sort word list

     ots_union_list (Art->wordStat, dict, ImpWords);

     ots_sort_list (ImpWords);

     ots_grade_doc (Art, ImpWords);

     ots_highlight_doc (Art, sumPercent);


     ots_print_myprogram (output_stream, Art); // <---- Your print function

     ots_free_article (Art); //free

     ots_free_wordlist (dict); //free

     ots_free_wordlist (ImpWords); //free

    For more examples look into main() in ots.c

    Nadav Rotem

    This archive was generated by hypermail 2.1.4 : Sun Jun 08 2003 - 07:30:09 EDT