Example #1
0
void Search::readStrGraph(Patterns &patterns,StrGraph &desc) {
    clear();
    map<StrGraph::Node*,Node*> recollect;
    for(StrGraph::node_iter ni = desc.nodes().begin(); ni!=desc.nodes().end(); ++ni) {
        Node *n = create_node(gd<Name>(*ni));
        recollect[*ni] = n;
        SearchStage &stage = gd<SearchStage>(n);
        DString limit = gd<StrAttrs>(*ni).look("limit","50");
        stage.limit = atoi(limit.c_str());
        DString action = gd<StrAttrs>(*ni).look("action","union");
        if(action=="union")
            stage.type = UnionInquiry;
        else if(action=="intersection")
            stage.type = IntersectionInquiry;
        else if(action=="pattern") {
            stage.type = PatternInquiry;
            DString pattern = gd<StrAttrs>(*ni).look("pattern","");
            Patterns::iterator pi = patterns.find(pattern);
            if(pi==patterns.end())
                throw UndefinedPattern(pattern);
            stage.pattern = &pi->second;
        }
        else if(action=="path") {
            stage.type = PathInquiry;
            DString ways = gd<StrAttrs>(*ni)["ways"];
            if(ways=="in")
                stage.goIn = true, stage.goOut = false;
            else if(ways=="both")
                stage.goIn = stage.goOut = true;
            else  // ways=="out" default
                stage.goIn = false, stage.goOut = true;
            stage.firstOnly = gd<StrAttrs>(*ni)["firstonly"]=="true";
            stage.shortest = gd<StrAttrs>(*ni)["shortest"]=="true";
            stage.weightattr = gd<StrAttrs>(*ni).look("weightattr","weight");
        }
        else
            throw UnknownAction(action);
    }
    for(StrGraph::graphedge_iter ei = desc.edges().begin(); ei!=desc.edges().end(); ++ei) {
        Edge *e = create_edge(recollect[(*ei)->tail],recollect[(*ei)->head]).first;
        DString input = gd<StrAttrs>(*ei).look("input","");
        gd<Name>(e) = input;
    }
}
Example #2
0
	static Pire::CountingScanner Do(const Patterns& patterns, bool /*surround*/)
	{
		Pire::CountingScanner sc;
		for (Patterns::const_iterator i = patterns.begin(), ie = patterns.end(); i != ie; ++i) {
			Pire::CountingScanner tsc = Pire::CountingScanner(
				Pire::Lexer(*i).Parse(), Pire::Lexer(".*").Parse());
			if (i == patterns.begin())
				tsc.Swap(sc);
			else {
				sc = Pire::CountingScanner::Glue(sc, tsc);
				if (sc.Empty()) {
					std::ostringstream msg;
					msg << "Scanner gluing failed at regexp " << *i << " - pattern too complicated";
					throw std::runtime_error(msg.str());
				}
			}
		}
		return sc;
	}
Example #3
0
	static Pire::Impl::Scanner<Relocation, Shortcutting> Do(const Patterns& patterns, bool surround)
	{
		typedef Pire::Impl::Scanner<Relocation, Shortcutting> Sc;
		Sc sc;
		for (Patterns::const_iterator i = patterns.begin(), ie = patterns.end(); i != ie; ++i) {
			Pire::Fsm fsm = Pire::Lexer(*i).Parse();
			if (surround)
				fsm.Surround();
			Sc tsc = fsm.Compile<Sc>();
			if (i == patterns.begin())
				tsc.Swap(sc);
			else {
				sc = Sc::Glue(sc, tsc);
				if (sc.Empty()) {
					std::ostringstream msg;
					msg << "Scanner gluing failed at regexp " << *i << " - pattern too complicated";
					throw std::runtime_error(msg.str());
				}
			}
		}
		return sc;
	}