예제 #1
0
CollectionScanner::BatchFile::BatchFile( const QString &batchPath )
{
    QFile batchFile( batchPath );

    if( !batchFile.exists() ||
        !batchFile.open( QIODevice::ReadOnly ) )
        return;

    QString path;
    uint mtime = 0;
    bool haveMtime = false;
    QXmlStreamReader reader( &batchFile );

    // very simple parser
    while (!reader.atEnd()) {
        reader.readNext();

        if( reader.isStartElement() )
        {
            QStringRef name = reader.name();

            if( name == QLatin1String("scanner") )
            {
                ; // just recurse into the element
            }
            else if( name == QLatin1String("directory") )
            {
                path.clear();
                mtime = 0;
                haveMtime = false;
            }
            else if( name == QLatin1String("path") )
                path = reader.readElementText(QXmlStreamReader::SkipChildElements);
            else if( name == QLatin1String("mtime") )
            {
                mtime = reader.readElementText(QXmlStreamReader::SkipChildElements).toUInt();
                haveMtime = true;
            }
            else
            {
                reader.skipCurrentElement();
            }
        }
        else if( reader.isEndElement() )
        {
            QStringRef name = reader.name();
            if( name == QLatin1String("directory") )
            {
                if( !path.isEmpty() )
                {
                    if( haveMtime )
                        m_timeDefinitions.append( TimeDefinition( path, mtime ) );
                    else
                        m_directories.append( path );
                }
            }
        }
    }

}
예제 #2
0
// feed adaptation data from a batch file containing entries (rawFile alignmentFile)
void FMLLREstimator::feedAdaptationData(const char *strBatchFile, const char *strAlignmentFormat, 
	double *dLikelihood) {

	BatchFile batchFile(strBatchFile,"features|alignment");
	batchFile.load();
	
	for(unsigned int i=0 ; i < batchFile.size() ; ++i) {
	//for(int i=0 ; i < 5 ; ++i) {
		
		// load the alignment
		Alignment *alignment = NULL;
		if (strcmp(strAlignmentFormat,"text") == 0) {
			AlignmentFile alignmentFile(m_phoneSet);	
			VPhoneAlignment *vPhoneAlignment = alignmentFile.load(batchFile.getField(i,"alignment"));
			assert(vPhoneAlignment);
			alignment = AlignmentFile::toAlignment(m_phoneSet,m_hmmManager,vPhoneAlignment);
			AlignmentFile::destroyPhoneAlignment(vPhoneAlignment);
		} else {
			alignment = Alignment::load(batchFile.getField(i,"alignment"),NULL);
			assert(alignment);	
		}
		
		// load the feature vectors
		FeatureFile featureFile(batchFile.getField(i,"features"),MODE_READ);
		featureFile.load();
		Matrix<float> *mFeatures = featureFile.getFeatureVectors();
		
		// load and apply the transform
		/*
		Transform *transform = new Transform();
		transform->load("/data/daniel/tasks/wsj/experiments/may16th_2013_CMNUtterance/5/fmllr1/transforms/440m.fmllr.bin");
		Matrix<float> *mFeaturesX = transform->apply(*mFeatures);
		mFeatures = mFeaturesX;
		delete transform;
		*/
		
		// check consistency
		if (mFeatures->getRows() != alignment->getFrames()) {
			BVC_ERROR << "inconsistent number of feature vectors / alignment file";
		}
		
		// accumulate adaptation data
		double dLikelihoodAlignment = 0.0;
		feedAdaptationData(*mFeatures,alignment,&dLikelihoodAlignment);
		BVC_VERB << "loaded file: " << batchFile.getField(i,"alignment") << " likelihood: " << FLT(10,2) 
			<< dLikelihoodAlignment << " (" << mFeatures->getRows() << "frames)";	
		*dLikelihood += dLikelihoodAlignment;
		
		// clean-up
		delete alignment;
		delete mFeatures;
	}
	double dLikelihoodFrame = (*dLikelihood)/m_fOccupancyTotal;
	BVC_VERB << "total likelihood: " << FLT(20,6) << *dLikelihood << " (likelihood per frame: " 
		<< FLT(8,4) << dLikelihoodFrame << ")";
}
예제 #3
0
// feed adaptation data from a batch file containing entries (rawFile alignmentFile)
void MLLRManager::feedAdaptationData(const char *strBatchFile, const char *strAlignmentFormat, 
	double *dLikelihood, bool bVerbose) {

	BatchFile batchFile(strBatchFile,"features|alignment");
	batchFile.load();
	
	*dLikelihood = 0.0;
	
	for(unsigned int i=0 ; i < batchFile.size() ; ++i) {	
	
		// load the alignment
		Alignment *alignment = NULL;
		// text format
		if (strcmp(strAlignmentFormat,"text") == 0) {	
			AlignmentFile alignmentFile(m_phoneSet,NULL);
			VPhoneAlignment *vPhoneAlignment = alignmentFile.load(batchFile.getField(i,"alignment"));
			assert(vPhoneAlignment);
			alignment = AlignmentFile::toAlignment(m_phoneSet,m_hmmManager,vPhoneAlignment);
			AlignmentFile::destroyPhoneAlignment(vPhoneAlignment);
		} 
		// binary format
		else {
			alignment = Alignment::load(batchFile.getField(i,"alignment"),NULL);
			assert(alignment);	
		}
		
		// load the feature vectors
		FeatureFile featureFile(batchFile.getField(i,"features"),MODE_READ);
		featureFile.load();
		unsigned int iFeatureVectors = 0;
		float *fFeatures = featureFile.getFeatureVectors(&iFeatureVectors);
		
		// check consistency	
		if (iFeatureVectors != alignment->getFrames()) {
			BVC_ERROR << "inconsistent number of feature vectors / alignment file";
		}
		
		// accumulate adaptation data
		double dLikelihoodAlignment = 0.0;
		feedAdaptationData(fFeatures,iFeatureVectors,alignment,&dLikelihoodAlignment);
		if (bVerbose) {
			printf("loaded file: %s likelihood: %12.2f\n",batchFile.getField(i,"alignment"),dLikelihoodAlignment);
		}
		*dLikelihood += dLikelihoodAlignment;
		
		// clean-up
		delete alignment;
		delete [] fFeatures;
	}
	
	if (bVerbose) {
		printf("total likelihood: %14.4f\n",*dLikelihood);
	}
}
예제 #4
0
bool
CollectionScanner::BatchFile::write( const QString &batchPath )
{
    QFile batchFile( batchPath );
    if( !batchFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
        return false;

    QXmlStreamWriter writer( &batchFile );
    writer.setAutoFormatting( true );

    writer.writeStartDocument();
    writer.writeStartElement( QLatin1String("scanner") );
    writer.writeComment("Batch file for amarokcollectionscanner "AMAROK_VERSION" created on "+QDateTime::currentDateTime().toString());

    foreach( const QString &dir, m_directories )
    {
        writer.writeStartElement( QLatin1String("directory") );
        writer.writeTextElement( QLatin1String("path"), dir );
        writer.writeEndElement();
    }
예제 #5
0
// load the fillers
void FillerManager::load() {

	BatchFile batchFile(m_strFile.c_str(),"lexUnit|insertionPenalty");
	batchFile.load();	
	
	for(unsigned int i=0 ; i < batchFile.size() ; ++i) {
		const char *strLexUnit = batchFile.getField(i,"lexUnit");
		const char *strIP = batchFile.getField(i,"insertionPenalty");
		float fIP = (float)atof(strIP);
	
		// check format
		unsigned int iLength = (unsigned int)strlen(strLexUnit);
		if ((iLength < 3) || (strLexUnit[iLength-1] != '>') || (strLexUnit[0] != '<')) {
			BVC_ERROR << "filler " << strLexUnit << " is not in the right format";
		}	
		// keep the filler
		Filler *filler = new Filler;
		filler->strLexUnit = strLexUnit;
		filler->fInsertionPenalty = fIP;
		m_vFiller.push_back(filler);
   }
}
예제 #6
0
void
CollectionScanner::Scanner::readBatchFile( const QString &path )
{
    QFile batchFile( path );

    if( !batchFile.exists() )
        error( tr( "File \"%1\" not found." ).arg( path ) );

    if( !batchFile.open( QIODevice::ReadOnly ) )
        error( tr( "Could not open file \"%1\"." ).arg( path ) );

    BatchFile batch( path );
    foreach( const QString &str, batch.directories() )
    {
        m_folders.append( str );
    }

    foreach( const CollectionScanner::BatchFile::TimeDefinition &def, batch.timeDefinitions() )
    {
        m_mTimes.insert( def.first, def.second );
    }
}
예제 #7
0
void EditorInterface::makeBatch(QString& batchFileName)
{
	FNTRACE("", "EditorInterface", "batchFileName", batchFileName);

	if (batchFileName.endsWith(".bat", Qt::CaseInsensitive))
		fileName = batchFileName.left(batchFileName.length()-4);
	else
		fileName = batchFileName;

	makeRelativePaths();

	batchFileName = fileName+".bat";
	QString debugFileName = fileName + "_debug.txt";

	QStringList args = makeArgs();

	QFile batchFile(batchFileName);
	if (!batchFile.open(QIODevice::WriteOnly | QIODevice::Text))
		ETHROW(Exception(QString("Failed to open %1 for writing").arg(batchFileName)));
	QTextStream batch(&batchFile);

	batch << "@echo off\n";
	if (QDir::drives().size()>1)
		batch << editorDir.absolutePath().left(2) << "\n";
	batch << "cd \"" << editorDir.absolutePath() << "\"\n" << editorName;
	for (QStringList::iterator arg = args.begin(); arg != args.end(); ++arg)
	{
		batch << ' ';
		if (arg->contains(' '))
			batch << '"'+(*arg)+'"';
		else
			batch << (*arg);
	}
	batch << " > \"" << debugFileName << "\"\n"
			"If ERRORLEVEL 0 goto DONE\n"
			"pause\n"
			":DONE\n";
}
예제 #8
0
파일: qe3.cpp 프로젝트: raynorpat/cake
void RunBSP(const char* name)
{
  // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=503
  // make sure we don't attempt to region compile a map with the camera outside the region
  if (region_active && !Region_cameraValid())
  {
    globalErrorStream() << "The camera must be in the region to start a region compile.\n";
    return;
  }

  SaveMap();

  if(Map_Unnamed(g_map))
  {
    globalOutputStream() << "build cancelled\n";
    return;
  }

  if (g_SnapShots_Enabled && !Map_Unnamed(g_map) && Map_Modified(g_map))
  {
    Map_Snapshot();
  }

  if (region_active)
  {
    const char* mapname = Map_Name(g_map);
    StringOutputStream name(256);
    name << StringRange(mapname, path_get_filename_base_end(mapname)) << ".reg";
    Map_SaveRegion(name.c_str());
  }

  Pointfile_Delete();

  bsp_init();

  if (g_WatchBSP_Enabled)
  {
    ArrayCommandListener listener;
    build_run(name, listener);
    // grab the file name for engine running
    const char* fullname = Map_Name(g_map);
    StringOutputStream bspname(64);
    bspname << StringRange(path_get_filename_start(fullname), path_get_filename_base_end(fullname));
    BuildMonitor_Run( listener.array(), bspname.c_str() );
  }
  else
  {
    char junkpath[PATH_MAX];
    strcpy(junkpath, SettingsPath_get());
    strcat(junkpath, "junk.txt");

    char batpath[PATH_MAX];
#if defined(POSIX)
    strcpy(batpath, SettingsPath_get());
    strcat(batpath, "qe3bsp.sh");
#elif defined(WIN32)
    strcpy(batpath, SettingsPath_get());
    strcat(batpath, "qe3bsp.bat");
#else
#error "unsupported platform"
#endif
    bool written = false;
    {
      TextFileOutputStream batchFile(batpath);
      if(!batchFile.failed())
      {
#if defined (POSIX)
        batchFile << "#!/bin/sh \n\n";
#endif
        BatchCommandListener listener(batchFile, junkpath);
        build_run(name, listener);
        written = true;
      }
    }
    if(written)
    {
#if defined (POSIX)
      chmod (batpath, 0744);
#endif
      globalOutputStream() << "Writing the compile script to '" << batpath << "'\n";
      globalOutputStream() << "The build output will be saved in '" << junkpath << "'\n";
      Q_Exec(batpath, NULL, NULL, true);
    }
  }

  bsp_shutdown();
}