<commit_before>#include <iostream>
#include "../../Parser/Tagger/converter.h"
#include "../../Grammatica/Grammar Structure/Grammar-with-Map/cfgzero.h"
#include "../../Grammatica/Syntax-Tree/parser.h"
#include "../../Grammatica/Syntax-Tree/syntaxtree.h"
#include "../../Grammatica/Grammar Structure/Grammar-with-Map/cfgq.h"
#include "../../Granular-Extractor/Database/OntologyDatabase.h"
#include "../../Granular-Extractor/Database/CorpusQueryGenerator.h"
#include "../../CONFIG/config.h"

using namespace std;

void testQueryGenerator(Converter& conv, const string& sentence);
void testOntologyInsertion(const string& query);/// @note PASSED

int main()
{
    bool done = false;
    // using one instance is better for efficiency
    Converter myConverter;
    string sentence;
    while(!done) {
        cout << "Sentence : ";
        getline(cin, sentence);
        testQueryGenerator (myConverter, sentence);
    }
//    testOntologyInsertion ();
    return 0;
}



/**
 * Test case for QueryGenerator class
 * @param none
 */
void testQueryGenerator(Converter &conv, const string &sentence) {
    std::cout << "---   Testing QueryGenerator -----\n";
    try {
        conv.setString (sentence);
        Parser P(CFGQ() , conv.getWords ());
        STvector S = P.parse ();
        cout << "Tree found : " << S.size () << endl;
        /// for now, make sure vector only have 1 SyntaxTree
        string stringQuery;
        QueryGenerator myQry;
        if(!S.empty ()) {
            stringQuery = myQry.getQueryOf (S[0]);
        } else {
            cout << "Sorry, no sensible structure found" << endl;
            throw unimplemented_exc();
        }
        cout << "result : " << stringQuery << endl;
        /// Phase 2 : Insertion to database
        cout << " Inserting to database : " << endl;
        testOntologyInsertion (stringQuery);
    } catch (const char* e) {
        cout << "something went wrong : " << "QueryGenerator" << endl;
    } catch (const exception &e) {
            cout << e.what() << endl;
    }
    cout << "-------- End of QueryGenerator test case -----\n\n";
}



 //// @note PASSED
void testOntologyInsertion(const string &query)
{
    /// testing query
    OntologyDatabase testOntologyDB;
//    OntologyDatabase testOntologyDB_two;
    /// Working
//    testOntologyDB.testInsertionQuery ("DELETE from ontology");
//    testOntologyDB.testInsertionQuery ("INSERT INTO ontology(sub, pred, obj) VALUES ('They', 'are' , 'teachers')");
    testOntologyDB.testInsertionQuery (query);
}
<commit_msg>Add test cases and implementation on testOntology<commit_after>#include <iostream>
#include "../../Parser/Tagger/converter.h"
#include "../../Grammatica/Grammar Structure/Grammar-with-Map/cfgzero.h"
#include "../../Grammatica/Syntax-Tree/parser.h"
#include "../../Grammatica/Syntax-Tree/syntaxtree.h"
#include "../../Grammatica/Grammar Structure/Grammar-with-Map/cfgq.h"
#include "../../Granular-Extractor/Database/OntologyDatabase.h"
#include "../../Granular-Extractor/Database/CorpusQueryGenerator.h"
#include "../../CONFIG/config.h"

using namespace std;

void testQueryGenerator(Converter& conv, const string& sentence);
void testOntologyInsertion(const string& query);/// @note PASSED
void testOntologyQuestion (const string& query, string &result);

int main()
{
    bool done = false;
    // using one instance is better for efficiency
    Converter myConverter;
    string sentence;
    while(!done) {
        cout << "Sentence : ";
        getline(cin, sentence);
        testQueryGenerator (myConverter, sentence);
    }
    return 0;
}



/**
 * Test case for QueryGenerator class
 * @param none
 */
void testQueryGenerator(Converter &conv, const string &sentence) {
    std::cout << "---   Testing QueryGenerator -----\n";
    try {
        conv.setString (sentence);
        Parser P(CFGQ() , conv.getWords ());
        STvector S = P.parse ();
        cout << "Tree found : " << S.size () << endl;
        /// for now, make sure vector only have 1 SyntaxTree
        string stringQuery;
        QueryGenerator myQry;
        if(!S.empty ()) {
            cout << "DEBUG(type) : " << sentenceLookUp[S[0].getSentenceType()] << endl;
            /// Here, query command will be generated based on SentenceType
            stringQuery = myQry.getQueryOf (S[0]);

            /// Phase 2 : Insertion or Request
            string tmp_result; /// For interrogative sentence, a reply is needed
            switch (S[0].getSentenceType())
            {
            case SentenceType::DECLARATIVE:
                cout << " Inserting to database : " << endl;
                testOntologyInsertion (stringQuery);
                break;
            case SentenceType::INTERROGATIVE:
                testOntologyQuestion (stringQuery, tmp_result);
                cout << ">> " << tmp_result << endl;
//                throw unimplemented_exc();
                break;
            default:
                break;
            }

        } else {
            cout << "I'm sorry Dave, I'm afraid I can't do that" << endl;
        }

    } catch (const exception &e) {
        cout << e.what() << endl;
    }
    cout << "-------- End of QueryGenerator test case -----\n\n";
}



 //// @note PASSED
void testOntologyInsertion(const string &query)
{
    /// testing query
    OntologyDatabase testOntologyDB;
    /// Working
    testOntologyDB.InsertionQuery (query);
}

/// @note TESTING. ...
void testOntologyQuestion (const string& query, string& result)
{
    OntologyDatabase testDB;
    testDB.QuestionQuery (query, result); /// modify result
}

{'fraction_non_alphanumeric': 0.14469914040114612, 'fraction_numerical': 0.0017908309455587394, 'mean_word_length': 2.420085731781996, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4401859', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1632, 'n_words': 418}