void LinguisticProcessingClientFactory::configureClientFactory(
  const std::string& id,
  Common::XMLConfigurationFiles::XMLConfigurationFileParser& configuration,
  std::deque<std::string> langs,
  std::deque<std::string> pipelines)
{
  LPCLIENTFACTORYLOGINIT;
  LINFO << "LinguisticProcessingClientFactory::configureClientFactory" << id;
  if (id.empty())
  {
    LERROR << "LinguisticProcessingClientFactory::configureClientFactory Trying to access to factory with empty name!";
    throw LinguisticProcessingException();
  }
  std::shared_ptr<AbstractLinguisticProcessingClientFactory> factory=
    AbstractLinguisticProcessingClientFactory::getFactory(id);
  if (factory==0) {
    LERROR << "No factory defined for client '" << id << "' !";
    throw LinguisticProcessingException();
  }
  std::deque<std::string>::iterator Itrlangs;
//     for (  Itrlangs=langs.begin();  Itrlangs!=langs.end();Itrlangs++)
      //std::cout<<"ici la langue : "<<*Itrlangs<<std::endl;
  factory->configure(
    configuration,
    langs,
    pipelines);
}
std::shared_ptr< AbstractProcessingClient > LinguisticProcessingClientFactory::createClient(
  const std::string& id) const
{
  LPCLIENTFACTORYLOGINIT;
  LINFO << "Create client '" << id << "'";
  if (id.empty())
  {
    LERROR << "LinguisticProcessingClientFactory::createClient Trying to create client with empty name!";
    throw LinguisticProcessingException();
  }
  const std::shared_ptr<AbstractLinguisticProcessingClientFactory> factory=
    AbstractLinguisticProcessingClientFactory::getFactory(id);
  if (factory==0) {
    LERROR << "No factory defined for client '" << id << "' !";
    throw LinguisticProcessingException();
  }

  return factory->createClient();
}
示例#3
0
文件: Text.cpp 项目: FaizaGara/lima
void Text::setGraph(LinguisticGraphVertex position,LinguisticGraph* graph)
{
  _currentVx=position;
  _tTokenGraph=graph;
  // go one step forward on the new path
  LinguisticGraphAdjacencyIt adjItr,adjItrEnd;
  boost::tie (adjItr,adjItrEnd) = adjacent_vertices(_currentVx,*_tTokenGraph);
  if (adjItr==adjItrEnd)
  {
    TOKENIZERLOGINIT;
    LERROR << "Tokenizer Text : no token forward !";
    throw LinguisticProcessingException();
  }
  _lastVx=*adjItr;
  if (++adjItr!=adjItrEnd) {
    TOKENIZERLOGINIT;
    LERROR << "Tokenizer Text : more than one next token !";
    throw LinguisticProcessingException();
  }
  //remove_edge(_currentVx,_lastVx,*_tTokenGraph);
}
AbstractProcessingClient* LinguisticProcessingClientFactory::createClient(
  const std::string& id) const 
{
  LPCLIENTFACTORYLOGINIT;
  LINFO << "Create client '" << id << "'";
  const AbstractLinguisticProcessingClientFactory* factory=
    AbstractLinguisticProcessingClientFactory::getFactory(id);
  if (factory==0) {
    LERROR << "No factory defined for client '" << id << "' !";
    throw LinguisticProcessingException();
  }
  
  return factory->createClient();
}
void CoreLinguisticProcessingClient::analyze(
    const LimaString& texte,
    const std::map<std::string,std::string>& metaData,
    const std::string& pipelineId,
    const std::map<std::string, AbstractAnalysisHandler*>& handlers,
    const std::set<std::string>& inactiveUnits) const

{
  Lima::TimeUtilsController timer("CoreLinguisticProcessingClient::analyze");
  CORECLIENTLOGINIT;
  // create analysis content
  AnalysisContent analysis;
  LinguisticMetaData* metadataholder=new LinguisticMetaData(); // will be destroyed in AnalysisContent destructor
  analysis.setData("LinguisticMetaData",metadataholder);

  metadataholder->setMetaData(metaData);
  LimaStringText* lstexte=new LimaStringText(texte);
  analysis.setData("Text",lstexte);
  
  LINFO << "CoreLinguisticProcessingClient::analyze(";
  for( std::map<std::string,std::string>::const_iterator attrIt = metaData.begin() ;
	attrIt != metaData.end() ; attrIt++ ) {
	LINFO << "attr:" << attrIt->first << "value:" << attrIt->second << ", " ;
  }
  LINFO;
  
  std::map<std::string,std::string>* metaDataPtr = const_cast<std::map<std::string,std::string>*>(&metaData);
  LINFO << "CoreLinguisticProcessingClient::analyze(" << (*metaDataPtr)["docid"] << "...)";

  // add date/time/location metadata in LinguisticMetaData
  if (metaData.empty()) {
    LDEBUG << "CoreLinguisticProcessingClient::analyze: no metadata";
  }
  for (map<string,string>::const_iterator it=metaData.begin(),
         it_end=metaData.end(); it!=it_end; it++) {
    if ((*it).first=="date") {
      try {
        const std::string& str=(*it).second;
        uint64_t i=str.find("T"); //2006-12-11T12:44:00
        /*if (i!=std::string::npos) {
          QTime docTime=posix_time::time_from_string(str);
          metadataholder->setTime("document",docTime);
          LDEBUG << "use '"<< str << "' as document time";
          }*/
        string date(str,0,i);
        QDate docDate=QDate::fromString(date.c_str(),Qt::ISODate);
        metadataholder->setDate("document",docDate);
        
        LDEBUG << "use '"<< date << "' as document date";
        LDEBUG << "use boost'"<< docDate.day() <<"/"<< docDate.month() <<"/"<< docDate.year() << "' as document date";
      }
      catch (std::exception& e) {
        LERROR << "Error in date conversion (date '"<< (*it).second
               << "' will be ignored): " << e.what();
      }
    }
    else if ((*it).first=="location") {
      metadataholder->setLocation("document",(*it).second);
        LDEBUG << "use '"<< (*it).second<< "' as document location";
    }
    else if ((*it).first=="time") {
      try {
        QTime docTime= QTime::fromString((*it).second.c_str(),"hh:mm:ss.z" );
        metadataholder->setTime("document",docTime);
        LDEBUG << "use '"<< (*it).second<< "' as document time";
      }
      catch (std::exception& e) {
        LERROR << "Error in ptime conversion (time '"<< (*it).second
               << "' will be ignored): " << e.what();
      }
    }
    else if ((*it).first=="docid") {
      LDEBUG << "use '"<< (*it).second<< "' as document id";
      metadataholder->setMetaData("DocId",(*it).second);
    }
  }
 
  // try to retreive offset
  try
  {
    const std::string& offsetStr=metadataholder->getMetaData("StartOffset");
    metadataholder->setStartOffset(atoi(offsetStr.c_str()));
  }
  catch (LinguisticProcessingException& )
  {
    metadataholder->setStartOffset(0);
  }

  const std::string& fileName=metadataholder->getMetaData("FileName");
  // get language
  const std::string& lang=metadataholder->getMetaData("Lang");
  LINFO  << "analyze file is: '" << fileName << "'";
  LINFO  << "analyze pipeline is '" << pipelineId << "'";
  LINFO  << "analyze language is '" << lang << "'";
  LDEBUG << "texte : " << texte;
  //LDEBUG << "texte : " << Common::Misc::limastring2utf8stdstring(texte);

  MediaId langId=MediaticData::single().getMediaId(lang);

  // get pipeline
  const MediaProcessUnitPipeline* pipeline=MediaProcessors::single().getPipelineForId(langId,pipelineId);
  if (pipeline==0)
  {
    LERROR << "can't get pipeline '" << pipelineId << "'";
    throw LinguisticProcessingException( std::string("can't get pipeline '" + pipelineId + "'") );
  }
  InactiveUnitsData* inactiveUnitsData = new InactiveUnitsData();
  for (std::set<std::string>::const_iterator it = inactiveUnits.begin(); it != inactiveUnits.end(); it++)
  {
//     const_cast<MediaProcessUnitPipeline*>(pipeline)->setInactiveProcessUnit(*it);
    inactiveUnitsData->insert(*it);
  }
  analysis.setData("InactiveUnits", inactiveUnitsData);
  
  // add handler to analysis
  LDEBUG << "add handler to analysis" ;
  for (auto hit = handlers.begin(); hit != handlers.end(); hit++)
  {
    LDEBUG << "    " << (*hit).first << (*hit).second;
  }
  AnalysisHandlerContainer* h = new AnalysisHandlerContainer(const_cast<std::map<std::string, AbstractAnalysisHandler*>& >(handlers));
  LDEBUG << "set data" ;
  analysis.setData("AnalysisHandlerContainer", h);

  // process analysis
  LDEBUG << "Process pipeline..." ;
  LimaStatusCode status=pipeline->process(analysis);
  LDEBUG << "pipeline process returned status " << (int)status ;
  if (status!=SUCCESS_ID)
  {
    std::stringstream s_mess;
    s_mess << "analysis failed : receive status " << (int)status << " from pipeline. exit";
    LERROR << s_mess.str();
    throw LinguisticProcessingException( s_mess.str() );
  }
}