src/PredFinder/elf/ElfRelation.cpp
/**
 * Converts this relation to an XML <relation> element using the
 * Xerces-C++ library.
 *
 * XMLPlatformUtils::Initialize() must be called before this method.
 *
 * @param doc An already-instantiated Xerces DOMDocument that
 * provides namespace context for the created element (since
 * Xerces doesn't support easy anonymous element import).
 * @return The constructed <relation> DOMElement
 *
 * @author nward@bbn.com
 * @date 2010.05.14
 **/
Converts this relation to an XML  element using the
Xerces-C++ library.

:Initialize() must be called before this method.

@param doc An already-instantiated Xerces DOMDocument that
provides namespace context for the created element (since
Xerces doesn't support easy anonymous element import).
@return The constructed  DOMElement


Converts this relation to an XML element using the Xerces - C ++ library . : Initialize () must be called before this method . @param doc An already - instantiated Xerces DOMDocument that provides namespace context for the created element ( since Xerces doesn ' t support easy anonymous element import ) . @return The constructed DOMElement
DOMElement* ElfRelation::to_xml(DOMDocument* doc, const std::wstring & docid) const {
	static bool show_source_attrib = ParamReader::getOptionalTrueFalseParamWithDefaultVal(
		"show_source_attrib",  true);
	static bool show_confidence_attrib = ParamReader::getOptionalTrueFalseParamWithDefaultVal(
		"show_confidence_attrib",  true);
	DOMElement* relation = SXMLUtil::createElement(doc, "relation");
	SXMLUtil::setAttributeFromStdWString(relation, "name", _name);
	if (_start.is_defined() && _end.is_defined()) {
        SXMLUtil::setAttributeFromEDTOffset(relation, "start", _start);
        SXMLUtil::setAttributeFromEDTOffset(relation, "end", _end);
	}
	if (show_confidence_attrib && _confidence > 0.0) {
		std::wostringstream confidence;
		confidence << std::fixed << std::setprecision(3) << _confidence;
		SXMLUtil::setAttributeFromStdWString(relation, "p", confidence.str());
	}
	if (show_confidence_attrib && _score_group > 0) {
		std::wostringstream score_group;
		score_group << _score_group;
		SXMLUtil::setAttributeFromStdWString(relation, "score_group", score_group.str());
	}
	if (show_source_attrib && !_source.empty()) {
		SXMLUtil::setAttributeFromStdWString(relation, "source", _source);
	}
	if (ParamReader::isParamTrue("elf_include_text_excerpts") && _text != L"") {
		DOMElement* text = SXMLUtil::createElement(doc, "text");
        SerifXML::xstring x_text = SerifXML::transcodeToXString(_text.c_str());
		DOMText* text_cdata = doc->createTextNode(x_text.c_str());
		text->appendChild(text_cdata);
		relation->appendChild(text);
	}
	bool sort_elf_elements = ParamReader::getOptionalTrueFalseParamWithDefaultVal("sort_elf_elements",  false);
	if (sort_elf_elements) {
		std::vector<ElfRelationArg_ptr> args = get_args();
		ElfRelationArgSortedSet sorted_args(args.begin(), args.end());
		BOOST_FOREACH(ElfRelationArg_ptr arg, sorted_args) {
			relation->appendChild(arg->to_xml(doc, docid, (arg->get_role() == L"rdf:subject" && (boost::starts_with(_name, L"rdf") || _name == L"ic:hasName"))));
		}
	} else {
		BOOST_FOREACH(ElfRelationArg_ptr arg, get_args()) {
			relation->appendChild(arg->to_xml(doc, docid, (arg->get_role() == L"rdf:subject" && (boost::starts_with(_name, L"rdf") || _name == L"ic:hasName"))));
		}
	}
	return relation;
}
DOMElement * ElfRelation :: to_xml ( DOMDocument * doc , const std :: wstring & docid ) const { static bool show_source_attrib = ParamReader :: getOptionalTrueFalseParamWithDefaultVal ( " " , true ) ; static bool show_confidence_attrib = ParamReader :: getOptionalTrueFalseParamWithDefaultVal ( " " , true ) ; DOMElement * relation = SXMLUtil :: createElement ( doc , " " ) ; SXMLUtil :: setAttributeFromStdWString ( relation , " " , _name ) ; if ( _start . is_defined ( ) && _end . is_defined ( ) ) { SXMLUtil :: setAttributeFromEDTOffset ( relation , " " , _start ) ; SXMLUtil :: setAttributeFromEDTOffset ( relation , " " , _end ) ; } if ( show_confidence_attrib && _confidence > 0.0 ) { std :: wostringstream confidence ; confidence << std :: fixed << std :: setprecision ( 3 ) << _confidence ; SXMLUtil :: setAttributeFromStdWString ( relation , " " , confidence . str ( ) ) ; } if ( show_confidence_attrib && _score_group > 0 ) { std :: wostringstream score_group ; score_group << _score_group ; SXMLUtil :: setAttributeFromStdWString ( relation , " " , score_group . str ( ) ) ; } if ( show_source_attrib && ! _source . empty ( ) ) { SXMLUtil :: setAttributeFromStdWString ( relation , " " , _source ) ; } if ( ParamReader :: isParamTrue ( " " ) && _text != L" " ) { DOMElement * text = SXMLUtil :: createElement ( doc , " " ) ; SerifXML :: xstring x_text = SerifXML :: transcodeToXString ( _text . c_str ( ) ) ; DOMText * text_cdata = doc -> createTextNode ( x_text . c_str ( ) ) ; text -> appendChild ( text_cdata ) ; relation -> appendChild ( text ) ; } bool sort_elf_elements = ParamReader :: getOptionalTrueFalseParamWithDefaultVal ( " " , false ) ; if ( sort_elf_elements ) { std :: vector < ElfRelationArg_ptr > args = get_args ( ) ; ElfRelationArgSortedSet sorted_args ( args . begin ( ) , args . end ( ) ) ; BOOST_FOREACH ( ElfRelationArg_ptr arg , sorted_args ) { relation -> appendChild ( arg -> to_xml ( doc , docid , ( arg -> get_role ( ) == L" " && ( boost :: starts_with ( _name , L" " ) || _name == L" " ) ) ) ) ; } } else { BOOST_FOREACH ( ElfRelationArg_ptr arg , get_args ( ) ) { relation -> appendChild ( arg -> to_xml ( doc , docid , ( arg -> get_role ( ) == L" " && ( boost :: starts_with ( _name , L" " ) || _name == L" " ) ) ) ) ; } } return relation ; }
Converts this relation to an XML <relation> element using the
 Xerces-C++ library.
Converts this relation to an XML <relation > element using the Xerces - C ++ library .
// Until we get rules firing in a predictable order, the source and confidence attributes may differ from run to run.
 // To make it easier to compare diffs, we add params that allow us to blank out the contents of these
 // attributes when set to false.
 /* defaultVal=*/ /* defaultVal=*/ // Create a new relation element
 // Copy the relation's properties in as attributes of the <relation>
 // Format the relation's confidence, if any, as an xsd:double with 3 digits of precision
 // Print score group only if we are printing scores
 // Copy the relation's source pattern in as an attribute.
 // Optionally print the text evidence for the relation
 // Extract the text for the entire match
 // Note that this parameter is also read by ElfDocument.
 /* defaultVal=*/ // Suppress type attribute on rdf:subject args of rdf:/rdfs: relations
 // Suppress type attribute on rdf:subject args of rdf:/rdfs: relations
 // Done
