int QueryWqlBaseList::parseResults( QString &results )
{

  int success = -1;
  QXmlSimpleReader parser;
  resetResults();

  QueryWqlBaseListHandler *handler  = new QueryWqlBaseListHandler( &m_results );
  QXmlInputSource source;
  source.setData(results);
  qDebug() << "QueryWqlBaseList::parseResults: " << results;
  parser.setContentHandler(handler);
  parser.setErrorHandler(handler);
  
  success = parser.parse(source);
  if(!success)
    {
      qDebug() << "Parse error: " << parser.errorHandler()->errorString();
      
    }
  delete handler;

  return (success ? 0 : -1);
}
Exemple #2
0
int main(int argc,char* argv[])
{
  QCoreApplication a(argc, argv);
  QsLogging::initQsLog();
  std::string resourcesPath=std::string(getenv("LIMA_RESOURCES"));
  std::string configDir=std::string(getenv("LIMA_CONF"));
  std::string lpConfigFile=std::string("lima-lp-tva.xml");
  std::string commonConfigFile=std::string("lima-common.xml");
  std::string clientId=std::string("lima-coreclient");
  std::string workingDir=std::string(".");

  std::deque<std::string> files;
  std::deque<std::string> pipelines;
  std::deque<std::string> langs;

  if (argc>1)
  {
    for (int i = 1 ; i < argc; i++)
    {
      std::string arg(argv[i]);
      std::string::size_type pos = std::string::npos;
      if ( arg[0] == '-' )
      {
        if (arg == "--help")
          usage(argc, argv);
        else if ( (pos = arg.find("--lp-config-file=")) != std::string::npos )
          lpConfigFile = arg.substr(pos+17);
        else if ( (pos = arg.find("--common-config-file=")) != std::string::npos )
          commonConfigFile = arg.substr(pos+21);
        else if ( (pos = arg.find("--config-dir=")) != std::string::npos )
          configDir = arg.substr(pos+13);
        else if ( (pos = arg.find("--resources-dir=")) != std::string::npos )
          resourcesPath = arg.substr(pos+16);
        else if ( (pos = arg.find("--client=")) != std::string::npos )
          clientId=arg.substr(pos+9);
        else if ( (pos = arg.find("--working-dir=")) != std::string::npos )
          workingDir=arg.substr(pos+14);
        else if ( (pos = arg.find("--language=")) != std::string::npos )
          langs.push_back(arg.substr(pos+11));
        else usage(argc, argv);
      }
      else
      {
        files.push_back(arg);
      }
    }
  }

  if(langs.empty()) {
    std::cerr << "No language specified. Aborting." << std::endl;
    return 1;
  }
    
  setlocale(LC_ALL,"fr_FR.UTF-8");

  AbstractLinguisticProcessingClient* client(0);

  // initialize common
  MediaticData::changeable().init(
    resourcesPath,
    configDir,
    commonConfigFile,
    langs);

  // initialize linguistic processing
  Lima::Common::XMLConfigurationFiles::XMLConfigurationFileParser lpconfig(configDir + "/" + lpConfigFile);
  LinguisticProcessingClientFactory::changeable().configureClientFactory(
    clientId,
    lpconfig,
    langs,
    pipelines);

  client=static_cast<AbstractLinguisticProcessingClient*>(LinguisticProcessingClientFactory::single().createClient(clientId));

  // Set the handlers
  std::map<std::string, AbstractAnalysisHandler*> handlers;
  BowTextWriter* bowTextWriter = new BowTextWriter();
  handlers.insert(std::make_pair("bowTextWriter", bowTextWriter));
  SimpleStreamHandler* simpleStreamHandler = new SimpleStreamHandler();
  handlers.insert(std::make_pair("simpleStreamHandler", simpleStreamHandler));
  BowTextHandler* bowTextHandler = new BowTextHandler();
  handlers.insert(std::make_pair("bowTextHandler", bowTextHandler));

  AnalysisTestCaseProcessor analysisTestCaseProcessor(workingDir, client, handlers);
    
  QXmlSimpleReader parser;
  TestCasesHandler tch(analysisTestCaseProcessor);

  parser.setContentHandler(&tch);
  parser.setErrorHandler(&tch);

  for (std::deque<std::string>::const_iterator it=files.begin();
       it!=files.end();
       it++)
  {
    std::cout << "process tests in " << *it << std::endl;
    try
    {
      QFile file(it->c_str());
      if (!file.open(QIODevice::ReadOnly))
      {
        std::cerr << "Error opening " << *it << std::endl;
        return 1;
      }
      if (!parser.parse( QXmlInputSource(&file)))
      {
        std::cerr << "Error parsing " << *it << " : " << parser.errorHandler()->errorString().toUtf8().constData() << std::endl;
        return 1;
      }
    }
    catch (Lima::LimaException& e)
    {
      std::cerr << __FILE__ << ", line " << __LINE__ << ": caught LimaException : " << std::endl << e.what() << std::endl;
    }
    catch (std::logic_error& e)
    {
      std::cerr << __FILE__ << ", line " << __LINE__ << ": caught logic_error : " << std::endl << e.what() << std::endl;
    }
    catch (std::runtime_error& e)
    {
      std::cerr << __FILE__ << ", line " << __LINE__ << ": caught runtime_error : " << std::endl << e.what() << std::endl;
    }

    TestCasesHandler::TestReport resTotal;
    std::cout << std::endl;
    std::cout << "=========================================================" << std::endl;
    std::cout << std::endl;
    std::cout << "  TestReport :   " << *it << " " << std::endl;
    std::cout << std::endl;
    std::cout << "\ttype           \tsuccess\tcond.\tfailed\ttotal" << std::endl;
    std::cout << "---------------------------------------------------------" << std::endl;
    for (std::map<std::string,TestCasesHandler::TestReport>::const_iterator resItr=tch.m_reportByType.begin();
         resItr!=tch.m_reportByType.end();
         resItr++)
    {
      std::string label(resItr->first);
      label.resize(15,' ');
      std::cout << "\t" << label << "\t" << resItr->second.success << "\t" << resItr->second.conditional << "\t" << resItr->second.failed << "\t" << resItr->second.nbtests << std::endl;
      resTotal.success+=resItr->second.success;
      resTotal.conditional+=resItr->second.conditional;
      resTotal.failed+=resItr->second.failed;
      resTotal.nbtests+=resItr->second.nbtests;
    }
    std::cout << "---------------------------------------------------------" << std::endl;
    std::cout << "\ttotal          \t" << resTotal.success << "\t" << resTotal.conditional << "\t" << resTotal.failed << "\t" << resTotal.nbtests << std::endl;
    std::cout << "=========================================================" << std::endl;
    std::cout << std::endl;
    tch.m_reportByType.clear();
  }
  delete client;
  delete bowTextWriter;
  delete simpleStreamHandler;
  delete bowTextHandler;
}
Exemple #3
0
int main(int argc,char* argv[])
{
  QCoreApplication a(argc, argv);
  QsLogging::initQsLog();
  string resourcesPath=string(getenv("LIMA_RESOURCES"));
  string configDir=string(getenv("LIMA_CONF"));
  string lpConfigFile=string("lima-lp-tvr.xml");
  string commonConfigFile=string("lima-common.xml");
  string clientId=string("lp-structuredXmlreaderclient");
  string workingDir=string(".");

  if (resourcesPath.empty())
  {
    resourcesPath = "/usr/share/apps/lima/resources/";
  }
  if (configDir.empty())
  {
    configDir = "/usr/share/config/lima/";
  }

  deque<string> files;
  deque<string> langs;
  deque<string> pipelines;

  if (argc>1)
  {
    for (int i = 1 ; i < argc; i++)
    {
      std::string arg(argv[i]);
      std::string::size_type pos = std::string::npos;
      if ( arg[0] == '-' )
      {
        if (arg == "--help")
          usage(argc, argv);
        else if ( (pos = arg.find("--lp-config-file=")) != std::string::npos )
          lpConfigFile = arg.substr(pos+17);
        else if ( (pos = arg.find("--common-config-file=")) != std::string::npos )
          commonConfigFile = arg.substr(pos+21);
        else if ( (pos = arg.find("--config-dir=")) != std::string::npos )
          configDir = arg.substr(pos+13);
        else if ( (pos = arg.find("--resources-dir=")) != std::string::npos )
          resourcesPath = arg.substr(pos+16);
        else if ( (pos = arg.find("--client=")) != std::string::npos )
          clientId=arg.substr(pos+9);
        else if ( (pos = arg.find("--working-dir=")) != std::string::npos )
          workingDir=arg.substr(pos+14);
        else if ( (pos = arg.find("--language=")) != std::string::npos )
          langs.push_back(arg.substr(pos+11));
        else usage(argc, argv);
      }
      else
      {
        files.push_back(arg);
      }
    }
  }

  setlocale(LC_ALL,"fr_FR.UTF-8");

  AbstractLinguisticProcessingClient* client(0);

  // initialize common
  MediaticData::changeable().init(
    resourcesPath,
    configDir,
    commonConfigFile,
    langs);

  // initialize linguistic processing
  Lima::Common::XMLConfigurationFiles::XMLConfigurationFileParser lpconfig(configDir + "/" + lpConfigFile);
  LinguisticProcessingClientFactory::changeable().configureClientFactory(
    clientId,
    lpconfig,
    MediaticData::single().getMedias());

  client=dynamic_cast<AbstractLinguisticProcessingClient*>(LinguisticProcessingClientFactory::single().createClient(clientId));
  
  
  ReaderTestCaseProcessor
    readerTestCaseProcessor(workingDir, client);
    
  QXmlSimpleReader parser;
  TestCasesHandler tch(readerTestCaseProcessor);

  parser.setContentHandler(&tch);
  parser.setErrorHandler(&tch);

  for (deque<string>::const_iterator it=files.begin();
       it!=files.end();
       it++)
  {
    cout << "process tests in " << *it << endl;
    try
    {
      QFile file(it->c_str());
      if (!file.open(QIODevice::ReadOnly))
      {
        std::cerr << "Error opening " << *it << std::endl;
        return 1;
      }
      if (!parser.parse( QXmlInputSource(&file)))
      {
        std::cerr << "Error parsing " << *it << " : " << parser.errorHandler()->errorString().toUtf8().constData() << std::endl;
        return 1;
      }
    }
    catch (Lima::LimaException& e)
    {
      cerr << "caught LimaException : " << endl << e.what() << endl;
    }
    catch (logic_error& e)
    {
      cerr << "caught logic_error : " << endl << e.what() << endl;
    }

    TestCasesHandler::TestReport resTotal;
    cout << endl;
    cout << "=========================================================" << endl;
    cout << endl;
    cout << "  TestReport :   " << *it << " " << endl;
    cout << endl;
    cout << "\ttype           \tsuccess\tcond.\tfailed\ttotal" << endl;
    cout << "---------------------------------------------------------" << endl;
    for (map<string,TestCasesHandler::TestReport>::const_iterator resItr=tch.m_reportByType.begin();
         resItr!=tch.m_reportByType.end();
         resItr++)
    {
      string label(resItr->first);
      label.resize(15,' ');
      cout << "\t" << label << "\t" << resItr->second.success << "\t" << resItr->second.conditional << "\t" << resItr->second.failed << "\t" << resItr->second.nbtests << endl;
      resTotal.success+=resItr->second.success;
      resTotal.conditional+=resItr->second.conditional;
      resTotal.failed+=resItr->second.failed;
      resTotal.nbtests+=resItr->second.nbtests;
    }
    cout << "---------------------------------------------------------" << endl;
    cout << "\ttotal          \t" << resTotal.success << "\t" << resTotal.conditional << "\t" << resTotal.failed << "\t" << resTotal.nbtests << endl;
    cout << "=========================================================" << endl;
    cout << endl;
    tch.m_reportByType.clear();
  }
}
Exemple #4
0
int main(int argc,char* argv[])
{
    QCoreApplication a(argc, argv);
    QsLogging::initQsLog();

    Param param = {
        std::string(getenv("LIMA_RESOURCES")==0?"/usr/share/apps/lima/resources":getenv("LIMA_RESOURCES")),
        std::string(getenv("LIMA_CONF")==0?"/usr/share/config/lima":getenv("LIMA_CONF")),
        std::string("lima-common.xml"),
        std::string("XXX-coreclient"),
        std::string("."),
        std::vector<std::string>()
    };

    if (argc>1)
    {
        for (int i = 1 ; i < argc; i++)
        {
            std::string arg(argv[i]);
            std::string::size_type pos = std::string::npos;
            if ( arg[0] == '-' )
            {
                if (arg == "--help")
                    usage(argc, argv);
                else if ( (pos = arg.find("--common-config-file=")) != std::string::npos )
                    param.commonConfigFile = arg.substr(pos+20);
                else if ( (pos = arg.find("--config-dir=")) != std::string::npos )
                    param.configDir = arg.substr(pos+13);
                else if ( (pos = arg.find("--resources-dir=")) != std::string::npos )
                    param.resourcesPath = arg.substr(pos+16);
                else if ( (pos = arg.find("--client=")) != std::string::npos )
                    param.clientId=arg.substr(pos+9);
                else if ( (pos = arg.find("--working-dir=")) != std::string::npos )
                    param.workingDir=arg.substr(pos+14);
                else usage(argc, argv);
            }
            else
            {
                param.files.push_back(std::string(arg));
            }
        }
    }

    setlocale(LC_ALL,"fr_FR.UTF-8");


    QXmlSimpleReader parser;

    // create TvgTestCaseProcessor
    // TvgTestCaseProcessor tvgTestCaseProcessor(param.workingDir, cerr);
    TvgTestCaseProcessor* tvgTestCaseProcessor(0);
    tvgTestCaseProcessor = new TvgTestCaseProcessor(param.workingDir, cerr);

    TestCasesHandler tch(*tvgTestCaseProcessor);

    parser.setContentHandler(&tch);
    parser.setErrorHandler(&tch);

    try
    {
        for( std::vector<std::string>::const_iterator fit = param.files.begin() ;
                fit != param.files.end() ; fit++ ) {
            string sfile(param.workingDir);
            sfile.append("/").append(*fit);
            cout << "parse " << sfile << endl;

            // cerr << "<?xml version='1.0' encoding='UTF-8'?>\n";
// cerr << "<testcases>\n";
            QFile file(sfile.c_str());
            if (!file.open(QIODevice::ReadOnly))
            {
                std::cerr << "Error opening " << sfile << std::endl;
                return 1;
            }
            if (!parser.parse( QXmlInputSource(&file)))
            {
                std::cerr << "Error parsing " << sfile << " : " << parser.errorHandler()->errorString().toUtf8().constData() << std::endl;
                return 1;
            }
            // cerr << "</testcases>\n";

            TestCasesHandler::TestReport resTotal;
            cout << endl;
            cout << "=========================================================" << endl;
            cout << endl;
            cout << "  TestReport :   " << sfile.c_str() << " " << endl;
            cout << endl;
            cout << "\ttype           \tsuccess\tcond.\tfailed\ttotal" << endl;
            cout << "---------------------------------------------------------" << endl;
            for (map<string,TestCasesHandler::TestReport>::const_iterator resItr=tch.m_reportByType.begin();
                    resItr!=tch.m_reportByType.end();
                    resItr++)
            {
                string label(resItr->first);
                label.resize(15,' ');
                cout << "\t" << label << "\t" << resItr->second.success
                     << "\t" << resItr->second.conditional << "\t"
                     << resItr->second.failed << "\t" << resItr->second.nbtests << endl;
                resTotal.success+=resItr->second.success;
                resTotal.conditional+=resItr->second.conditional;
                resTotal.failed+=resItr->second.failed;
                resTotal.nbtests+=resItr->second.nbtests;
            }
            cout << "---------------------------------------------------------" << endl;
            cout << "\ttotal          \t" << resTotal.success
                 << "\t" << resTotal.conditional << "\t" << resTotal.failed
                 << "\t" << resTotal.nbtests << endl;
            cout << "=========================================================" << endl;
            cout << endl;
            tch.m_reportByType.clear();
        }
    }
    catch (Lima::LimaException& e)
    {
        cerr << "caught LimaException : " << endl << e.what() << endl;
    }
    catch (logic_error& e)
    {
        cerr << "caught logic_error : " << endl << e.what() << endl;
    }

    if( tvgTestCaseProcessor != 0 )
        delete tvgTestCaseProcessor;
    // cerr << "main: after MLPlatformUtils::Terminate. before end..." << endl;
}
Exemple #5
0
int run(int argc, char** argv)
{
  readCommandLineArguments(argc, argv);

  if (param->help)
  {
    usage(argc, argv);
    exit(0);
  }

  std::string resourcesPath = (getenv("LIMA_RESOURCES")!=0) ? string(getenv("LIMA_RESOURCES")) : string("/usr/share/apps/lima/resources");
  std::string configPath = (param->configDir.size()>0) ? param->configDir : string("");
  if (configPath.size() == 0)
    configPath = string(getenv("LIMA_CONF"));
  if (configPath.size() == 0)
    configPath = string("/usr/share/config/lima");

  if (QsLogging::initQsLog(QString::fromUtf8(configPath.c_str())) != 0)
  {
    LOGINIT("Common::Misc");
    LERROR << "Call to QsLogging::initQsLog(\"" << configPath << "\") failed.";
    return EXIT_FAILURE;
  }

  // Necessary to initialize factories
  Lima::AmosePluginsManager::single();

  setlocale(LC_ALL,"fr_FR.UTF-8");

  // check that input file exists
  {
    ifstream fin(param->input.c_str(), std::ifstream::binary);
    if (!fin.good())
    {
      cerr << "can't open input file " << param->input << endl;
      exit(-1);
    }
    fin.close();
  }

  // parse charchart
  if (param->charChart == "") {
    cerr << "please specify CharChart file with --charChart=<file> option" << endl;
    exit(0);
  }
  CharChart charChart;
  charChart.loadFromFile(param->charChart);

  try
  {
    cerr << "parse charChart file : " << param->charChart << endl;
//     cerr << "TODO: to implement at "<<__FILE__<<", line "<<__LINE__<<"!" <<std::endl;
//     exit(2);
//     charChart = 0;
/*    ParseCharClass parseCharClass;
    parseCharClass.parse(param->charChart);
    charChart = ParseChar::parse(param->charChart, parseCharClass);*/
  }
  catch (exception& e)
  {
    cerr << "Caught exception while parsing file " << param->charChart << endl;
    cerr << e.what() << endl;
    exit(-1);
  }

  if (param->extractKeys != "")
  {
    // just extract keys
    ofstream fout(param->extractKeys.c_str(), std::ofstream::binary);
    if (!fout.good())
    {
      cerr << "can't open file " << param->extractKeys << endl;
      exit(-1);
    }
    KeysLogger keysLogger(fout,&charChart,param->reverseKeys);

    cerr << "parse input file : " << param->input << endl;
    try
    {
      QXmlSimpleReader parser;
      //     parser->setValidationScheme(SAXParser::Val_Auto);
      //     parser->setDoNamespaces(false);
      //     parser->setDoSchema(false);
      //     parser->setValidationSchemaFullChecking(false);
      parser.setContentHandler(&keysLogger);
      parser.setErrorHandler(&keysLogger);
      QFile file(param->input.c_str());
      if (!file.open(QIODevice::ReadOnly))
      {
        std::cerr << "Error opening " << param->input << std::endl;
        return 1;
      }
      if (!parser.parse( QXmlInputSource(&file)))
      {
        std::cerr << "Error parsing " << param->input << " : " << parser.errorHandler()->errorString().toUtf8().constData() << std::endl;
        return 1;
      }
      else
      {
        std::cerr << std::endl;
      }
    }
    catch (const XMLException& toCatch)
    {
      std::cerr << "An error occurred  Error: " << toCatch.what() << endl;
      throw;
    }
    fout.close();
  } else {
    // compile dictionaries

    cerr << "parse property code file : " << param->propertyFile << endl;
    PropertyCodeManager propcodemanager;
    propcodemanager.readFromXmlFile(param->propertyFile);

    cerr << "parse symbolicCode file : " << param->symbolicCodes << endl;
    map<string,LinguisticCode> conversionMap;
    propcodemanager.convertSymbolicCodes(param->symbolicCodes,conversionMap);
    cerr << conversionMap.size() << " code read from symbolicCode file" << endl;
/*    for (map<string,LinguisticCode>::const_iterator it=conversionMap.begin();
         it!=conversionMap.end();
         it++)
    {
      cerr << it->first << " -> " << it->second << endl;
    }*/

    AbstractAccessByString* access(0);
    if (param->fsaKey!="") {
      cerr << "load fsa access method : " << param->fsaKey << endl;
      FsaAccessSpare16* fsaAccess=new FsaAccessSpare16();
      fsaAccess->read(param->fsaKey);
      access=fsaAccess;
    } else {
      cerr << "ERROR : no access Keys defined !" << endl;
      exit(-1);
    }
    cerr << access->getSize() << " keys loaded" << endl;

    cerr << "parse input file : " << param->input << endl;
    DictionaryCompiler handler(&charChart,access,conversionMap,param->reverseKeys);

    QXmlSimpleReader parser;
//     parser->setValidationScheme(SAXParser::Val_Auto);
//     parser->setDoNamespaces(false);
//     parser->setDoSchema(false);
//     parser->setValidationSchemaFullChecking(false);
    try
    {
      parser.setContentHandler(&handler);
      parser.setErrorHandler(&handler);
      QFile file(param->input.c_str());
      if (!file.open(QIODevice::ReadOnly))
      {
        std::cerr << "Error opening " << param->input << std::endl;
        return 1;
      }
      if (!parser.parse( QXmlInputSource(&file)))
      {
        std::cerr << "Error parsing " << param->input << " : " << parser.errorHandler()->errorString().toUtf8().constData() << std::endl;
        return 1;
      }
    }
    catch (const XMLException& toCatch)
    {
      cerr << "An error occurred  Error: " << toCatch.what() << endl;
      throw;
    }

    cerr << "write data to output file : " << param->output << endl;
    ofstream fout(param->output.c_str(),ios::out | ios::binary);
    if (!fout.good())
    {
      cerr << "can't open file " << param->output << endl;
      exit(-1);
    }
    handler.writeBinaryDictionary(fout);
    fout.close();
    delete access;
  }
  return EXIT_SUCCESS;
}