Boost logo

Boost :

From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2008-02-07 03:56:57


Thorsten Ottosen skrev:
> Hi Eric,
>
> (Apologies in advance for such a stupid question.)

I case it helps, then below is my complete function.

-Thorsten

-----------------------

     NaiveModel NaiveModel::loadNetFile( const std::string& file )
     {
         using namespace boost::xpressive;

         NaiveModel res( file );
         std::string data = readFile( file );

         std::vector<Float> costWeights;
         std::vector<Float> costConversion;
         std::vector<std::string> causeNames;
         std::vector<std::string> actionNames;
         std::map<std::string,std::string>
                                   actionNameToId;
         std::vector<std::string> questionNames;
         std::map<std::string,std::string>
                                   questionNameToId;
         std::vector<Float> causeProbs;
         std::vector<Float> actionProbs;
         std::vector<Float> questionProbs;

         bx::sregex space;
         bx::sregex nodeStart;
         bx::sregex nodeEnd;
         bx::sregex _float;
         bx::sregex name;
         bx::sregex modelConfiguration;
         bx::sregex causeNode;
         bx::sregex actionNode;
         bx::sregex actions;
         bx::sregex questionNode;
         bx::sregex questions;
         bx::sregex causeProbabilities;
         bx::sregex actionPotential;
         bx::sregex actionProbabilities;
         bx::sregex questionProbabilities;
         bx::sregex netFile;

         space = _s | _ln;

         nodeStart = +_d >> +space >> '{' >> +space;

         nodeEnd = as_xpr(';') >> +space >> '}';

         _float = +_d | +_d >> (as_xpr('.') | ',') >> *_d;

         // @todo: consider -+~(set='"')
         name = *space >> '"' >> +(~set['"']) >> '"';

         modelConfiguration = as_xpr("net") >> *space >> '{' >> -*_ >> '}';

         causeNode = *_ >> "HR_Desc = \"All causes\";" >> *space
>> "states = (" >>
                     +(name[push_back(ref(causeNames),as<std::string>(_) )])
>> -*_ >> nodeEnd;

         actionNode = (as_xpr( "node C" ) >> nodeStart >>
                      "label = " >> (s1=name) >>
                      -*_ >> "HR_Desc = \"Action\"" >>
                      -*_ >> "HR_ID = \"" >> (s2=+_d) >>
                      -*_ >> nodeEnd)[ ref(actionNameToId)[s1] =
as<std::string>(s2) ];

         actions = +( *space >> actionNode );

         questionNode = (as_xpr( "node C" ) >> nodeStart >>
                        "label = " >> (s1=name) >>
                        -*_ >> "HR_Desc = \"Question\"" >>
                        -*_ >> "HR_ID = \"" >> (s2=+_d) >>
                        -*_ >> nodeEnd)[ ref(questionNameToId)[s1] =
as<std::string>(s2) ];

         questions = +( *space >> questionNode );

         causeProbabilities = -*_ >> "potential (CXXX" >> -*_ >> "data =
(" >>
                              +( *space >>
_float[push_back(ref(causeProbs),as<Float>(_))] )
>> *space >> ")" >> nodeEnd;

         sregex row = *space >>
_float[push_back(ref(actionProbs),as<Float>(_))] >>
                       space >>
                      -*_ >> _ln;

         actionPotential = -*_ >> "potential (C" >>
                           -*_ >> "data = (" >>
                           +row >>
                           -*_ >> '}';

         actionProbabilities = +( *space >> actionPotential );

         netFile = *space >>
                   modelConfiguration >>
                   causeNode >>
                   actions >>
                   optional( questions ) >>
                   causeProbabilities >>
                   actionProbabilities >>
                   //questionProbabilities >>

                   *_;

         bx::smatch what;
         if( bx::regex_search( data, what, netFile ) )
         {
             Engine::print( causeNames );
             Engine::printMap( actionNameToId );
             Engine::printMap( questionNameToId );
             Engine::print( questionNames );
             Engine::print( causeProbs );
             Engine::print( actionProbs );

             //std::cerr << "\n\n" << what[0] << "\n\n" << std::endl;
         }
         else
             std::cerr << "\n\ndid not match file" << file << "!\n\n" <<
std::endl;

         //DEZIDE_ENFORCE_MSG( causeProbs.size() == causeNames().size(),
         // "Invalid parsing of causes!" );

         //std::cerr << data;
         return res;
     }


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk