src/PredFinder/elf/ElfDocument.cpp
/**
 * Reads this document as an ELF XML file from the specified file.
 *
 * XMLPlatformUtils::Initialize() must be called before this method.
 *
 * @param input_file The path to the ELF XML file to read.
 *
 * @author nward@bbn.com
 * @date 2010.08.30
 **/
Reads this document as an ELF XML file from the specified file.

:Initialize() must be called before this method.

@param input_file The path to the ELF XML file to read.


Reads this document as an ELF XML file from the specified file . : Initialize () must be called before this method . @param input_file The path to the ELF XML file to read .
ElfDocument::ElfDocument(const std::string & input_file) {
	DOMDocument* xml = XMLUtil::loadXercesDOMFromFilename(input_file.c_str());
	if (xml == NULL)
		throw std::runtime_error("ElfDocument::ElfDocument(std::string): Could not parse XML");
	DOMElement* doc = xml->getDocumentElement();
	if (doc == NULL)
		throw std::runtime_error("ElfDocument::ElfDocument(std::string): Could not get <doc>");
    _id = SXMLUtil::getAttributeAsStdWString(doc, "id");
	if (_id == L"")
		throw std::runtime_error("ElfDocument::ElfDocument(std::string): No id attribute specified on <doc>");
	_version = SXMLUtil::getAttributeAsStdWString(doc, "elf-version");
	if (_version == L"")
		throw std::runtime_error("ElfDocument::ElfDocument(std::string): No elf-version attribute specified on <doc>");
	_source = SXMLUtil::getAttributeAsStdWString(doc, "source");
	if (_source == L"")
		throw std::runtime_error("ElfDocument::ElfDocument(std::string): No source attribute specified on <doc>");
	_contents = SXMLUtil::getAttributeAsStdWString(doc, "contents");
	if (_contents == L"")
		throw std::runtime_error("ElfDocument::ElfDocument(std::string): No contents attribute specified on <doc>");
	bool exclusive_end_offsets = false;
	DOMNodeList* individual_nodes = SXMLUtil::getNodesByTagName(doc, "individual");
	ElfIndividualSet individuals;
	for (XMLSize_t r = 0; r < individual_nodes->getLength(); r++) {
		DOMElement* individual_element = dynamic_cast<DOMElement*>(individual_nodes->item(r));
		try {
			ElfIndividual_ptr individual = boost::make_shared<ElfIndividual>(individual_element, _id, _source, exclusive_end_offsets);
			if (individual.get() != NULL)
				individuals.insert(individual);
			else
				throw std::runtime_error("Returned ElfIndividual was NULL");
		} catch (std::exception& e) {
			SessionLogger::info("LEARNIT") << "ElfDocument::ElfDocument(std::string): bad <individual>, skipping: " << e.what() << std::endl;
		}
	}
	DOMNodeList* relation_nodes = SXMLUtil::getNodesByTagName(doc, "relation");
	for (XMLSize_t r = 0; r < relation_nodes->getLength(); r++) {
		DOMElement* relation_element = dynamic_cast<DOMElement*>(relation_nodes->item(r));
		try {
			ElfRelation_ptr relation = boost::make_shared<ElfRelation>(relation_element, individuals, exclusive_end_offsets);
			if (relation.get() != NULL)
				_relations.insert(relation);
			else
				throw std::runtime_error("Returned ElfRelation was NULL");
		} catch (std::exception& e) {
			SessionLogger::info("LEARNIT") << "ElfDocument::ElfDocument(std::string): bad <relation>, skipping: " << e.what() << std::endl;
		}
	}
}
ElfDocument :: ElfDocument ( const std :: string & input_file ) { DOMDocument * xml = XMLUtil :: loadXercesDOMFromFilename ( input_file . c_str ( ) ) ; if ( xml == NULL ) throw std :: runtime_error ( " " ) ; DOMElement * doc = xml -> getDocumentElement ( ) ; if ( doc == NULL ) throw std :: runtime_error ( " " ) ; _id = SXMLUtil :: getAttributeAsStdWString ( doc , " " ) ; if ( _id == L" " ) throw std :: runtime_error ( " " ) ; _version = SXMLUtil :: getAttributeAsStdWString ( doc , " " ) ; if ( _version == L" " ) throw std :: runtime_error ( " " ) ; _source = SXMLUtil :: getAttributeAsStdWString ( doc , " " ) ; if ( _source == L" " ) throw std :: runtime_error ( " " ) ; _contents = SXMLUtil :: getAttributeAsStdWString ( doc , " " ) ; if ( _contents == L" " ) throw std :: runtime_error ( " " ) ; bool exclusive_end_offsets = false ; DOMNodeList * individual_nodes = SXMLUtil :: getNodesByTagName ( doc , " " ) ; ElfIndividualSet individuals ; for ( XMLSize_t r = 0 ; r < individual_nodes -> getLength ( ) ; r ++ ) { DOMElement * individual_element = dynamic_cast < DOMElement * > ( individual_nodes -> item ( r ) ) ; try { ElfIndividual_ptr individual = boost :: make_shared < ElfIndividual > ( individual_element , _id , _source , exclusive_end_offsets ) ; if ( individual . get ( ) != NULL ) individuals . insert ( individual ) ; else throw std :: runtime_error ( " " ) ; } catch ( std :: exception & e ) { SessionLogger :: info ( " " ) << " " << e . what ( ) << std :: endl ; } } DOMNodeList * relation_nodes = SXMLUtil :: getNodesByTagName ( doc , " " ) ; for ( XMLSize_t r = 0 ; r < relation_nodes -> getLength ( ) ; r ++ ) { DOMElement * relation_element = dynamic_cast < DOMElement * > ( relation_nodes -> item ( r ) ) ; try { ElfRelation_ptr relation = boost :: make_shared < ElfRelation > ( relation_element , individuals , exclusive_end_offsets ) ; if ( relation . get ( ) != NULL ) _relations . insert ( relation ) ; else throw std :: runtime_error ( " " ) ; } catch ( std :: exception & e ) { SessionLogger :: info ( " " ) << " " << e . what ( ) << std :: endl ; } } }
Reads this document as an ELF XML file from the specified file.
Reads this document as an ELF XML file from the specified file .
// Read the file and get the root element
 // Read the document metadata attributes
 // Check how we're handling offsets (currently everyone is correctly inclusive)
 // Read all of the <individual>s in this document
 //   We read these first so that they're available for lookup when reading <relation>s
 // Store the read individual
 // Read all of the <relation>s in this document
