void CSwordModuleInfo::buildIndex() {
wchar_t wcharBuffer[BT_MAX_LUCENE_FIELD_LENGTH + 1];
//we don't want the linked entries indexed again
module()->setSkipConsecutiveLinks(true);
m_cancelIndexing = false;
//Without this we don't get strongs, lemmas, etc
backend()->setFilterOptions ( CBTConfig::getFilterOptionDefaults() );
//make sure we reset all important filter options which influcence the plain filters.
backend()->setOption( CSwordModuleInfo::strongNumbers, false );
backend()->setOption( CSwordModuleInfo::morphTags, false );
backend()->setOption( CSwordModuleInfo::morphSegmentation, false );
backend()->setOption( CSwordModuleInfo::footnotes, false );
backend()->setOption( CSwordModuleInfo::headings, false );
backend()->setOption( CSwordModuleInfo::scriptureReferences, false );
backend()->setOption( CSwordModuleInfo::redLetterWords, false );
// do not use any stop words
const TCHAR* stop_words[] = { NULL };
lucene::analysis::standard::StandardAnalyzer an( (const TCHAR**)stop_words );
QString index = getModuleStandardIndexLocation();
QDir dir("/");
dir.mkpath( getGlobalBaseIndexLocation() );
dir.mkpath( getModuleBaseIndexLocation() );
dir.mkpath( getModuleStandardIndexLocation() );
if (lucene::index::IndexReader::indexExists(index.toAscii().constData())) {
if (lucene::index::IndexReader::isLocked(index.toAscii().constData()) ) {
lucene::index::IndexReader::unlock(index.toAscii().constData());
}
}
boost::scoped_ptr<lucene::index::IndexWriter> writer( new lucene::index::IndexWriter(index.toAscii().constData(), &an, true) ); //always create a new index
writer->setMaxFieldLength(BT_MAX_LUCENE_FIELD_LENGTH);
writer->setUseCompoundFile(true); //merge segments into a single file
writer->setMinMergeDocs(1000);
*m_module = sword::TOP;
unsigned long verseLowIndex = m_module->Index();
*m_module = sword::BOTTOM;
unsigned long verseHighIndex = m_module->Index();
//verseLowIndex is not 0 in all cases (i.e. NT-only modules)
unsigned long verseIndex = verseLowIndex + 1;
unsigned long verseSpan = verseHighIndex - verseLowIndex;
//Index() is not implemented properly for lexicons, so we use a
//workaround.
if (type() == CSwordModuleInfo::Lexicon){
verseIndex = 0;
verseLowIndex = 0;
verseSpan = ((CSwordLexiconModuleInfo*)this)->entries()->size();
}
emit indexingProgress(0);
sword::SWKey* key = m_module->getKey();
//VerseKey for bibles
sword::VerseKey* vk = dynamic_cast<sword::VerseKey*>(key);
if (vk) {
// we have to be sure to insert the english key into the index, otherwise we'd be in trouble if the language changes
vk->setLocale("en_US");
//If we have a verse based module, we want to include the pre-chapter etc. headings in the search
vk->Headings(1);
}
//holds UTF-8 data and is faster than QString.
QByteArray textBuffer;
// we start with the first module entry, key is automatically updated
// because key is a pointer to the modules key
m_module->setSkipConsecutiveLinks(true);
for (*m_module = sword::TOP; !(m_module->Error()) && !m_cancelIndexing; (*m_module)++) {
//If it is a sword-heading, store in buffer and index later in Verse X:1
if (vk) {
if (vk->Verse() == 0) {
textBuffer.append( m_module->StripText() );
continue;
}
}
boost::scoped_ptr<lucene::document::Document> doc(new lucene::document::Document());
//index the key
lucene_utf8towcs(wcharBuffer, key->getText(), BT_MAX_LUCENE_FIELD_LENGTH);
//doc->add(*lucene::document::Field::UnIndexed((const TCHAR*)_T("key"), (const TCHAR*)wcharBuffer));
doc->add(*(new lucene::document::Field((const TCHAR*)_T("key"), (const TCHAR*)wcharBuffer, lucene::document::Field::STORE_YES | lucene::document::Field::INDEX_NO)));
// index the main text
//at this point we have to make sure we disabled the strongs and the other options
//so the plain filters won't include the numbers somehow.
lucene_utf8towcs(wcharBuffer, (const char*) textBuffer.append(m_module->StripText()), BT_MAX_LUCENE_FIELD_LENGTH);
//doc->add(*lucene::document::Field::UnStored((const TCHAR*)_T("content"), (const TCHAR*)wcharBuffer));
doc->add(*(new lucene::document::Field((const TCHAR*)_T("content"), (const TCHAR*)wcharBuffer, lucene::document::Field::STORE_NO | lucene::document::Field::INDEX_TOKENIZED)));
textBuffer.resize(0); //clean up
//.........这里部分代码省略.........
/*! \brief This function reads the input file containing the details of the transformation being used.*/
int read_rotation_information(struct parameter_struct *parameters){
string filename(parameters->rotation_info_file);
PetscErrorCode ierr;
//open rotation file as xml document.
TiXmlDocument doc(filename);
bool loadOkay = doc.LoadFile();
if ( !loadOkay )
{
PetscPrintf(PETSC_COMM_WORLD,"Could not load rotation info file '%s'. Error='%s'. Exiting.\n", parameters->rotation_info_file, doc.ErrorDesc() );
return 1;
}
TiXmlHandle docHandle(&doc);
//find ROTATION_OP tag.
parameters->number_rotation_sectors = 1;
TiXmlElement* parent_element = docHandle.FirstChild("ROTATION_OPS").Element();
if ( parent_element)
{
if (parent_element->Attribute("number") == NULL )
{
PetscPrintf(PETSC_COMM_WORLD,"You must specify the number of rotation operators.\n");
return 1;
}
parameters->number_rotation_ops = atoi(parent_element->Attribute("number"));
ierr = PetscMalloc(parameters->number_rotation_ops *sizeof(struct rotation_information), ¶meters->rotation_info); CHKERRQ(ierr);
for ( int rot_idx = 0 ; rot_idx < parameters->number_rotation_ops ; rot_idx ++ )
{
TiXmlElement* element = docHandle.FirstChild("ROTATION_OPS").Child("ROTATION_OP", rot_idx).Element(); //tags surrounding the mapping. Has attribute "number" which contains the
//number of times the rotation op can be applied before getting back to the start.
TiXmlElement* element2;
if ( element)
{
if (element->Attribute("number") == NULL ) {
PetscPrintf(PETSC_COMM_WORLD,"You must specify a number attribute to the rotation operation.\n");
return 1;
}
parameters->rotation_info[rot_idx].num_sectors = atoi(element->Attribute("number"));
parameters->rotation_info[rot_idx].num_relevant_sectors = parameters->rotation_info[rot_idx].num_sectors;
parameters->number_rotation_sectors *= parameters->rotation_info[rot_idx].num_sectors;
ierr = PetscMalloc( parameters->rotation_info[rot_idx].num_sectors * sizeof(PetscScalar),¶meters->rotation_info[rot_idx].phases);CHKERRQ(ierr);
//allocate space for the mapping masks.
ierr = PetscMalloc( parameters->rotation_info[rot_idx].num_sectors * sizeof(uPetscInt*),¶meters->rotation_info[rot_idx].mapping_masks);CHKERRQ(ierr);
for ( int i = 0 ; i < parameters->rotation_info[rot_idx].num_sectors ; i++ ) {
ierr = PetscMalloc(parameters->number_particles * sizeof(uPetscInt), ¶meters->rotation_info[rot_idx].mapping_masks[i]);CHKERRQ(ierr);
}
//applying 0 rotations will give the same stage so add masks that do not move any particles.
for ( int i = 0 ; i < parameters->number_particles ; i++ ) {
parameters->rotation_info[rot_idx].mapping_masks[0][i] = ((uPetscInt)1) << i;
}
//read in the mappings to position 1 which is a single rotation with the op.
for ( int i = 0 ; i < parameters->number_particles ; i++ ) {
element2 = docHandle.FirstChild("ROTATION_OPS").Child("ROTATION_OP", rot_idx).Child("MAPPING",i).Element();
if ( element2 ) {
parameters->rotation_info[rot_idx].mapping_masks[1][atoi(element2->Attribute("to"))-1] = ((uPetscInt)1) << (atoi(element2->Attribute("from"))-1);
} else {
PetscPrintf(PETSC_COMM_WORLD,"Mapping %d does not exist.\n",i);
return 1;
}
}
//Now iterate this rotation to fill in the masks for the other possible mutiples of the rotation.
for ( int i = 2 ; i < parameters->rotation_info[rot_idx].num_sectors ; i++ ) {
for ( int j = 0 ; j < parameters->number_particles ; j++ ) {
parameters->rotation_info[rot_idx].mapping_masks[i][j] = parameters->rotation_info[rot_idx].mapping_masks[1][log2_uPetscInt(parameters->rotation_info[rot_idx].mapping_masks[i-1][j])];
}
}
//print out the mapping for each number of rotations that can be applied. For debugging purposes.
/*for (int i = 0 ; i < parameters->rotation_info.num_sectors ; i++ ) {
PetscPrintf(PETSC_COMM_WORLD,"Applying %d rotations:\n",i);
for ( int j = 0 ; j < parameters->number_particles ; j++ ) {
PetscPrintf(PETSC_COMM_WORLD,"Site %d moved to site %d.\n",j,(int)log2_uPetscInt(parameters->rotation_info.mapping_masks[i][j]));
}
}*/
parameters->rotation_info[rot_idx].sector_modulo = 1;
parameters->rotation_info[rot_idx].sector_divisor = 1;
for ( int j = 0 ; j <= rot_idx ; j++ )
{
parameters->rotation_info[rot_idx].sector_modulo *= parameters->rotation_info[j].num_sectors;
if ( j < rot_idx) parameters->rotation_info[rot_idx].sector_divisor *= parameters->rotation_info[j].num_sectors;
}
} else {
PetscPrintf(PETSC_COMM_WORLD,"No ROTATION_OP %d tag in rotation info file.\n",rot_idx);
return 1;
}
}
//.........这里部分代码省略.........
开发者ID:nmoran,项目名称:DoQO,代码行数:101,代码来源:rotation.C
示例4: next
Data next() {
Document doc(_cursor->next());
return make_pair(_sorter->extractKey(doc), doc);
}
int load_db_init(t_db_info *db_info, t_cfg *cfg)
{
std::string gamepath(std::string(cfg->GamePath) + std::string(cfg->Game));
TiXmlDocument doc(gamepath.c_str());
const char *buf;
int int_buf;
int i;
char err_msg[BUF_SIZE];
if (doc.LoadFile() == false)
{
char *err = "Failed to load game database file: ";
strcpy(err_msg, err);
strcat(err_msg, gamepath.c_str());
//send_error_trap(err_msg, 1);
return (put_error(err_msg));
}
puts("\n<load_db_init>");
TiXmlElement* elm_root = doc.FirstChildElement("root");
if (elm_root)
{
TiXmlElement* elm_head = elm_root->FirstChildElement("head");
if (elm_head)
{
TiXmlElement* elm_version = elm_head->FirstChildElement("version");
if (elm_version)
{
if ((buf = elm_version->Attribute("db_name")) == NULL)
return(put_error("DB is imcomplete: db_name"));
strcpy(db_info->game, (char*)buf);
printf("Game: [%s]\n", db_info->game);
if ((buf = elm_version->Attribute("db_verion")) == NULL)
return(put_error("DB is imcomplete: db_verion"));
strcpy(db_info->version, (char*)buf);
printf("version: [%s]\n", db_info->version);
}
else
return(put_error("DB as not members name <version> in <head>"));
}
else
return(put_error("DB as not members name <head> in <root>"));
TiXmlElement* elm_races = elm_root->FirstChildElement("races");
if (elm_races)
{
TiXmlElement* elm_race = elm_races->FirstChildElement("race");
if (elm_race)
{
if ((buf = elm_race->Attribute("name")) == NULL)
return(put_error("DB is imcomplete: race name"));
strcpy(db_info->races[0], (char*)buf);
printf("race[0]: [%s]\n", db_info->races[0]);
}
else
return(put_error("DB as not members name <race> in <races>"));
for (i = 1; elm_race = elm_race->NextSiblingElement("race"); i++)
{
if ((buf = elm_race->Attribute("name")) == NULL)
return(put_error("DB is imcomplete: race name"));
strcpy(db_info->races[i], (char*)buf);
printf("race[%i]: [%s]\n", i, db_info->races[i]);
}
db_info->races[i][0] = 0;
}
else
return(put_error("DB as not members name <races> in <head>"));
TiXmlElement* elm_maps = elm_root->FirstChildElement("maps");
if (elm_maps)
{
TiXmlElement* elm_map = elm_maps->FirstChildElement("map");
if (elm_map)
{
if ((buf = elm_map->Attribute("name")) == NULL)
return(put_error("DB is imcomplete: map name"));
strcpy(db_info->map_def[0].name, (char*)buf);
printf("map[0]: [%s]", db_info->map_def[0].name);
if ((elm_map->QueryIntAttribute((const char*)"max_players", &int_buf))
!= TIXML_SUCCESS)
return(put_error("DB is imcomplete: map max_players"));
db_info->map_def[0].max_players = int_buf;
printf(" max_players: [%i]\n", db_info->map_def[0].max_players);
}
else
return(put_error("DB as not members name <map> in <maps>"));
for (i = 1; elm_map = elm_map->NextSiblingElement("map"); i++)
{
if ((buf = elm_map->Attribute("name")) == NULL)
return(put_error("DB is imcomplete: map name"));
strcpy(db_info->map_def[i].name, (char*)buf);
printf("map[%i]: [%s]", i, db_info->map_def[i].name);
if ((elm_map->QueryIntAttribute((const char*)"max_players", &int_buf))
!= TIXML_SUCCESS)
return(put_error("DB is imcomplete: map max_players"));
db_info->map_def[i].max_players = int_buf;
printf(" max_players: [%i]\n", db_info->map_def[i].max_players);
//.........这里部分代码省略.........
/*! Reads the entire interface from a file, looking for keywords
inside the file. Loads the size of the dof space, all eg's
(which define the size of the eg space), any normalization
factors (optional) and the origin of the eg space (optional).
The size of the dof space must be loaded before any eg's,
origin, etc can be loaded; is must also match the number of
dof's in this robot.
*/
int
EigenGraspInterface::readFromFile(QString filename)
{
//open xml file at "filename"
bool ok;
QString fileType = filename.section('.',-1,-1);
QString xmlFilename;
if (fileType == "xml"){
//the file itself is XML
xmlFilename = filename;
} else {
QTWARNING("Could not open " + xmlFilename);
DBGA("Old non-xml file format is no longer supported");
return 0;
}
//load the graspit specific information in XML format or fail
TiXmlDocument doc(xmlFilename);
if(doc.LoadFile()==false){
DBGA("Failed to open EG file: " << filename.latin1());
QTWARNING("Could not open " + xmlFilename);
return 0;
}
//get the dimensions
int numDims = 0;
QString valueStr;
clear();
TiXmlElement* root = doc.RootElement();
if(root == NULL){
DBGA("The "<<filename.toStdString()<<" file must contain a root tag named EigenGrasps.");
return 0;
} else{
valueStr = root->Attribute("dimensions");
numDims = valueStr.toDouble(&ok); if (!ok) {DBGA("ERROR: Dimension should contain a number.");return 0;}
if (numDims <= 0) {
DBGA("invalid number of dimensions in EigenGrasps tag in file: "<<filename.toStdString());
return 0;
}
}
//get the list of EG's
std::list<const TiXmlElement*> elementList = findAllXmlElements(root, "EG");
int numEG = countXmlElements(root, "EG");
if (numEG < 1) {
DBGA("Number of Eigengrasps specified: " << numEG);
return 0;
}
std::list<const TiXmlElement*>::iterator p = elementList.begin();
while(p!=elementList.end()){
EigenGrasp *newGrasp = new EigenGrasp(numDims);
if (!newGrasp->readFromXml(*p++)) return 0;
newGrasp->normalize();
mGrasps.push_back(newGrasp);
}
//get the orgin and process (if none setsimpleorgin)
elementList = findAllXmlElements(root, "ORIGIN");
int numORG = countXmlElements(root, "ORIGIN");
if (!numORG) {
DBGA("No EG origin found; using automatic origin");
mOrigin = new EigenGrasp(numDims);
setSimpleOrigin();
}
else if(numORG==1)
{
mOrigin = new EigenGrasp(numDims);
if (!mOrigin->readFromXml(*(elementList.begin()))){ return 0;}
checkOrigin();
}
else
{
DBGA("Multiple Origins specified in Eigen Grasp file.");
return 0;
}
//get the norm and process (if none set to all 1's)
elementList = findAllXmlElements(root, "NORM");
int numNORM = countXmlElements(root, "NORM");
if (!numNORM) {
DBGA("No normalization data found; using factors of 1.0");
mNorm = new EigenGrasp(numDims);
mNorm->setOnes();
}
else if(numNORM==1)
{
mNorm = new EigenGrasp(numDims);
if (!mNorm->readFromXml(*(elementList.begin()))){ return 0;}
DBGA("EG Normalization data loaded from file");
}
else
//.........这里部分代码省略.........
请发表评论