コード例 #1
0
ファイル: MultXmlReader.cpp プロジェクト: aymara/lima
MultXmlReaderPrivate::MultXmlReaderPrivate(const std::string& filename,
                           std::ostream& output):
    m_parser(new QXmlSimpleReader())
{

  //  Create the handler object and install it as the document and error
  //  handler for the parser-> Then parse the file and catch any exceptions
  //  that propogate out
  //
  try {
    MultXmlHandler handler(output);
    m_parser->setContentHandler(&handler);
    m_parser->setErrorHandler(&handler);
    m_parser->setFeature("http://qt-project.org/xml/features/report-start-end-entity",true);
    QFile file(filename.c_str());
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
      throw XMLException();
    if (!m_parser->parse( QXmlInputSource(&file)))
    {
      throw XMLException();
    }
  }
  catch (const XMLException& e) {
    BOWLOGINIT;
    LERROR << "An XML exception occurred: " << e.what() ;
    throw;
  }
}
コード例 #2
0
void RouteDataGen::downloadReady (QNetworkReply *reply)
{
    currentNetworkRequest = 0;
    emit dataFinished();

    if (reply->error() != QNetworkReply::NoError)
    {
        QString errorString(reply->errorString());

        qDebug() << errorString;

        #if defined(Q_WS_MAEMO_5)
            QMaemo5InformationBox::information(NULL, errorString, QMaemo5InformationBox::NoTimeout);
        #endif

        reply->deleteLater();
        return;
    }

    if (!this->xmlReader.parse(QXmlInputSource(reply)))
    {
        qDebug() << "Parsing failed" << endl;
    }

    reply->deleteLater();
}
コード例 #3
0
ファイル: qt_action_manager.cpp プロジェクト: bw-github/wgtf
void QtActionManager::loadActionData( QIODevice & source )
{
	QXmlSimpleReader actions;
	QtActionContentHandler contentHandler( *this );
	actions.setContentHandler( &contentHandler );
	QtActionErrorHandler errorHandler;
	actions.setErrorHandler( &errorHandler );
	const auto result = actions.parse( QXmlInputSource( &source ) );
	if (!result)
	{
		NGT_ERROR_MSG( "Failed to parse actions\n" );
	}
}
コード例 #4
0
void flowwidget::LoadXML(std::istream &data) {
    QXmlSimpleReader qxsr;
    qxsr.setContentHandler(XMLHandlr);
    qxsr.setErrorHandler(XMLHandlr);

    QIODevice* iodev = new IOStreamBridge(data);
    if (qxsr.parse(QXmlInputSource(iodev))) {
        std::cerr << "[FlowWidget] Recentering nodes and adjusting scale." << std::endl;
        double GenMinimumX = std::numeric_limits<double>::max();
        double GenExtremeX = std::numeric_limits<double>::min();
        double GenMinimumY = std::numeric_limits<double>::max();
        double GenExtremeY = std::numeric_limits<double>::min();
        std::for_each(XMLHandlr->OrphanNodes.begin(), XMLHandlr->OrphanNodes.end(),
                      [&](std::pair<std::string, FlowNode> nodepair) {
            NodeSize ns = getNodeSize(QFont("sans-serif", BaseFontSize*nodepair.second.FontSizeMult), QFont("sans-serif", BaseFontSize*nodepair.second.FontSizeMult*1.5), nodepair.second);
            if (nodepair.second.CenterPosX - double(ns.Width/2) < GenMinimumX)
                GenMinimumX = nodepair.second.CenterPosX - double(ns.Width/2);
            if (nodepair.second.CenterPosX + double(ns.Width/2) > GenExtremeX)
                GenExtremeX = nodepair.second.CenterPosX + double(ns.Width/2);
            if (nodepair.second.CenterPosY - double(ns.Height/2) < GenMinimumY)
                GenMinimumY = nodepair.second.CenterPosY - double(ns.Height/2);
            if (nodepair.second.CenterPosY + double(ns.Height/2) > GenExtremeY)
                GenExtremeY = nodepair.second.CenterPosY + double(ns.Height/2);
        });

        QLineF XLine(QPointF(GenMinimumX, 0), QPointF(GenExtremeX, 0));
        QLineF YLine(QPointF(GenMinimumY, 0), QPointF(GenExtremeY, 0));
        if (XLine.length() > YLine.length()) {
            PermaScale = 1.0/XLine.length();
        } else {
            PermaScale = 1.0/YLine.length();
        }

        double NewCenterX = (GenMinimumX + GenExtremeX) / 2.0;
        double NewCenterY = (GenMinimumY + GenExtremeY) / 2.0;
        std::cerr << "[FlowWidget] Nodes are off by X " << -NewCenterX << ", Y " << -NewCenterY <<
                     ", deducted from XMin " << GenMinimumX << ", XMax " << GenExtremeX <<
                     ", YMin " << GenMinimumY << ", YMax" << GenExtremeY << std::endl;
        for (auto itr = XMLHandlr->OrphanNodes.begin(); itr != XMLHandlr->OrphanNodes.end(); itr++) {
            itr->second.CenterPosX -= NewCenterX;
            itr->second.CenterPosY -= NewCenterY;
        }
        std::cerr << "[FlowWidget] Recentered nodes. Ready!" << std::endl;
    } else {
        std::cerr << "[FlowWidget] Error loading XML." << std::endl;
    }
}
コード例 #5
0
LimaStatusCode SpecificEntitiesLoader::
process(AnalysisContent& analysis) const
{
  // get analysis graph
  AnalysisGraph* graph=static_cast<AnalysisGraph*>(analysis.getData(m_graph));
  if (graph==0)
  {
    LOGINIT("LP::SpecificEntities");
    LERROR << "no graph '" << m_graph << "' available !";
    return MISSING_DATA;
  }

  //create a RecognizerData (such as in ApplyRecognizer) to be able to use
  //CreateSpecificEntity actions
  RecognizerData* recoData=new RecognizerData;
  analysis.setData("RecognizerData",recoData);
  RecognizerResultData* resultData=new RecognizerResultData(m_graph);
  recoData->setResultData(resultData);
  
  try
  {
    SpecificEntitiesLoader::XMLHandler handler(m_language,analysis,graph);
    m_parser->setContentHandler(&handler);
    m_parser->setErrorHandler(&handler);
    QFile file(getInputFile(analysis).c_str());
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
      throw XMLException();
    if (!m_parser->parse( QXmlInputSource(&file)))
    {
      throw XMLException();
    }
  }
  catch (const XMLException& )
  {
    LOGINIT("LP::SpecificEntities");
    LERROR << "Error: failed to parse XML input file";
  }

  // remove recognizer data (used only internally to this process unit)
  recoData->deleteResultData();
  resultData=0;
  analysis.removeData("RecognizerData");

  return SUCCESS_ID;
}
コード例 #6
0
XMLConfigurationFileParserPrivate::XMLConfigurationFileParserPrivate(const XMLConfigurationFileParserPrivate& p)
{
    m_configuration = p.m_configuration;
    m_configurationFileName = p.m_configurationFileName;
//     m_parser = p.m_parser; // TODO sale: SAXParser::operator= n'est pas surchargé. Mais peut marcher...
    XMLConfigurationFileHandler handler(m_configuration);
    m_parser.setContentHandler(&handler);
    m_parser.setErrorHandler(&handler);
    QFile file(m_configurationFileName);
    if (!file.open(QIODevice::ReadOnly))
    {
      XMLCFGLOGINIT;
      LERROR << "XMLConfigurationFileParser unable to open" << m_configurationFileName;
      throw std::runtime_error(std::string("XMLConfigurationFileParser Unable to open ") + m_configurationFileName.toUtf8().constData());
    }
    if (!m_parser.parse( QXmlInputSource(&file)))
    {
      XMLCFGLOGINIT;
      LERROR << "XMLConfigurationFileParser unable to parse" << m_configurationFileName << ":" << m_parser.errorHandler()->errorString();
      throw XMLException(std::string("XMLConfigurationFileParser Unable to parse ") + m_configurationFileName.toUtf8().constData() + " : " + m_parser.errorHandler()->errorString().toUtf8().constData());
    }
}
コード例 #7
0
XMLConfigurationFileParserPrivate::XMLConfigurationFileParserPrivate(
  const QString &configurationFileName) :
    m_parser(),
    m_configurationFileName(configurationFileName)
{
    XMLCFGLOGINIT;
    LINFO << "XMLConfigurationFileParser creating parser for: "
          << configurationFileName;

    //
    //  Create the handler object and install it as the document and error
    //  handler for the parser-> Then parse the file and catch any exceptions
    //  that propogate out
    //
    XMLConfigurationFileHandler handler(m_configuration);
    m_parser.setContentHandler(&handler);
    m_parser.setErrorHandler(&handler);
    QFile file(m_configurationFileName);
    if (!file.open(QFile::ReadOnly))
    {
      XMLCFGLOGINIT;
      LERROR << "Error opening " << m_configurationFileName;
      throw std::runtime_error(std::string("XMLConfigurationFileParser Unable to open ")
          + m_configurationFileName.toUtf8().constData());
    }
    if (!m_parser.parse( QXmlInputSource(&file)))
    {
      LERROR << "Error parsing " << m_configurationFileName;
      throw XMLException(std::string("XMLConfigurationFileParser Unable to parse ")
          + m_configurationFileName.toUtf8().constData() + " : "
          + m_parser.errorHandler()->errorString().toUtf8().constData());
    }
    {
      LOGINIT("FilesReporting");
      LINFO << "File parsed:" << m_configurationFileName;
    }
    
}
コード例 #8
0
ファイル: ExampleLoader.cpp プロジェクト: Geekking/lima
LimaStatusCode ExampleLoader::process(AnalysisContent& analysis) const
{
  // get linguistic graph
  AnalysisGraph* anaGraph=static_cast<AnalysisGraph*>(analysis.getData("PosGraph"));
  LinguisticGraph* lingGraph=anaGraph->getGraph();
  if (lingGraph==0)
  {
    PROCESSORSLOGINIT;
    LERROR << "no graph 'PosGraph' available !";
    return MISSING_DATA;
  }
  else{
    try{
      ExampleLoader::XMLHandler handler(m_language,analysis,anaGraph);
      m_parser->setContentHandler(&handler);
      m_parser->setErrorHandler(&handler);
      QFile file("/tmp/mm-lp.morphoSyntacticalAnalysis-changed.tmp");
      if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        throw XMLException();
      if (!m_parser->parse( QXmlInputSource(&file)))
      {
        throw XMLException();
      }
      LinguisticGraph::vertex_iterator vxItr,vxItrEnd;
      boost::tie(vxItr,vxItrEnd) = boost::vertices(*lingGraph);
      for (;vxItr!=vxItrEnd;vxItr++){
       MorphoSyntacticData* morphoData=get(vertex_data,*lingGraph, *vxItr);
        Token* ft=get(vertex_token,*lingGraph,*vxItr);
        if( ft!=0){
          const QString tag=QString::fromStdString(static_cast<const Common::MediaticData::LanguageData&>(Common::MediaticData::MediaticData::single().mediaData(m_language)).getPropertyCodeManager().getPropertyManager("MICRO").getPropertySymbolicValue(handler.m_tagIndex[ft->position()]));

          const Common::PropertyCode::PropertyCodeManager& codeManager=static_cast<const Common::MediaticData::LanguageData&>(Common::MediaticData::MediaticData::single().mediaData(m_language)).getPropertyCodeManager();
          const Common::PropertyCode::PropertyAccessor m_propertyAccessor=codeManager.getPropertyAccessor("MICRO");

          const QString graphTag=QString::fromStdString(static_cast<const Common::MediaticData::LanguageData&>(Common::MediaticData::MediaticData::single().mediaData(m_language)).getPropertyCodeManager().getPropertyManager("MICRO").getPropertySymbolicValue(morphoData->firstValue(m_propertyAccessor)));

          cout << " la premiere categorie de  " << ft->stringForm() << " est " << graphTag << endl;
          //si différence entre valeur de la map et noeud du graphe à la position n, remplacer la valeur du noeud //par la valeur de la map
          if(tag!=graphTag){
            const QString tagBefore=QString::fromStdString(static_cast<const Common::MediaticData::LanguageData&>(Common::MediaticData::MediaticData::single().mediaData(m_language)).getPropertyCodeManager().getPropertyManager("MICRO").getPropertySymbolicValue(morphoData->at(0).properties));
            
            cout << "le token a la position " << ft->position() << " passe de " << morphoData->at(0).properties  << endl;
            morphoData->at(0).properties=handler.m_tagIndex[ft->position()];
            cout << " a la position " << morphoData->at(0).properties << endl;
            
            const QString tagAfter=QString::fromStdString(static_cast<const Common::MediaticData::LanguageData&>(Common::MediaticData::MediaticData::single().mediaData(m_language)).getPropertyCodeManager().getPropertyManager("MICRO").getPropertySymbolicValue(morphoData->at(0).properties));
            
            cout << "Et la chaîne passe de " << tagBefore << " à " << tagAfter << endl;
           
           //LinguisticCode lc = morphoData->at(0).properties;
           
           put(vertex_data, *lingGraph, *vxItr, morphoData);
           cout << " a la position " << morphoData->at(0).properties << endl;
           }
        }
      }
    }
    catch (const XMLException& ){
      PROCESSORSLOGINIT;
      LERROR << "Error: failed to parse XML input file";
    }
     return SUCCESS_ID;
  }
}