src/PredFinder/elf/ElfRelation.cpp
/**
 * Reads this ElfRelation from an XML <relation> element.
 *
 * XMLPlatformUtils::Initialize() must be called before this method.
 *
 * @param relation The DOMElement containing a <relation>.
 * @param individuals The read <individual>s from this <relation>'s
 * containing document that are passed through to <arg>s for id lookup.
 *
 * @author nward@bbn.com
 * @date 2010.08.31
 **/
Reads this ElfRelation from an XML  element.

:Initialize() must be called before this method.

@param relation The DOMElement containing a .
@param individuals The read s from this 's
containing document that are passed through to s for id lookup.


Reads this ElfRelation from an XML element . : Initialize () must be called before this method . @param relation The DOMElement containing a . @param individuals The read s from this ' s containing document that are passed through to s for id lookup .
ElfRelation::ElfRelation(const DOMElement* relation, const ElfIndividualSet & individuals, bool exclusive_end_offsets) {
	_name = SXMLUtil::getAttributeAsStdWString(relation, "name");
	if (_name == L"")
		throw std::runtime_error("ElfRelation::ElfRelation(DOMElement*, ElfIndividualSet): No name attribute specified on <relation>");
	_source = SXMLUtil::getAttributeAsStdWString(relation, "source");
	std::wstring start = SXMLUtil::getAttributeAsStdWString(relation, "start");
	if (start != L"") {
		_start = EDTOffset(boost::lexical_cast<int>(start));
	} else {
		_start = EDTOffset();
	}
	std::wstring end = SXMLUtil::getAttributeAsStdWString(relation, "end");
	if (end != L"") {
		_end = EDTOffset(boost::lexical_cast<int>(end));
	} else {
		_end = EDTOffset();
	}
	std::wstring confidence = SXMLUtil::getAttributeAsStdWString(relation, "p");
	if (confidence != L"") {
		_confidence = boost::lexical_cast<double>(confidence);
	} else {
		_confidence = Pattern::UNSPECIFIED_SCORE;
	}	
	std::wstring score_group = SXMLUtil::getAttributeAsStdWString(relation, "score_group");
	if (score_group != L"") {
		_score_group = boost::lexical_cast<int>(score_group);
	} else {
		_score_group = Pattern::UNSPECIFIED_SCORE_GROUP;
	}
	if (exclusive_end_offsets && _end.is_defined())
		--_end;
	DOMNodeList* text_nodes = SXMLUtil::getNodesByTagName(relation, "text");
	if (text_nodes->getLength() == 0) {
		_text = L"";
	} else if (text_nodes->getLength() == 1) {
		_text = SerifXML::transcodeToStdWString(text_nodes->item(0)->getTextContent());
	} else {
		throw std::runtime_error("ElfRelation::ElfRelation(DOMElement*, ElfIndividualSet): More than one <text> child specified in <relation>");
	}
	if ((!_start.is_defined() && _end.is_defined()) || (_start.is_defined() && !_end.is_defined())) {
		throw std::runtime_error("ElfRelation::ElfRelation(DOMElement*, ElfIndividualSet): Invalid offset attributes on <relation>, specify both or neither");
	} else if ((_start.is_defined() && _end.is_defined() && _text == L"") || (!_start.is_defined() && !_end.is_defined() && _text != L"")) {
		throw std::runtime_error("ElfRelation::ElfRelation(DOMElement*, ElfIndividualSet): <relation> must specify both offset attributes and <text> child or neither");
	}
	DOMNodeList* arg_nodes = SXMLUtil::getNodesByTagName(relation, "arg");
	for (XMLSize_t a = 0; a < arg_nodes->getLength(); a++) {
		DOMElement* arg_element = dynamic_cast<DOMElement*>(arg_nodes->item(a));
		ElfRelationArg_ptr arg = boost::make_shared<ElfRelationArg>(arg_element, individuals, exclusive_end_offsets);
		if (arg.get() != NULL)
			insert_argument(arg);
		else
			throw std::runtime_error("ElfRelation::ElfRelation(DOMElement*, ElfIndividualSet): bad <arg> element in <relation>");
	}
}
ElfRelation :: ElfRelation ( const DOMElement * relation , const ElfIndividualSet & individuals , bool exclusive_end_offsets ) { _name = SXMLUtil :: getAttributeAsStdWString ( relation , " " ) ; if ( _name == L" " ) throw std :: runtime_error ( " " ) ; _source = SXMLUtil :: getAttributeAsStdWString ( relation , " " ) ; std :: wstring start = SXMLUtil :: getAttributeAsStdWString ( relation , " " ) ; if ( start != L" " ) { _start = EDTOffset ( boost :: lexical_cast < int > ( start ) ) ; } else { _start = EDTOffset ( ) ; } std :: wstring end = SXMLUtil :: getAttributeAsStdWString ( relation , " " ) ; if ( end != L" " ) { _end = EDTOffset ( boost :: lexical_cast < int > ( end ) ) ; } else { _end = EDTOffset ( ) ; } std :: wstring confidence = SXMLUtil :: getAttributeAsStdWString ( relation , " " ) ; if ( confidence != L" " ) { _confidence = boost :: lexical_cast < double > ( confidence ) ; } else { _confidence = Pattern :: UNSPECIFIED_SCORE ; } std :: wstring score_group = SXMLUtil :: getAttributeAsStdWString ( relation , " " ) ; if ( score_group != L" " ) { _score_group = boost :: lexical_cast < int > ( score_group ) ; } else { _score_group = Pattern :: UNSPECIFIED_SCORE_GROUP ; } if ( exclusive_end_offsets && _end . is_defined ( ) ) -- _end ; DOMNodeList * text_nodes = SXMLUtil :: getNodesByTagName ( relation , " " ) ; if ( text_nodes -> getLength ( ) == 0 ) { _text = L" " ; } else if ( text_nodes -> getLength ( ) == 1 ) { _text = SerifXML :: transcodeToStdWString ( text_nodes -> item ( 0 ) -> getTextContent ( ) ) ; } else { throw std :: runtime_error ( " " ) ; } if ( ( ! _start . is_defined ( ) && _end . is_defined ( ) ) || ( _start . is_defined ( ) && ! _end . is_defined ( ) ) ) { throw std :: runtime_error ( " " ) ; } else if ( ( _start . is_defined ( ) && _end . is_defined ( ) && _text == L" " ) || ( ! _start . is_defined ( ) && ! _end . is_defined ( ) && _text != L" " ) ) { throw std :: runtime_error ( " " ) ; } DOMNodeList * arg_nodes = SXMLUtil :: getNodesByTagName ( relation , " " ) ; for ( XMLSize_t a = 0 ; a < arg_nodes -> getLength ( ) ; a ++ ) { DOMElement * arg_element = dynamic_cast < DOMElement * > ( arg_nodes -> item ( a ) ) ; ElfRelationArg_ptr arg = boost :: make_shared < ElfRelationArg > ( arg_element , individuals , exclusive_end_offsets ) ; if ( arg . get ( ) != NULL ) insert_argument ( arg ) ; else throw std :: runtime_error ( " " ) ; } }
Reads this ElfRelation from an XML <relation> element.
Reads this ElfRelation from an XML <relation > element .
// Read the required relation attributes
 // Read the optional relation attributes
 // No confidence specified
 // No score group specified
 // Adjust the offsets if necessary
 // Get the string contents of the <text> element if any
 // Check the validity of the offsets and text
 // Read all of the <arg>s in this <relation>
