src/LearnIt/MatchInfo.cpp
/* Given a mapping from slot labels to proposition paths, return an XML string describing
 * the proposition tree that follows those paths.  Paths that share links should be 
 * 'collapsed' together.  
 * 
 * Preconditions: slotPaths is non-empty; and all paths in slotPaths must start with the
 * same proposition.
 */
Given a mapping from slot labels to proposition paths, return an XML string describing
the proposition tree that follows those paths.  Paths that share links should be
'collapsed' together.

slotPaths is non-empty; and all paths in slotPaths must start with the
same proposition.
Given a mapping from slot labels to proposition paths return an XML string describing the proposition tree that follows those paths . Paths that share links should be ' collapsed ' together . slotPaths is non - empty ; and all paths in slotPaths must start with the same proposition .
int MatchInfo::writePropInfoFromSlotPaths(const std::map<int, PropPath> &slotPaths, 
										   learnit::SeedInstanceMatch* out, size_t depth) {
	const Proposition* prop = (*slotPaths.begin()).second[depth].prop;
	typedef std::pair<int, PropPath> SlotAndPath;
	typedef std::pair<const Proposition*, std::wstring> PropAndRole;	
	BOOST_FOREACH(SlotAndPath slotAndPropPath, slotPaths) {
		assert(slotAndPropPath.second[depth].prop == prop);
	}
	learnit::Prop* propOut = out->add_prop();
	int propIndex = out->prop_size()-1;
	getPropStartTag(prop,propOut);
	std::map<PropAndRole, std::map<int, PropPath> > pathsViaChild;
	std::map<PropAndRole, std::vector<int> > slotsAtChild;
	std::map<PropAndRole, std::wstring> lexAtChild;
	std::set<PropAndRole> children;
	BOOST_FOREACH(SlotAndPath slotAndPath, slotPaths) {
		int slot_num = slotAndPath.first;
		PropPath path = slotAndPath.second;
		if (path.size() > (depth+1)) {
			PropAndRole child = make_pair(path[depth+1].prop, path[depth].role);
			if (path[depth+1].end) {
				if (path[depth+1].role.empty()){
					slotsAtChild[child].push_back(slot_num);
				} else {
					lexAtChild[child] = path[depth+1].role;
				}
			} else {
				pathsViaChild[child][slot_num] = path;
			}
			children.insert(child);
		}
	}
	BOOST_FOREACH(PropAndRole child, children) {
		std::wstring role = child.second;
		learnit::Arg* arg = propOut->add_arg();
		arg->set_role(UnicodeUtil::toUTF8StdString(role));
		if (slotsAtChild.count(child)) {
			BOOST_FOREACH(int slot_num, slotsAtChild[child]) {
				arg->add_slot(slot_num);
			}
		}
		if (lexAtChild.count(child)){
			arg->set_lex(UnicodeUtil::toUTF8StdString(lexAtChild[child]));
		}
		if (pathsViaChild[child].empty()) {
		} else {
			arg->add_propchildid(writePropInfoFromSlotPaths(pathsViaChild[child], out, depth+1));
		}
	}
	return propIndex;
}
int MatchInfo :: writePropInfoFromSlotPaths ( const std :: map < int , PropPath > & slotPaths , learnit :: SeedInstanceMatch * out , size_t depth ) { const Proposition * prop = ( * slotPaths . begin ( ) ) . second [ depth ] . prop ; typedef std :: pair < int , PropPath > SlotAndPath ; typedef std :: pair < const Proposition * , std :: wstring > PropAndRole ; BOOST_FOREACH ( SlotAndPath slotAndPropPath , slotPaths ) { assert ( slotAndPropPath . second [ depth ] . prop == prop ) ; } learnit :: Prop * propOut = out -> add_prop ( ) ; int propIndex = out -> prop_size ( ) - 1 ; getPropStartTag ( prop , propOut ) ; std :: map < PropAndRole , std :: map < int , PropPath > > pathsViaChild ; std :: map < PropAndRole , std :: vector < int > > slotsAtChild ; std :: map < PropAndRole , std :: wstring > lexAtChild ; std :: set < PropAndRole > children ; BOOST_FOREACH ( SlotAndPath slotAndPath , slotPaths ) { int slot_num = slotAndPath . first ; PropPath path = slotAndPath . second ; if ( path . size ( ) > ( depth + 1 ) ) { PropAndRole child = make_pair ( path [ depth + 1 ] . prop , path [ depth ] . role ) ; if ( path [ depth + 1 ] . end ) { if ( path [ depth + 1 ] . role . empty ( ) ) { slotsAtChild [ child ] . push_back ( slot_num ) ; } else { lexAtChild [ child ] = path [ depth + 1 ] . role ; } } else { pathsViaChild [ child ] [ slot_num ] = path ; } children . insert ( child ) ; } } BOOST_FOREACH ( PropAndRole child , children ) { std :: wstring role = child . second ; learnit :: Arg * arg = propOut -> add_arg ( ) ; arg -> set_role ( UnicodeUtil :: toUTF8StdString ( role ) ) ; if ( slotsAtChild . count ( child ) ) { BOOST_FOREACH ( int slot_num , slotsAtChild [ child ] ) { arg -> add_slot ( slot_num ) ; } } if ( lexAtChild . count ( child ) ) { arg -> set_lex ( UnicodeUtil :: toUTF8StdString ( lexAtChild [ child ] ) ) ; } if ( pathsViaChild [ child ] . empty ( ) ) { } else { arg -> add_propchildid ( writePropInfoFromSlotPaths ( pathsViaChild [ child ] , out , depth + 1 ) ) ; } } return propIndex ; }
Given a mapping from slot labels to proposition paths, return an XML string describing
 the proposition tree that follows those paths.
Given a mapping from slot labels to proposition paths return an XML string describing the proposition tree that follows those paths .
// Check our precondition; and get the root of the proposition tree.
 // Write an XML tag for the root.
 // Divide up the slots, according to which child proposition they
 // appear with.
 //out << std::wstring(depth*4+2, L' '); // indentation
 //out << "<Arg role=\"" 
 //	<< MainUtilities::encodeForXML(child.second) << "\"";
 // For multiple slots, this gives 'slots="6 3 4 "'
 //out << L" slot=\"";
 //out << slot_num << L" ";
 //out << L"\"";
 //out << L" lex=\"";
 //out << MainUtilities::encodeForXML(lexAtChild[child]);
 //out << L"\"";
 //out << "/>\n";
 //out << ">\n";
 //out << std::wstring(depth*4+2, L' '); // indentation
 //out << "</Arg>\n";
 //out << std::wstring(depth*4, L' ') << "</Prop>\n";
